the data type of redis

来源:互联网 发布:淘宝上的车秒贷怎么样 编辑:程序博客网 时间:2024/05/18 02:16


exists  key

del key

type key

keys *  ?  [a-b]  \?

1.String

set key value

get key

incr key

incrby  key   increment

incrbyfloat key  increment

decr  key

decrby key decrement

append  key  value

strlen   key

mset  key  value [ key  value... ]

mget  key  [  key ... ]

getbit  key   offset

setbit  key  offset  value

bitcount  key   [ start ]   [ end ]       //  the counts from the start byte to end byte 

bitop   operation   result   key1  key2    // the  operation include  " and   or   xor   not "

bitpos   key  bitValue(0 or 1)  [ start ]   [ end ]      // get  the bit position whose value is bitValue of the key begin with  the start byte  and end up with the end byte


2.Hash    ( key  field   value [ field  value ... ])

hset key field  value

hget key field

hmset  key  field value [ field value ... ]

hget  key field [ field ... ]

hgetalll  key

hexists  key   field

hsetnx  key  field  value   // like  the command  hset  , the distinction  is if  field exists  then  the command  hsetnx  do nothing

hincrby  key  field increment

hdel  key  field [ filed ... ]

hkeys  key   // get all the field of  the key

hvals  key   // get all the value  of the key

hlen  key    // get all


3.List   (the  inside  structure is  doubly  linked  list)

lpush  key  value [ value ... ]

rpush  key  value [ value ... ]

lpop  key

rpop  key

llen  key    // the element number  of  key

lrange  key  start   end

/*

* when count > 0 then delete the first  count  element which element is value  of the key on the left

*when  count< 0 then  delete the last   abs(count)  element  which element is value  of  the key on the  right

*when  count=0 then  delete all the element  which  field  is value

*/

lrem  key  count  value

lindex  key  index   // get the index  element of the key

lset  key  index  value   // set the result of the index  element  is value of the key(list)

linsert  key before | after  pivot   value   //  find the result  is pivot from left to right ,then according to the before or after to insert

rpoplpush  source  destination   //  pop one element on the right from source to push one element on the left for the destination every time


4.set   ( inside structure is hash table :  disorder  、unique)

sadd  key member [ member ... ]   // if key is not exists then create it , if the member is exists ,then ignore it

srem  key member [ member ...]    // if member is exists then pop it ,else  ingore it

smembers  key     // show all the members

sismember  key  member   // judge  the member is or not exists

sdiff   key  [ key ... ]         // subtract

sinter key [ key ... ]         // intersect

sunion  key [ key .... ]     // union

scard  key   // get the number of the set

sdiffstore  destination  key [ key ... ]         // function equeals  sdiff  ,  the distinction is sdiffstore don't show the result ,but counld set the result to destination

sinterstore  destination  key [ key ... ]      // same as above

sunionstore  destination  key [ key ... ]    // same as above

/*

* when count > 0 , then get count numbers different random elements from set , if count is greater than the size of set , then show all the elements

* when count < 0 , then get  |count|  numbers random  elements from set , but the elements maybe equal to each  other

*/

srandmember  key  count

spop  key   //  pop a random element of the set


5.zset ( ordered set )

zadd  key  score  member [ score  member .. ]    // add one or more  member and  score of the member to the ordered set  called  key

zscore  key  member  // get the score of the member

zrange  key  start  stop  [ withscores ]      //  get the start index to  end index members of order  set  from small to large

zrevrange  key  start  stop  [ withscores ]

zrangebyscore  key   min  max  [  withscore ] [ limit  offset  count  ]  //  get the member of ordered set that  the score between  min and max

example : zrangebyscore  score  80 100

                   zrangebyscore score  80 (100

                   zrangebyscore  score  (80  +inf

                   zrangebyscore   score  -inf   +inf

                   zrangebyscore  score  80 100 limit  1  3

                   zrevrangebyscore  score 100 0 limit  0 3   // get the top three members whose score less than or equal to 100

zincrby  key  increment  member  //  make the score of the member belong to the zset  to add  ' increment '

zcard  key   /// get the counts of the zset

zcount  key  min  max   // get the counts between the min and max of the zset

zrem  key  member [ member ... ]  // del the one or more member

zremrangebyrank  key start top  //  del the members from start index to top index  according to the  score from small to large

zremrangebyscore  key  min  max  //  del the member according to the score between min and max

zrank  key  member  //  get the rank of the member that had ordered from small to large

/*

* get the intersection include key and key ...

* weights means  the score need multiply  the weight  everyone

* aggregage means to get the sum | min | max with the key and key

*/

zinterstore  destination  numkeys  key [ key ... ]  [ weights  weight  [weight ...] ]  [ aggregate sum |  min | max ]

zunionstroe  destination numkeys  key [ key ... ] [ weights weight [ weight ... ] ] [ aggregate sum | min | max ]      // like zinterstore