Two Round Trips Too Many
Three ways to release a Redis lock held under SET lock:invoice:88 <my_token> NX PX 30000.
# release_a
r.delete("lock:invoice:88")
# release_b
if r.get("lock:invoice:88") == my_token:
r.delete("lock:invoice:88")
# release_c
RELEASE = """
if redis.call("get", KEYS[1]) == ARGV[1] then
return redis.call("del", KEYS[1])
else
return 0
end
"""
r.eval(RELEASE, 1, "lock:invoice:88", my_token)
release_a is clearly unsafe. What is still wrong with release_b?
Sign in to answer questions and track your progress
Sign In