Yan Lincle
Yan Lincle

Reputation: 291

how to execute redis command in shell

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.

Upvotes: 23

Views: 39779

Answers (2)

Mark Setchell
Mark Setchell

Reputation: 208077

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

Upvotes: 43

Konstantin Yaniv
Konstantin Yaniv

Reputation: 455

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

Upvotes: 20

Related Questions