Redis-Data type common commands

Source: Internet
Author: User

5 types of data are inseparable from key, first listing the key's related commands.

Key related Operations
    • List rules-compliant keys

      KEYS pattern

      Pattern supports the Glob style wildcard format, which is:

      ? A character
      * Any number of characters
      [] Declaring in-range characters
    • Check if key exists

    • Delete key

      DEL key
    • View the type of key

      TYPE key

String
    • Assignment value

    • Integer increment or decrement, only if value is numeric

      INCR keyDECR key

      If you want to increase the number specified

      INCRBY key valueDECRBY key value
    • Floating-point number increase

      INCRBYFLOAT key value
    • Trailing append

      APPEND key value
    • Get length

      STRLEN key
    • Bit-related operations
      Specify access to the index:

      SETBIT key index valueGETBIT key index

      Get 1 of the quantity

      BITCOUNT key indexFrom indexTo

      Bitwise operations that support and OR not XOR operations, such as:

      BITOP OR key3 key1 key2

Hash column
    • Assignment value

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

      HEXISTS key field

      Does not exist then assign Value hsetnx key field value

    • Field increment

      HINCRBY key field value
    • Delete a field

      HDEL key field1 field2
    • View field Information

      View field names

      HKEYS key

      View field values

      HVALS key

      Number of fields

      HLEN key

List
    • Both ends increase

    • Both ends eject

      LPOP keyRPOP key
    • Get the number of elements

      LLEN key
    • Get by index
      Gets the specified index value

      LINDEX key index  

      Get fragments

      LRANGE key indexFrom indexTo
    • Assigning values by index

      LSET key index value

      Or find the pivot element from left to right in the list and insert value in front or back as determined by before or after

      LINSERT key BEFORE|AFTER pivot value
    • Delete specified value

      Delete elements before count values are value

      LREM key count value

      Keep only elements in the index range

      LTRIM key indexFrom indexTo

Collection
    • Add/Remove

    • List all elements

      SMEMBERS key
    • Set length

      SCARD key
    • Determine if there is

      SISMEMBER key value
    • Collection comparison

      • Subtraction

        SDIFF key1 key2
      • Intersection

        SINTER key1 key2
      • and set

        SUNION key1 key2

        Of course, we can also save the results of the comparison:

      • Subtraction

        SDIFFSTORE key3 key1 key2
      • Intersection

        SINTERSTORE key3 key1 key2
      • and set

        SUNIONSTORE key3 key1 key2
    • Random Fetch/Eject
      Count is the number of returns, negative numbers return |count|, but can be repeated.

      SRANMEMBER key count

      Pop

      SPOP key

Ordered collection
  • add element
  • ZADD key score1 value1 score2 value2
  • Delete Element

    • Delete the 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
  • Get points

    ZSCORE key value
  • Get elements

    • Gets the elements within the specified range, in the score positive and reverse order, with the same fractions, in the UTF-8 encoding order of value, and score if the Withscore is added.

      ZRANGE key indexFrom indexTo [WITHSCORES]ZREVRANGE key indexFrom indexTo [WITHSCORES]
    • Gets the elements within the specified fractional range, still sorted by fractions.
      Takes score to the element between Min and Max, which by default includes elements equal to Min and Max.
      If you do not plan to include, then add "(" in front of Min or Max.
      The last limit usage is similar to SQL.

      ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]
    • Get element rank

      ZRANK key valueZREVRANK key value
  • Number of elements

    Collection size

    ZCARD key

    Specifies the number of points in the range, as with Zrangebyscore, where Min and Max are included by default, including Min and Max.

    ZCOUNT key min max

Redis-Data type common commands

Related Article

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.