Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all keys with their values in redis

Tags:

redis

I know that in order to get all the list of all keys in Redis, I have to use KEYS *, but is there a way to output all keys together with their values?

Few minutes of searching did not yield any result.

P.S. thank you very much for answers, but I am looking for a native solution. I can write a function that iterates through all the output of KEYS * by myself.

like image 631
Salvador Dali Avatar asked Oct 14 '13 06:10

Salvador Dali


People also ask

How do you get all keys value to Redis?

There is no native way of doing this. The Redis command documentation contains no native commands for getting the key and value of multiple keys. The most native way of doing this would be to load a lua script into your redis using the SCRIPT LOAD command or the EVAL command.

How do I view Redis data?

A Redis server has 16 databases by default. You can check the actual number by running redis-cli config get databases. In interactive mode, the database number is displayed in the prompt within square braces. For example, 127.0. 0.1:6379[13] shows that the 13th database is in use.


1 Answers

There is no native way of doing this.

The Redis command documentation contains no native commands for getting the key and value of multiple keys.

The most native way of doing this would be to load a lua script into your redis using the SCRIPT LOAD command or the EVAL command.

Bash Haxx solution

A workaround would be to use some bash magic, like this:

echo 'keys YOURKEY*' | redis-cli | sed 's/^/get /' | redis-cli  

This will output the data from all the keys which begin with YOURKEY

Note that the keys command is a blocking operation and should be used with care.

like image 107
firelynx Avatar answered Sep 22 '22 01:09

firelynx