Five basic Types
Key (keys)
Common commands:
Keys * Check the name of all keys exists keys in the current library
to determine if a key exists. A return of 1 indicates that there is, and 0 means not present.
move key (that key) db (which library, as shown in the second library labeled 1), the current library is gone and moved to another library.
expire key seconds: Sets the expiration time for the given key.
TTL key to see how many seconds have expired, 1 means never expires, 2 indicates expired. (Time to Leave)
using this command, after the key expires, the in-memory key will be removed, keys *, get key can not find this expired key. The key created by default is never expired. Type
key to see what your key is. such as type MyList. The List is returned. Type strkey. A string is returned. A type keyword usage similar to JavaScript.
DEL Key: This command is used to remove key when a key is present.
DUMP Key: Serializes the given key and returns the serialized value.
expireat key timestamp:expireat functions like expire and is used to set the expiration time for a key. The difference is that the time parameter accepted by the Expireat command is a UNIX timestamp (Unix timestamp).
pexpire Key millseconds: Sets the expiration time of the key in milliseconds.
Randomkey: Randomly returns a key from the current database.
raname key Newkey: Change the name of the key.
Renamenx key Newkey: Rename key to Newkey only if Newkey does not exist.
Redis string "string"
Single value single Vlaue
Common:
Set key value: Sets the values for the specified key.
Get key: Gets the value of the specified key.
DEL key: Deletes the value of the specified key.
GETRANGE Key Start end: Returns the child character of the string value in key.
Getset Key value: Sets the value of the given key to value and returns the old value of the key.
Getbit Key Offset: The string value stored on key, which gets the bit on the specified offset (bit). MGET Key1[key2 ...]
: Gets the value that has (one or more) a given key.
Setbit Key Offset value: Sets or clears a bit (bit) on the specified offset for the string value stored by key.
Setex Key seconds value (set with expire): Associates value values to key and sets the expiration time of key to seconds (in seconds).
Associates a value of values to a key and sets the lifetime of the key to seconds (in seconds). If the key already exists, the Setex command will overwrite the old value.
Similarly, the set can also cover Setex. This command is similar to the following two commands: Set key value EXPIRE key seconds # Setting the lifetime difference is that Setex is an atomic (atomic) operation, the associated value and setting the time to live two actions will be completed at the same time, the command in Redi
S is useful when used as a cache.
Setnx key value (set if not exist): Sets the value of key only if the key does not exist.
SETRANGE Key Offset Value: Use the value parameter to write to the string value stored by the key, starting with offsets offset.
STRLEN key: Returns the length of the string value stored by key. MSET key Value[key Value ...]
(more set): Set one or more key-value pairs at the same time. Msetnx key Value[key Value ...] Set one or more key-value pairs at the same time, when and only if the given key does not exist. If one exists, then the execution of the statement fails, returning 0. This is important to distinguish the sadd of the SET below. "Sadd SET01 1 1 2 2 3 3 "This is successful, and successfully inserted into the set01 there are three values, 1 2 3, respectively.
Psetex key milliseconds value: This command is similar to the Setex command, but it sets the lifetime of the key in milliseconds, rather than the Setex command, in seconds. INCR key: Increase the number value stored in key by one.
Returns the added value. Incrby Key Increment: Adds the value stored by key to the given increment value (increment).
Returns the added value.
Incrbyfloat Key Increment: Adds the value stored by key to the given floating-point increment value (increment). DECR key: Subtract one of the numeric values stored in key.
Returns the value after subtracting. Decrby key Decrement:key stores the value minus the given decrement value (decrement).
Returns the value after subtracting.
If the added or minus value is not a number, then the error is ... APPEND key value: If key already exists and is a string, the APPEND command appends value to the end of the original value of the key. and returns the final length of the string. If key does not exist, create one.
It is worth mentioning that Redis if the successful execution generally returns 1, greater than 1 of the number, the execution fails to return 0, nil, error, and so on. Redis lists (list)
Single-valued Multiple value
Blpop Key1[key2] Timeout: Moves out and gets the first element of the list, if no element of the list blocks the list until the wait time out or the popup element is found.
Brpop Key1[key2] Timeout: Moves out and gets the last element of the list, if no element of the list blocks the list until the wait time out or the popup element is found.
Rpoplpush source Destination: Removes the last element of the list and adds the element to the other list header and returns it. Brpoplpush source Destination timeout: POPs a value from the list, inserts the pop-up element into the head of another element, and returns it, if no element of the list blocks the list until the wait time-out or the popup element is found.
This method is a blocking version of Rpoplpush.
LINDEX Key index: Gets the elements in the list by index. Linsert Key Before |
After pivot value: Inserts a value in the list key, either before or after the value pivot.
When pivot does not exist in the list key, no action is taken.
When key does not exist, key is treated as an empty list, and no action is taken.
If key is not a list type, an error is returned.
Llen key: Gets the list length.
Lpop key: Moves out and gets the first element of the list.
Rpop key: Removes and gets the last element of the list.
Rpush Key Value1[value2]: Adds one or more values to the tail of the list.
Rpushx Key value: Inserts one or more value values into the footer of the list key when and only if key exists and is a list.
As opposed to the Rpush command, when key does not exist, the RPUSHX command does nothing.
Lpush Key Value1[value2]: Inserts one or more values into the list header.
Lpushx Key value: Inserts one or more values into the list header that already exists.
Lrange key start stop: Gets the element within the specified range of the list.
Returns the element in the specified interval in the list key, with the interval specified by the offset start and stop.
The subscript (index) parameter start and stop all end with 0, that is, 0 represents the first element of the list, 1 represents the second element of the list, and so on. You can also use a negative subscript to 1 to indicate the last of the listElement, 2 represents the second-to-last element of the list, and so on.
Lrem Key Count value: Removes the element in the list that is equal to the parameter value, based on the value of the parameter count.
The value of count can be one of the following: Count > 0: Searches from the header to the end of the table, removes the element equal to value, and counts as count.
Count < 0: Searches the header starting at the end of the table, removing the element equal to value, and the number is the absolute value of count.
Count = 0: Removes all values that are equal to value in the table.
LSET Key Index Value: Sets the values of the list elements by index. LTRIM Key start stop: Trims a list (trim), which means that the list retains only the elements within the specified interval, and the elements that are not within the specified range are deleted.
List Performance Summary:
It is a list of strings, left and right can be inserted to add;
If the key does not exist, create a new linked list;
If the key already exists, what's new;
If the value is all removed, the corresponding key disappears.
The operation of the list is very efficient, whether it is the head or tail, but if the intermediate element is operated, the efficiency is slightly lower. Redis Collection (set)
Sadd Key Member1[member2]: Adds one or more members to the collection.
SCard Key: Gets the number of members of the collection.
smembers key: Returns all members in the collection.
Sdiff Key1[key2 ...] : Returns the difference set for the given all collections. All items in the first set and not in any of the subsequent set.
sdiffstore Destination Key1[key2]: Returns the set of differences given for all sets and is stored in destination.
SINTER Key1[key2]: Returns the intersection of all collections given.
sinterstore Destination Key1[key2]: Returns the intersection of all sets given and stored in destination.
Sismember Key member: Determines whether the member element is a member of the collection key.
Smove Source Destination member: Moves the member element from the source collection to the destination collection.
SPOP key: Removes and returns a random element in the collection.
srandmember Key [count]: returns one or more random numbers in the collection.
Srem Key Member1[member2]: Removes one or more members from the collection.
sunion Key1[key2]: Returns the set of all the given sets. Automatic de-weight.
sunionstore Destination Key1[key2]: The assembly of all the given collections is stored in the destination collection.
sscan key Cursor[match Pattern][count COUNT]: Iterates over the elements in the collection.
specific Sscan usage crossing Web document: http://redisdoc.com/key/scan.html
Redis Hash (hash)
Hdel key field1[field2 ...] : Delete one or more specified hash fields in the hash table key, and the nonexistent fields will be ignored.
hexists key field: View Hash table key, whether the specified field exists.
hget key field: Gets the value that is stored in the specified field in the hash table.
Hgetall key: Gets all the fields and values of the specified key in the hash table.
hincrby key field increment: Adds an incremental increment to the integer value of the specified field in the hash table key.
hincrbyfloat key field increment: Adds an incremental increment to the floating point value of the specified field in the hash table key.
Hkeys key: Gets all the fields in the hash table.
Hlen key: Gets the number of fields in the hash table.
hmget key field1[field2 ...] : Gets the value of all given fields.
hmset key field1 value1 [Field2 value2 ...] : Set multiple Field-value (domain-value) pairs to the hash table key at the same time.
hset key field value: Sets the values of field fields in the hash table key to value.
hsetnx key Field Vlaue: Sets the value of the hash table field only if field fields do not exist.
hvals key: Gets all the values in the hash table.
HSCAN key cursor [MATCH pattern] [count Count]: Iterates over key-value pairs in the hash table.
hstrlen key field:
returns the string length of the value in the hash table key that is associated with the given field field (string lengths).
if the given key or domain does not exist, then the command returns 0.
Redis ordered set "Zset (sorted set)"
On set basis, add a score value.
Before set is K1 v1 v2 v3,
Now Zset is K1 score1 v1 score2 v2
Zadd key Score1 member1 [Score2 member2 ...]
: Adds one or more members to an ordered collection, or updates a member score that already exists.
Zcard key: Gets the number of members of an ordered collection.
Zcount Key min Max: Calculates the number of members that specify interval fractions in an ordered collection.
Zincrby Key Increment member: The fractional plus increment increment of the specified member in an ordered collection. Zinterstore destination Numkeys Key[key ...]
: Computes the intersection of one or more ordered sets given, where the number of a given key must be specified with the Numkeys parameter and the intersection (result set) is stored to destination.
By default, the score value of a member in the result set is the sum of the score values for that member under all given sets.
For more information, please see redisdoc.com's instructions.
Zlexcount Key min Max: An ordered set key key that has the same score for all members, this command returns the number of elements in the collection that are in the range of Min and Max.
The min parameter of this command and the value of the Max parameter are the same as the min parameter of the Zrangebylex command and the max parameter.
Zrange key start Stop [Withscores]: Returns the members of an ordered set within a specified range by an index interval.
Returns the member of the ordered set key, within the specified interval.
The positions of the members are sorted by increasing the score value (from small to large).
Members with the same score value are sorted by dictionary order (lexicographical order).
Use the Zrevrange command if you want members to be arranged in descending order of score values (from large to small).
The subscript parameter start and stop are based on 0, that is, 0 indicates the first member of an ordered set, 1 indicates the second member of an ordered set, and so on.
You can also use a negative subscript, which means 1 for the last member, 2 for the penultimate member, and so on.
An out-of-range subscript does not cause an error.
For example, when the value of start is larger than the maximum subscript for an ordered set, or Start > Stop, the Zrange command simply returns an empty list. On the other hand, if the value of the stop parameter is larger than the maximum subscript for an ordered set, Redis treats stop as the maximum subscript。
You can return the member and its score value by using the Withscores option, which returns the format representation of the list in Value1,score1, ..., Valuen,scoren.
The client library may return some more complex data types, such as arrays, tuples, and so on. Zrangebylex key min Max [LIMIT offset count]: When all members of an ordered collection have the same score, the elements of an ordered set are sorted according to the dictionary order of the members (lexicographical ordering), and the Life
Allows you to return a member with a value between Min and Max, given an ordered collection key key.
If the members in an ordered set have different scores, the result returned by the command is unspecified (unspecified). The command uses the MEMCMP () function of the C language to compare each member of the collection by byte-by-bit (Byte-by-byte Compare) and returns the sorted collection member in order from low to high.
If a portion of the two strings is the same, then the command will assume that the longer string is larger than the shorter string. The optional Limit offset count parameter is used to get the matching element in the specified range (just like the SELECT LIMIT offset count statement in SQL).
One thing to note is that if the value of the offset parameter is very large, then the command needs to traverse to the position specified by offset before returning the result, which adds the most O (N) complexity to the command.
The legal min and Max parameters must contain (or [, in which (the specified value is not included in the range), and [that is, the closed interval (the specified value is included in the range). Special values + and-have special meanings in the min parameter and the max parameter, where + denotes positive infinity, and-represents negative infinity.
Therefore, the command Zrangebylex <zset>-+ is sent to an ordered collection that has the same score for all members, and the command returns all elements in the ordered collection.
Zrangebysocre key min Max [Withscores][limit]: Returns the members of a specified interval by a fraction of an ordered collection.
Zrank Key member: Returns the index of the specified member in the ordered collection. Zrem key Member[member ...] : Removes one of the ordered setsor more members.
Zremrangebylex Key min Max: Removes all members of the given dictionary interval in the ordered collection.
Zremrangebyrank Key start stop: Removes all members of the given rank range in the ordered collection.
Zremrangebyscore Key min Max: Removes all members of a given fractional interval in an ordered collection.
Zrevrange key start Stop [Withscores]: Returns the member within the specified interval in the ordered collection, indexed, from high to low.
Zrevrangebyscore key Max Min[withscores]: Returns the members within the specified fractional range in the ordered collection, sorted from highest to lowest.
Zrevrank Key member: Returns the rank of the specified member in the ordered collection, sorted by the descending (large to small) fractional value of the ordered collection member.
Zscore Key member: Returns the fractional value of the member in the ordered collection. Zunionstore destination Numkeys Key[key ...]
: Computes the set of a given one or more ordered sets and stores it in a new key. Zscan key cursor [MATCH pattern][count COUNT]: Iterates over elements in an ordered collection (including element members and element scores).
Look at the above you need to know what the following are meant:
Zadd/zrange
zrangebyscore key starts score end score [Withscores][limit]
at the same time "Start score" and "End Socre" have an inclusion in the non-included usage.
Zrangebyscore Xxxzset 3 (6: This is the subset that returns >=3 && <6.
Please see the official website for specific usage.
zrem key A score corresponding value value, the function is to delete the element.
zcard/zcount key score interval/zrank key values, the function is to get the subscript value/zscore key corresponding to the value, get the score. The
Zrevrank key values value, which is the inverse of the index.
Zrevrange: Get all in reverse order.
zrevrangebyscore Key Maxscore Minscore