fancy fancy - 1 month ago 6
Javascript Question

Is there anyway to retrieve all keys that start with a particular string in redis?

Is there anyway to retrieve all keys that start with a particular string in redis?

I want to do something like storing:

'thing1:userid1' : ' ';
'thing1:userid2' : ' ';
'thing2:userid1' : ' ';
'thing2:userid2' : ' ';


and retrieve every
thing1
without having to know every user.

Answer
REDIS.keys("thing1:*")

However, you might want to consider using a map.

REDIS.hset("thing1", "user1", "")
REDIS.hset("thing1", "user2", "")
REDIDS.hgetall("thing1")

Do be careful with this in production. Redis can only process one command at a time, and KEYS is very slow. It has to look at every key in the entire database.

Comments