Skip to content Skip to sidebar Skip to footer

How To Search A Key Pattern In Redis Hash?

I have a hash table whose keys are of pattern USER_TEL like: bob_123456 : Some address mary_567894 : other address john_123456 : third address Now, I'd like to get addresses of a

Solution 1:

You should use HSCAN command.

For example:

redis> HMSET address_book bob_123456 Address1 mary_567894 Address2 john_123456 Address3
OK
redis> HSCAN address_book 0match *_123456
1) "0"2) 1) "bob_123456"2) "Address1"3) "john_123456"4) "Address3"

Update

Python implementation:

r = Redis(....) #redis urlfor address in r.hscan_iter('address_book', match='*_123456'):
  print(address)

Post a Comment for "How To Search A Key Pattern In Redis Hash?"