Redis Grammar

Common
    keys *
    keys n*e
    keys n?
    del my1 my2 my3
    exists my1
    rename a b
    expire a 1000
    ttl a
    type a

String
    set key value [EX seconds] [PX milliseconds] [NX(不存在才成功)|XX(已存在才成功)]
    eg: set name imooc EX 10 NX
    set name imooc
    mset name imooc age 10
    get name
    mget name1 name2
    getset name imooc
    del name
    incr a
    decr a
    incrby a 100
    decrby a 100
    append name zhangsan
    setnx name imooc (如果存在key,则失败,返回0)
    msetnx name imooc age 10 (有一个失败,整个都失败)
    setex name 10 imooc (设置失效时间)
    getrange name 0 5 (截取字符,从索引0到索引5)

Hash
    hset myhash username liyong
    hmset myhash a 1 b 2
    hget myhash username
    hmget myhash a b
    hgetall myhash
    hdel myhash a
    hdel myhash a b
    hincrby myhash a 100
    hexists myhash a
    hlen myhash
    hkeys myhash
    hvals myhash

List
    lpush mylist a b c (insert by left side)
    c index:0/-3
    b index:1/-2
    a index:2/-1

    rpush mylist a b c (insert by right side)
    a index:0/-3
    b index:1/-2
    c index:2/-1

    lindex mylist 0
    lrange mylist 0 -1 (show item from first to the end)
    lrange mylist 0 -2 (show item from first to the reciprocal second)
    lpop mylist (eject the the left item)
    rpop mylist
    llen mylist
    lpushx mylist x (insert x into the left side when mylist has items)
    rpushx mylist x
    lrem mylist 0 a (remove all item is a in mylist)
    lrem mylist 2 a (remove two a from the beginning)
    lrem mylist -2 a (remove two a from the end)
    lset mylist 3 x (insert x which the index is 3)
    linsert mylist before a x (insert x before the first a)
    linsert mylist after a x (insert x after the first a)
    rpoplpush mylist mylist2 (eject the right item in mylist and insert it into the left side in mylist2)

Set
    sadd myset a b c
    sadd myset a (can not success)
    srem myset a b
    smembers myset 
    sismember myset a
    sdiff myset1 myset2 (myset1 - myset2)
    sinter myset1 myset2 (交集)
    sunion myset1 myset2 (并集)
    scard myset
    srandmember myset 
    sdiffstore newset1 oldset1 oldset2
    sinterstore newset1 oldset1 oldset2
    sunionstore newset1 oldset1 oldset2

Sorted Set
    zadd mysort 70 a 80 b 90 c
    zadd mysort 100 a (replace the a's score)
    zscore mysort a (show a's score)
    zcard mysort (show count)
    zrem mysort a b
    zrange mysort 0 -1 (show all items by score asc)
    zrange mysort 0 -1 withscores (从小到大)
    zrevrange mysort 0 -1 withscores (从大到小)
    zrangebyscore mysort 0 100 withscores limit 0 2
    zrank mysort b (show rank of b,从小到大)
    zrevrank mysort b (show rank of b,从大到小)
    zremrangebyrank mysort 0 4 (remove by index)
    zremrangebyscore mysort 80 100 (remove by score)
    zincrby mysort 10 a (add 10 to item a)
    zcount mysort 80 90

发布订阅
    SUBSCRIBE channela
    PUBLISH channela test_content , 返回收到消息的客户端数量
    UNSUBSCRIBE channela , 不如不指定,则取消订阅所有消息

事务
    MULTI
        开始事务
    ....
    EXEC
        执行
    DISCARD
        清空命令并取消事务

    WATCH key...
    WATCH key...之后的第一个事务T1里,若对watch的key进行处理时,其他client进程对某一个key进行操作,则事务T1会执行失败。
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

西门催学不吹雪ㅤ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值