Closed mistoo closed 4 years ago
Hi @mistoo, thanks for the issue report. I am quite busy at the moment, as I am traveling. I may have time only in 1 or 2 weeks to look at this and publish a fix.
Any chance to commit this fix?
Having the set
-command work correctly seems pretty important for a redis client. ;)
(that's not to diminish your work, thanks a lot for this shard that otherwise works perfectly for me! 🙇)
The problem is that there doesn't seem to be a workaround (short of monkey-patching) for users who need these parameters.
Fwiw, here's the monkey-patch for anyone else who needs this:
# Include this anywhere in your code to make
# the NX and XX parameters work.
class Redis
module Commands
def set(key, value, ex = nil, px = nil, nx = nil, xx = nil)
q = ["SET", key.to_s, value.to_s]
q << "EX" << ex.to_s if ex
q << "PX" << px.to_s if px
q << "NX" if nx
q << "XX" if xx
string_or_nil_command(q)
end
end
end
I forgot about this issue completely. A fix is in master now.
Awesome, thanks!
redis.set("foo", "bar", nx: true)
raises exception:Quick fix (not sure if it's correct):