basic

The Redis command is size insensitive

Basic commands

  • keys
    • Description of the command: Searches for all keys that match the specified pattern (regular expression)
    • Command format:KEYS pattern
  • exists
    • Description: Returns whether the key exists
    • Command format:EXISTS key [key ...]
      • return 1Exists.
  • expire
    • Description of the command: Set the expiration time of a key. When the expiration time is exceeded, the key is automatically deleted
    • Command format:EXPIRE key seconds
      • ifkeyIf yes, run it againRefresh expiration time.
      • secondsThe unit is second.
  • ttl
    • Description: The remaining key expiration time is returned
    • Command format:TTL key
      • ifkeyDoes not exist or expired, return2 -
      • ifkeyExists and no expiration time is set- 1
  • move
    • The description of the command is as followskeyMove to the given databasedbamong
    • Command format:MOVE key db
      • If the target database has a givenkeyOr,keyDoes not exist in the current database, that ismoveWill not take effect
  • type
    • Description Of the command: ReturnkeyThe storage ofvalueThe type of data structure that it can returnstring, list, set, zsethashAnd so on
    • Command format:TYPE key
  • persist
    • Description of the command: Removes the specified valuekeyExpiration time of
    • Command format:PERSIST key
  • del
    • Description Of the command: Delete a specified batchkeys, if delete some ofkeyIf no, ignore it
    • Command format:DEL key [key ...]

String String

The command

  • SET
    • Description of the command: Sets the key to the specified string value
    • Command format:SET key value [EX seconds] [PX milliseconds] [NX|XX]
      • ifkeyExisting, overwrite directly
      • If there is an expiration time, it will refresh
      • EXIndicates the expiration timesecondsFor the unit
      • PXIndicates the expiration timemsFor the unit
      • NXSay onlykey When there is noTo set upkeyThe value of the
      • XXSay onlykey Presence ofTo set upkeyThe value of the
    • Pay attention to
      • Due to theSETCommands plus options have been completely replacedSETNX, SETEX, PSETEXSo in future releases, Redis may not recommend using andEventually abandonedThese commands
  • GET
    • Description Of the command: Returnkeyvalue
    • Command format:GET key
      • ifkeyDoes not exist, returnnil
      • ifkeyvaluenotstring, returns an error.
  • GETRANGE
    • Gets a substring of a string
    • Command format:GETRANGE key start end
      • startendIt can be positive or negative. A positive number that is, fromOn the leftSo let’s start with negative numbersOn the rightLet’s start counting.- 1That’s the last character,2 -It’s the second to last.
  • GETset
    • Description of the command: Obtain the value firstkeyThe old value of, and then givekeySet the new value
    • Command format:GETSET key newvalue
      • newvalueSaid the new value
  • APPEND
    • Description of the command: AppendvalueTo the originalvalueAt the end of the
    • Command format:APPEND key value
      • ifkeyIf yes, append the value to the end of the original value
      • ifkeyIf no, create a new onekeyThen append
  • SETRANGE
    • Description of the command: Overwrite the correspondingkeyvalueThe specified range of values
    • Command format:SETRANGE key offset value
      • If the offset exceeds the length of the existing string value, 0 needs to be added to reach the offset. The maximum length of offset is 229=5368709112^{29} = 536870911229=536870911

  • STRLEN
    • Description Of the command: ReturnkeystringtypevalueThe length of the
    • Command format:STRLEN key
      • keystringType, an error is returned
  • SETNX
    • The meaning of this command is as followskeySet values for thevalueIf thekeyIt doesn’t exist. It’s equivalent in this caseSETCommand. whenkeyThere is,Do nothing.SETNXIs short for SET if Not eXists.
    • Command format:SETNX key value
  • SETEX
    • Description of the command: SetkeyCorresponding stringvalueAnd setkeyIn a givensecondsThe timeout period expires
    • Command format:SETEX key seconds value
  • INCR
    • The description of the command is as follows: Specifies the value of the storagekeyPerforms the atomic increment operation on the numeric value of
    • Command format:INCR key
      • If the specifiedkeyDoes not exist, then in executionincrBefore the operation, its value is set to0
      • If you specifykeyExists, but the value is not a character type orValues cannot be expressed as integersThat is, return an error
      • This operation is limited to64Bit signed integer data
  • INCRBY
    • The meaning of this command is as followskeyThe corresponding number plus the specified step sizedecrement
    • Command format:INCRBY key increment
      • keyIf it does not exist, it is set to 0 first
      • keyCharacters that exist but are not numeric are returned in error
      • Maximum operation support64Bit a signed positive number
  • DECR
    • Description: YeskeySubtract the corresponding number1operation
    • Command format:DECR key
  • DECRBY
    • The meaning of this command is as followskeyThe corresponding number minus the specified step sizedecrement
    • Command format:DECRBY key decrement

List the List

The command

  • LPUSH
    • Insert a value to the first position on the left of the list (if the list does not exist, a new list will be created automatically)
    • Command format:LPUSH key element1 element2 element3
  • RPUSH
    • Insert a value to the first position on the right of the list (the list does not exist, a new list will be created automatically)
    • Command format:RPUSH key element1 element2 element3
  • LPUSHX
    • When a list exists, insert a value to the first position on the left of the list
    • Command format:LPUSHX key element1 element2 element3
  • RPUSHX
    • When a list exists, insert a value to the first position on the right of the list
    • Command format:RPUSHX key element1 element2 element3
  • LPOP
    • The command is used to display the first left element in the list
    • Command format:LPOP key
      • Return nil if key does not exist
  • RPOP
    • Description of the command: Displays the element in the first position on the right of the list
    • Command format:RPOP key
      • Return nil if key does not exist
  • BLPOP
    • The meaning of this command is a blocking list. If givenkeyThere’s at least one non-empty list, thenPops the head element of the first non-empty list encountered, along with the name key of the list to which the pop-up element belongsIs returned to the caller. If givenkeyDoes not exist or contains an empty list,BLPOPBlocking the connection, until there is another client for the givenkeyAny one ofperformLPUSHRPUSHSo far the command.
    • Command format:BLPOP list1 list2 list3 timeout
      • If list1 is empty and list2 is not, the first element of List2 and the name of List2 are returned;
      • If list1, list2, and List3 are empty or do not exist, a block is initiated waiting for the list to insert elements
      • Timeout Specifies a non-zero timeout parameter for blocking. When timeout=0, the blocking time is unlimited.
  • BRPOP
    • Command meaning: The command has the same meaningBLPOPConsistent. The difference is from the listTail (right) startsPop-up element
    • Command format:BRPOP list1 list2 list3 timeout
      • According to thelist1 > list2 > list3Sequential start check non-empty list iflist1Is empty,list2Not null, that is, returnlist2The first element in the tail.
  • LRANGE
    • Description: Returns the elements in a specified range in a list.
    • Command format:LRANGE key start end
      • startendAre allStart with zeroThe offset of.
      • startendCan beA negative number.- 1Represents the last element of the list,2 -It’s the penultimate element.
        • Such as:LRANGE mylist 0 -1 Representing the output listAll the elements.
  • LINDEX
    • Description Of the command: Return to the listSpecify the subscriptValue of, subscript from0Start index.
    • Command format:LINDEX key index
      • keyReturn when not a listerror
      • indexIt could be negative.- 1Represents the last element,2 -Represents the penultimate element
  • LLEN
    • Description: Returns the length of a list.
    • Command format:LLEN key
      • keyReturns if it does not exist0
      • keyThere is, butNot a listWhen to return toerror
  • LREM
    • Removes a specified number of specific elements from a list
    • Command format:LREM list count element
      • listIs the list name
      • countIs the number of removals
        • count > 0Left to rightStart removing matched elements
        • count = 0Removes all matching elements
        • count < 0Right to leftStart removing matched elements
      • elementSpecifying element values
  • LTRIM
    • Truncate a list of elements, that is, to find a list of subsets.
    • Command format:LTRIM key start stop
      • startstopIs made up of0Start counting.0Represents the first element of the list.
        • Such asLTRIM mylist 0 2Only the list is retained as a resultbefore3Elements.
  • RPOPLPUSHstartstopIt could be a negative number,- 1Represents what’s in the listThe last element.2 -The penultimate
    • Eject the first element on the right of the source list and insert it into the first position on the left of the target list.
    • Command format:RPOPLPUSH source destination
      • sourceSource list. ifsourceDoes not exist, returnnilNo further operation is performed.
      • destinationTarget list.
      • ifsourcedestinationPointing to the same list is equivalent to removing the listThe last element(the first element on the right) and insert into the listHead (left)
  • BRPOPLPUSH
    • Command meaning:RPOPLPUSHBlocked version of.
    • Command format:BRPOPLPUSH source destination timeout
      • timeout nonzeroThe blocking time of.timeout = 0That is, the client connection is blocked indefinitely.
  • LSET
    • Command description: Set the subscript position specified in the list.index) is the specified value (value)
    • Command format:LSET key index value
      • indexOut of range, returnserror
  • LINSERT
    • Inserts a value before or after the specified element value in the list.
    • Command format:LINSERT key BEFORE|AFTER pivot value
      • keyWhen it doesn’t exist,No action is performed.
      • keyThere is, but ** is not onelist**, returns error
    • Command example:
      • LINSERT mylist BEFORE "world" "There"
        • Said tomylistIn the listworldInsert before elementThereThe element

Set the Set

The command

  • SADD

    • Add one or more specified member elements to the key of the collection
    • Command format:SADD key member [member ...]
      • If the collectionkeyDoes not exist, a new collection is created and elements are added to the collection
      • If the element is already in the collectionkeyIf, it willIgnore that elementContinue to insert other elements
      • ifkeyThe type ofIs not set, an error is returned
      • Redisversion> = 2.4, can accept multiple parameters;2.4 Previous versionEvery timeOnly allowAdd an element
  • SPOP

    • Description of the command: FromkeyIn the collectionRemove and returnOne or morerandomThe element
    • Command format:SPOP key [count]
      • countRepresents the collection from whichkeyRemove and returnHow many random elements
      • countThis parameter is not available in earlier versions2.6, 2.8, 3.0This parameter cannot be used in the version
      • countWhen the parameter value is passedThe number of elements greater than the setReturns the entire collection
      • keyReturns if it does not existnil
  • SCARD

    • Description: Returns the number of elements in a collection
    • Command format:SCARD key
      • keyReturns if it does not exist0
  • SREM

    • Removes the specified element from the collection
    • Command format:SREM key member [member ...]
      • ifkey It’s not a set, an error is returned
      • ifkeyIf the collection does not exist, return0
      • Multiple element parameters can be specified, less than2.4Only one element parameter can be specified in the version of
      • ifkeyIn the collectionThere is noThe specified element is ignored
  • SMOVE

    • Move an element from the source collection to the target collection
    • Command format:SMOVE source destination member
      • ifsourceIf the source collection does not exist, nothing is done and returns0
      • ifsourceThe source collection does not contain the specified element, does nothing and returns0
      • fromsourceRemoves the specified element from the source collection and adds it todestinationTarget collection, returns on successful execution1
      • ifdestinationIf the specified element exists in the target collection, the command is executedWill only remove sourceElements of the source collection
      • ifsource destinationIs not a collection type, an error is returned
  • SISMEMBERS

    • Check whether the specified element exists in the collection
    • Command format:SISMEMBER key member
      • If it exists, it returns1; Returns if it does not exist0
  • SMEMBERS

    • Description: Returns all elements of the key set
    • Command format:SMEMBERS key
  • SRANDMEMBER

    • Description: Returns a specified number of random elements in a collection
    • Command format:SRANDMEMBER key [count]
      • Command is executed without removing elements from the collection
      • Redis 2.6Start, acceptablecountparameter
      • ifcountPositive and greater thanThe total number of elements of the collection, returns all elements of the collection,No extra elementsThere are no repeating elements
      • ifcountPositive and less thanThe total number of elements in the collectioncountZero random elements, no repeating elements
      • ifcountNegative and the absolute value is greater thanThe total number of elements in the collection, then the returned result appearsAn element occurs more than onceThe number of elements returned is alsoWill be equal to countThe absolute value of
  • SSCAN

    • Iterates incrementally over a collection element
    • Command format:SSCAN cursor [MATCH pattern] [COUNT count]
  • SDIFF

    • Find the elements of the difference between a set and a given set
    • Command format:SDIFF key [key ...]
      • keyIf it does not exist, the default value isAn empty set

  • SDIFFSTORE
    • Take the difference between two sets and save the result to the target set
    • Command format:SDIFFSTORE destination key [key ...]
      • Such asSDIFFSTORE key key1 key2In the commandkeyIs the target set, which is used to save the difference setReturns the number of elements of the difference set
      • If the target setdestinationIf yes, override
  • SUNION
    • The command is used to obtain the union of multiple sets
    • Command format:SUNION key [key ...]
      • There is nothekeyBe regarded asEmpty collection

  • SUNIONSTORE
    • Fetch the union of multiple sets and save the result to the target set
    • Command format:SUNIONSTORE destination key [key ...]
      • destinationRepresents the target set
      • If the target setdestinationIf yes, thenCover to rewrite
      • After the command is executed successfully, the number of elements in the union is returned
  • SINTER
    • Fetch the intersection of multiple sets
    • Command format:SINTER key [key ...]
      • If only one empty set exists in the specified set, the result must be empty
      • keyIf it does not exist, it is considered an empty set

  • SINTERSTORE
    • Take the intersection of multiple sets and save the result to the target set
    • Command format:SINTERSTORE destination key [key ...]
      • destinationIs the target set
      • Overrides if the target collection already exists

Hash Hash

The command

  • HSET
    • Description of the command: sets a key/value pair in a specified hash set
    • Command format:HSET key field value
      • If you specify the hash setkeyIf it does not exist, a new hash set will be created and associated withkeyassociated
      • If the field already exists, its value is overridden
  • HMSET
    • Description of this command: Indicates a specified passkeyHash set addedMultiple key-value pairs
    • Command format:HMSET key field value [field value ...]
      • ifkeyIf the hash set does not exist, a new hash set is created
  • HSETNX
    • Description of the command: If the specified field does not exist in the specified key hash set, a field is added and its value is set
    • Command format:HSETNX key field value
      • ifkeyIf the hash set does not exist, a new hash set is created
      • iffieldIf a field exists, its value will not be set
  • HGET
    • Description Gets the value of the specified field in the specified hash set
    • Command format:HGET key field
      • The field does not exist orkeyIf no, returnnil
  • HMGET
    • Description: Gets the values of multiple fields in a specified hash set
    • Command format:HMGET key field [field ...]
      • Returns each field that does not exist in the hash setnil

      • The return order is the same as the field request order
  • HEXISTS
    • Description Of the command: Checks whether the specified field exists in the hash set
    • Command format:HEXISTS key field
      • Exists, return1
      • Does not exist, return0
  • HGETALL
    • Description: Gets all the fields in the specified hash set and their corresponding values
    • Command format:HGETALL key
      • If key does not exist, an empty list is returned
      • Returns the value next to the name of each field in the list
  • HKEYS
    • Description of the command: Returns the names of all fields in a hash set
    • Command format:HKEYS key
      • keyReturns an empty list if it does not exist
  • HVALS
    • Description: Returns the values of all fields in the hash set
    • Command format:HVALS key
      • keyReturns an empty list if it does not exist
  • HLEN
    • Description: Returns the total number of fields in a hash set
    • Command format:HLEN key
      • keyReturns if it does not exist0
  • HSTRLEN
    • Returns the length of a string for the value of a specified field in the hash set
    • Command format:HSTRLEN key field
      • ifkeyDoes not exist orfieldIf no, return0
  • HDEL
    • Description of the command: Deletes a specified field in a hash set
    • Command format:HDEL key field [field ...]
      • 2.4The above version, accept multiplefieldParameter, the lower version can only accept one
      • keyIf no, return0
      • The result returned, indicating how many fields were deleted
  • HSCAN
    • Iterates incrementally over a collection element
    • Command format:HSCAN cursor [MATCH pattern] [COUNT count]
  • HINCRBY
    • Adds a value to the value of a specified field in a given hash set.
    • Command format:HINCRBY key field increment
      • incrementRepresents the increased step size
      • If the field does not exist, set it to0, and then perform the add operation
  • HINCRBYFLOAT
    • Description Of the command: Indicates the specified valuekeyOf the hash set offieldField value executionfloat Types of incrementvalue-added
    • Syntax: HINCRBYFLOAT Key field increment
      • The value of the field must be numeric
      • incrementIf it can be resolved intofloatThe value of the type

Ordered set Zset

Commands to add and query

  • ZADD
    • Description of the command: Add an element to an ordered collection.
    • Command format:ZADD key [NX|XX] [CH] [INCR] score member [score member ...]
      • parameterXX, NX, CH, INCROnly in the> = redis 3.0.2Version of
      • ifkeyType is not an ordered collection, an error is returned
      • canAdd multiple at a timeThe scorescore+ elementmember
      • If the corresponding member element already exists, that is, to modify the member elementscoreValue, andUpdate to theCorrect sort position
      • Score valuescoreIs aA double - precision floating-point typeNumeric string.-infMinus infinity,+infThat means plus infinity. Numerical range
        ( 2 53 ) = 9007199254740992 (2 ^ {53}) = – 9007199254740992

        ( 2 53 ) = 9007199254740992 (2 ^ {53}) = 9007199254740992
      • XX option, which updates existing elements. If none exists, no operation is performed
      • NX option, which does not update existing elements, but simply adds new ones
      • The CH option returns the total number of elements that have changed, including newly added elements and elements that already exist but have updated scores (the same scores will not be updated)
      • INCR option, which increments the specified element
      • Elements with the same score are sorted according to dictionary rules for the elements. Lexicographical ordering uses binary and compares byte arrays of strings.
  • ZRANGE
    • The command returns a specified range of elements in an ordered collection.
    • Command format:ZRANGE key start stop [WITHSCORES]
      • The returned elements are sorted by fraction from lowest to highest, or by dictionary if the score is the same
      • startstopIs a zero based index,0Represents the first element,1Represents the second element,- 1That’s the last to last element,2 -Represents the penultimate element
      • startstopAll containRange. Such asZRANGE myzset 0 1Returns the first and second elements of the collection
      • start Is greater than stopReturns an empty list.stopGreater than the length of the collection, returns the collection by defaultThe last oneThe element
      • WITHSCORESOption to return elements and fractions together. Format, such as:Element_1, SCORE_1, ELement_2, SCORE_2... , element_N, score_N
  • ZRANGEBYLEX
    • Description: Returns a member of a specified range in a collectionDictionaries are sorted in positive order, but requires elements ofThe scores have to be the same.
      • Command format:ZRANGEBYLEX key min max [LIMIT offset count]
        • scorescoreWhen inconsistent,Do not use this commandBecause the return result is inaccurate
        • minRepresents the smallest element in the sort position[The beginning can also be used(Start, can be used-Instead of
        • maxRepresents the largest element in the sort position[The beginning can also be used(Start, can be used+Instead of
        • LIMITIndicates whether the return result is paged and must be specifiedoffsetcount
          • offsetRepresents the starting position of the return result
          • countRepresents the number of results
  • ZRANGEBYSCORE
    • Description of the command: returns a score in an ordered setminmaxAll elements between (including fractions andminmaxEqual)
    • Command format:ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]
      • WITHSCORESOption, which returns the element and its score
      • By default, min and Max are closed ranges. To specify an open range, run theminmaxprefix(

  • ZRANK
    • Description: Returns the ranking of the specified elements in the collection, ascending from small to large
    • Command format:ZRANK key member
      • Ranking in0To start,scoreThe smallest element is ranked as0
      • memberReturns if it is not an element of the collectionnil
  • ZSCAN
    • Iterates incrementally over a collection element
    • Command format:ZSCAN key cursor [MATCH pattern] [COUNT count]
  • ZSCORE
    • The value of the specified element in the collection is returnedscoreScore value
    • Command format:ZSCORE key member
      • The return value isString representationthedoubleType of floating point Numbers

Command for statistics

  • ZCARD
    • Description: Returns the number of elements in a collection
    • Command format:ZCARD key
  • ZCOUNT
    • Description: Returns the number of elements in a specified fraction range
    • Command format:ZCOUNT key min max
  • ZLEXCOUNT
    • Description of the command: indicates a collection of statisticsBetween specified membersNumber of members of
    • Command format:ZLEXCOUNT key min max
      • Such aszlexcount zset [member1 [member5
      • minmaxIt can be either a fraction value or an element value

The command to delete an element

  • ZPOPMIN
    • The description of the command is as follows: Delete and return theThe lowest scorethecountAn element
      • Command format:ZPOPMIN key [count]
        • countThe default value of1. whencountIs greater than1, the element with the lowest score is first followed by the element with the lowest score, and then recursively.
        • The return value is a list of scores and elements
  • ZPOPMAX
    • Command meaning:
    • Command format:
  • BZPOPMIN
    • Command meaning:
    • Command format:
  • BZPOPMAX
    • Command meaning:
    • Command format:
  • ZREM
    • Command meaning:
    • Command format:
  • ZREMRANGEBYRANK
    • Command meaning:
    • Command format:
  • ZREMRANGEBYSCORE
    • Command meaning:
    • Command format:

Command to sort elements

  • ZREVRANK
    • Command meaning:
    • Command format:
  • ZREVRANGE
    • Command meaning:
    • Command format:
  • ZREVRANGEBYLEN
    • Command meaning:
    • Command format:
  • ZREVRANGEBYSCORE
    • Command meaning:
    • Command format:

Commands for collection operations

  • ZINCRBY
    • Command meaning:
    • Command format:
  • ZINTERSTORE
    • Command meaning:
    • Command format:
  • ZUNIONSTORE
    • Command meaning:
    • Command format:

Geospatial

Cardinality statistics Hyperloglog

Bitmap Bitmap