Redis common commands include: 1. Connection operation command; 2. Persistence command; 3. Remote service control command; 4. Value operation command; 5. String command; 6. List command; 7. Set Command; 8. hash command, etc.
##[Recommended course: redis tutorial]
Redis common commands are:
(1) Connection operation command
- quit: close the connection (connection)
- auth: simple password authentication
- help cmd: View cmd help
(2) Persistence
- save: Save data to disk synchronously
- bgsave: Save data to disk asynchronously
- lastsave: Returns the Unix timestamp of the last time data was successfully saved to disk
- shundown: Synchronously saves data to disk and then shuts down the service
(3) Remote service control
- info: Provides server information and statistics
- monitor: Live dump of received requests
- slaveof: Change replication policy settings
- config: Configure at runtime Redis server
(4) Commands for value operations
- exists(key): Confirm whether a key exists
- del(key): Delete a key
- type(key): The type of return value
- keys(pattern): Returns all keys that satisfy the given pattern
- randomkey: Randomly returns a key in the key space
- rename (oldname, newname): Rename key
- dbsize: Return the number of keys in the current database
- expire: Set an activity for a key Time (s)
- ttl: Get the activity time of a key
- select(index): Query by index
- move(key, dbindex): Move the key in the current database to the dbindex database
- flushdb: Delete all keys in the currently selected database
- flushall: Delete all keys in all databases
(5) String
- set (key, value): Assign value to the string named key in the database
- get(key): Return the value of the string named key in the database
- getset(key, value): Assign the last value to the string named key
- mget(key1, key2,…, key N): Return to the library The value of multiple strings in
- setnx(key, value): add string, name is key, value is value
- setex(key , time, value): Add string to the library and set the expiration time
- mset(key N, value N): Set the values of multiple strings in batches
- msetnx(key N, value N): If all the strings named key i do not exist
- incr(key): The string named key is incremented 1 operation
- incrby(key, integer): Add integer to the string named key
- decr(key): The string named key Decrement operation by 1
- decrby(key, integer): The string named key is reduced by integer
- append(key, value): The name is The value of the string of key is appended with value
- substr(key, start, end): Returns the substring of the value of the string named key
(6)List
##rpush(key, value): Add an element with value as value at the end of the list named key
lpush(key, value): Add an element whose value is value to the head of the list named key llen(key): Return the list named key The length of -
##lrange(key, start, end): Returns the elements between start and end in the list named key
-
ltrim (key, start, end): intercept the list named key
-
lindex(key, index): return the element at the index position in the list named key
- lset(key, index, value): Assign a value to the element at index position in the list named key
-
lrem(key, count, value): Delete count The element whose value is value in the list of keys
-
lpop(key): Return and delete the first element in the list named key
-
rpop(key): Return and delete the last element in the list named key
-
blpop(key1, key2,… key N, timeout): The block version of the lpop command.
-
brpop(key1, key2,…key N, timeout): block version of rpop.
-
rpoplpush(srckey, dstkey): Return and delete the tail element of the list named srckey, and add the element to the head of the list named dstkey
(7) Set
sadd(key, member): Add element
## to the set named key #membersrem(key, member): Delete the element in the set named key
memberspop(key): Randomly return and delete the element in the set named key an element
smove(srckey, dstkey, member): Move to the set element
-
scard(key): Return the base of the set named key
sismember(key, member): Whether member is an element of the set named key
sinter(key1, key2,…key N): Find Intersection
sinterstore(dstkey, (keys)): Find the intersection and save the intersection to the set of dstkey
sunion(key1, (keys) )): Find the union
sunionstore(dstkey, (keys)): Find the union and save the union to the set of dstkey
sdiff(key1, (keys)): Find the difference set
sdiffstore(dstkey, (keys)): Find the difference set and save the difference set to the dstkey set
smembers(key): Returns all elements of the set named key
- ##srandmember(key): Randomly returns an element of the set named key
(8) Hash
- hset(key, field, value): Add to the hash named key Element
- fieldhget(key, field): Returns the value corresponding to the field in the hash named key
- hmget(key, (fields) ): Returns the value corresponding to field i in the hash named key
- hmset(key, (fields)): Adds the element field
## to the hash named key
#hincrby(key, field, integer): Increase the value of the field in the hash named key by integer hexists(key, field): Named key Whether there is a field with the key field in the hash hdel(key, field): Delete the field with the key field in the hash named key-
hlen(key): Returns the number of elements in the hash named key-
##hkeys(key): Returns all keys in the hash named key
- hvals(key): Returns the values corresponding to all keys in the hash named key
##hgetall(key): Returns all keys in the hash named key (field) and its corresponding value
Summary: The above is the entire content of this article, I hope it will be helpful to everyone.
The above is the detailed content of What are the commonly used commands in redis?. For more information, please follow other related articles on the PHP Chinese website!