Redis Tutorial (V): Redis common commands

Source: Internet
Author: User
Tags auth lua redis stdin server port redis server redis tutorial
Redis Common Command set

1 Connection operation Command quit: Close the connection (connection) Auth: simple password Authentication help cmd: View cmd assistance, for example: helping quit

2 Persistent Save: Synchronize data to disk Bgsave: Asynchronously save data to disk Lastsave: Returns the last Unix timestamp that successfully saved data to disk Shundown: Synchronize data to disk, and then turn off services


3 Remote Service Control info: Provide server information and statistics Monitor: Live dump received request slaveof: Change replication Policy settings config: Configure Redis server at run time


4 The value of the operation of the command exists (key): Confirm a key exists del (key): Delete a key type (key): Return the value of the type keys (pattern): Return to meet the given patterns of all key Randomkey: A Keyrename (Oldname, newname) that returns a key space at random: rename key dbsize: Returns the number of keys in the current database expire: Set a key's active time (s) TTL: Gets the active time of a key Select (Index): Query Move (key, Dbindex) by index: Moves the key in the current database to the Dbindex database flushdb: Deletes all keys in the currently selected database Flushall: Delete all key in all databases


5) String Set (key, value): Assign a value of string to a key in a database to a number of values get (key): Returns a string with the name key in the database Getset (key, value): Assigns the last value Mget (Key1, Key2,..., key N) to a string named key: Returns the value SETNX (key, value) of multiple strings in the library: adding a string, Name Key, value Setex (key, time, value): Add string to library, set expiration time Mset (key n, value N): Batch set multiple string values Msetnx ( Key N, value N): If all strings named Key i do not exist incr (key): string Increment 1 Operation Incrby (key, Integer) with name key: string with Name key increases integer DECR (key): string minus 1 operation with name Key Decrby (Key, Integer): string with Name key reduces integer append (key, value): Value of string with name key appended value SUBSTR (key, start, end): Returns a substring of the value of string that is named key


6) List   Rpush (key, value): Adds a value of element Lpush (key, value) at the end of the list named key : Adds a value of   element Llen (key) to the list header named key: Returns the length of the list with the name Key Lrange (key, start, end): Returns the element between start and end in the list named key LTrim (key, start, end): Intercepts the name Key's list lindex (key, index): Returns the element LSet (key, index, value) of the index position in the list named key. : the element assigned to the index position in the list named key is Lrem (key, Count, value): The element Lpop (key) that deletes the value of the list with the Count key: Returns and Deletes the first element in the list named key Rpop (key): Returns and Deletes the tail element blpop (key1, Key2,... key N, timeout) in the list named key: The block version of the Lpop command. Brpop (Key1, Key2,... key N, timeout): The block version of Rpop. Rpoplpush (Srckey, Dstkey): Returns and Deletes 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): adding element member Srem (key, member) to set with name key   : Deletes element member Spop (key) in set with Name key &NBSP: Randomly returns and Deletes an element Smove (Srckey, Dstkey, member)   in set with the name key;: Move to collection element SCard (key &NBSP: Returns the cardinality Sismember (key, member) of the set with the name key  :member is the element sinter (Key1, Key2,... key N)   of the set with the name key;: Find intersection Sinterstore (Dstkey, (keys)) &NBSP: Seek the intersection and save the intersection to the Dstkey collection sunion (Key1, (keys))  : Seek and set Sunionstore (Dstkey, (keys)) &NBSP: The set and save the set to the Dstkey collection Sdiff (Key1, (keys)  : The difference set Sdiffstore (Dstkey, (keys))  : To find the difference set and save the difference to the collection of Dstkey Smembers (Key)  : Returns all elements of the set with the name Key Srandmember (key)  : A random return element of a set named key


8Hash hset (key, field, value): Adds the element field Hget (key, field) to the hash named key: Returns the value hmget of the field corresponding to the hash with the name key ( Key, (Fields)): Returns the value Hmset (Key, (fields)) of the field I in the hash named key: Add the Element field Hincrby to the hash named key (Key, field, integer) : Adds the value of the field in the hash named key to the integer hexists (Key, field): The domain Hdel (key, field) in the hash with the name keys field : Delete domain Hlen (key) with field in hash with name key: Returns the number of elements in a hash named key Hkeys (key): Returns all keys Hvals (key) in a hash named key : Returns the value Hgetall (key) corresponding to all keys in the hash named key: Returns all keys (field) and their corresponding value in the hash named key


Redis Advanced Applications1, security settings after the client connected to any operation to specify the password before, an external user can be a second 150W access, the specific operation of the password modification settings redis.conf inside the Requirepass attribute to give the password, of course, I give here is Primos Then if you want to operate can be used to authorize the use of the landing: Sudo/opt/java/redis/bin/redis-cli-a Primos or enter the future auth Primos and then you can operate at random
2, master-slave copy to do this operation when I prepared two virtual machines, IP is 192.168.15.128 and 192.168.15.133 through master-slave replication can allow multiple slave server has the same database copy with master server specific configuration is Slave configuration slave slaveof 192.168.15.128 6379 Masterauth If there is no master-slave synchronization then check if the firewall is not the problem, I use the Primos, set the sudo ufw UFW 6379 on it. This time can see the specific situation through the info 3, transaction processing Redis support for the transaction is relatively simple, redis can only ensure that a client-initiated transaction in the command can be executed continuously, and the middle will not insert other client's command. When a client issues a multi command in a connection, the connection goes into the context of a transaction, and the subsequent commands are not executed immediately, but are first placed in a queue, and when the EXEC command is executed, Redis executes all the commands in the queue sequentially. For example, I have the following example set the multi set age of set age-exec get-the content should be the multi set-set age-exec get- The content of the time becomes 10, fully embodies the way in order to execute the queue discard cancel all transactions, that is, transaction rollback however, when redis transaction execution has individual errors, the transaction is not rolled back, the error content is executed, the wrong content is discarded directly, The latest is 2.6.7 also have this problem optimistic lock watch key if no watch key changes then outdate transactions can not be executed
4, the persistence mechanism Redis is a support persisted memory database snapshotting snapshot way, the default storage way, the default writes the DUMP.RDB the binary file, may configure Redis in n seconds if more than M key is modified to take the snapshot automatically Append-only file aof mode, when using AOF, Redis appends every function to the file, and when the Redis restarts, the saved write commands in the file are executed in memory. 5, publish subscription message Sbusribe Publish operation, in fact, similar to the following Linux message Release 6, the use of virtual memory can configure the VM function, save the path, maximum memory online, page number, page size, the maximum worker thread temporarily modify 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 connecting server
-R <repeat> Execute specified command N times
-I <interval> when-r is used, waits <interval> seconds per command.
It is 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 raw formatting to 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 the 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) Empty the database

FLUSHDB//Clear all keys for current database

Flushall//Clear all keys for all databases






Redis Common Commands

Redis Common commands (sample)

Redis Advanced Applications

Jedis Interface Classification Description

Redis Novice Introduction (Baidu Library)

Redis Chinese Starter Manual (Baidu Library)
Redis design and implementation (recommended)

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.