An Interest In:
Web News this Week
- May 1, 2024
- April 30, 2024
- April 29, 2024
- April 28, 2024
- April 27, 2024
- April 26, 2024
- April 25, 2024
October 1, 2022 04:56 pm GMT
Original Link: https://dev.to/smpnjn/how-to-get-all-keys-in-redis-2ge6
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 someKeyName
Interestingly, Redis 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 - sosomeKqy
,someKay
,someKyy
, etc, are all valid.someK*y
- the asterisk represents any character including spaces - sosomeKy
is validsomeK[a-d]y
- to matchsomeKay
,someKby
,someKcy
orsomeKdy
.someK[ea]y
, - to matchsomeKey
orsomeKay
someK[^10]y
- where[^10]
means any number before 10 not including 10.someK[^e]y
- where[^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 KEYS *
:
KEYS *
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.
Original Link: https://dev.to/smpnjn/how-to-get-all-keys-in-redis-2ge6
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To