redis common data type Operation Command

redis common data type Operation Command:
        http://redisdoc.com/
        http://doc.redisfans.com/

redis key (key) commonly used (commonly red font is small)

  1. DEL key # This command is used to delete the key in the key presence
  2. key * # View all the current key database
  3. TYPE key # key is to see what type
  4. EXISTS key # to check whether there is a given key
  5. EXPIRE key seconds # key for a given set an expiration time
  6. TTL key # to see how many seconds expired, -1 means never expires, -2 said that it has expired. If expired with the keys * can not find the key expired
  7. KEYS pattern # find all the key match a given pattern (pattern) of
  8. MOVE key db # key will move the current database to a given database db them. Without this key the current database
  9. DUMP key # sequence of a given key, and return values ​​are serialized
  10. EXPIREAT key timestamp # EXPIRE and similar, are used to set the expiration time for the key. Except that the time parameter EXPIRE accepted command is a UNIX timestamp (unix timestamp)
  11. PEXPIRE key milliseconds # set the key expiration time in milliseconds
  12. PEXPIREAT key milliseconds-timestamp # key set an expiration time stamp (unix timestamp) in milliseconds
  13. PERSIST key # expiration time of the removal key, key will endure.
  14. PITL key # milliseconds return key expiration time remaining
  15. RANDOMKEY # returns a random key from the current database
  16. RENAME key NewKeyName # modify the name of the key
  17. RENAMENX key NewKeyName # only when NewKeyName does not exist, the key renamed NewKeyName

 string commonly used (conventional small red) - single-valued value Single

  1. SET key value # Set the value of the specified key
  2. GET key # 获取指定key的值
  3. GETRANGE key start end # 返回key中字符串值的子字符MGET key1 [key2...] # 获取所有(一个或多个)给定key的值。more get
  4. SETEX key seconds value # 将值value关联到key,并将key的过期时间设为seconds(以秒为单位)
  5. SETNX key value # 只有在key不存在时设置key的值
  6. SETRANGE key offset value # 用value参数覆写给定key所存储的字符串,从偏移量offset开始
  7. STRLEN key # 返回key所存储的字符串的长度
  8. MSET key value [key2 value2...] # 同时设置一个或多个key-value对 more set
  9. MSETNX key value [key2 value2...] # 同时设置一个或多个key-value对,当且仅当所有给定key都不存在,有一个key存在就设置失败
  10. INCR key # 将key中存储的数字值增1 key的值必须是数字必须是数字
  11. INCRBY key increment # 将key所存储的值加上给定的增量值(increment)必须是数字
  12. DECR key # 将key中存储的数字值减1 decrease缩写 必须是数字
  13. DECRBY key decrement # key所存储的值减去给定的减量值(decrement)必须是数字
  14. APPEND key value # 如果key已经存在并且是一个字符串,APPEND命令将value追加到key原来的值的末尾
  15. GETSET key value # 将给定key的值设为value,并返回key的旧值(old value)
  16. GETBIT key offset # 对key所存储的字符串值,获取指定偏移量上的位(bit)
  17. SETBIT key offset value # 对key所存储的字符串值,设置或清除指定偏移量上的位(bit)
  18. PSETEX key milliseconds value # 这个命令和SETEX命令相似,但它以毫秒为单位设置key的生存时间,而不是像SETEX命令那样,以秒为单位
  19. INCRBYFLOAT key increment # 将key所存储的值加上给定的浮点增量值(increment)

 列表(list)常用(红色是小常用)--单值多value

  1. lpush #left push
  2. rpush # right push
  3. lrange # list range
  4. lpop # left pop
  5. rpop # right pop
  6. lindex #按照索引下标获得元素(从上到下)list index
  7. llen #list len 列表长度
  8. lrem key count value#删count个value从左到右删
  9. ltrim key 开始index 结束index #截取指定范围的值再赋值给key

  10. rpoplpush 源列表 目标列表 #源列表右边出栈一个value 给目标列表的左边。
    源列表的尾给目标列表的头


  11. lset key index value #把列表key的第index个索引值改为value
  12. linsert key before/after 值1(列表中有的值) 值2(要插入的值)
  13. 性能总结

    常用

redis 集合(set)中常用(红色是小常用)--单值多value

  1. sadd key member1 [member2..]#向集合添加一个或多个成员
  2. smembers key#返回集合中的所有成员
  3. sismember key member#
  4. scard key#获取集合里面的成员个数
  5. srem key value #删除集合中元素
  6. srandmember key n #随机出n个元素
  7. spop key #随机出栈
  8. smove key1 key2 value(在key1里某个值)#将key1里的某个值赋给key2
  9. 数学集合类
    sdiff key1 [key2]#返回给定所有集合的差集(在第一个set里面而不在后面任何一个set里面的项)


    sinter  #交集

    sunion #并集

常用:

redis hash(哈希)中常用,标红是小常用--KV模式不变,但V是一个键值对

  1. hset key key1 value1 [key2 value2...]
  2. hget key1 key2
  3. hmset key key1 value1 key2 value2...
  4. hmget  key key1 key2 key3...# hash more get
  5. hgetall key1#查看key1的所有key和value
  6. hdel key1 key2 #删除key1的key2的对应value
  7. hlen key # 查看hash的长度
  8. hexists key # 在key里面的某个值的key
  9. hkeys
  10. hvals
  11. hincrby  #只有数字的才能这样操作
  12. hincrbyfloat #只有数字的才能这样操作
  13. hsetnx

 

redis 有序集合Zset(sorted set) 

在set基础上,加一个score值。

之前set是k1 v1 v2 v3,

现在zset是k1 score v1 score v2

  1. zadd
  2. zrange
  3. zrangebyscore key 开始score 结束score#withscores ; (不包含;limit返回限制  limit开始下标步 多少步


  4. zrem key 某score下对应的value值,作用是删除元素
  5. zcard key # 统计元素个数
  6. zcount key score区间 # 统计区间的元素个数
  7. zrank key value # 获取下标值
  8. zscore key 对应值 #获取对应值的分数
  9. zrevrank key value值 # 逆序获得下标值 
  10. zrevrange
  11. zrevrangebyscore key 结束score 开始score

Guess you like

Origin blog.csdn.net/m0_37264741/article/details/93381087