lua-resty-lock icon indicating copy to clipboard operation
lua-resty-lock copied to clipboard

Being able to set an expiration time per key, and not just per dict

Open subnetmarco opened this issue 8 years ago • 2 comments

Currently it's only possible to set an expiration time to the entire dictionary when creating a new instance:

local obj = resty_lock:new("locks_dict", {exptime = 10})

It would be nice to allow setting an expiration time per key too, like:

local obj = resty_lock:new("reports_locks")
obj:lock("test", {exptime = 10})

So that one dictionary can be used to set multiple keys with a different expiration time:

local obj = resty_lock:new("reports_locks")
obj:lock("test", {exptime = 10})
obj:lock("test2", {exptime = 4})
obj:lock("test3", {exptime = 50})

subnetmarco avatar Jan 19 '16 01:01 subnetmarco

@thefosk I'd go for the simpler and more efficient form below:

obj:lock(key, timeout)

where the timeout argument is optional (default to the value set in the constructor option).

agentzh avatar Jan 19 '16 18:01 agentzh

@thefosk And patches welcome :)

agentzh avatar Jan 19 '16 18:01 agentzh