Redis provides a rich command (command) for operating on databases and various data types. These commands can be used on Linux terminals. When programming, such as using Redis' Java language pack, these commands have corresponding methods. Let's summarize the commands provided by Redis.
1, the connection operation related commands
quit: close the connection (connection)
auth: simple password authentication
2, the operation of the value operation
exists(key): Confirm whether a key exists
del(key): Delete a key
type(key): Type of return value
keys( Pattern): returns all the keys that satisfy the given pattern
randomkey: a key that randomly returns the key space
rename(oldname, newname): renames the key from oldname to newname, if newname Exist, delete the key indicated by newname
dbsize: return the number of keys in the current database
expire: set the active time of a key(s)
ttl: get one Key activity time
select(index): query by index
move(key, dbindex): Transfer the key in the current database to the database with dbindex index
Flushdb: delete all keys in the current selection database
flushall: delete all keys in all databases
3, commands for String operations
set(key, value): Give the value of the string named key in the database value
get(key): return the value of the string named key in the database
getset( Key, value): Give the string named key the last value
mget(key1, key2,…, key N): return multiple strings in the library (their names are key1, key2… Value
setnx(key, value): If there is no string named key, add string to the library, the name is key, the value is value
setex(key, time , value): Add a string (name is key, value) to the library, and set the expiration time time
mset(key1, value1, key2, value2,…key N, value N): At the same time assign a value to multiple strings, the name of the key i is assigned value i
msetnx(key1, value1, key2, value2,…key N, value N): if all strings with the name key i are If it does not exist, add a string to the library. The name key i is assigned the value i
incr(key): the string with the name key is incremented by 1
incrby(key, integer): name Key string increases integer
decr(key): string with key name minus 1 operation
decrby(key, integer): string with name key reduces integer
Append(key, value): The value of the string whose name is key is appended with value
substr(key, start, end): Returns the substring of the value of the string named key
4. Commands for List operations
rpush(key, value): Add an element with a value of value at the end of the list named key
lpush(key, value): in the name key The list header adds an element with a value of
llen(key): returns the length of the list whose name is key
lrange(key, start, end): returns the list named key The element between start and end (subscript starts from 0, the same below)
ltrim(key, start, end): intercepts the list named key, retains the element between start and end
lindex(key, index): Returns the element at the index position in the list named key
lset(key, index, value): assigns the value of the index position to the list named key.
lrem(key, count, Value): Deletes the elements whose value is value in the list whose name is key. Count is 0, delete all elements with value, count>0 removes count elements with value from beginning to end, count<0 is deleted from end to end |
Count|
An element with a value of value. Lpop(key): Returns and deletes the first element rpop(key) in the list named key: returns and deletes the tail element blpop (key1, key2, … key N, timeout) in the list named key: lpop command The block version. That is, when timeout is 0, if the list named name key i does not exist or the list is empty, the command ends. If timeout > 0, then wait for timeout seconds when the above situation is encountered, if the problem is not resolved, then perform a pop operation on the list started by keyi+1.
brpop(key1, key2,… key N, timeout): The block version of rpop. Refer to the previous command.
rpoplpush(srckey, dstkey): Returns and deletes the tail element of the list named srckey, and adds the element to the header of the list named dstkey
5. Command
sadd(key, member): Add an element to a set named key
srem(key, member) : Delete the element in the set named key member
spop(key) : Randomly returns and deletes an element in the set named key
smove(srckey, dstkey, member) : Moves the member element from the collection named srckey to the name dstkey Collection
scard(key) : Returns the cardinality of the set named key
sismember(key, member) : Tests if the member is an element of the set named key
sinter(key1, key2,…key N) : Intersection
sinterstore(dstkey, key1, key2,…key N) : Find the intersection and save the intersection to the collection of dstkey
sunion(key1, key2,…key N) : Find the union
sunionstore(dstkey, key1, key2,…key N) : Find the union and save the union to the collection of dstkey
sdiff(key1, key2,…key N) : difference set
sdiffstore(dstkey, key1, key2,…key N) : Find the difference set and save the difference set to the dstkey set
smembers(key) : Returns all elements of a set named key
srandmember(key) : Randomly returns an element of the set named key