Search code examples
python-2.7redisredis-py

redis: matching partial keys of hash


In a hash, I have a bunch of keys-values pairs

my keys are in the following format: name:city

john:newyork
kate:chicago
lisa:atlanta

Im using python to access redis and in https://redis-py.readthedocs.org/en/latest/, i dont see any hash operations that does the partial matching

i would like to be able to get all keys in the hash with a city name

is that possible?


Solution

  • I was able to achieve matching hash keys partially by:

    pool = redis.ConnectionPool(host='localhost', port=6379, db=0)
    r = redis.StrictRedis(connection_pool=pool)
    cmd = "hscan <hashname> 0 match *:atlanta"
    print r.execute_command(cmd)