您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
redis-sort命令之外部排序by的使用以及結合get以及redis批量執行多命令的使用
发布时间:2021-12-26 17:06:14编辑:雪饮阅读()
[BY pattern] 结合[GET pattern]
*是占位符,只是取出来的不是sort的tst的结果,而是将tst的集代入到get后的key_*中的结果
爲了更好的看出效果對比,可以實現下redis批量執行多條命令,首先我們建立如command.txt:
set key sort4
get key
mset test_1 1000 test_2 900 test_3 800 test_4 700 test_5 600 test_6 500 test_7 400 test_8 300 test_9 200 test_10 100
mset user_1 us1 user_2 us2 user_3 us3 user_4 us4 user_5 us5 user_6 us6 user_7 us7 user_8 us8 user_9 us9 user_10 us10
sort skey by test_*
sort skey by test_* get test_* get user_*
set key sort5
get key
mset test_1 100 test_2 200 test_3 300 test_4 400 test_5 500 test_6 600 test_7 700 test_8 800 test_9 900 test_10 1000
mset user_1 us1 user_2 us2 user_3 us3 user_4 us4 user_5 us5 user_6 us6 user_7 us7 user_8 us8 user_9 us9 user_10 us10
mset article_10 art1 article_9 art2 article_8 art3 article_7 art4 article_6 art5 article_5 art6 article_4 art7 article_3 art8 article_2 art9 article_1 art10
sort skey by test_*
sort skey by test_* get test_* get user_* get article_*
然後我們執行效果如:
[root@localhost www.fpm.com]# cat command.txt | redis-cli -h 127.0.0.1 -p 6379
OK
"sort4"
OK
OK
1) "10"
2) "9"
3) "8"
4) "7"
5) "6"
6) "5"
7) "4"
8) "3"
9) "2"
10) "1"
1) "100"
2) "us10"
3) "200"
4) "us9"
5) "300"
6) "us8"
7) "400"
8) "us7"
9) "500"
10) "us6"
11) "600"
12) "us5"
13) "700"
14) "us4"
15) "800"
16) "us3"
17) "900"
18) "us2"
19) "1000"
20) "us1"
OK
"sort5"
OK
OK
OK
1) "1"
2) "2"
3) "3"
4) "4"
5) "5"
6) "6"
7) "7"
8) "8"
9) "9"
10) "10"
1) "100"
2) "us1"
3) "art10"
4) "200"
5) "us2"
6) "art9"
7) "300"
8) "us3"
9) "art8"
10) "400"
11) "us4"
12) "art7"
13) "500"
14) "us5"
15) "art6"
16) "600"
17) "us6"
18) "art5"
19) "700"
20) "us7"
21) "art4"
22) "800"
23) "us8"
24) "art3"
25) "900"
26) "us9"
27) "art2"
28) "1000"
29) "us10"
30) "art1"
可以看到get也是可以一次使用多个get
关键字词:redis,sort,by,get,批量,多條,命令