rails / kredis

Higher-level data structures built on Redis
MIT License
1.38k stars 78 forks source link

Should Kredis::Types::Proxy#multi be fault tolerant? #153

Open BigBlue79 opened 3 months ago

BigBlue79 commented 3 months ago

We're working on storing some ephemeral, nice-to -have data in a Kredis.ordered_set. During a recent game day where we intentionally took down our redis instance, I was a little surprised to see that some of the Kredis operations were fault-tolerant, but some weren't.

It looks like the current implementation uses method_missing to delegate methods from OrderedSet (and others) to the underlying redis proxy, but redis.multi is not wrapped in the failsafe. As a result, in the event of a redis connection failure, commands that are straightforwardly delegated to the underlying redis do not raise errors, but the same commands that wrapped in redis.multi do raise an error.

Now there are varying degrees of fault-tolerance, depending on the method you choose

os = Kredis.ordered_set("testing")

os.elements
# => [] 

os.remove("something")
# => nil 

os.append("something")
# => Connection refused - connect(2) for 127.0.0.1:6379 (redis://localhost:6379) (Redis::CannotConnectError)

os.prepend("something")
# => Connection refused - connect(2) for 127.0.0.1:6379 (redis://localhost:6379) (Redis::CannotConnectError)

Is this the intended behaviour, or should Kredis operations be fault-tolerant by default?

maxim commented 1 month ago

Just to add, there was this comment explaining the intent to rethink how failsafe works. I'm watching the project to see if anything gets decided on that front.