美文网首页
Redis cheat sheet

Redis cheat sheet

作者: 盲狙小堡垒 | 来源:发表于2018-03-14 04:50 被阅读33次

    basic

    set key value
    get key
    set cnt 100
    incr cnt 
    incrby cnt 50
    mset a 1 b 2 c 3
    mget a b c
    type key
    randomkey  // random get a key
    clear     // clear the screen
    rename old new
    renamex old new   // if new exists, this will fail
    dbsize   // total amount of keys
    

    push pop

    rpush list A C F G  // left push  return the list length
    lpush list B
    lrange list 0 -1  // output list[0,-1]
    exists list
    del list
    rpush list A B C
    rpop list
    
    

    hash

    hset myhash field1 "Hello" field2 "world"
    hget myhash field2
    

    set (s) and ordered set (z)(ordered by the score)

    sadd set 1 2 3 4
    smembers set
    sismember set 5
    zadd zset 1 "value1" 2 "value2"
    zrange zset 0 -1 withscores
    
    

    life-cycle

    expire key 100 // key will be removed after 10 seconds
    set key 100 ex 30  // 30 seconds
    ttl key   // find how many time left 
    

    相关文章

      网友评论

          本文标题:Redis cheat sheet

          本文链接:https://www.haomeiwen.com/subject/hjrnfftx.html