openresty / openresty/lua-resty-redis

Use lazy generation instead of hardcode commands?

Open
#84 1 comment 1 reaction 0 assignees View on GitHub

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-redis as soon as the new version of redis is released. If the latest version of redis adds command X, people may use add_commands to work around. However, once we update lua-resty-redis and 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.