Skip to content
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

Use atomic set and redis pool size #124

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
- master
- release/*
- test-please/*
- use-atomic-set
pull_request:
paths-ignore:
# ignore top-level markdown files (CHANGELOG.md, README.md, etc.)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ storage_config = {
}
```

Redis >= 2.6.0 is required as this storage requires [PEXPIRE](https://redis.io/commands/pexpire).
Redis >= 2.6.12 is required as this storage requires [SET EX](https://redis.io/commands/set).

### vault

Expand Down
30 changes: 14 additions & 16 deletions lib/resty/acme/storage/redis.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function _M.new(conf)
scan_count = conf.scan_count or 10,
username = conf.username,
password = conf.password,
pool_size = conf.pool_size or 1,
},
mt
)
Expand Down Expand Up @@ -95,35 +96,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
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)
Expand Down