I believe the KEYS and SCAN commands will allow you to find keys that match patterns like that. It supports glob-style patterns like this:
h?llo matches hello, hallo and hxllo
h*llo matches hllo and heeeello
h[ae]llo matches hello and hallo, but not hillo
h[^e]llo matches hallo, hbllo, … but not hello
h[a-b]llo matches hallo and hbllo
If you go this route, use SCAN. KEYS blocks the single thread that Redis commands run against for the entire run. SCAN pulls back the data in batches and scales better.
However, you might want to consider storing it as a Hash or JSON instead of a String and using Search. You can define an index with the FT.CREATE command and then use the FT.SEARCH command to find what you are looking for.
redis.cloud:6379> HSET customer:1 customer "Willy Wonka" project "Chocolate Consumption" task "Eat More Chocloate" location "United Kingdon"
redis.cloud:6379> FT.CREATE customer:index PREFIX 1 customer: SCHEMA customer TAG project TAG task TAG location TAG
redis.cloud:6379> FT.SEARCH customer:index "@project:{Choco*} @task:{Eat More Chocolate}"
2
Answers
I believe the KEYS and SCAN commands will allow you to find keys that match patterns like that. It supports glob-style patterns like this:
If you go this route, use SCAN. KEYS blocks the single thread that Redis commands run against for the entire run. SCAN pulls back the data in batches and scales better.
You’ll want to call SCAN multiple times with the returned number until you get a 0 back. Not all calls will return values:
However, you might want to consider storing it as a Hash or JSON instead of a String and using Search. You can define an index with the FT.CREATE command and then use the FT.SEARCH command to find what you are looking for.
Hope that helps.
You should definitely not use REDIS this way as performances will be terrible.
But, you are looking for
KEYS
command :Not sure if the pipe has to be escaped or not. I believe it doesn’t.
You probably rather take a look at that then : https://redis.io/docs/interact/search-and-query/indexing/ and index your objects properly for way better performances.