Redis and redis Design and Implementation

Source: Internet
Author: User

Redis and redis Design and Implementation

Keys are indispensable for all five data types. commands related to keys are listed first.

KEY-related operations
  • List the KEYS that match the rule

    KEYS pattern

    Pattern supports the glob-style wildcard format, namely:

    ? One character
    * Any number of characters
    [] Characters in the declared range
  • Check whether the KEY exists

    EXISTS key 
  • Delete KEY

    DEL key
  • View the KEY type

    TYPE key

 

String
  • Value assignment

    SET key valueGET key valueMSET key1 value1 key2 value2MGET key1 key2 
  • Integer increase or decrease, only when value is a number

    INCR keyDECR key

    If you want to increase the specified quantity

    INCRBY key valueDECRBY key value
  • Floating point increase

    INCRBYFLOAT key value
  • Tail append

    APPEND key value
  • Get Length

    STRLEN key
  • Bit operations
    Access to the specified index:

    SETBIT key index valueGETBIT key index

    Obtain the number of 1

    BITCOUNT key indexFrom indexTo

    Bitwise operation. and or not xor operations are supported, for example:

    BITOP OR key3 key1 key2

 

Hash
  • Value assignment

    HSET key field valueHGET key fieldHMSET key field1 value1 field2 value2HMGET key filed1 field2HGETALL key
  • Determine whether a field exists

    HEXISTS key field

    If no value exists, the value is HSETNX key field value.

  • Field Increment

    HINCRBY key field value
  • Delete Field

    HDEL key field1 field2
  • View Field Information

    View Field Names

    HKEYS key

    View Field Values

    HVALS key

    Field quantity

    HLEN key

 

List
  • Add at both ends

    LPUSH key value1 value2 value3RPUSH key value1 value2 value3 
  • Both Ends

    LPOP keyRPOP key
  • Obtain the number of elements

    LLEN key
  • Retrieve by index
    Obtains the specified index value.

    LINDEX key index  

    Get clip

    LRANGE key indexFrom indexTo
  • Assign values by index

    LSET key index value

    Alternatively, you can search for the values element from left to right in the list and insert the values to the beginning or end based on BEFORE or AFTER.

    LINSERT key BEFORE|AFTER pivot value
  • Delete a specified value

    Delete the first count elements with the value

    LREM key count value

    Only elements within the index range are retained.

    LTRIM key indexFrom indexTo

 

Set
  • Add/delete

    SADD key value1 value2SREM key value1 value2 
  • List all elements

    SMEMBERS key
  • Set length

    SCARD key
  • Determine whether there is

    SISMEMBER key value
  • Set comparison

    • Difference set

      SDIFF key1 key2
    • Intersection

      SINTER key1 key2
    • Union

      SUNION key1 key2

      Of course, we can save the comparison results as follows:

    • Difference set

      SDIFFSTORE key3 key1 key2
    • Intersection

      SINTERSTORE key3 key1 key2
    • Union

      SUNIONSTORE key3 key1 key2
  • Random acquisition/pop-up
    Count indicates the number of returned results. If the number is negative, | count | times are returned, but can be repeated.

    SRANMEMBER key count

    Pop-up

    SPOP key

     

Ordered Set
  • Add Element
  • ZADD key score1 value1 score2 value2
  • Delete Element

    • Deletes a specified element.

      ZREM key value1 value2
    • Delete by index range

      ZREMRANGEBYRANGE key indexFrom indexTo
    • Delete by score range

      ZREMRANGEBYSCORE key min max
  • Score increase

    ZINCRBY key score value
  • Score

    ZSCORE key value
  • Get Element

    • Get the elements in the specified range, in the positive and inverted order of SCORE, the SCORE is sorted in the UTF-8 encoding order of value at the same time, if WITHSCORE is added, the output carries the SCORE.

      ZRANGE key indexFrom indexTo [WITHSCORES]ZREVRANGE key indexFrom indexTo [WITHSCORES]
    • Obtains the elements within the specified score range, and is still sorted by score.
      Take the SCORE as an element between min and max. By default, it includes elements equal to min and max.
      If not, add "(" before min or max.
      The final limit usage is similar to that of SQL.

      ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]
    • Obtain element ranking

      ZRANK key valueZREVRANK key value
  • Element quantity

    SET SIZE

    ZCARD key

    Number within the specified score range. Like ZRANGEBYSCORE, min and max are involved by default, including min and max.

    ZCOUNT key min max

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.