lujiajing1126 / redis-cli

A Redis-Cli Tool written in typescript for terminal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there any way to execute rdcli with multiple command parameters?

joshuakeel opened this issue · comments

Hi there,

I'm trying to run multiple commands programmatically, but I'm having a hard time figuring out how to do this (if there is even a way). Basically I need to login to the Redis instance, then run multiple commands, but I need to do this programmatically. I'm trying to run this as a job from my CI/CD server, so I won't be there to type the commands into the REPL. :)

Here's an example of what I'd like to see:

npx rdcli -h host -a password --tls ping ping

This would run the Redis ping command twice.

Alternatively, I could read in the commands from a file:

npx rdcli -h host -a password --tls < commands.txt

Neither of these approaches work. Is there a way to accomplish what I want to do?

I prefer to support lua script.

Does Lua script meets your requirements?

@lujiajing1126 I would imagine it would, but I'd have to know more to be sure. I want to ensure that Node.js and NPM packages are the only dependencies. In other words, I wouldn't want to have to also install a Lua interpreter. If Lua is just embedded in redis-cli, however, that should be fine, as long as I can use Lua to script out running multiple commands sequentially.

So I think the answer is yes, it does meet my requirements, as long as those things are true. Thanks for the speedy response! How long do you think it might take to implement Lua scripting? I'm wondering if I should look for an alternative interim solution.

@lujiajing1126 I would imagine it would, but I'd have to know more to be sure. I want to ensure that Node.js and NPM packages are the only dependencies. In other words, I wouldn't want to have to also install a Lua interpreter. If Lua is just embedded in redis-cli, however, that should be fine, as long as I can use Lua to script out running multiple commands sequentially.

So I think the answer is yes, it does meet my requirements, as long as those things are true. Thanks for the speedy response! How long do you think it might take to implement Lua scripting? I'm wondering if I should look for an alternative interim solution.

As I understand, lua scripting does not rely on the client.

A possible workaround is

$ npx redis-cli eval "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}" 2 key1 key2 first second
1) key1
2) key2
3) first
4) second

while the quoted string is the content of your lua script. With the help of cat, you can use the following command,

$ npx redis-cli eval "$(cat script.lua)" 2 key1 key2 first second
1) key1
2) key2
3) first
4) second

where you may put the script into a file.

@lujiajing1126 Thanks a bunch for pointing me in the right direction. I was able to get it working. Example:

npx rdcli -h host -a password --tls "eval \"return redis.call('ping');\" 0"

I had to add double quotes around the command I'm passing in to rdcli, and also escape the double quotes surrounding my Lua script.

Works like a charm! Hopefully this helps someone else doing some automation work. 😀 💯