Transferred from: http://www.linuxidc.com/Linux/2012-12/75693.htm
Suppose two redis servers, IP: 192.168.1.101 and 192.168.1.103, how to access the Redis on the 103 on 101 through REDIS-CLI. Before remote connection 103, let's talk about some key parameters of REDIS-CLI:
Usage: redis-cli [OPTIONS] [cmd [arg [arg ...]]
-H < host Ip>, default is 127.0.0.1
-p < port;, default is 6379
-A < Password, if Redis is locked, you need to pass the password
--help, displaying Help information
By introducing the RENDIS-CLI usage, connecting 103 on 101 should be simple:
[root@linuxidc001 ~]# redis-cli-h 192.168.1.103-p 6379
Redis 192.168.1.103:6379>
Set each string value to 103 on 101 User.1.name=zhangsan
Redis 192.168.1.103:6379> Set User.1.name Zhangsan
Ok
See OK to indicate that the setup was successful. Then login directly on the 103 to see if you can get to this value.
Redis 192.168.1.103:6379> Keys *
Redis 192.168.1.103:6379> Select 1
1. Commands related to connection operationQuit: Close connection (connection) Auth: simple Password Authentication2. Commands for value operationsExists (key): Verify that a key exists del (key): Delete a key type (key): The type of the return value keys (pattern): Returns all keys that satisfy a given pattern Randomkey: Randomly returns a key rename (Oldname, newname) for key space: Rename key from Oldname to newname and delete newname if newname exists Dbsize: Returns the number of keys in the current database expire: Set a key's active time (s) TTL: Get the active time of a key Select (index): Query by index Move (key, Dbindex) : Transfers the key from the current database to a database with a Dbindex index FLUSHDB: Deletes all key Flushall in the currently selected database: Deletes all keys in all databases3. Commands for string manipulationSet (key, value): Assigns the value of a string named key in the database to the values "get" (key): Returns a string of value getset (key, value) named key in the database : Assigns a string named key to the last value Mget (Key1, Key2,..., key N): Returns multiple strings in the library whose names are Key1,key2 ... Value Setnx (key, value): If a string with the name key does not exist, add a string to the library with the name key, value Setex (key, Time, value): Adds a string to the library named key Value) at the same time, set the expiration Time Mset (Key1, value1, Key2, value2,... key N, value N): Assigning multiple strings at the same time, string assignment with the name key I, Value I msetnx ( Key1, value1, Key2, value2,... key N, value N): If all strings with the name key I do not exist, a string is added to the library, the name key I is assigned value I incr (key) : string with the name key incremented by 1 operations Incrby (key, Integer): String with Name Key added integer DECR (key): string minus 1 operation with name Key Decrby (key, Integer) : string with name key is reduced by integer append (key, value): String value with Name key appended value substr (key, start, end): Returns a substring of the value of string with the name key4. Commands for list operationsRpush (key, value): Adds a value of element Lpush (key, value) at the end of the list with the name key: Adds an element of 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 list named key (subscript starting from 0, below) LTrim (key, start, end) : intercepts the list named key, preserving the element between start and end Lindex (key, index): Returns the element LSet (key, index, value) of the index position in the list named key : Assigns the element of the index position in the list named key to value Lrem (key, Count, value): Removes the element that has the value in the list of Count names key. Count is 0, removing all elements that have values of value, Count>0 removes the element with count values from start to end, Count<0 removes |count| values as value from the tail. Lpop (Key): Returns and removes the first element in the list named key Rpop (key): Returns and removes the tail element in list named key Blpop (Key1, Key2,... key N, timeout): The block version of the Lpop command. That is, when timeout is 0 o'clock, if a list with the name key I does not exist or the list is empty, the command ends. If timeout>0, if this is the case, wait for timeout seconds, and if the problem is not resolved, perform a pop operation on the list starting with keyi+1. Brpop (Key1, Key2,... key N, timeout): The block version of Rpop. Refer to the previous command. 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 Dstkey5. Commands for set operationsSadd (Key, member): Adds an element to the 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 named key Smove (Srckey, Dstkey, member): Moves the member element from the collection named Srckey to the collection named Dstkey SCard (Key): Returns the cardinality of the set named Key Sismember (key, member ): Test whether the member is a set element named Key sinter (Key1, Key2,... key N): Intersection Sinterstore (Dstkey, Key1, Key2,... key N): The set of intersection and save intersection to Dstkey Su Nion (Key1, Key2,... key N): Gather Sunionstore (Dstkey, Key1, Key2,... key N): Set and save the set to Dstkey collection Sdiff (key1, Key2,... key N): Differential set SDI Ffstore (Dstkey, Key1, Key2,... key N): Set of differences and save the difference to Dstkey collection smembers (key): Returns all elements of a set named Key Srandmember (key) : Randomly returns an element of set with the name key6. Commands for Zset (sorted set) operation Zadd (key, Score, member): Adds an element member,score for sorting to a zset named key. If the element already exists, the order of the element is updated according to score. Zrem (Key, member): Delete the element in Zset named key member Zincrby (key, Increment, member): If the element Zset already exists in member named Key, The score of the element increases increment; otherwise, the element is added to the collection, and its score value is increment Zrank (key, member) : Returns the rank of the member element (that is, index, starting from 0) of the Zset with the name key (the element has been sorted score from small to large), and returns "nil" Zrevrank (key, member) if there is no member element : Returns the rank of the member element (that is, index, starting from 0) of the Zset with the name key (the element has been sorted by score from large to small), and returns "nil" Zrange (key, start, end) If there is no member element : Returns all elements of index from start to end (key, start, end) in Zset with the name key (the element has been sorted score from small to large) : Returns all elements of Zset (key, Min, Max) from start to end of the index named key (the element has been sorted by score from large to small) Zrangebyscore: Returns Zset in the name Key score >= Min and score all elements of <= Max Zcard (key): Returns the cardinality of the Zset named Key Zscore (key, Element): Returns the zset of element elements in score with the name key Zremrangebyrank (Key, Min, max): Removes Zset rank >= min in the name of key and all elements of rank <= max Zremrangebyscore (key, Min, Max) : Remove all elements of score >= min and score <= Max in Zset named Key Zunionstore/zinterstore (Dstkeyn, Key1,..., KeyN, WEIGHTS W1,... WN, Aggre GATE SUm| min| MAX): Sets and intersections of N Zset, and saves the last collection in Dstkeyn. For the score of each element in a collection, multiply the weight parameter for the aggregate operation before doing it. If weight is not provided, the default is 1. The default aggregate is sum, that is, the score of the elements in the result set is the value of the sum operation for all the corresponding elements of the collection, while Min and Max means that the score of the elements in the result set are the minimum and maximum values in the corresponding elements of all the collections.7, the command of the hash operationHset (Key, field, value): Adds an element to the hash named key Field<->value hget (Key, field): Returns the value hmget of the field in the hash named key (key , Field1, ..., field N): Returns the value Hmset (key, field1, value1,..., field N, Value N) of the hash with the name key, and adds the element to the hash named key field I <->value I Hincrby (Key, field, integer): Adds an integer hexists (key, field) to the value of field in the hash named key : A hash with the name key is a field Hdel (Key, field): Delete The field with the key named key field Hlen (key): Returns the number of elements in the hash named key Hkeys (key) : Returns all keys in a hash named key hvals (key): Returns the value Hgetall (key) for all keys in a hash with the name key: Returns all keys (field) and their corresponding value in a hash with the name key8. PersistenceSave: Synchronize data to disk Bgsave: Asynchronously saves data to disk Lastsave: Returns the UNIX timestamp Shundown when the data was last successfully saved to disk: Synchronize data to disk, and then close the service9. Remote Service ControlInfo: Provide server information and statistics Monitor: real-time dump received request slaveof: Change replication Policy settings config: Configure the Redis server at run time