set 保存一个键值对
get 通过指定键,获得对应的值
mset 一次性保存多个键值对
mget 一次性指定多个键,获得多个键对应的值
getset 指定键,获得该键对应原来的值,重新设置一个新的值
append 给指定键,对应的值,追加一个字符串
getrange 获得指定键,对应的字符串的子字符串
incrby 给指定的键对应的值,添加一个增量
strlen 通过字符串长度(统计字节的长度)
set get 使用
mset mget 使用
192.168.184.130:9379> mset {t}name "wangjun" {t}age 19
OK
192.168.184.130:9379> keys *
1) "{t}name"
2) "{t}age"
3) "345"
4) "wangfei"
5) "mykey"
192.168.184.130:9379> {t}name
(error) ERR unknown command `{t}name`, with args beginning with:
192.168.184.130:9379> get {t}name
"wangjun"
192.168.184.130:9379> mget {t}name {t}age
1) "wangjun"
2) "19"
192.168.184.130:9379> mset aa 'aa' bb 'bb'
(error) CROSSSLOT Keys in request don't hash to the same slot
Redis getrange 命令用于设置指定 key 的值截取
192.168.184.130:9379> GETRANGE mykey 0 3
"this"
192.168.184.130:9379> GETRANGE mykey 0 -1
"this is my test key"
192.168.184.130:9379>
Redis Getset 命令用于设置指定 key 的值,并返回 key 的旧值。
192.168.184.130:9379> set db mongodb
-> Redirected to slot [2826] located at 192.168.184.130:9179
OK
192.168.184.130:9179> get db
"mongodb"
192.168.184.130:9179> getset db redis
"mongodb"
192.168.184.130:9179> get db
"redis"
192.168.184.130:9179>
Redis Incr 命令将 key 中储存的数字值增一
192.168.184.130:9179> set page_view 20
-> Redirected to slot [15749] located at 192.168.184.130:9379
OK
192.168.184.130:9379> INCR page_view
(integer) 21
192.168.184.130:9379> get page_view
"21"
192.168.184.130:9379> INCR page_view
(integer) 22
192.168.184.130:9379>
Redis Strlen 命令用于获取指定 key 所储存的字符串值的长度。当 key 储存的不是字符串值时,返回一个错误
192.168.184.130:9379> set mylen 'hello world'
-> Redirected to slot [7705] located at 192.168.184.130:7379
OK
192.168.184.130:7379> get mylen
"hello world"
192.168.184.130:7379> strlen mylen
(integer) 11
Redis Append 命令用于为指定的 key 追加值。
如果 key 已经存在并且是一个字符串, APPEND 命令将 value 追加到 key 原来的值的末尾。
如果 key 不存在, APPEND 就简单地将给定 key 设为 value ,就像执行 SET key value 一样。
192.168.184.130:7379> EXISTS myphone
-> Redirected to slot [13957] located at 192.168.184.130:9379
(integer) 0
192.168.184.130:9379> APPEND myphone 'iphonex'
(integer) 7
192.168.184.130:9379> get myphone
"iphonex"
192.168.184.130:9379> APPEND myphone 'nokia'
(integer) 12
192.168.184.130:9379> get myphone
"iphonexnokia"
192.168.184.130:9379>
网友评论