Henley Wing Chiu
Henley Wing Chiu

Reputation: 22515

How to set redis connection timeout?

Where in the configuration file do I set the connection timeout for Redis?

I know there is a timeout setting in the config file, but that only applies for idle connections. I want the timeout to apply when I want to read from redis. I want it to time out only after N seconds, rather than the default.

Upvotes: 18

Views: 80447

Answers (3)

Aditya Rewari
Aditya Rewari

Reputation: 2687

  • You basically need a read-timeout

  • This will be a client side property

  • Mention this in your application.


I'll examplify for Laravel framework of PHP

specify it at database.php file ('read_timeout' => 60)

    'redis' => [

    'client' => 'predis',

        'cluster' => false,

        'default' => [
            'host' => env('REDIS_HOST', 'localhost'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => 0,
            'read_timeout' => 60,
        ],

    ],

];

Upvotes: 0

Otavio Voiski
Otavio Voiski

Reputation: 29

On console of redis set this configuration

config set timeout 300

Upvotes: 2

Illuminati
Illuminati

Reputation: 4619

For anyone who is still looking for this, on a redis connnection string you can specify connectTimeout like below.

<add key="RedisConnectionString" value="your-redis-server,abortConnect=false,connectTimeout=1000,ssl=false,,password=your-password" />

Upvotes: 21

Related Questions