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 all uses who have the same TEL in their keys.
What I came up with is:
tel = 123456
r.hmget('address_book', '*_%s' % tel)
I get [None]
instead of the values.
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 0 match *_123456
1) "0"
2) 1) "bob_123456"
2) "Address1"
3) "john_123456"
4) "Address3"
Python implementation:
r = Redis(....) #redis url
for address in r.hscan_iter('address_book', match='*_123456'):
print(address)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With