当前位置:网站首页>Redis common commands

Redis common commands

2022-07-07 09:20:00 Wow, it's a small dish

Other operating

  • select 0 Select the first 0 A database
  • randamkey Get random key, For example, three key:key1,key2,key3, Will return these three randomly key One of them
  • move myString 1 Put the current database key Move to a database , The target library has , You can't move
  • type key Returns the current key Of value type , May be string,list etc.
  • keys * Returns all current key
  • del key1 Delete key1
  • exists key Judge whether it exists key 0 Why not 1 be for the purpose of
  • expire key1 10 Set up key1 Expires in ten seconds
  • pexpire key1 5000 Set up key1 Expire in five seconds
  • persist key1 Delete expiration time

string

  • set key1 value1 ex 10 Set up key1 And the value ,10 It will expire in seconds
  • set key value Set up key and value
  • get key obtain key Of value
  • getrange key1 0 -1 Intercepting string , Including head and tail , from 0 Start
  • getset key1 newvalue Set and return the old value
  • mset key1 value1 key2 value2 key3 value3 Batch settings key and value Value
  • mget key1 key2 key3 Batch acquisition key1 key2 key3 Value
  • setnx key value Insert if it doesn't exist (not exists) return 0 or 1, Represents the success or failure of the operation
  • set key value nx Insert if it doesn't exist return value
  • set key value xx Must exist before inserting , Returns the inserted value
  • setrange key index value from index Start replacing value , Return string length
  • incr key Increasing key
  • incrby key2 10 to key2 Increasing 10
  • decr key2 key2 Decline 1
  • decrby key2 5 key2 Decline 5
  • incrbyfloat key3 0.5/-0.5 Floating point number increase or decrease
  • append key tail Additional
  • strlen key return key The length of

hash

  • hset hashname key1 value Go to hashname Of hash To add a key-value pair
  • hget hashname key1 obtain hashname in key Of value
  • hmset hashname key1 value1 key2 value2 Set key value pairs in batch
  • hmget hashname key1 key2 Batch fetch value
  • hgetall hashname Get all key value
  • hexists hashname key1 Judge key Whether there is return 0,1
  • hsetnx hashname keynx value Set nonexistent key
  • hincrby hashname key1 10/-2 Set up key1 Increasing 10
  • hdel hashname key Delete key
  • hkeys hashname Get all key
  • hvals hashname Get all value
  • hlen hashname To obtain the length of the ( Namely map The number of key value pairs inside )

list

  • lpush listname value1 value2 value3 Insert left
  • rpush listname value1 value2 value3 Right insert
  • lrange listname start end From 0 Everything from the first to the last ( Including head and tail )
  • lpop listname Pop up an element on the left
  • rpop listname Pop up an element on the right
  • llen listname Get the length of the list ( Element number )
  • lrem listname conunt value Remove elements for example :lrem list1 2 ccc : Delete list1 The two values from the left are ccc The elements of , The returned value is the number of deleted
  • lindex listname index(0,1 etc. ) Take out No n It's worth , Index starts from zero
  • lset list index value Set the value of the index
  • ltrim list startindex endindex Intercept list Some of the elements of , Delete other elements
  • linsert list before value towards list Medium value Insert... Before element
  • linsert list after value towards list Medium value Insert after element
  • rpoplpush sourcelist destinationlist take sourcelist Pop up an element on the right , Insert left destinationlist, Return that element
  • sort listname alpha Alphabetical order

set

  • sadd set value1 value2 value3 towards set Add elements to it , Returns the number of elements successfully added
  • smembers set set All elements in
  • srem set value1 value2 Delete elements from the collection , Returns the number of successfully deleted
  • sismember set value Judge value Whether there is set in , return 0 perhaps 1
  • scard set obtain set Number of members of the set
  • sdiff set1 set2 seek set1 and set2 And return
  • sinter set1 set2 seek set1 and set2 Intersection of and return to
  • sunion set1 set2 seek set1 and set2 Union
  • srandom set from set Take random elements
  • spop set Pop up the first element from the collection , Return the pop-up element

zset Ordered set ( Ranking List )

  • zadd zset score value … towards zset Add elements to it , Can be added more than once , Returns the number of added elements , for example zadd zset 1 jack 2 mike 3 lily If there is only one element , Just return the score of this element
  • zincrby zset score value to value Elements increase scores , for example :zincrby zset 2 lily to lily Element increases by two points
  • zcard zset obtain set Number of members of the set
  • zscore zset value Get the score of this element
  • zrange zset beginindex endindex withscores Get all the elements of the set through fractional sorting , And show the score , With head and tail
  • zcount zset minscore maxscore Get the number of members in the specified score interval
  • zrangebyscore zset min max withscores Gets the element of the specified range ( With head and tail )
  • zrangebyscore zset min max withscores limit 0,10 Pagination ( skip 0 strip , take 10 Data , If you inquire about page 5 , Namely 40,10)
  • zrem zset value1 value2 Remove elements from collection , The return value is the number of elements removed
  • zremrangebyrank minrank maxrank Remove the elements of the specified ranking interval
  • zremrangebyscore minscore maxscore Remove the element of the specified score interval
  • zrank zset element Returns the index of the specified element , from 0 Start
  • zrevrank zset element Returns the index of the specified element , In reverse order of fractions
原网站

版权声明
本文为[Wow, it's a small dish]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130626220898.html