使用集合中的哈希对redis中的集合进行排序
sort set in redis with hash in the collection
我们以这种方式使用 REPL redis-cli 在 redis 中创建了 3 个哈希:
hmset redishop:items:Articulo1 artist "Martin Wessely" price 12.99 name "Handcrafted Trees Mug"
hmset redishop:items:Articulo2 artist "Martin Wessely" price 13.99 name "Handcrafted Trees Mug"
hmset redishop:items:Articulo3 artist "Martin Wessely" price 14.99 name "Handcrafted Trees Mug"
我检查了在 redis 中创建的结构是否正确,这些就在那里:
hgetall redishop:items:Articulo3
现在我们以这种方式将散列添加到一个集合中:
sadd redishop:list-all redishop:items:Articulo3
sadd redishop:list-all redishop:items:Articulo2
sadd redishop:list-all redishop:items:Articulo1
现在我们正在玩命令 SORT:
SORT redishop:list-all BY redishop:items:*->price
SORT redishop:list-all BY redishop:items:*->price GET redishop:items:*->price
SORT redishop:list-all BY redishop:items:*->price GET # GET redishop:items:*->price
我们从来没有得到结果,集合中的哈希值为空,我不明白为什么?
另一方面,如果我们创建散列并以其他方式设置:
multi
hmset redishop:items:Articulo1 artist "Martin Wessely" price 12.99 name "Handcrafted Trees Mug"
sadd redishop:list-all Articulo1
hmset redishop:items3:Articulo2 artist "Martin Wessely" price 13.99 name "Handcrafted Trees Mug"
sadd redishop:list-all Articulo2
hmset redishop:items3:Articulo3 artist "Martin Wessely" price 14.99 name "Handcrafted Trees Mug"
sadd redishop:list-all Articulo3
exec
通过这种方式,命令 SORT 可以完美地工作并且哈希被插入到集合中,但我不明白为什么在 redis 文档的基础上:
命令 multi only 标记事务块的开始。后续命令将使用 EXEC 排队等待原子执行。
当我使用键 key:key:key 创建散列时,如果我使用 : or , or - 并且在 redis 中最重要的是我们没有根据文档创建结构树:
https://redis.io/topics/data-types-intro
他们告诉您包含 : 或点是更好或好的方法,但他们不会告诉您他正在创建结构树。然后我不明白为什么当你在集合中添加哈希时,如果类型 Articulo1 而不是 redishop:items:Articulo1 是好的,但在其他情况下是错误的????实际上,当您键入 hgetall Articulo1 时,您会收到一个空值,但是当您键入 hgetall redishop:items:Articulo1 时,您会得到所有的错误值。这太奇怪了。
- exec 只执行所有的语句,因为这些原因应该是相同的,使它有 multi 或没有 multi。
请对这个问题有任何帮助或解释都会有很大帮助。
提前致谢。
Now we are playing with the command SORT
注意 SORT
的时间复杂度和内存要求,我通常建议不要使用它。
We never get results, the hash in the set are with value null and I dont understand why?
问题在于您如何调用 SORT
并指定 GET 和 BY 子句。由于您的 Set 成员是完整的(哈希)键名,因此您应该如何处理示例数据:
127.0.0.1:6379> SORT redishop:list-all BY *->price
1) "redishop:items:Articulo1"
2) "redishop:items:Articulo2"
3) "redishop:items:Articulo3"
127.0.0.1:6379> SORT redishop:list-all BY *->price GET *->price
1) "12.99"
2) "13.99"
3) "14.99"
In this way the command SORT works perfectly
在这种情况下,您仅使用键名称的 "id" 部分填充 Set,因此 GET 和 BY 子句映射到实际数据。澄清一下,这与 MULTI
块的使用(或缺乏)无关。
我们以这种方式使用 REPL redis-cli 在 redis 中创建了 3 个哈希:
hmset redishop:items:Articulo1 artist "Martin Wessely" price 12.99 name "Handcrafted Trees Mug"
hmset redishop:items:Articulo2 artist "Martin Wessely" price 13.99 name "Handcrafted Trees Mug"
hmset redishop:items:Articulo3 artist "Martin Wessely" price 14.99 name "Handcrafted Trees Mug"
我检查了在 redis 中创建的结构是否正确,这些就在那里:
hgetall redishop:items:Articulo3
现在我们以这种方式将散列添加到一个集合中:
sadd redishop:list-all redishop:items:Articulo3
sadd redishop:list-all redishop:items:Articulo2
sadd redishop:list-all redishop:items:Articulo1
现在我们正在玩命令 SORT:
SORT redishop:list-all BY redishop:items:*->price
SORT redishop:list-all BY redishop:items:*->price GET redishop:items:*->price
SORT redishop:list-all BY redishop:items:*->price GET # GET redishop:items:*->price
我们从来没有得到结果,集合中的哈希值为空,我不明白为什么?
另一方面,如果我们创建散列并以其他方式设置:
multi
hmset redishop:items:Articulo1 artist "Martin Wessely" price 12.99 name "Handcrafted Trees Mug"
sadd redishop:list-all Articulo1
hmset redishop:items3:Articulo2 artist "Martin Wessely" price 13.99 name "Handcrafted Trees Mug"
sadd redishop:list-all Articulo2
hmset redishop:items3:Articulo3 artist "Martin Wessely" price 14.99 name "Handcrafted Trees Mug"
sadd redishop:list-all Articulo3
exec
通过这种方式,命令 SORT 可以完美地工作并且哈希被插入到集合中,但我不明白为什么在 redis 文档的基础上:
命令 multi only 标记事务块的开始。后续命令将使用 EXEC 排队等待原子执行。
当我使用键 key:key:key 创建散列时,如果我使用 : or , or - 并且在 redis 中最重要的是我们没有根据文档创建结构树: https://redis.io/topics/data-types-intro
他们告诉您包含 : 或点是更好或好的方法,但他们不会告诉您他正在创建结构树。然后我不明白为什么当你在集合中添加哈希时,如果类型 Articulo1 而不是 redishop:items:Articulo1 是好的,但在其他情况下是错误的????实际上,当您键入 hgetall Articulo1 时,您会收到一个空值,但是当您键入 hgetall redishop:items:Articulo1 时,您会得到所有的错误值。这太奇怪了。
- exec 只执行所有的语句,因为这些原因应该是相同的,使它有 multi 或没有 multi。
请对这个问题有任何帮助或解释都会有很大帮助。 提前致谢。
Now we are playing with the command SORT
注意 SORT
的时间复杂度和内存要求,我通常建议不要使用它。
We never get results, the hash in the set are with value null and I dont understand why?
问题在于您如何调用 SORT
并指定 GET 和 BY 子句。由于您的 Set 成员是完整的(哈希)键名,因此您应该如何处理示例数据:
127.0.0.1:6379> SORT redishop:list-all BY *->price
1) "redishop:items:Articulo1"
2) "redishop:items:Articulo2"
3) "redishop:items:Articulo3"
127.0.0.1:6379> SORT redishop:list-all BY *->price GET *->price
1) "12.99"
2) "13.99"
3) "14.99"
In this way the command SORT works perfectly
在这种情况下,您仅使用键名称的 "id" 部分填充 Set,因此 GET 和 BY 子句映射到实际数据。澄清一下,这与 MULTI
块的使用(或缺乏)无关。