Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing batches of commands using redis cli

Tags:

redis

I have a long text file of redis commands that I need to execute using the redis command line interface:

e.g.

DEL 9012012 DEL 1212 DEL 12214314 

etc.

I can't seem to figure out a way to enter the commands faster than one at a time. There are several hundred thousands lines, so I don't want to just pile them all into one DEL command, they also don't need to all run at once.

like image 697
LTME Avatar asked May 30 '12 19:05

LTME


People also ask

How do I run Redis commands?

To start Redis client, open the terminal and type the command redis-cli. This will connect to your local server and now you can run any command. In the above example, we connect to Redis server running on the local machine and execute a command PING, that checks whether the server is running or not.

What does Redis-CLI command do?

The Redis command line interface ( redis-cli ) is a terminal program used to send commands to and read replies from the Redis server.

What are the benefits of pipelining multiple commands from a client to a Redis server?

A Request/Response server can be implemented so that it is able to process new requests even if the client hasn't already read the old responses. This way it is possible to send multiple commands to the server without waiting for the replies at all, and finally read the replies in a single step.


2 Answers

the following code works for me with redis 2.4.7 on mac

./redis-cli < temp.redisCmds 

Does that satisfy your requirements? Or are you looking to see if there's a way to programmatically do it faster?

like image 152
ControlAltDel Avatar answered Nov 10 '22 19:11

ControlAltDel


If you don't want to make a file, use echo and \n

echo "DEL 9012012\nDEL 1212" | redis-cli 
like image 40
Sanghyun Lee Avatar answered Nov 10 '22 21:11

Sanghyun Lee