Redis 常用命令学习二:字符串类型命令

1.赋值与取值命令

127.0.0.1:6379> set foo helloredis
OK
127.0.0.1:6379> get foo
"helloredis"
127.0.0.1:6379> get bar
(nil)

2.数字键值递增

127.0.0.1:6379> set int 3
OK
127.0.0.1:6379> incr int
(integer) 4
127.0.0.1:6379> get int
"4"

3.增加指定的整数

127.0.0.1:6379> set int 3
OK
127.0.0.1:6379> incr int
(integer) 4
127.0.0.1:6379> get int
"4"

4.减少指定的整数

127.0.0.1:6379> DECRBY int 12
(integer) -2
127.0.0.1:6379> get int
"-2"

5.向尾部追加值

127.0.0.1:6379> set redis hello
OK
127.0.0.1:6379> append redis ' world'
(integer) 11
127.0.0.1:6379> get redis
"hello world"

6.获取值的字符串长度

127.0.0.1:6379> strlen int
(integer) 2
127.0.0.1:6379> strlen redis
(integer) 11

7.同时设置获取多个键值

127.0.0.1:6379> mset k1 233 k2 666 k3 555
OK
127.0.0.1:6379> mget k1 k2 k3
1) "233"
2) "666"
3) "555"

8.位操作

127.0.0.1:6379> set qiao f
OK
127.0.0.1:6379> getbit qiao 0
(integer) 0
127.0.0.1:6379> setbit qiao 1 0
(integer) 1
127.0.0.1:6379> get qiao
"&"
127.0.0.1:6379> bitcount qiao
(integer) 3
127.0.0.1:6379> bitcount qiao 1 4
(integer) 0
127.0.0.1:6379> set sun q
OK
127.0.0.1:6379> bitop or qiao sun
(integer) 1
posted @ 2017-12-25 23:06  潇湘旧友  阅读(185)  评论(0编辑  收藏  举报