在Redis中,如果要存储对象数组,我们应该使用哈希来存储对象,并将其键添加到一个列表中:
HMSET concept:unique_id name "concept"
...
LPUSH concepts concept:unique_id
...
我想获取列表中的所有哈希值(或对象),但是该列表仅包含哈希键,因此需要两个步骤完成。这是我在Python中的做法:
def get_concepts():
list = r.lrange("concepts", 0, -1)
pipe = r.pipeline()
for key in list:
pipe.hgetall(key)
pipe.execute()
需要迭代并获取每个单独的项目吗?能否进行更多优化?