openresty / openresty/lua-resty-redis
Use lazy generation instead of hardcode commands?
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 2k
- Forks
- 447
- Avg merge
- 2h 24m
- Merged PRs (30d)
- 3
Description
In https://github.com/openresty/lua-resty-redis/blob/master/lib/resty/redis.lua#L27 there is a list of redis commands contains more than one hundred entries...
Well, why not use lazy generation instead? For example,
M.__index = function (self, name)
if _M[name] == nil then
_M[name] = function (self, ...)
do_cmd(self, name, ...)
end
end
return _M[name]
end
It is quite shorter.
IMHO, there are pros and cons to replace hardcore command list to lazy generation:
Cons:
- Bad for auto completion
- Require additional comparison
Pros:
- Easier to maintain. No need to keep update with redis's command list. Use hardcore command list has a problem. We may not update
lua-resty-redisas soon as the new version of redis is released. If the latest version of redis adds command X, people may useadd_commandsto work around. However, once we updatelua-resty-redisand add command X, they will generate method X twice. - No need to generate one hundred methods each time we require the package.(In most time, I only use 3~6 redis commands in a lua file, which is just 5% of whole commands!)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with lib/resty/redis.lua around line 27 and inspect how the hardcoded command list and add_commands are used. Compare the proposed lazy-generation behavior with existing command access and command-extension behavior; done means the tradeoffs are resolved and the project has an agreed implementation and validation approach.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua, redis
- Domain
- databases
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100