Basic syntax of Redis database (1)

REmote DIctionary Server (Redis) is a key-value storage system written by Salvatore Sanfilippo. Redis is an open source log-type, Key-Value database written in ANSI C language, complying with BSD protocol, supporting network, memory-based and persistent, and providing APIs in multiple languages. It is often referred to as a data structure server because values ​​can be of types such as String, Hash (Map), list (list), sets (sets) and sorted sets (sorted sets). Redis keys (key) The following table gives the basic commands related to Redis keys:

  • Serial Number Command Description

  • 1 DEL key This command is used to delete the key when the key exists.

  • 2 DUMP key Serializes the given key and returns the serialized value.

  • 3 EXISTS key Checks whether the given key exists.

  • 4 EXPIRE key seconds Sets the expiration time for the given key.

  • 5 EXPIREAT key timestamp EXPIREAT is similar to EXPIRE in that it is used to set the expiration time for the key. The difference is that the time parameter that the EXPIREAT command accepts is a UNIX timestamp (unix timestamp).

  • 6 PEXPIRE key milliseconds Set the expiration time of the key in milliseconds.

  • 7 PEXPIREAT key milliseconds-timestamp Set the timestamp of the key expiration time (unix timestamp) in milliseconds

  • 8 KEYS pattern Finds all keys matching the given pattern.

  • 9 MOVE key db Move the key of the current database to the given database db.

  • 10 PERSIST key Remove the expiration time of the key, and the key will persist.

  • 11 PTTL key Returns the remaining expiration time for the key in milliseconds.

  • 12 TTL key Returns the remaining time to live (TTL, time to live) for the given key in seconds.

  • 13 RANDOMKEY Returns a random key from the current database.

  • 14 RENAME key newkey Modify the name of the key

  • 15 RENAMENX key newkey Rename key to newkey only if newkey does not exist.

  • 16 TYPE key Returns the type of the value stored by key. Redis String (String) The following table lists common redis string commands:

  • Serial number command and description

  • 1 SET key value

  • Set the value of the specified key

  • 2 GET key

  • Get the value of the specified key.

  • 3 GETRANGE key start end

  • Returns the subcharacter of the string value in key

  • 4 GETSET key value

  • Sets the value of the given key to value and returns the old value of the key.

  • 5 GETBIT key offset

  • For the string value stored in key, get the bit at the specified offset.

  • 6 MGET key1 [key2..]

  • Get all (one or more) values ​​for the given key.

  • 7 SETBIT key offset value

  • Sets or clears the bit at the specified offset for the string value stored at key.

  • 8 SETEX key seconds value

  • Associate the value value to key and set the key's expiration time to seconds (in seconds).

  • 9 SETNX key value

  • Set the value of key only if key does not exist.

  • 10 SETRANGE key offset value

  • Overwrites the string value stored at the given key with the value parameter, starting at offset offset.

  • 11 STRLEN key

  • Returns the length of the string value stored at key.

  • 12 MSET key value [key value ...]

  • Set one or more key-value pairs at the same time.

  • 13 MSETNX key value [key value ...]

  • Simultaneously set one or more key-value pairs if and only if none of the given keys exist.

  • 14 PSETEX key milliseconds value

  • This command is similar to the SETEX command, but it sets the key's lifetime in milliseconds instead of seconds like the SETEX command.

  • 15 INCR key

  • Increments the numeric value stored in key by one.

  • 16 INCRBY key increment

  • Adds the value stored at key to the given increment.

  • 17 INCRBYFLOAT key increment

  • Adds the value stored at key to the given floating-point increment.

  • 18 DECR key

  • Decrements the numeric value stored in key by one.

  • 19 DECRBY key decrement

  • The value stored at key minus the given decrement.

  • 20 APPEND key value

  • If the key already exists and is a string, the APPEND command appends the specified value to the end of the original value of the key.

  • Redis hash (Hash)

  • The following table lists the basic related commands of redis hash:

  • Serial number command and description

  • 1 HDEL key field1 [field2] delete one or more hash table fields

  • 2 HEXISTS key field Check whether the specified field exists in the hash table key.

  • 3 HGET key field Gets the value of the specified field stored in the hash table.

  • 4 HGETALL key Gets all fields and values ​​of the specified key in the hash table

  • 5 HINCRBY key field increment is the integer value of the specified field in the hash table key plus increment increment.

  • 6 HINCRBYFLOAT key field increment is the floating point value of the specified field in the hash table key plus increment increment.

  • 7 HKEYS key to get all fields in the hash table

  • 8 HLEN key Get the number of fields in the hash table

  • 9 HMGET key field1 [field2] Get the value of all given fields

  • 10 HMSET key field1 value1 [field2 value2 ] Simultaneously set multiple field-value (field-value) pairs to the hash table key.

  • 11 HSET key field value Set the value of the field field in the hash table key to value.

  • 12 HSETNX key field value Set the value of the hash table field only when the field field does not exist.

  • 13 HVALS key Get all the values ​​in the hash table

  • 14 HSCAN key cursor [MATCH pattern] [COUNT count] Iterates the key-value pairs in the hash table. Redis List (List) The following table lists the basic commands related to the list: Sequence number command and description

  • 1 BLPOP key1 [key2 ] timeout Move out and get the first element of the list, if the list has no elements it will block the list until the wait times out or an element that can be popped is found.

  • 2 BRPOP key1 [key2 ] timeout Move out and get the last element of the list, if the list has no elements it will block the list until the wait times out or an element that can be popped is found.

  • 3 BRPOPLPUSH source destination timeout Pops a value from the list, inserts the popped element into another list and returns it; if the list has no elements, the list will be blocked until the wait times out or an element that can be popped is found.

  • 4 LINDEX key index Get the elements in the list by index

  • 5 LINSERT key BEFORE|AFTER pivot value inserts elements before or after the elements of the list

  • 6 LLEN key to get the length of the list

  • 7 LPOP key move out and get the first element of the list

  • 8 LPUSH key value1 [value2] Insert one or more values ​​into the head of the list

  • 9 LPUSHX key value inserts a value into the head of an existing list

  • 10 LRANGE key start stop Get elements within the specified range of the list

  • 11 LREM key count value removes list elements

  • 12 LSET key index value Set the value of the list element by index

  • 13 LTRIM key start stop Trim a list, that is, let the list retain only the elements within the specified range, and the elements not within the specified range will be deleted.

  • 14 RPOP key removes and gets the last element of the list

  • 15 RPOPLPUSH source destination removes the last element of a list and adds that element to another list and returns

  • 16 RPUSH key value1 [value2] Add one or more values ​​to a list

  • 17 RPUSHX key value Add a value to an existing list Redis set (Set) The following table lists the basic commands of Redis set: Serial number command and description

  • 1 SADD key member1 [member2] Add one or more members to the set

  • 2 SCARD key to get the number of members of the set

  • 3 SDIFF key1 [key2] Returns the difference of all sets given

  • 4 SDIFFSTORE destination key1 [key2] Returns the difference of all sets given and stored in destination

  • 5 SINTER key1 [key2] Returns the intersection of all sets given

  • 6 SINTERSTORE destination key1 [key2] Returns the intersection of all sets given and stored in destination

  • 7 SISMEMBER key member Determines whether the member element is a member of the set key

  • 8 SMEMBERS key returns all members in the set

  • 9 SMOVE source destination member Move the member element from the source collection to the destination collection

  • 10 SPOP key removes and returns a random element in the set

  • 11 SRANDMEMBER key [count] Returns one or more random numbers in the collection

  • 12 SREM key member1 [member2] removes one or more members from the set

  • 13 SUNION key1 [key2] Returns the union of all the given sets

  • 14 SUNIONSTORE destination key1 [key2] The union of all the given sets is stored in the destination set

  • 15 SSCAN key cursor [MATCH pattern] [COUNT count] Iterate over the elements in the set Redis sorted set (sorted set) The following table lists the basic commands of redis sorted set: Sequence number command and description

  • 1 ZADD key score1 member1 [score2 member2] Add one or more members to the sorted set, or update the scores of existing members

  • 2 ZCARD key to get the number of members of the sorted set

  • 3 ZCOUNT key min max counts the number of members of the specified interval score in the sorted set

  • 4 ZINCRBY key increment member In the ordered set, add the increment to the score of the specified member

  • 5 ZINTERSTORE destination numkeys key [key ...] Computes the intersection of one or more given sorted sets and stores the result set in a new sorted set key

  • 6 ZLEXCOUNT key min max Calculate the number of members in the specified dictionary interval in the sorted set

  • 7 ZRANGE key start stop [WITHSCORES] Returns an ordered set through the index interval into members in the specified interval

  • 8 ZRANGEBYLEX key min max [LIMIT offset count] Returns the members of the sorted set through the dictionary interval

  • 9 ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT] Returns the members in the specified interval of the sorted set by score

  • 10 ZRANK key member Returns the index of the specified member in the sorted set

  • 11 ZREM key member [member ...] removes one or more members from the sorted set

  • 12 ZREMRANGEBYLEX key min max removes all members of the given dictionary interval in the sorted set

  • 13 ZREMRANGEBYRANK key start stop removes all members of the given ranking range in the sorted set

  • 14 ZREMRANGEBYSCORE key min max removes all members of the given score interval in the sorted set

  • 15 ZREVRANGE key start stop [WITHSCORES] Returns the members in the specified interval of the ordered set, through the index, the scores are from high to bottom

  • 16 ZREVRANGEBYSCORE key max min [WITHSCORES] Returns the members in the specified score interval in the sorted set, the scores are sorted from high to low

  • 17 ZREVRANK key member Returns the rank of the specified member in the ordered set, and the ordered set members are sorted in descending order (from large to small)

  • 18 ZSCORE key member Returns the ordered set, the score value of the member

  • 19 ZUNIONSTORE destination numkeys key [key ...] Calculates the union of one or more ordered sets given and stores in a new key

  • 20 ZSCAN key cursor [MATCH pattern] [COUNT count] Iterate over the elements in the sorted set (including element members and element scores)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325819300&siteId=291194637