0
我有redis鍵和這些鍵的值作爲哈希集(鍵,值對)。我正在使用python來檢索關鍵值。 例如:使用通配符搜索迭代Redis哈希鍵
top_link:files
key: file_path/foldername1
value: filename1
key: file_path/foldername2
value: filename2
key: test_path/foldername3
value: filename3
我想找出所有的hash組鍵,其鍵名稱以「FILE_PATH」
我試圖
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)
開始有沒有更好的方式來發現所有的哈希以「file_path」開頭的密鑰。 SCAN似乎正在做我正在努力實現的目標。但是所有的例子都顯示了頂層關鍵字(top_link:files)的掃描,而不是關於散列鍵的掃描。有什麼建議麼? 謝謝。
當我如下使用HSCAN,它給了我整個哈希集合的元組。 但你能告訴我如何獲取匹配的密鑰?redis_connection.hscan(「top_link:files」,match =「file_path *」) – user2406718
謝謝。有效。 – user2406718