1

我在 redis 中有一个包含一系列 ID 的列表。每个 id 对于单个对象都是唯一的,我将其作为 JSON 字符串存储在单独的键上。

所以我有类似的东西:

redis> LRANGE mylist 0 -1
1) "one"
2) "two"
3) "three"

而且我有单独的键mylist:one, mylist:two, mylist:three

我将 id 保存到一个列表中,以便在我的应用程序上构建一个简单的 FIFO 队列。

从每个单独的键中获取 mylist 中的所有 id 及其匹配值的最有效方法是什么?有没有更好的方法来解决它?

4

1 回答 1

2

最有效的方法可能是使用SORT 命令

# Populate list
rpush mylist one two three
set mylist:one 1
set mylist:two 2
set mylist:three 3

# Retrieve all items with their corresponding values
sort mylist by nosort get # get mylist:*
1) "one"
2) "1"
3) "two"
4) "2"
5) "three"
6) "3"
于 2012-07-11T13:52:12.683 回答