您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
redis-sort命令之外部排序by的使用
发布时间:2021-12-26 16:09:11编辑:雪饮阅读()
使用外部key进行排序
通过外部key进行排序,是通过[BY pattern]来实现的。通常外部key对应的都是一个string类型的数据。
给一个具体的例子来看下效果。
先添加一個集合
127.0.0.1:6379> sadd skey 1 2 3 4 5 6 7 8 9 10
(integer) 10
外部倒序排
127.0.0.1:6379> mset test_1 10 test_2 9 test_3 8 test_4 7 test_5 6 test_6 5 test_7 4 test_8 3 test_9 2 test_10 1
OK
127.0.0.1:6379> sort skey by test_*
1) "10"
2) "9"
3) "8"
4) "7"
5) "6"
6) "5"
7) "4"
8) "3"
9) "2"
10) "1"
外部正序排:
127.0.0.1:6379> mset test_1 1 test_2 2 test_3 3 test_4 4 test_5 5 test_6 6 test_7 7 test_8 8 test_9 9 test_10 10
OK
127.0.0.1:6379> sort skey by test_*
1) "1"
2) "2"
3) "3"
4) "4"
5) "5"
6) "6"
7) "7"
8) "8"
9) "9"
10) "10"
关键字词:redis,sort,by