Reputation: 533
I have a redis resource in IBM Cloud(IBM Cloud Databases for Redis). I want to execute the redis commands such as 'config set notify-keyspace-events $KExe' in a remote session.
I use the below command to connect to connect to the redis instance through redli.
ibmcloud login --apikey <api key> -a https://cloud.ibm.com -g <resource group name> -r <region>
ibmcloud cdb deployment-connections <ibm redis instance name> -s --user admin --password <password>
I am able to connect with the redis instance, and it give the output as 'Connected to 4.0.10'. I can, then, execute the redis commands and type 'exit' to exit out of the redis session. How can I automate this part of execution of redis commands, get those executed remotely, and then exit out of the redis session?
Upvotes: 1
Views: 1268
Reputation: 2464
I'm not too familiar with redis, but I believe the following will work (at least it appeared to work for me)
ibmcloud cdb deployment-connections redisdeleteme -s --user admin --password PASSWORD << 'EOF'
config set notify-keyspace-events $KExe
config get notify-keyspace-events
EOF
When executed it looked like this:
~ $ ibmcloud cdb deployment-connections redisdeleteme -s --user admin --password PASSWORD << 'EOF'
> config set notify-keyspace-events $KExe
> config get notify-keyspace-events
> EOF
Connected to 4.0.10
OK
1) "notify-keyspace-events"
2) "$xeKE"
Upvotes: 1
Reputation: 45325
You can execute Redis commands from Bash command line:
./redis-cli -h XXX.XXX.XXX.XXX -p YYYY HMSET 'users' 'joe' '12345' 'maria' 'qwerty' 'sim' '1970-01-01'
It is what are you searching for?
And you can create a file with your commands and execute them as:
./redis-cli -h XXX.XXX.XXX.XXX -p YYYY < commandsfile.txt
Upvotes: 1