redis命令(2)--字符串类型

1.赋值

 set key value 

  如果key已存在,则value被新值覆盖

 

localhost:6379> set name yanlei
OK

2.取值

   get key value

 

localhost:6379> get name
"yanlei"

 3.递增数值

   incr key  (key的value必须为数字)

localhost:6379> get name
"yanlei"
localhost:6379> set index 1
OK
localhost:6379> get index
"1"
localhost:6379> incr index
(integer) 2
localhost:6379> incr index
(integer) 3
localhost:6379> get index
"3"
localhost:6379> set name yanlei
OK
localhost:6379> incr name
(error) ERR value is not an integer or out of range//非数字报错

 4.增加指定整数

     incrby key num 

   

localhost:6379> set index 1
OK
localhost:6379> incrby index 5
(integer) 6

 5.递减数值

   decr key

 

localhost:6379> set index 10
OK
localhost:6379> decr index
(integer) 9

 6.减少指定整数

  decrby key num

 

localhost:6379> set index 10
OK
localhost:6379> decrby index 6
(integer) 4

 7.增加指定的浮点数

    incrbyfloat key floatvalue

  

127.0.0.1:6379> set price 7.7
OK
127.0.0.1:6379> incrbyfloat price 1.1
"8.8"

 8.向尾部增加字符串

 append key value

 

localhost:6379> set city shengyang
OK
localhost:6379> append city ' of china'
(integer) 18
localhost:6379> get city
"shengyang of china"

 9.获取字符串长度

   strlen key

localhost:6379> set money 123456
OK
localhost:6379> strlen money
(integer) 6

 10.设置(获取)多个键 值

  mset key1 value1 key2 value2 ....

  mget key1 key2 ...

 

localhost:6379> mset brand focus color block price 120000
OK
localhost:6379> mget brand color price
1) "focus"
2) "block"
3) "120000"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值