iterating over Redis hash keys with a wild card search

Viewed 2527

I have redis keys and the values of those keys as hash set(key,value pairs). I am using python to retreive the key values. ex:

top_link:files
    key: file_path/foldername1
    value: filename1

    key: file_path/foldername2
    value: filename2

    key: test_path/foldername3
    value: filename3

I want to find out all hash set keys whose key name starts with "file_path"

I tried

all_keys = redis_connection.hscan_iter("top_link:files")
for key in all_keys:
  if key.startswith("file_path"):
    redis_connection.hget("top_link:files",key)

is there a better way to find all the hash keys that start with "file_path". SCAN seems to do what i am trying to achieve. But all the examples shows scan on top level keys (top_link:files) but not on hash keys. Any suggestions? Thank you.

1 Answers
Related