vseloved / cl-redis

Redis client for Common Lisp
Other
188 stars 38 forks source link

RECONNECT issue #17

Closed tuscland closed 10 years ago

tuscland commented 10 years ago

Hello,

In the event that the connection to the REDIS server is closed or there is a timeout, an automatic reconnection process exists, which is fine.

However, my REDIS provider requires me to provide my credentials using the AUTH command. Unfortunately, the existing reconnect process does not take that in account.

Here is a typical example:

 72 > (red:get "my key")

Error: Redis error: End of file while reading stream #<FLEXI-STREAMS:FLEXI-IO-STREAM 4170905093>.
  1 (continue) Try to reconnect and repeat action.
  2 (abort) Return to level 0.
  3 Return to top loop level 0.

Type :b for backtrace or :c <option number> to proceed.
Type :bug-form "<subject>" for a bug report template or :? for other options.

MINITEX-UPDATER 73 : 1 > :c 1

Error: Redis error: NIL

ERR operation not permitted
  1 (abort) Return to level 0.
  2 Return to top loop level 0.

I tried something like this:

(handler-bind ((redis:redis-connection-error
                                     (lambda (condition)
                                       (when-let (restart (find-restart :reconnect))
                                         (invoke-restart restart))
                                       (red:auth "xyzw"))))
                       (red:get "my key"))

This does not work because the reconnect-restart takes care of re-executing the form that caused a connection error, therefore the call to red:get happens before the red:auth specified in the handler. I would like to avoid using a error handler around my redis related code.

I would be happy to know about your opinion / suggestions.

Best, Cam

tuscland commented 10 years ago

I have found a solution by extending the class redis-connection. Please have a look here: https://github.com/vseloved/cl-redis/pull/18

tuscland commented 10 years ago

Thanks for the merge!