Redis Common Commands

Source: Internet
Author: User
Tags redis server

http://blog.csdn.net/guochunyang/article/details/47317415Redis Common Command Set

1) Connection Operation command

    • Quit: Close connection (connection)
    • Auth: simple Password Authentication
    • Help cmd: View cmd assistance, for example: helper quit

2) Persistence

    • Save: Synchronize data to disk
    • Bgsave: Asynchronously saving data to disk
    • Lastsave: Returns the UNIX timestamp when the data was last successfully saved to disk
    • Shundown: Save data synchronously to disk, and then close the service


3) Remote Service control

    • Info: Provide information and statistics about the server
    • Monitor: Live dump of received requests
    • slaveof: Changing Replication policy settings
    • Config: Configure the Redis server at run time


4) command for value operation

    • Exists (key): Verify that a key exists
    • Del (key): Delete a key
    • Type (key): Return value types
    • Keys (pattern): Returns all keys that satisfy the given pattern
    • Randomkey: Randomly returns one of the key spaces
    • Keyrename (Oldname, newname): Rename key
    • Dbsize: Returns the number of keys in the current database
    • Expire: Set the active time of a key (s)
    • TTL: Get the active time of a key
    • Select (Index): Query by index
    • Move (Key, Dbindex): Moves 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): Assigns a value to a string named key in the database
    • Get (Key): Returns the value of a string named key in the database
    • Getset (key, value): Assigns the last value to a string named key
    • Mget (Key1, Key2,..., key N): Returns the value of multiple strings in the library
    • SETNX (key, Value): Add string, name key, value
    • Setex (Key, Time, value): Adds a string to the library, sets the expiration times
    • Mset (key n, value N): Sets the value of multiple strings in bulk
    • Msetnx (key n, value N): If all strings with the name key I do not exist
    • INCR (Key): 1 operation with a string named key
    • Incrby (Key, Integer): String with Name Key added integer
    • DECR (key): string minus 1 operation with name key
    • Decrby (Key, Integer): string with the name key reduced by integer
    • Append (key, value): String value with the name key appended value
    • SUBSTR (key, start, end): Returns a substring of the value of string with the name key


6)List

    • Rpush (key, value): Adds an element of value to the list at the end of the name key
    • Lpush (key, value): Adds an element of value to the list header with the name key
    • Llen (Key): Returns the length of the list named key
    • Lrange (key, start, end): Returns the element between start and end in list named key
    • LTrim (key, start, end): Intercepts the list named key
    • Lindex (key, index): Returns the element of the index position in the list named key
    • LSet (key, index, value): Assigns a value to the element of the index position in the list named key
    • Lrem (Key, Count, value): Deletes the value in the list of Count key elements
    • Lpop (Key): Returns and removes the first element in a list named key
    • Rpop (Key): Returns and Deletes the tail 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): The block version of Rpop.
    • Rpoplpush (Srckey, Dstkey): Returns and removes the tail element of the list named Srckey, and adds the element to the head of the list named Dstkey


7)Set

    • Sadd (Key, member): Adds an element to a set named Key member
    • Srem (Key, member): Removes the element in the set named Key member
    • Spop (key): Randomly returns and deletes an element in a set with the name key
    • Smove (Srckey, Dstkey, member): Move to the collection element
    • SCard (Key): Returns the cardinality of a set named key
    • Sismember (Key, member): Member is a set element with the name key
    • Sinter (Key1, Key2,... key N): Intersection
    • Sinterstore (Dstkey, (keys)): Seek the intersection and save the intersection to the collection of Dstkey
    • Sunion (Key1, (keys)): Seek and set
    • Sunionstore (Dstkey, (keys)): Sets and saves the assembly to the Dstkey collection
    • Sdiff (Key1, (keys)): Differential set
    • Sdiffstore (Dstkey, (keys)): Differential set and save the difference set to the collection of Dstkey
    • Smembers (Key): Returns all elements of a set with the name key
    • Srandmember (key): Randomly returns an element of a set with the name key


8)Hash

    • Hset (Key, field, value): Adds an element to a hash named key field
    • Hget (Key, field): Returns the value of field corresponding to the hash named key
    • Hmget (Key, fields): Returns the value of field I in the hash named key
    • Hmset (Key, fields): Adds an element to a hash named key field
    • Hincrby (Key, field, integer): Adds an integer to the value of field in the hash named key
    • Hexists (Key, field): A field with the key field in the hash named key
    • Hdel (Key, field): Delete The field with the key field in the hash named key
    • Hlen (Key): Returns the number of elements in a hash with the name key
    • Hkeys (Key): Returns all keys in a hash with the name key
    • Hvals (Key): Returns the value corresponding to all keys in a hash with the name key
    • Hgetall (Key): Returns all keys (field) and their corresponding value in a hash with the name key

Redis Advanced Applications1. Security     Set the client connection after any action is required before specifying a password, an external user can make 150W visits a second, Specific operation password modification settings redis.conf inside the Requirepass attribute to give the password, of course, I give here is primos  after if you want to operate can be used when the login authorization: sudo/opt/java/redis/bin/ Redis-cli-a Primos or enter after Auth Primos then can be arbitrary operation  2, master and slave copy do this operation when I prepared two virtual machine, IP is 192.168.15.128 and 192.168.15.133     through master-slave replication you can allow multiple slave servers to have the same database copy as master server configuration is configured on slave above slaveslaveof 192.168.15.128 6379masterauth Primos If there is no master-slave synchronization then check the firewall is not a problem, I use UFW, set the sudo ufw allow 6379 can be this time through info to see the specific situation  3, Transactional Redis support for transactions is relatively straightforward, and Redis can only guarantee that commands in one client-initiated transaction can be executed consecutively, without inserting other client commands in the middle. When a client issues a multi command in a connection, the connection goes into the context of a transaction, and the subsequent command is not executed immediately, but is placed first in a queue, and Redis executes all the commands in the queue sequentially when the EXEC command is executed. For example, I have an example of the set of age 100multiset, 10set, 20execget age --This content should be 20multiset, 20set, 10exec get age&nbsp ;--This time the content is 10, fully reflects the way in the order of the queue execution discard   cancel all transactions, that is, the transaction rollback but when the Redis transaction executes an individual error, the transaction does not roll back, the error is executed, Wrong content directly give up, currently the latest is 2.6.7 also have this problem optimistic lock watch key if no watch key has changed so outdate transaction is not executable  4, persistence mechanism  redis is a support for the persistence of the internalDeposit database snapshotting Snapshot mode, default storage mode, default write Dump.rdb binary file, you can configure Redis in n seconds if more than M key has been modified to automatically snapshot Append-only file aof mode, Using AOF, Redis appends each function to the file, and when the Redis restarts, the saved write commands in the file are re-executed in memory. 5, publish the subscription message Sbusribe Publish operation, in fact, similar to Linux under the release of the message 6, the use of virtual memory can configure the VM function, save the path, the maximum memory on-line, the page number, page size, the maximum worker thread temporarily modify the IP address ifconfig eth0 192.168.15.129

REDIS-CLI parameters

USAGE:REDIS-CLI [OPTIONS] [cmd [arg [arg ...]]
-H -P <port> Server Port (default:6379)
-S <socket> Server sockets (Overrides hostname and port)
-A <password> password to use when connecting to the server
-R <repeat> Execute specified command N times
-I <interval> when-r is used, waits <interval> seconds per command.
It's possible to specify Sub-second times like-i 0.1
-N <db> Database number
-X Read last argument from STDIN
-D <delimiter> multi-bulk delimiter in for raw formatting (default: \ n)
-C Enable Cluster mode (follow-ask and-moved redirections)
--raw use of raw formatting for replies (default when STDOUT are not a TTY)
--latency Enter A special mode continuously sampling latency
--slave simulate a slave showing commands received from the master
--pipe Transfer Raw Redis protocol from stdin to server
--bigkeys Sample Redis keys looking for big keys
--eval <file> Send An eval command using the Lua script at <file>
--help Output this Help and exit
--version Output version and exit

Examples:
cat/etc/passwd | Redis-cli-x Set MYPASSWD
REDIS-CLI Get MYPASSWD
Redis-cli-r Lpush mylist X
Redis-cli-r 100-i 1 Info | grep Used_memory_human:
REDIS-CLI--eval Myscript.lua key1 key2, arg1 arg2 arg3
(Note:when using--eval the comma separates keys[] from argv[] items)

Common commands:

1) View keys number

Keys *//View all keys

Keys prefix_*//View all keys prefixed with "Prefix_"

2) Clear the database

FLUSHDB//Clears all keys for the current database

Flushall//Clears all keys for all databases

Redis Common Commands

Redis Common Commands (example)

Redis Advanced Applications

Jedis Interface Classification Description

Introduction to Redis Novice (Baidu Library)

Redis Chinese Starter Manual (Baidu Library)

Redis design and implementation (recommended)

Redis Common Command Set

1) Connection Operation command

    • Quit: Close connection (connection)
    • Auth: simple Password Authentication
    • Help cmd: View cmd assistance, for example: helper quit

2) Persistence

    • Save: Synchronize data to disk
    • Bgsave: Asynchronously saving data to disk
    • Lastsave: Returns the UNIX timestamp when the data was last successfully saved to disk
    • Shundown: Save data synchronously to disk, and then close the service


3) Remote Service control

    • Info: Provide information and statistics about the server
    • Monitor: Live dump of received requests
    • slaveof: Changing Replication policy settings
    • Config: Configure the Redis server at run time


4) command for value operation

    • Exists (key): Verify that a key exists
    • Del (key): Delete a key
    • Type (key): Return value types
    • Keys (pattern): Returns all keys that satisfy the given pattern
    • Randomkey: Randomly returns one of the key spaces
    • Keyrename (Oldname, newname): Rename key
    • Dbsize: Returns the number of keys in the current database
    • Expire: Set the active time of a key (s)
    • TTL: Get the active time of a key
    • Select (Index): Query by index
    • Move (Key, Dbindex): Moves 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): Assigns a value to a string named key in the database
    • Get (Key): Returns the value of a string named key in the database
    • Getset (key, value): Assigns the last value to a string named key
    • Mget (Key1, Key2,..., key N): Returns the value of multiple strings in the library
    • SETNX (key, Value): Add string, name key, value
    • Setex (Key, Time, value): Adds a string to the library, sets the expiration times
    • Mset (key n, value N): Sets the value of multiple strings in bulk
    • Msetnx (key n, value N): If all strings with the name key I do not exist
    • INCR (Key): 1 operation with a string named key
    • Incrby (Key, Integer): String with Name Key added integer
    • DECR (key): string minus 1 operation with name key
    • Decrby (Key, Integer): string with the name key reduced by integer
    • Append (key, value): String value with the name key appended value
    • SUBSTR (key, start, end): Returns a substring of the value of string with the name key


6)List

    • Rpush (key, value): Adds an element of value to the list at the end of the name key
    • Lpush (key, value): Adds an element of value to the list header with the name key
    • Llen (Key): Returns the length of the list named key
    • Lrange (key, start, end): Returns the element between start and end in list named key
    • LTrim (key, start, end): Intercepts the list named key
    • Lindex (key, index): Returns the element of the index position in the list named key
    • LSet (key, index, value): Assigns a value to the element of the index position in the list named key
    • Lrem (Key, Count, value): Deletes the value in the list of Count key elements
    • Lpop (Key): Returns and removes the first element in a list named key
    • Rpop (Key): Returns and Deletes the tail 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): The block version of Rpop.
    • Rpoplpush (Srckey, Dstkey): Returns and removes the tail element of the list named Srckey, and adds the element to the head of the list named Dstkey


7)Set

    • Sadd (Key, member): Adds an element to a set named Key member
    • Srem (Key, member): Removes the element in the set named Key member
    • Spop (key): Randomly returns and deletes an element in a set with the name key
    • Smove (Srckey, Dstkey, member): Move to the collection element
    • SCard (Key): Returns the cardinality of a set named key
    • Sismember (Key, member): Member is a set element with the name key
    • Sinter (Key1, Key2,... key N): Intersection
    • Sinterstore (Dstkey, (keys)): Seek the intersection and save the intersection to the collection of Dstkey
    • Sunion (Key1, (keys)): Seek and set
    • Sunionstore (Dstkey, (keys)): Sets and saves the assembly to the Dstkey collection
    • Sdiff (Key1, (keys)): Differential set
    • Sdiffstore (Dstkey, (keys)): Differential set and save the difference set to the collection of Dstkey
    • Smembers (Key): Returns all elements of a set with the name key
    • Srandmember (key): Randomly returns an element of a set with the name key


8)Hash

    • Hset (Key, field, value): Adds an element to a hash named key field
    • Hget (Key, field): Returns the value of field corresponding to the hash named key
    • Hmget (Key, fields): Returns the value of field I in the hash named key
    • Hmset (Key, fields): Adds an element to a hash named key field
    • Hincrby (Key, field, integer): Adds an integer to the value of field in the hash named key
    • Hexists (Key, field): A field with the key field in the hash named key
    • Hdel (Key, field): Delete The field with the key field in the hash named key
    • Hlen (Key): Returns the number of elements in a hash with the name key
    • Hkeys (Key): Returns all keys in a hash with the name key
    • Hvals (Key): Returns the value corresponding to all keys in a hash with the name key
    • Hgetall (Key): Returns all keys (field) and their corresponding value in a hash with the name key

Redis Advanced Applications1. Security     Set the client connection after any action is required before specifying a password, an external user can make 150W visits a second, Specific operation password modification settings redis.conf inside the Requirepass attribute to give the password, of course, I give here is primos  after if you want to operate can be used when the login authorization: sudo/opt/java/redis/bin/ Redis-cli-a Primos or enter after Auth Primos then can be arbitrary operation  2, master and slave copy do this operation when I prepared two virtual machine, IP is 192.168.15.128 and 192.168.15.133     through master-slave replication you can allow multiple slave servers to have the same database copy as master server configuration is configured on slave above slaveslaveof 192.168.15.128 6379masterauth Primos If there is no master-slave synchronization then check the firewall is not a problem, I use UFW, set the sudo ufw allow 6379 can be this time through info to see the specific situation  3, Transactional Redis support for transactions is relatively straightforward, and Redis can only guarantee that commands in one client-initiated transaction can be executed consecutively, without inserting other client commands in the middle. When a client issues a multi command in a connection, the connection goes into the context of a transaction, and the subsequent command is not executed immediately, but is placed first in a queue, and Redis executes all the commands in the queue sequentially when the EXEC command is executed. For example, I have an example of the set of age 100multiset, 10set, 20execget age --This content should be 20multiset, 20set, 10exec get age&nbsp ;--This time the content is 10, fully reflects the way in the order of the queue execution discard   cancel all transactions, that is, the transaction rollback but when the Redis transaction executes an individual error, the transaction does not roll back, the error is executed, Wrong content directly give up, currently the latest is 2.6.7 also have this problem optimistic lock watch key if no watch key has changed so outdate transaction is not executable  4, persistence mechanism  redis is a support for the persistence of the internalDeposit database snapshotting Snapshot mode, default storage mode, default write Dump.rdb binary file, you can configure Redis in n seconds if more than M key has been modified to automatically snapshot Append-only file aof mode, Using AOF, Redis appends each function to the file, and when the Redis restarts, the saved write commands in the file are re-executed in memory. 5, publish the subscription message Sbusribe Publish operation, in fact, similar to Linux under the release of the message 6, the use of virtual memory can configure the VM function, save the path, the maximum memory on-line, the page number, page size, the maximum worker thread temporarily modify the IP address ifconfig eth0 192.168.15.129

REDIS-CLI parameters

USAGE:REDIS-CLI [OPTIONS] [cmd [arg [arg ...]]
-H -P <port> Server Port (default:6379)
-S <socket> Server sockets (Overrides hostname and port)
-A <password> password to use when connecting to the server
-R <repeat> Execute specified command N times
-I <interval> when-r is used, waits <interval> seconds per command.
It's possible to specify Sub-second times like-i 0.1
-N <db> Database number
-X Read last argument from STDIN
-D <delimiter> multi-bulk delimiter in for raw formatting (default: \ n)
-C Enable Cluster mode (follow-ask and-moved redirections)
--raw use of raw formatting for replies (default when STDOUT are not a TTY)
--latency Enter A special mode continuously sampling latency
--slave simulate a slave showing commands received from the master
--pipe Transfer Raw Redis protocol from stdin to server
--bigkeys Sample Redis keys looking for big keys
--eval <file> Send An eval command using the Lua script at <file>
--help Output this Help and exit
--version Output version and exit

Examples:
cat/etc/passwd | Redis-cli-x Set MYPASSWD
REDIS-CLI Get MYPASSWD
Redis-cli-r Lpush mylist X
Redis-cli-r 100-i 1 Info | grep Used_memory_human:
REDIS-CLI--eval Myscript.lua key1 key2, arg1 arg2 arg3
(Note:when using--eval the comma separates keys[] from argv[] items)

Common commands:

1) View keys number

Keys *//View all keys

Keys prefix_*//View all keys prefixed with "Prefix_"

2) Clear the database

FLUSHDB//Clears all keys for the current database

Flushall//Clears all keys for all databases

Redis Common Commands

Redis Common Commands (example)

Redis Advanced Applications

Jedis Interface Classification Description

Introduction to Redis Novice (Baidu Library)

Redis Chinese Starter Manual (Baidu Library)

Redis design and implementation (recommended)

Redis Common Commands

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.