解释:将key改名为newkey
[plain] view plaincopyprint? 01.redis 127.0.0.1:6379> smembers diff 02.1) "zhangsan01" 03.redis 127.0.0.1:6379> rename diff diff01 04.OK 05.redis 127.0.0.1:6379> smembers diff 06.(empty list or set) 07.redis 127.0.0.1:6379> smembers diff01 08.1) "zhangsan01" 09.redis 127.0.0.1:6379> rename diff diff01 10.(error) ERR no such key redis 127.0.0.1:6379> smembers diff 1) "zhangsan01" redis 127.0.0.1:6379> rename diff diff01 OK redis 127.0.0.1:6379> smembers diff (empty list or set) redis 127.0.0.1:6379> smembers diff01 1) "zhangsan01" redis 127.0.0.1:6379> rename diff diff01 (error) ERR no such key 注意:当key和newkey相同或key不存在时,返回错误;当newkey已存在时,rename将覆盖旧值。
9)renamenx 语法:renamenx key newkey
解释:当且仅当newkey不存在时,改名key
[plain] view plaincopyprint? 01.redis 127.0.0.1:6379> renamenx diff01 stu #stu存在 02.(integer) 0 03.redis 127.0.0.1:6379> renamenx diff01 diff #diff不存在 04.(integer) 1 redis 127.0.0.1:6379> renamenx diff01 stu #stu存在 (integer) 0 redis 127.0.0.1:6379> renamenx diff01 diff #diff不存在 (integer) 1 10)del
语法:del key [key ...]
解释:删除一个或多个key
[plain] view plaincopyprint? 01.redis 127.0.0.1:6379> del score1 02.(integer) 1 03.redis 127.0.0.1:6379> del union diff aa #key aa 不存在 04.(integer) 2 redis 127.0.0.1:6379> del score1 (integer) 1 redis 127.0.0.1:6379> del union diff aa #key aa 不存在 (integer) 2 11)move
语法:move key db
解释:将key移动到指定db
[plain] view plaincopyprint? 01.redis 127.0.0.1:6379> smembers stu #默认0 02.1) "zhangsan01" 03.2) "wangwu" 04.redis 127.0.0.1:6379> move stu 1 #移动到 1 05.(integer) 1 06.redis 127.0.0.1:6379> smembers stu 07.(empty list or set) 08.redis 127.0.0.1:6379> select 1 #选择db 1 09.OK 10.redis 127.0.0.1:6379[1]> smembers stu 11.1) "zhangsan01" 12.2) "wangwu" redis 127.0.0.1:6379> smembers stu #默认0 1) "zhangsan01" 2) "wangwu" redis 127.0.0.1:6379> move stu 1 #移动到 1 (integer) 1 redis 127.0.0.1:6379> smembers stu (empty list or set) redis 127.0.0.1:6379> select 1 #选择db 1 OK redis 127.0.0.1:6379[1]> smembers stu 1) "zhangsan01" 2) "wangwu" 12)sort
语法:sort key [BY pattern] [LIMIT offset count] [GET pattern [GET pattern ...]] [ASC|DESC] [ALPHA] [STORE destination]
解释:返回或保持给定列表,集合,有序集合key中经过排序的元素
[plain] view plaincopyprint? 01.redis 127.0.0.1:6379> sort lst.tech limit 0 2 alpha desc #按字符集排序 02.1) "tec06" 03.2) "tec05" 04.redis 127.0.0.1:6379> sort lst.stud 05.1) "1" 06.2) "2" 07.3) "3" 08.redis 127.0.0.1:6379> sort lst.stud desc 09.1) "3" 10.2) "2" 11.3) "1" 12.redis 127.0.0.1:6379> keys stu.* 13.1) "stu.name.2" 14.2) "stu.name.3" 15.3) "stu.level.1" 16.4) "stu.level.2" 17.5) "stu.level.3" 18.6) "stu.name.1" 19.redis 127.0.0.1:6379> sort lst.stud by stu.level.* desc get stu.level.* get stu.name.* 20.1) "3" 21.2) "admin" 22.3) "2" 23.4) "joe" 24.5) "1" 25.6) "jim" 26.redis 127.0.0.1:6379> sort lst.stud by stu.level.* asc get stu.name.* 27.1) "jim" 28.2) "joe" 29.3) "admin" redis 127.0.0.1:6379> sort lst.tech limit 0 2 alpha desc #按字符集排序 1) "tec06" 2) "tec05" redis 127.0.0.1:6379> sort lst.stud 1) "1" 2) "2" 3) "3" redis 127.0.0.1:6379> sort lst.stud desc 1) "3" 2) "2" 3) "1" redis 127.0.0.1:6379> keys stu.* 1) "stu.name.2" 2) "stu.name.3" 3) "stu.level.1" 4) "stu.level.2" 5) "stu.level.3"毕业论文 6) "stu.name.1" redis 127.0.0.1:6379> sort lst.stud by stu.level.* desc get stu.level.* get stu.name.* 1) "3" 2) "admin" 3) "2" 4) "joe" 5) "1" 6) "jim" redis 127.0.0.1:6379> sort lst.stud by stu.level.* asc get stu.name.* 1) "jim" 2) "joe" 3) "admin" sort虽然很“厉害”,但尽量不要让redis服务器来sort大量的数据。可以通过设定阀值减少要sort的数据,或把排序操作向前移,在web服务器或各个应用上来sort。
上一页 [1] [2]
|