0
点赞
收藏
分享

微信扫一扫

006redis的string类型


目录


set/ get( setnx)
mset/mget
incr/decr/incrby/decrby/incrbyfloat
append
strlen



setnx命令格式


SET key value [EX seconds] [PX milliseconds] [NX|XX]
summary: Set the string value of a key
since: 1.0.0
group: string



可以通过EX seconds  设置key有效期,单位是秒。例如: Ex 60 表示设置的key在60s后失效


可以通过PX milliseconds 设置key有效期,单位是毫秒。例如: PX 60000 标识设置key在60s后失效


通过since发现,该命令自从1.0.0 版本就存在了


group标识该命令属于string组



SETNX key value


summary: Set the value of a key, only if the key does not exist


since: 1.0.0


group: string     



GET key
summary: Get the value of a key
since: 1.0.0
group: string



对比set和setnx发现,set k v 每次更新都会成功,而setnx  k v 只有k不存在时候才能set成功




2、mset/mget命令格式



MSET key value [key value ...]
summary: Set multiple keys to multiple values
since: 1.0.1
group: string

MGET key [key ...]
summary: Get the values of all the given keys
since: 1.0.0
group: string



Mset可以同时为多个k v 赋值,MGET可以对多个K取数值




3、incr/decr/incrby/decrby/incrbyfloat命令格式



3.1、每执行一次key对应的value数值自动加1
INCR key
summary: Increment the integer value of a key by one
since: 1.0.0
group: string

3.2、每执行一次key对应的value数值自动减1
DECR key
summary: Decrement the integer value of a key by one
since: 1.0.0

3.3、每执行一次key对应的value数值自动加increment
INCRBY key increment
summary: Increment the integer value of a key by the given amount
since: 1.0.0

3.4、每执行一次key对应的value数值自动减increment
DECRBY key decrement
summary: Decrement the integer value of a key by the given number
since: 1.0.0




4、append命令格式


4.1、每次执行对key对应的value都会添加
APPEND key value
summary: Append a value to a key
since: 2.0.0
group: string


4.2、计算key对应的value长度
STRLEN key
summary: Get the length of the value stored in a key
since: 2.2.0
group: string



5、strlen命令格式


计算key对应的value长度
STRLEN key
summary: Get the length of the value stored in a key
since: 2.2.0
group: string











举报

相关推荐

[Redis] String类型

redis的string类型用法

Redis之String类型

初识redis:String类型

Redis操作String类型

Redis中String数据类型

0 条评论