Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to execute redis command in shell

Tags:

shell

redis

all: I want to operate redis in my shell,my locate redis ip:127.0.0.1 port:6379,i want to insert data to the redis in my shell,but i don't know how to operate redis in my own shell,is there any redis command like mysql -e to execute in the shell directly.

like image 602
Yan Lincle Avatar asked Jul 08 '15 08:07

Yan Lincle


People also ask

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.

How do you check if Redis-cli is installed?

How to Check Redis installed version. Open terminal, Type redis-server --version or redis-server -v in the command line. You can also check with the redis-cli command.


2 Answers

Please note that Konstantin’s answer is better.

Just use echo with redis-cli like this:

# Delete list of cores
echo DEL cores | redis-cli

# Add a new core to the list of cores
echo LPUSH cores 1 | redis-cli 

# Wait forever for a core to become available
echo BLPOP cores 0 | redis-cli
like image 149
Mark Setchell Avatar answered Oct 08 '22 11:10

Mark Setchell


It's is simpler to call commands directly, without pipelines:

> redis-cli -n 0 LPUSH mylist "hello"
(integer) 1

Be shure that you pass -n option, it's like mysql use <database> statement, it's set used database (first index is zero). When you run command from cli redis don't uses default database. To get information about databases which has some keys use command:

> INFO keyspace
db0:keys=4,expires=0,avg_ttl=0

More options here: https://redis.io/topics/rediscli

like image 42
Konstantin Yaniv Avatar answered Oct 08 '22 10:10

Konstantin Yaniv