I have Hash keys like this in my cache –
products:P101
products:P211
products:P327
...
Now i want to HSCAN on these cache items using widlcard but it is not working
hscan "products:P121" 0 //this works
scan 0 match products:* //this works
hscan "products:*" 0 //this does not work
I also want to check in my c# .net core application whether any items exists using wild card scan
I used below code but it does not return any data –
var db = s_redis.GetDatabase();
var cachedItem = db.HashScan("products:*");
var count = cachedItem.ToList().Count; //this is always 0
Can someone please help me to make below 2 things work
c# - var cachedItem = db.HashScan("products:*"); //this is always 0
cmd - hscan "products:*" 0 //this does not work
2
Answers
HSCAN is used to scan the fields of Redis hash, not keys. In order to scan keys, you need to use SCAN command.
This scans all fields of the hash located at key ‘products:P121’.
This scans all keys, and only return keys that match the ‘products:*’ pattern.
This scans all fields of the hash locate at key products:*. In your case, there’s no hash named *products:**, and that’s why it does not work.
You must give the name of the hashmap you want to search
HSCAN name_of_the_hash cursor MATCH pattern