-1

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
user979189
  • 1,230
  • 2
  • 15
  • 39

2 Answers2

0

HSCAN is used to scan the fields of Redis hash, not keys. In order to scan keys, you need to use SCAN command.

hscan "products:P121" 0 //this works

This scans all fields of the hash located at key 'products:P121'.

scan 0 match products:* //this works

This scans all keys, and only return keys that match the 'products:*' pattern.

hscan "products:*" 0 //this does not work

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.

for_stack
  • 21,012
  • 4
  • 35
  • 48
0

You must give the name of the hashmap you want to search

HSCAN name_of_the_hash cursor MATCH pattern

user898384
  • 204
  • 3
  • 6