-
Notifications
You must be signed in to change notification settings - Fork 0
Use atomic set #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
7feffcc
5f4dd87
0bf946b
179c8ba
2f9c085
5e1f1a5
5a654e5
d84a8ac
62c5f19
85a8846
353e371
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,35 +95,32 @@ local function remove_namespace(namespace, keys) | |
end | ||
end | ||
|
||
-- TODO: use EX/NX flag if we can determine redis version (>=2.6.12) | ||
function _M:add(k, v, ttl) | ||
k = self.namespace .. k | ||
local ok, err = op(self, 'setnx', k, v) | ||
local ok, err | ||
if ttl then | ||
ok, err = op(self, 'set', k, v, "nx", "px", math.floor(ttl * 1000)) | ||
else | ||
ok, err = op(self, 'set', k, v, "nx") | ||
end | ||
if err then | ||
return err | ||
elseif ok == 0 then | ||
elseif ok == ngx.null then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happened here? I can't find There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return "exists" | ||
end | ||
if ttl then | ||
local _, err = op(self, 'pexpire', k, math.floor(ttl * 1000)) | ||
if err then | ||
return err | ||
end | ||
end | ||
end | ||
|
||
function _M:set(k, v, ttl) | ||
k = self.namespace .. k | ||
local _, err = op(self, 'set', k, v) | ||
local err, _ | ||
if ttl then | ||
_, err = op(self, 'set', k, v, "px", math.floor(ttl * 1000)) | ||
else | ||
_, err = op(self, 'set', k, v) | ||
end | ||
if err then | ||
return err | ||
end | ||
if ttl then | ||
local _, err = op(self, 'pexpire', k, math.floor(ttl * 1000)) | ||
if err then | ||
return err | ||
end | ||
end | ||
end | ||
|
||
function _M:delete(k) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder who uses such antique versions anyway (current is 7.0, 2.6 is not listed in release notes but seems to be from 2015).
Or are there two different versioning schemes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, https://gist.github.com/lqez/3944436 11 years ago. Maybe it's just 🦖 old.