redis common data type Operation Command:
http://redisdoc.com/
http://doc.redisfans.com/
redis key (key) commonly used (commonly red font is small)
- DEL key # This command is used to delete the key in the key presence
- key * # View all the current key database
- TYPE key # key is to see what type
- EXISTS key # to check whether there is a given key
- EXPIRE key seconds # key for a given set an expiration time
- 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
- KEYS pattern # find all the key match a given pattern (pattern) of
- MOVE key db # key will move the current database to a given database db them. Without this key the current database
- DUMP key # sequence of a given key, and return values are serialized
- 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)
- PEXPIRE key milliseconds # set the key expiration time in milliseconds
- PEXPIREAT key milliseconds-timestamp # key set an expiration time stamp (unix timestamp) in milliseconds
- PERSIST key # expiration time of the removal key, key will endure.
- PITL key # milliseconds return key expiration time remaining
- RANDOMKEY # returns a random key from the current database
- RENAME key NewKeyName # modify the name of the key
- RENAMENX key NewKeyName # only when NewKeyName does not exist, the key renamed NewKeyName
string commonly used (conventional small red) - single-valued value Single
- SET key value # Set the value of the specified key
- GET key # 获取指定key的值
- GETRANGE key start end # 返回key中字符串值的子字符MGET key1 [key2...] # 获取所有(一个或多个)给定key的值。more get
- SETEX key seconds value # 将值value关联到key,并将key的过期时间设为seconds(以秒为单位)
- SETNX key value # 只有在key不存在时设置key的值
- SETRANGE key offset value # 用value参数覆写给定key所存储的字符串,从偏移量offset开始
- STRLEN key # 返回key所存储的字符串的长度
- MSET key value [key2 value2...] # 同时设置一个或多个key-value对 more set
- MSETNX key value [key2 value2...] # 同时设置一个或多个key-value对,当且仅当所有给定key都不存在,有一个key存在就设置失败
- INCR key # 将key中存储的数字值增1 key的值必须是数字必须是数字
- INCRBY key increment # 将key所存储的值加上给定的增量值(increment)必须是数字
- DECR key # 将key中存储的数字值减1 decrease缩写 必须是数字
- DECRBY key decrement # key所存储的值减去给定的减量值(decrement)必须是数字
- APPEND key value # 如果key已经存在并且是一个字符串,APPEND命令将value追加到key原来的值的末尾
- GETSET key value # 将给定key的值设为value,并返回key的旧值(old value)
- GETBIT key offset # 对key所存储的字符串值,获取指定偏移量上的位(bit)
- SETBIT key offset value # 对key所存储的字符串值,设置或清除指定偏移量上的位(bit)
- PSETEX key milliseconds value # 这个命令和SETEX命令相似,但它以毫秒为单位设置key的生存时间,而不是像SETEX命令那样,以秒为单位
- INCRBYFLOAT key increment # 将key所存储的值加上给定的浮点增量值(increment)
列表(list)常用(红色是小常用)--单值多value
- lpush #left push
- rpush # right push
- lrange # list range
- lpop # left pop
- rpop # right pop
- lindex #按照索引下标获得元素(从上到下)list index
- llen #list len 列表长度
- lrem key count value#删count个value从左到右删
- ltrim key 开始index 结束index #截取指定范围的值再赋值给key
- rpoplpush 源列表 目标列表 #源列表右边出栈一个value 给目标列表的左边。
源列表的尾给目标列表的头- lset key index value #把列表key的第index个索引值改为value
- linsert key before/after 值1(列表中有的值) 值2(要插入的值)
- 性能总结
常用
redis 集合(set)中常用(红色是小常用)--单值多value
- sadd key member1 [member2..]#向集合添加一个或多个成员
- smembers key#返回集合中的所有成员
- sismember key member#
- scard key#获取集合里面的成员个数
- srem key value #删除集合中元素
- srandmember key n #随机出n个元素
- spop key #随机出栈
- smove key1 key2 value(在key1里某个值)#将key1里的某个值赋给key2
- 数学集合类
sdiff key1 [key2]#返回给定所有集合的差集(在第一个set里面而不在后面任何一个set里面的项)
sinter #交集
sunion #并集常用:
redis hash(哈希)中常用,标红是小常用--KV模式不变,但V是一个键值对
- hset key key1 value1 [key2 value2...]
- hget key1 key2
- hmset key key1 value1 key2 value2...
- hmget key key1 key2 key3...# hash more get
- hgetall key1#查看key1的所有key和value
- hdel key1 key2 #删除key1的key2的对应value
- hlen key # 查看hash的长度
- hexists key # 在key里面的某个值的key
- hkeys
- hvals
- hincrby #只有数字的才能这样操作
- hincrbyfloat #只有数字的才能这样操作
- hsetnx
redis 有序集合Zset(sorted set)
在set基础上,加一个score值。
之前set是k1 v1 v2 v3,
现在zset是k1 score v1 score v2
- zadd
- zrange
- zrangebyscore key 开始score 结束score#withscores ; (不包含;limit返回限制 limit开始下标步 多少步
- zrem key 某score下对应的value值,作用是删除元素
- zcard key # 统计元素个数
- zcount key score区间 # 统计区间的元素个数
- zrank key value # 获取下标值
- zscore key 对应值 #获取对应值的分数
- zrevrank key value值 # 逆序获得下标值
- zrevrange
- zrevrangebyscore key 结束score 开始score