Redis provides a variety of commands to operate databases and data types. These commands can be used on Linux terminals. During programming, such as using the redis Java Language Pack, these commands have corresponding methods. The following is a summary of the commands provided by redis.
Official site command list: http://redis.io/commands
1. Connection operation-related commands
Quit: disconnect)
Auth: Simple Password Authentication
2. commands for value operations
Exists (key): Check whether a key exists.
Del (key): deletes a key.
Type (key): Type of the returned value
Keys (pattern): returns all keys that meet the given pattern.
Randomkey: returns a random key of the key space.
Rename (oldname, newname): Rename the key from oldname to newname. If newname exists, delete the key represented by newname.
Dbsize: returns the number of keys in the current database.
Expire: Set the activity time of a key (s)
TTL: obtains the activity time of a key.
Select (INDEX): query by index
Move (key, dbindex): transfers the key in the current database to a database with a dbindex index.
Flushdb: delete all keys in the selected database.
Flushall: delete all keys in all databases
3. String operation commands
Set (key, value): assign value to the string named key in the database
Get (key): returns the value of a string named key in the database.
GetSet (Key, value): Assign the last value to the string named key.
Mget (key1, key2 ,..., Key N): returns multiple strings in the database (their names are key1, key2 ...) Value
Setnx (Key, value): If there is no string named key, add a string to the database, with the name key and Value
Setex (Key, time, value): to add a string (Name: Key, value: value) to the database, and set the expiration time
Mset (key1, value1, key2, value2 ,... Key N, value n): assign values to multiple strings at the same time.
Msetnx (key1, value1, key2, value2 ,... Key N, value n): If none of the strings whose names are key I exist, add the string to the database and assign the value of key I to value I.
Incr (key): Add 1 to a string named key
Incrby (Key, integer): Add integer to the string named key
Decr (key): String minus 1 operation whose name is key
Decrby (Key, integer): reduce integer in the string with the name of key
Append (Key, value): append the value of string with the name of key
Substr (Key, start, end): returns the substring of the value of the string named key.
4. List Operation commands
Rpush (Key, value): adds an element with the value at the end of the list named key.
Lpush (Key, value): adds an element with value to the list header named key.
Llen (key): returns the length of the list named key.
Lrange (Key, start, end): returns the element between start and end in the list named key (subscript starts from 0, the same below)
Ltrim (Key, start, end): truncates the list named key and retains the elements between start and end.
Lindex (Key, index): returns the index position element of the list named key.
Lset (Key, index, value): assign a value to the element at the index position in the list named key
Lrem (Key, Count, value): deletes the Count elements with the value in the list named key. If the value of count is 0, all elements with the value are deleted. If the value of count is greater than 0, the elements with the value are deleted from the beginning to the end, count <0 from the end to the header | count | elements with a value. Lpop (key): return and delete the first element rpop (key) in the list named key: return and delete the ending element blpop (key1, key2 ,... Key N, timeout): The Block version of The lpop command. That is, when the timeout value is 0, the command ends if the list named key I does not exist or the list is empty. If the timeout value is greater than 0, wait for timeout seconds in the case of the preceding situation. If the problem persists, perform the pop operation on the list starting with keyi + 1.
Brpop (key1, key2 ,... Key N, timeout): rpop block version. Refer to the previous command.
Rpoplpush (srckey, dstkey): returns and deletes the end element of the list named srckey, and adds this element to the header of the list named dstkey.
5. Set operation commands
Sadd (Key, member): add the element member to the set named key.
Srem (Key, member): deletes the element member from the set named key.
Spop (key): Randomly returns and deletes an element in a set named key.
Smove (srckey, dstkey, member): Move the member element from the set named srckey to the set named dstkey.
Scard (key): returns the base number of a set named key.
Sismember (Key, member): Tests whether Member is an element of a set named key.
Sinter (key1, key2 ,... Key N): calculates the intersection.
Sinterstore (dstkey, key1, key2 ,... Key N): calculates and saves the intersection to the dstkey set.
Sunion (key1, key2 ,... Key N): returns the union.
Sunionstore (dstkey, key1, key2 ,... Key N): calculates the Union set and saves the Union set to the dstkey set.
Sdiff (key1, key2 ,... Key N): returns the difference set.
Sdiffstore (dstkey, key1, key2 ,... Key N): calculates the difference set and saves the difference set to the dstkey set.
Smembers (key): returns all elements of a set named key.
Srandmember (key): Random return of an element of the Set named key
6. commands for zset (sorted set) Operations
Zadd (Key, score, member): add the element member to the zset named key. Score is used for sorting. If the element already exists, the sequence of the element is updated based on the score.
Zrem (Key, member): deletes the element member in the zset named key.
Zincrby (Key, increment, member): If the element member already exists in the zset named key, the score of this element is added with increment; otherwise, this element is added to the set, the score value is increment.
Zrank (Key, member): returns the rank (index, starting from 0) of the member element in the zset (the element has been sorted by score in ascending order) with the key name ), if no member element exists, "nil" is returned"
Zrevrank (Key, member): return the rank (index, starting from 0) of the member element in the zset (the element has been sorted by score in descending order) with the key name ), if no member element exists, "nil" is returned"
Zrange (Key, start, end): returns all the elements of index from start to end in the zset with the name of key (the elements have been sorted by score in ascending order ).
Zrevrange (Key, start, end): returns all the elements of index from start to end in the zset with the name of key (the elements have been sorted by score in ascending order ).
Zrangebyscore (Key, Min, max): returns all zcard (key) elements of the zset with the name of key, namely, score> = min and score <= MAX ): returns the base zscore (Key, element) of a zset named key. zremrangebyrank (Key, Min, max) of the element in the zset named key is returned ): delete all zremrangebyscore (Key, Min, max) elements in the zset with rank> = min and rank <= MAX ): delete all the elements with score> = min and score <= max in the zset named key.
Zunionstore/zinterstore (dstkeyn, key1 ,..., Keyn, weights W1 ,... Wn, aggregate sum | min | max): returns the Union and intersection of N zsets, and saves the last set in dstkeyn. For the score of each element in the Set, the score must be multiplied by the weight parameter before the aggregate operation. If weight is not provided, the default value is 1. The default aggregate value is sum, that is, the score of the element in the result set is the sum calculation value for all the corresponding elements in the Set, while min and Max refer, the score of an element in the result set is the minimum and maximum values of all elements in the set.
7. commands for hash operations
Hset (Key, field, value): Add an element field to the hash named key <-> Value
Hget (Key, field): returns the value of the field in the hash with the key name.
Hmet (Key, field1 ,..., Field N): return the value corresponding to field I in the hash with the key name.
Hmset (Key, field1, value1 ,..., Field N, value n): Add field I to the hash with the key name <-> value I
Hincrby (Key, field, integer): adds an integer to the field value in the hash named key.
Hexists (Key, field): indicates whether the hash with the key as the field exists.
Hdel (Key, field): Delete the field in the hash key named key.
Hlen (key): returns the number of elements in the hash key.
Hkeys (key): returns all keys in the hash key
Hvals (key): return the value corresponding to all keys in the hash with the key name.
Hgetall (key): returns all the keys (fields) and their corresponding values in the hash key.
8. Persistence
Save: synchronize and save data to the disk.
Bgsave: asynchronously saves data to the disk.
Lastsave: returns the Unix timestamp from which data is successfully saved to the disk.
Shundown: synchronize and save the data to the disk, and then close the service.
9. Remote Service Control
Info: provides server information and statistics.
Monitor: Real-time dump of received requests
Slaveof: changes the replication policy settings
Config: configure the redis server at runtime