chameleonbr / node-red-contrib-redis

Node RED client for Redis with pub/sub, list, lua scripting and other commands support.
MIT License
46 stars 42 forks source link

redis JSON - error #57

Closed lu4t closed 2 years ago

lu4t commented 2 years ago

first let me start off by saying congrats for this set of nodes.

I have been using them for a while, and all perfect. Last week I tried to use them with redis JSON, and I am affraid they are not working as expected, even though the commands are available. Here is what I get everytime I try a JSON.SET:

ReplyError: ERR wrong number of arguments for 'JSON.SET' command at parseError (/data/node_modules/redis-parser/lib/parser.js:179:12) at parseType (/data/node_modules/redis-parser/lib/parser.js:302:14)

I did some research, and I believe the modules are not parsing the commands correctly. And the why and how I got this idea is:

Here is the format expected by redis server: https://redis.io/commands/json.set/

From there, the command structure expected by the server is: JSON.SET doc $ '{"a":2}'

if I use the cli, and send this command instead (without the "$" symbol), I got the error below (which is the same literal as the one I got from the module):

JSON.SET test '{"str":"example","int":20}' "ERR wrong number of arguments for 'JSON.SET' command"

if I run on the cli the command as per the docs, (with the $ symbol) got no error:

JSON.SET test $ '{"str":"example","int":20}' "OK"

and the object is added to redis.

Thanks for your help!

pauldeng commented 2 years ago

Try this, hope it will be helpful to you:

[{"id":"59e754e4781d2926","type":"redis-command","z":"2c71e369871e1bf1","server":"a0efbb89.5e42d8","command":"JSON.SET","name":"","topic":"","params":"[]","paramsType":"json","payloadType":"json","block":false,"x":420,"y":1380,"wires":[["cdfaa27d9d03d099"]]},{"id":"21d790f62da7f954","type":"inject","z":"2c71e369871e1bf1","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"doc\",\"$\", \"{\\\"a\\\":2}\"]","payloadType":"json","x":210,"y":1380,"wires":[["59e754e4781d2926"]]},{"id":"cdfaa27d9d03d099","type":"debug","z":"2c71e369871e1bf1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":650,"y":1380,"wires":[]},{"id":"a0efbb89.5e42d8","type":"redis-config","name":"local","options":"{}","cluster":false,"optionsType":"json"}]

Cheers mate.

lu4t commented 2 years ago

Thanks @pauldeng , it works :)