Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving Redis query output to file

Using redis-cli I connected to specific server:

redis-cli -h 10.1.xx.xx

And select 1

Then just to get list of one key features:

KEYS data_column*

THis will print list of that column values on command line. However, there are like quite many values, I want to save query output to file.

In general, using > file_name after the command works. But in this case, it does not work, as its on redis server, though from command line. How to save such query result?

like image 415
xavi Avatar asked Nov 02 '15 15:11

xavi


People also ask

Can Redis write to disk?

Within Redis, there are two different ways of persisting data to disk. One is a method called snapshotting that takes the data as it exists at one moment in time and writes it to disk. The other method is called AOF, or append—only file, and it works by copying incoming write commands to disk as they happen.

What is save in Redis?

The SAVE commands performs a synchronous save of the dataset producing a point in time snapshot of all the data inside the Redis instance, in the form of an RDB file. You almost never want to call SAVE in production environments where it will block all the other clients. Instead usually BGSAVE is used.

Where is Redis dump RDB?

rdb file in the /var/lib/redis/ directory. You'll want to update the permissions so the file is owned by the redis user and group: sudo chown redis:redis /var/lib/redis/dump.


2 Answers

Simply use:

./redis-cli -h 10.1.xx.xx -n 1 keys 'data_column*' >file.txt
like image 61
Didier Spezia Avatar answered Oct 19 '22 00:10

Didier Spezia


echo "keys data_column*" | redis-cli -h 10.1.xx.xx -p xx > file.txt
like image 6
hjiam2 Avatar answered Oct 19 '22 00:10

hjiam2