从redis检索多个hash,并使用python将keyvalues与另一个dict或hash进行比较

2024-04-27 05:13:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我的数据以多个散列形式存储在redis中。我需要将这些散列匹配到具有相同键的字典,如果这些键的值相同,则需要检索所有这些散列。我是Redis的新手,找不到解决办法

red_db.hset("trip1", "Customer_associated", "Garima")
red_db.hset("trip1", "trip_date", "06/09/2019")
red_db.hset("trip1", "trip_source", "Hyderabad")
red_db.hset("trip1", "trip_destination", "Banglore")
red_db.hset("trip2", "Customer_associated", "Sravya")
red_db.hset("trip2", "trip_date", "06/09/2019")
red_db.hset("trip2", "trip_source", "Hyderabad")
red_db.hset("trip2", "trip_destination", "Vijaywada")
red_db.hset("trip3", "Customer_associated", "Kartik")
red_db.hset("trip3", "trip_date", "06/09/2019")
red_db.hset("trip3", "trip_source", "Banglore")
red_db.hset("trip3", "trip_destination", "Vijaywada")
print(red_db.hgetall("trip1"))

现在,我有了

req1 = {'User_Id': 1, 'trip_date':"06/09/2019",'trip_source':"Hyderabad", 'trip_destination':"Banglore"}

如何获取所有匹配哈希(trip1/trip2/trip3)


Tags: sourcedbdateredcustomerdestinationtripassociated