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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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
回答2:
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:
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