Skip to content

Conversation

@burre
Copy link

@burre burre commented Apr 18, 2019

Hi there!

I ran into a problem when I tried to work with the RedisJSON module, because its commands consist of a prefix and the command itself, separated by a dot. Having looked at other similar modules, I found that they also use a similar approach.

But the resty/redis client implementation, based on the __index "magic" method, cannot handle such commands. Calling the method (function) through [] also did not bring results. So I did a little trick.

I propose to use the "underscore" (_) instead of the "dot" (.) when calling the method, and swap them back in the client code. For example:

local client = redis:new()

local ok, err = client:connect(host, port)
-- error checking goes here

client:json_set("key", "root", '{"key" : "value"}')

Perhaps this is too simple solution, but it works for me and, I hope, for someone else.

@spacewander
Copy link
Member

Maybe you could introduce the namespace concept? Like this:

redis.register_module_prefix('json')
local client = redis:new()

local ok, err = client:connect(host, port)
-- error checking goes here

--  works like `redis.set`, but use a separate `redis.json` table and a `json.` prefix.
client.json.set("key", "root", '{"key" : "value"}')

@burre
Copy link
Author

burre commented Apr 19, 2019

@spacewander Thanks a lot. It is a more complicated solution but more elegant as well.
I'ii try implement it.

@zhuizhuhaomeng
Copy link
Contributor

#211
please use this feature in this PR.
@burre

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants