How to get all keys in Redis
In Redis, we use
KEYS to retrieve specific keys we’ve defined in our database. For example, if we’d created a Redis key like this:
set someKeyName someValue
Then we could get that value by using
KEYS like this:
KEYS support glob style patterns - so we can match many keys using text familiar to you if you’ve ever worked with regex. Here are some examples:
someK?y- the question mark represents any one character - so
someKyy, etc, are all valid.
someK*y- the asterisk represents any character including spaces - so
someK[a-d]y- to match
someK[ea]y, - to match
[^10]means any number before 10 not including 10.
[^e]means any letter before e, but not including e.
This glob style pattern support also lets us retrieve all keys at once. Since the asterisk (*) or wild card symbol is supported, to retrieve all keys in redis at once, you only have to run
If you have a lot of keys, this may not be what you want to do - but for certain use cases, it can be quite useful to retrieve all keys in Redis at once.
More Tips and Tricks for Redis
- How to Install Redis
- How to Create and Manipulate a List in Redis
- Getting Started with Redis and Node.JS
- How to get all keys in Redis
- How to create key value pairs with Redis
- How to delete all keys and everything in Redis
- Make your SSR site Lightning Fast with Redis Cache
- A Complete Guide to Redis Hashes