Redis-cli --csv option (exporting to csv)

2019-03-11 01:25发布

I would like to export a subset of my Redis data on the slave to a csv file. I notice a new csv output option was added to redis-cli but I am unable to find documentation of how it works. Enabling the option prints the command outputs to screen in csv format. What is the best way to get this into a csv file?

标签: redis
3条回答
等我变得足够好
2楼-- · 2019-03-11 01:43

Go to src redis directory and run the below command

./redis-cli $command > $file_name

Exemple: ./redis-cli SMEMBERS "$KEY" > $file_name(RANDOM NAME)

this worked for me.

查看更多
放我归山
3楼-- · 2019-03-11 01:47

In case of socket and/or multiple redis servers, you'd need to do:

redis-cli -s /path/to/socket --csv your-command > stdout.csv 2> stderr.txt

E.g.

redis-cli -s /var/run/redis/redis4.sock --csv lrange my_list 0 -1 > stdout.csv 2> stderr.txt
查看更多
时光不老,我们不散
4楼-- · 2019-03-11 01:56

Cutting edge!

I've just looked at the source code & all it does is output the commands as comma separated values to stdout. Which is no big surprise.

So you could just redirect it to a file, in the standard way, as long as you're on Linux?

e.g./

redis-cli --csv your-command > stdout.csv 2> stderr.txt
查看更多
登录 后发表回答