redis 127.0.0.1:6379> set name wwl 设置key对应的值为String类型的value
OK
redis 127.0.0.1:6379> get name
"wwl"
redis 127.0.0.1:6379> get name
"wwl"
redis 127.0.0.1:6379> del name
(integer) 1
redis 127.0.0.1:6379> exists name
(integer) 0
redis 127.0.0.1:6379> set name Pengdi
OK
redis 127.0.0.1:6379> get name
"Pengdi"
redis 127.0.0.1:6379> setnx name Jenny 设置key对应的值为string类型的value。如果key已经存在则返回0,nx是not exist的意思。
(integer) 0
redis 127.0.0.1:6379> get name
"Pengdi"
redis 127.0.0.1:6379> setex color 5 red
OK
redis 127.0.0.1:6379> get color
(nil)
redis 127.0.0.1:6379> setex color 5 red 设置key对应的值为string类型的value,并指定此键值对应的有效期.这里指定有效期为5秒.
OK
redis 127.0.0.1:6379> get color
"red"
redis 127.0.0.1:6379> get color
"red"
redis 127.0.0.1:6379> get color
(nil)
redis 127.0.0.1:6379> set mail pengdi11@yahoo.com.cn
OK
redis 127.0.0.1:6379> get mail
"pengdi11@yahoo.com.cn"
redis 127.0.0.1:6379> setrange mail 9 gmail.com 设置指定key的value值的子字符串
(integer) 21
redis 127.0.0.1:6379> get mail
"pengdi11@gmail.com.cn"
redis 127.0.0.1:6379> get name
"Pengdi"
redis 127.0.0.1:6379> mset key1 ppd1 key2 ppd2 一次设置多个key的值,成功返回ok表示所有的值都设置了,失败返回0表示没有任何值被设置。
OK
redis 127.0.0.1:6379> get key1
"ppd1"
redis 127.0.0.1:6379> get name
"Pengdi"
redis 127.0.0.1:6379> getset name Wilian 设置key的值,并返回key的旧值。
"Pengdi"
redis 127.0.0.1:6379> get name
"Wilian"
redis 127.0.0.1:6379> get mail
"pengdi11@gmail.com.cn"
redis 127.0.0.1:6379> getrange name 0,9
(error) ERR wrong number of arguments for 'getrange' command
redis 127.0.0.1:6379> getrange name 0 9 获取指定key的value值的子字符串
"Wilian"
redis 127.0.0.1:6379> getrange mail 0 9
"pengdi11@g"
redis 127.0.0.1:6379> mget key1 key2 一次获取多个key的值,如果对应key不存在则对应返回nil
1) "ppd1"
2) "ppd2"
redis 127.0.0.1:6379> set age 20
OK
redis 127.0.0.1:6379> incr age 对key的值做加加操作,并返回新的值。
(integer) 21
redis 127.0.0.1:6379> get age
"21"
redis 127.0.0.1:6379> incrby age 5 指定加数
(integer) 26
redis 127.0.0.1:6379> get age
"26"
redis 127.0.0.1:6379> get name
"Wilian"
redis 127.0.0.1:6379> append name .peng 给指定key的字符串值追加value,返回新字符串值的长度
(integer) 11
redis 127.0.0.1:6379> get name
"Wilian.peng"
redis 127.0.0.1:6379> strlen name 取指定key的value值的长度
(integer) 11