redis-lua icon indicating copy to clipboard operation
redis-lua copied to clipboard

Lack of auto-reconnect

Open buendia opened this issue 14 years ago • 3 comments

Lack of auto-reconnect causes major unreliability in production.

Why is that there is no re-connect like redis-rb?

One trivial solution is every time the client is called, to check for a live connection:

redis_client = Redis.connect('127.0.0.1', 6379)
function redis()
  local ok, err = pcall(redis_client:ping())
  if not ok then redis_client = Redis.connect('127.0.0.1', 6379); end

  return redis_client;
end

There are two problems with this approach:

  • Keep calling pcall(redis_client:ping()) is not efficient.
  • This does not work for the pubsub subscriber case.

buendia avatar Jul 12 '11 14:07 buendia

There are two reasons why automatic reconnection is not implemented in redis-lua:

  1. it's not something trivial to implement in a generic way. Aside from the need to keep track of the current database after using SELECT, you cannot simply reconnect while using MULTI / EXEC, SUBSCRIBE or when pipelining commands.
  2. the current design of redis-lua poses some issues in that regard, but it's something that will get addressed with the next major version.

Currently redis-lua 2.0.2 allows developers to define a custom error handler for the Redis module (see Redis.error), you might want to look into that and eventually implement your own automatic reconnection strategy that fits your use case. Admittedly Redis.error is not that good for this specific case but you can catch every error being raised inside the library and act accordingly. It's better than forcing a sub-par or half-baked feature on users for now.

nrk avatar Jul 17 '11 08:07 nrk

I think that, at least, redis:ping() should return false without error.

Now there is no easy way to check the connection.

linuxmaniac avatar Mar 28 '14 10:03 linuxmaniac