Redis中hash的排序方法:使用sort对hash进行排序,代码如下:插入几条hash数据。127.0.0.1:6379> hmset soft:1 id 1 title mobile download 123 created 122O
使用sort对hash进行排序,代码如下:
插入几条hash数据。
127.0.0.1:6379> hmset soft:1 id 1 title mobile download 123 created 122
OK
127.0.0.1:6379> hmset soft:2 id 2 title Android download 456 created 77
OK
127.0.0.1:6379> hmset soft:3 id 3 title iOS download 789 created 88
OK
127.0.0.1:6379> hmset soft:4 id 4 title Macos download 1011 created 98
对象中有4组数据,因此再建了一个set集合,存放内容如下。
127.0.0.1:6379> sadd soft 1 2 3 4
(integer) 4
127.0.0.1:6379> smembers soft
1) "1"
2) "2"
3) "3"
4) "4"
使用“sort”指令来进行排序。
127.0.0.1:6379> sort soft by soft:*->download desc get soft:*->title
1) "macos"
2) "ios"
3) "android"
4) "mobile"
--结束END--
本文标题: redis中的hash怎么排序
本文链接: https://www.lsjlt.com/news/113190.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
2024-05-21
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0