Retrieving/Listing all key/value pairs in a Redis db

Jagtesh Chadha picture Jagtesh Chadha · Sep 26, 2010 · Viewed 76.1k times · Source

I'm using an ORM called Ohm in Ruby that works on top of Redis and am curious to find out how the data is actually stored. I was wondering if there is way to list all the keys/values in a Redis db.

Any lead will go a long way in helping me out (I'm basically stuck atm). Thanks in advance!

Update:
A note for others trying this out using redis-cli, use this:

$ redis-cli keys
* (press * followed by Ctrl-D)
... (prints a list of keys and exits)
$

Thanks @antirez and @hellvinz!

Answer

antirez picture antirez · Sep 26, 2010

You can explore the Redis dataset using the redis-cli tool included in the Redis distribution.

Just start the tool without arguments, then type commands to explore the dataset.

For instance KEYS will list all the keys matching a glob-style pattern, for instance with: keys * you'll see all the keys available.

Then you can use the TYPE command to check what type is a given key, if it's a list you can retrieve the elements inside using LRANGE mykey 0 -1. If it is a Set you'll use instead SMEMBERS mykey and so forth. Check the Redis documentation for a list of all the available commands and how they work.