I have a very small data saved in Redis and the following is working as expected that will allow me to download all keys.
redis-cli keys *
Is there any way to get the keys+values *
?
Redis GET all Keys To list the keys in the Redis data store, use the KEYS command followed by a specific pattern. Redis will search the keys for all the keys matching the specified pattern. In our example, we can use an asterisk (*) to match all the keys in the data store to get all the keys.
To get the value stored in a key, you can use the GET command followed by the name of the key. The above command tells Redis to fetch the value stored in the specified key. We can use the GET command followed by the unique value as: GET username:3.
To start Redis client, open the terminal and type the command redis-cli. This will connect to your local server and now you can run any command.
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.
There's no command for that, but you can write a script to do so.
You will need to perform for each key a "type" command:
> type <key>
and depending on the response perform:
get <key>
hgetall <key>
lrange <key> 0 -1
smembers <key>
zrange <key> 0 -1 withscores
Keep in mind that for hashes and sorted sets you will be getting the keys/scores and values.
A possible sh
implementation:
#!/bin/sh -eu keys=`redis-cli keys '*'` if [ "$keys" ]; then echo "$keys" | while IFS= read -r key; do type=`echo | redis-cli type "$key"` case "$type" in string) value=`echo | redis-cli get "$key"`;; hash) value=`echo | redis-cli hgetall "$key"`;; set) value=`echo | redis-cli smembers "$key"`;; list) value=`echo | redis-cli lrange "$key" 0 -1`;; zset) value=`echo | redis-cli zrange "$key" 0 -1 withscores`;; esac echo "> $key ($type):" echo "$value" | sed -E 's/^/ /' done fi
But do note:
Warning: consider
KEYS
as a command that should only be used in production environments with extreme care. It may ruin performance when it is executed against large databases. This command is intended for debugging and special operations, such as changing your keyspace layout.
https://redis.io/commands/keys
Short answer:
for i in $(redis-cli KEYS '*'); do echo $i; redis-cli GET $i; done
Long answer:
To get all keys:
redis-cli KEYS '*'
to get the value for a key:
redis-cli GET <your-key>
and if you want all values:
for i in $(redis-cli KEYS '*'); do redis-cli GET $i; done
and finally all keys and values:
for i in $(redis-cli KEYS '*'); do echo $i; redis-cli GET $i; done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With