-
Notifications
You must be signed in to change notification settings - Fork 452
feat: add a surface to support Redis module #211
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
Conversation
lib/resty/redis.lua
Outdated
| local function do_cmd(self, cmd, ...) | ||
| local module_prefix = rawget(self, "_module_prefix") | ||
| if module_prefix then | ||
| self._module_prefix = nil |
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.
bad indent.
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.
@doujiang24
Fixed.
lib/resty/redis.lua
Outdated
|
|
||
| function _M.register_module_prefix(mod) | ||
| _M[mod] = function(self) | ||
| self._module_prefix = mod .. "." |
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.
| self._module_prefix = mod .. "." | |
| self._module_prefix = mod |
move the .. "." to line 414: https://github.com/openresty/lua-resty-redis/pull/211/files#diff-adb515948c05651051c83fd6fb3ce7ceR414
to avoid creating a new string for better performance.
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.
@doujiang24
There will be more new strings, as each time the cmd argument need to be a concatenated string in line 414.
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.
@spacewander I don't think so.
it will generate a new string when calling the module function, like redis:bp().
and generate another string when calling the method, like :add().
that means will generate two string in redis:bp:add().
while module_prefix .. "." .. cmd will generate one string.
doujiang24
left a comment
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 think this way may have better performance, thoughts?
local dot_cmds = {
"bf.add", "bf.exists",
}
for i = 1, #dot_cmds do
local cmd = dot_cmds[i]
local name = string.gsub(cmd, ".", "_")
_M[name] =
function (self, ...)
return _do_cmd(self, cmd, ...)
end
end
lib/resty/redis.lua
Outdated
|
|
||
| function _M.register_module_prefix(mod) | ||
| _M[mod] = function(self) | ||
| self._module_prefix = mod .. "." |
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.
@spacewander I don't think so.
it will generate a new string when calling the module function, like redis:bp().
and generate another string when calling the method, like :add().
that means will generate two string in redis:bp:add().
while module_prefix .. "." .. cmd will generate one string.
OK, maybe we can just a much simpler solution like https://github.com/openresty/lua-resty-redis/pull/167/files |
it has two issues:
|
doujiang24
left a comment
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 like the new module function call style: redis:bf():add().
No description provided.