String

  • SET the key value [EX seconds] [PX milliseconds] [XX | NX] SET values for the string key, O (1)

  • GET key Gets the value of the string key, O(1)

  • GETSET gets the old value and sets the new value, O(1)

  • MSET key value [key value …] Sets values for multiple string keys at once, O(N), where N is the number of string keys specified by the user

  • MGET key [key …] Gets the value of multiple string keys at once, O(N), where N is the number of string keys specified by the user

  • MSET key value [key value …] Set values for multiple string keys at once, O(N), where N is the number of string keys specified by the user

  • STRLEN key Gets the string value in bytes, O(1)

  • GETRANGE key start end Gets the string value O(N), where N is the length of the returned content

  • SETRANGE Key index substitute sets the specified index range of the string value, O(N), where N is the length of the modified content

  • APPEND key suffix appends the new content to the end of the value, O(N), where N is the length of the new content

  • INCRBY key increment DECRBY Key increment DECRBY Key increment

  • INCR key DECR key adds and subtracts integer values, O(1)

  • INCRBYFLOAT key increment O(1)

  • Cache, lock, ID generator, counter, speed limiter

Hash

  • HSET hash field value specifies the hash field value. O(1)

  • HSETNX Hash Field Value Sets the value of the hash field only if it does not exist, O(1)

  • HGET Hash field retrieves the value of the field, O(1)

  • O(1) HINCRBY Hash field increment Increment

  • HINCRBYFLOAT Hash Field increment Performs floating-point addition or subtraction of a numeric value stored in a hash field, O(1)

  • HSTRLEN Hash field The length of the field value in bytes, O(1)

  • HEXISTS hash field checks whether the field exists, O(1)

  • HDEL Hash field delete field, O(1)

  • HLEN hash retrits the number of fields contained in the hash, O(1)

  • HMSET hash field value [field value …] Set values for multiple fields at once, O(N), where N is the number of fields to be set

  • HMGET hash field [field …] Get the value of multiple fields at once, O(N), where N is the number of fields given by the user

  • HKEYS hash HVALS hash HGETALL Hash Retrieves all fields, all values, and all fields and values, O(N), where N is the number of fields contained in the hash

  • HSCAN hash cursor [MATCH Pattern] [COUNT number] Iterates incrementally over the key-value pairs contained in a given hash, O(N), where N is the number of iterated elements

  • Short url, user login session, store graph data

List

  • LPUSH list item [item …] Push the element to the left of the list, O(N), where N is the number of elements pushed into the list

  • RPUSH list item [item …] Push the element to the right of the list, O(N), where N is the number of elements pushed into the list

  • LPUSHX list item RPUSHX list item only pushes existing lists, O(1)

  • LPOP List pops out the leftmost element of the list, O(1)

  • RPOP List pops out the element at the far right of the list, O(1)

  • RPOPLPUSH source target RPOPLPUSH source target O(1)

  • LLEN list gets the length of the list, O(1)

  • LINDEX list index gets the element on the specified index, O(N), where N is the length of the given list

  • LRANGE list start end Gets the elements in the specified index range, O(N), where N is the length of the given list

  • LSET list index new_element Sets the new element for the specified index, O(N), where N is the length of the given list

  • LINSERT list BEFORE | AFTER target_element new_element insert element list, O (N), N is the length of a given list

  • LTRIM List start end Builds a list, O(N), where N is the length of the given list

  • LREM List Count Element Removes the specified element from the list, O(N), where N is the length of the given list

  • BLPOP list [list …] Timeout Blocking left pop-up operation, O(N), where N is the number of lists given by the user

  • BRPOP list [list …] Timeout Blocking right side pop-up operation, O(N), N is the number of lists given by the user

  • BRPOPLPUSH source target timeout Block popup, O(1)

  • Message queues, paging, to-do lists

Set

  • SADD set element [element …] Adds elements to the collection, O(N), where N is the number of elements given by the user

  • SREM set element [element …] Removes elements from the collection, O(N), where N is the number of elements given by the user

  • SMOVE Source Target Element Moves elements from one set to another, O(1)

  • SMEMBERS set gets all the elements contained in the collection, O(N), where N is the number of elements contained in the collection

  • SCARD set gets the number of elements in the set, O(1)

  • SISMEMBER set Element checks if a given element exists in the set, O(1)

  • SRANDMEMBER set [count] gets the elements in the collection randomly, O(N), where N is the number of returned elements

  • SPOP key [count] randomly removes a specified number of elements from the collection, O(N), where N is the number of elements removed

  • SINTERSTORE [destination_key] set [set …] Perform the intersection calculation for the set, O(N*M), where N is the number of the given set and M is the size of the set containing the fewest elements in the given set

  • SUNION [destination_key] set [set …] Performs a union calculation on the set, O(N), where N is the sum of the number of elements contained in all given sets

  • SIDFF [destination_key] set [set …] The difference set calculation is performed on the set, O(N), where N is the sum of the number of elements contained in all given sets

  • SSCAN hash cursor [MATCH Pattern] [COUNT number] Iterates progressively over the elements contained in a given set, O(N), where N is the number of iterated elements

  • Unique counter, tagging, liking, voting, social relations, sweepstakes, co-following and recommended following, product filter

Sorter Set

  • ZADD sorted_set [XX|NX] [CH] score member [score member …] Add or update members, O(M*log(N)), where M is the number of given members and N is the number of members contained in the ordered set

  • ZREM sorted_set member [member …] Removes the specified member, O(M*log(N)), where M is the number of given members and N is the number of members contained in the ordered set

  • ZSCORE sorted_set member = O(1)

  • ZINCRBY sorted_set increment member O(log(N)) where N is the number of members in an ordered set

  • ZCARD sorted_set gets the size of the ordered set, O(1)

  • Z[REV]RANK sorted_set member Obtains the RANK of members in the ordered set, O(log(N)), N is the number of members in the ordered set

  • Z[REV]RANGE sorted_set start end [WITHSCORES] returns the number of members in the specified index RANGE, O(log(N) + M), N is the number of members in the ordered set, M is the number of members returned by the command

  • Z[REV]RANGEBYSCORE sorted_set Max min [WITHSCORES] [LIMIT offset count] O(log(N) + M) M is the number of members returned by the command

  • ZCOUNT sorted_set min Max Counts the number of members in the specified score range, O(log(N)), where N is the number of members in the ordered set

  • ZREMRANGEBYRANK sorted_set start end Removes members in the specified rank range, O(log(N) + M), where N is the number of members contained in the ordered set and M is the number of members removed

  • ZREMRANGEBYSCORE sorted_set min Max Removes members within the specified score range, O(log(N) + M), where N is the number of members contained in the ordered set and M is the number of members removed

  • ZUNIONSTORE destination numbers sorted_set [sorted_set …] [AGGRECATE SUM | MIN | MAX] [WEIGHTS weight [weight…]] ordered set and set operations, O (N * log (N)), an ordered set of N for a given total number of members

  • ZINTERSTORE destination numbers sorted_set [sorted_set …] [AGGRECATE SUM | MIN | MAX] [WEIGHTS weight [weight…]] an ordered set of intersection operation, O (N * log (N) * M), N is the cardinality of the ordered set with the smallest cardinality of any given ordered set, and M is the number of ordered sets

  • Z[REV]RANGEBYLEX sorted_set min Max [LIMIT offset count] returns the members in the specified lexicographical range, O(log(N) + M), where N is the number of elements in the ordered set and M is the number of members returned by the command

  • ZLEXCOUNT sorted_set min Max Counts the number of members in the range specified in the lexicographical order, O(log(N)), where N is the number of members contained in the ordered set

  • ZREMRANGEBYLEX sorted_set min Max Removes members within the range specified in the lexicographical order, O(log(N) + M), where N is the number of elements contained in the ordered set and M is the number of members removed

  • ZPOP [MAX | MIN] sorted_set [count] popup score the highest and the lowest members, O (N), N for command removes the number of elements

  • BZPOP[MAX|MIN] sorted_set [sorted_set …] Timeout Blocks to pop up the highest and lowest members, O(N), where N is the number of elements removed by the command

  • ZSCAN hash cursor [MATCH Pattern] [COUNT number] Iterates over the members and scores of a given ordered set in a progressive manner, O(N), where N is the number of iterated elements

  • Leaderboards, timelines, product recommendations, automatic completion

HyperLogLog

  • PFADD hyperloglog element [element …] Count the collection elements, O(N), where N is the number of elements given by the user

  • PFCOUNT hyperloglog [hyperloglog …] Returns the approximate cardinality of the set, O(N), where N is the number of HyperLogLog given by the user

  • PFMERGE destination hyperloglog [hyperloglog …] Calculate the union of multiple HyperLogLog, O(N), where N is the number of HyperLogLog given by the user

  • Unique counter, detect duplicate information, weekly/monthly/annual counter

Bitmap

  • SETBIT bitmap offset value Sets the value of the binary bits, O(1)

  • GETBIT bitmap offset Gets the value of binary bits, O(1)

  • BITCOUNT key [start end] Indicates the number of bits to be counted. O(N) indicates the number of bytes to be counted

  • BITPOS bitmap value [start end] Searches for the first specified binary bit value, O(N), where N is the number of bytes involved in the search

  • BITOP [AND|OR|XOR|NOT] result_key bitmap [bitmap …] Performs a binary operation, O(N), where N is the total number of bytes involved in the search

  • BITFIELD bitmap [SET | GET | INCRBY | OVERFLOW] the bitmap stored in the integer value, O (N), N a given number of sub commands for the user

  • User behavior recorder, 0-1 matrix, compact counter

GEO

  • GEOADD location_set longitude latitude name [longitude latitude name …] Storage coordinates, O(log(N) * M), where N is the number of locations currently contained in the location set and M is the number of locations given by the user

  • GEOPOS location_set name [name …] Gets the coordinates of the specified position, O(log(N) * M), where N is the number of positions currently contained in the position set and M is the number of positions given by the user

  • GEODIST location_set name1 name2 [m | km | mi | ft] to calculate the linear distance between two places, O (log (N)), N for location set contains the location of the quantity at present

  • GEORADIUS location_set longitude latitude redius unit [WITHHASH] [WITHDIST] [WITHCOORD] [ASC|DESC] [COUNT n] Find other positions within the specified coordinate radius, O(N), where N is the number of positions checked when the command implements range lookup

  • GEORADIUSBYMEMBER location_set name radius unit [WITHHASH] [WITHDIST] [WITHCOORD] [ASC | DESC] [COUNT n] find other locations within a radius of the specified location, O(N), where N is the number of positions checked during the command range search

  • GEOHASH location_set name [name …] Gets the Geohash value for the specified location, O(N), where N is the number of locations given by the user

  • User location, find nearby users

Stream

  • XADD stream [MAXLEN len] id field value [field value …] Append new elements to the end of the stream, O(log(N)), where N is the number of elements the stream currently contains

  • XTRIM stream MAXLEN len Trims the stream, O(log(N) + M), where N is the number of elements contained in the stream before trimming and M is the number of elements removed

  • XDEL stream [id id… id] removes the specified element, O(log(N) + M), where N is the number of elements contained in the stream and M is the number of elements removed

  • XLEN Strem gets the number of elements in the stream, O(1)

  • X[REV]RANGE stream start-id end-id [COUNT n] Access elements in the stream, O(log(n) + M), where n is the number of elements contained in the stream and M is the number of elements returned by the command

  • XREAD [BLOCK ms] [COUNT n] STREAMS stream1 stream2 … id1 id2 … Get stream elements in blocking or non-blocking mode, O((log(N) + M) * I), get a single stream complexity of O(log(N) + M), I is the number of streams

  • XGROUP CREATE stream group start_id CREATE a consumer group, O(1)

  • XGROUP SETID Stream group ID changes the last delivery message ID of the consumer group, O(1)

  • XGROUP DELCONSUMER Stream group consumer deletes a consumer, O(N), where N is the number of messages being processed by the deleted consumer

  • XGROUP DESTROY Stream Group Removes a consumer group, O(N + M) where N is the number of messages that are still in the ‘pending’ state and M is the number of consumers that belong to the group

  • XREADGROUP GROUP group consumer [COUNT n] [BLOCK ms] STREAMS stream [stream …] id [id …] Read the consumer group, O((log(N) + M) * I), get the complexity of a single stream is O(log(N) + M), I is the number of streams

  • XACK stream group id [id id …] The consumer confirmation message, O(N), where N is the number of message ids given by the user

  • XPENDING Stream group [start stop count] [consumer] Displays information about pending messages, O(log(N) + M), where N is the number of pending messages in the consumer group and M is the number of messages returned by the command

  • XCLAIM stream group new_consumer max_pending_time id [id id …] Transfer the attribution of the message, O(N), N is the number of message ids given by the user

  • XINFO CONSUMERS stream group-name Displays information about the stream and consumer group. O(N), where N is the number of CONSUMERS in the consumer group

  • Message queue,

DataBase

  • SELECT db from database O(1)

  • KEYS pattern retrives all KEYS that match a given match, O(N), where N is the number of KEYS contained in the database

  • SCAN cursor [MATCH pattern] [COUNT Number] Iterates keys that MATCH the given parity, O(N), where N is the number of iterated elements

  • RANDOMKEY returns a RANDOMKEY, O(1)

  • SORT key [ASC|DESC] [ALPHA] [LIMIT offset count] [[GET pattern] [GET pattern] …] [STORE destination] sorts the value of the key, O(N * log(N) + M), where N is the number of sorted elements and M is the number of elements returned by the command

  • EXISTS key [key …] Check if the given key exists, O(N), where N is the number of keys given by the user

  • DBSIZE Retrieves the number of key-value pairs the database contains, O(1)

  • TYPE Key Indicates the TYPE of the key. O(1)

  • RENAME[NX] origin new RENAME key, O(1)

  • MOVE key DB Moves the given key to another database, O(1)

  • DEL key [key …] Removes the specified key, O(N), where N is the number removed

  • UNLINK key [key …] Removes the specified key asynchronously, O(N), where N is the number of keys removed

  • FLUSHDB [async] flushes the current database, O(N), where N is the number of key-value pairs in the flushed database

  • FLUSHALL [async] flushes all databases, O(N), where N is the number of key-value pairs in all databases that are flushed

  • SWAPDB x y exchange database, O(1)

  • Online replacement database

Expire

  • [P] EXPIRE key seconds | milliseconds sets the survival time, O (1)

  • [P] EXPIREAT key seconds_timestamp | milliseconds_timestamp set expiration time, O (1)

  • [P]TTL key TTL key TTL, O(1)

  • Automatic expired login session, automatic elimination of unpopular data

Transaction

  • MULTI Start transaction, O(1)

  • EXEC executes a transaction whose complexity is the sum of the complexity of all commands contained in the transaction

  • DISCARD DISCARD transaction, O(N), where N is the number of commands in the transaction queue

  • WATCH key [key …] Keys are monitored, O(N), where N is the number of monitored keys

  • UNWATCH Unmonitors keys, O(N), where N is the number of keys that are unmonitored

Lua Script

  • EVAL script numkeys key [key …] arg [arg …] Execute the script

  • SCRIPT LOAD SCRIPT Cache SCRIPT

  • EVALSHA sha1 numkeys key [key …] arg [arg …] Execute cached scripts

  • SCRIPT EXISTS sha1 [sha1 …] Check whether the script is cached

  • SCRIPT FLUSH Removes all cached scripts

  • SCRIPT KILL Forces a running SCRIPT to stop

Persistence

  • SAVE blocks the server and creates an RDB file, O(N), where N is the total number of key-value pairs contained in all databases of the server

  • BGSAVE creates a non-blocking RDB file, O(N), where N is the total number of key-value pairs contained in all databases on the server

  • BGREWRITEAOF triggers the AOF rewrite operation, O(N), where N is the total number of key-value pairs contained in all databases on the server

  • Shut down the server SHUTDOWN [save | nosave]

Pub / Sub

  • PUBLISH Channel Message Sends a message to a channel, O(N+M), where N is the number of subscribers for a given channel and M is the total number of schemas currently subscribed to by the server

  • SUBSCRIBE channel [channel …] Subscription channels, O(N), where N is the number of channels entered by the user

  • UNSUBSCRIBE channel [channel …] Unsubscribe channel, O(N), N is the number of channels entered by the user

  • PSUBSCRIBE pattern [pattern …] Subscription mode, O(N), where N is the number of modes entered by the user

  • PUNSUBSCRIBE pattern [pattern …] Unsubscribe mode, O(N*M), where N is the number of modes given by the user and M is the total number of modes currently subscribed by the server

  • PUBSUB CHANNELS [pattern] Check the subscribed CHANNELS, O(N), where N is the total number of CHANNELS currently subscribed by the server

  • PUBSUB NUMSUB [channel channel …] View the number of subscribers of a channel, O(N), where N is the number of channels given by the user

  • PUBSUB NUMPAT View the total number of subscribed modes, O(1)

  • Broadcasting system

Module

  • ReJson

  • RediSQL

  • RediSearch

Replication

  • REPLICAOF host port sets the server to the secondary server

  • REPLICAOF no one cancels the replication

  • ROLE View the ROLE of the server

Sentinel

  • SENTINEL Masters captures information about all monitored master servers

  • SENTINEL master

    gets information about the specified monitored primary server

  • SENTINEL Slaves

    Gets the slave server information of the monitored master server

  • SENTINEL

    Obtain information about other sentinels

  • SENTINEL get-master-addr-by-name

    Obtains the IP address and port number of the specified primary server

  • SENTINEL reset Resets the primary server status

  • SENTINEL failover

    Forcibly performs failover

  • SENTINEL ckquorum

    Checks the number of sentinels available

  • SENTINEL flushconfig Forcibly writes configuration files

  • SENTINEL monitor

    < IP >
    monitors a given master server

  • SENTINEL remove < mars-name > Unmonitors a given master server

  • SENTINEL set

Cluster

  • CLUSTER MEET IP port Adds a node to a CLUSTER

  • CLUSTER NODES Displays information about all NODES in a CLUSTER

  • CLUSTER MYID Displays the running ID of the current node

  • CLUSTER INFO Displays CLUSTER information

  • CLUSTER FORGET node-id Removes a node from a CLUSTER

  • CLUSTER REPLICATE master-id changes a node to a slave node

  • CLUSTER REPLICAS node-id displays all secondary nodes of a given node

  • The CLUSTER FAILOVER [FORCE | TAKEOVER] enforcing FAILOVER

  • RESET the node CLUSTER RESET [SOFT | HARD]

  • CLUSTER SLOTS Displays the information about SLOTS and nodes

  • CLUSTER ADDSLOTS slot [slot …] Assign slots to nodes

  • CLUSTER DELSLOTS slot [slot …] Unassign slots to nodes

  • CLUSTER FLUSHSLOTS unassigns all slots to a node

  • CLUSTER KEYSLOT key Displays the slot where the key resides

  • CLUSTER COUNTKEYSINSLOT Slot Displays the number of keys in a slot

  • CLUSTER GETKEYSINSLOT Slot Count Obtains the slot keys

Reference: Redis User Manual, Huang Jianhong Machine Press, September 2019

The original:www.ciphermagic.cn/redis-comma…