Linux Redis Remote Access __linux

Source: Internet
Author: User
Tags redis iptables redis server
#1. Install iptables-services and disable FIREWALLD, enable Iptables and ip6tables: Yum install iptables-services systemctl
Firewalld.service
systemctl Enable Iptables.service
systemctl enable Ip6tables.service
#2. Start a service
Systemctl Stop Firewalld.service
systemctl start iptables.service
systemctl start Ip6tables.service
#3. Open Redis port, modify firewall profile
vi/etc/sysconfig/iptables
-A input-m State--state new-m tcp-p TCP--dport 6379-j ACCEPT
#4. Restart Service
iptables restart
#5. Server configuration:
cd Usr/local/redis/bin
vi redis.conf
#填入
Port 6379
bind 192.168.19.131   (remote Access does not require a bind IP)
#6. Start server:
./redis-server redis.conf
#7. Test: Windows opens cmd 
telnet 192.168.19.131 6379
#也可以windows安装redis open cmd:
redis-cli-h 192.168.19.131-p 6379
#ok!
#注意: Do not use service iptables save because it will revert to iptables before modification.


Reference:

Suppose two redis servers, IP: 192.168.1.101 and 192.168 1.103, how to access Redis on 101 via REDIS-CLI. Before remote connection 103, let's talk about several 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 lock, need to pass the password

--HELP, display 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, indicating that the setting was successful. Then log on directly to the 103 to see if you can get this value.

Redis 192.168.1.103:6379> Keys *

Redis 192.168.1.103:6379> Select 1


1, the connection operation related commandsQuit: Close connection (connection) Auth: simple Password Authentication2, the value of the operation of the commandExists (key): Confirm a key exists del (key): Delete a key type (key): Return the type of the value of the key (pattern): Returns all keys that satisfy a given pattern Randomkey: A key rename (Oldname, newname) that returns the key space at random: Rename the key from Oldname to NewName and delete the key represented by NewName if it exists Dbsize: Returns the number of keys in the current database expire: Set a key's active time (s) TTL: Get a Key's active time Select (index): Query by index Move (key, Dbindex) : Transfer key from current database to database with Dbindex index FLUSHDB: Delete all key flushall in the current selection database: Delete all keys in all databases3. Commands for string OperationsSet (key, value): Assign a value of string to a key in the database (key): Values Getset (key, value) that returns a string with the name key in the database : Assigns the last value Mget (Key1, Key2,..., key N) to a string named key: Returns multiple strings in the library (their name is 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 and value Setex (key, Time, values): Add a string to the library (name key , values are value) at the same time, set the expiration Time Mset (Key1, value1, Key2, value2,... key N, value N): Assign values to multiple strings at the same time, string assignment value I msetnx with Name Key I ( Key1, value1, Key2, value2,... key N, value N): If all strings with the name key I do not exist, add a string to the library and the name Key I assignment is value I incr (key) : string increment 1 with Name key operation Incrby (Key, Integer): string with Name key increases integer DECR (key): string minus 1 with name Key Decrby (key, Integer) : string with Name key reduces integer append (key, value): String with Name key appended value substr (key, start, end): substring that returns the value of string with the name key4. Commands for list operationRpush (key, value): Adds a value of element Lpush (key, value) at the end of the list named key: Add a value of element Llen (key) to the list header named key : Returns the length of the list named key Lrange (key, start, end): Returns the element between start to end in the list named key (subscript starting from 0, same below) LTrim (key, start, end) : intercepts the list named key, preserving the element lindex (key, index) between start and end: 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 Value Lrem (key, Count, value): Deletes the element with value in the list with the Count name key. Count is 0 to delete all elements of value, Count>0 deletes the element with the count value of value from the end, Count<0 deletes the element with value of |count| from the tail. 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: The block version of the Lpop command. That is, when timeout is 0 o'clock, the command ends if a list named key I does not exist or the list is empty. If timeout>0, then wait timeout seconds if the problem is not resolved, and then 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 Deletes 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): add Element member Srem (key, member) to set with name key: Delete element member Spop (key) in set with Name key: Random return and delete one element in set named key Smove (Srckey, Dstkey, member): Moves the member element from the collection named Srckey to the collection Dstkey (key) named SCard: Returns the cardinality of the set with the name Key Sismember (Key, member ): Test whether member is a set element named Key sinter (Key1, Key2,... key N): Intersection Sinterstore (Dstkey, Key1, Key2,... key N): Find the intersection and save the intersection to the Dstkey collection Su Nion (Key1, Key2,... key N): Seek and set Sunionstore (Dstkey, Key1, Key2,... key N): Set and Save the collection to Dstkey's set Sdiff (Key1, Key2,... key N): Differential set SDI Ffstore (Dstkey, Key1, Key2,... key N): The difference set and saves the difference set to the Dstkey collection Smembers (key): Returns all elements of a set named Key Srandmember (key) : Random return of an element of a set named key6, the Zset (sorted set) operation of the command Zadd (key, Score, member): Adds element Member,score to the zset named key for sorting. If the element already exists, the order of the elements is updated according to score. Zrem (Key, member): Deletes the element member Zincrby (key, increment, member) in the Zset named key: If element member already exists in the Zset with the name key The score of the element is incremented increment; otherwise, the element is added to the collection and its score value is increment Zrank (key, member) : Returns the name of key Zset (element has been sorted by score from small to large) in the member element rank (that is, index, starting from 0), if there is no member element, return "nil" zrevrank (key, member) : Returns the rank (index, starting from 0) of the member element in the Zset with the name key (the element has been sorted by score from large to small), and if there is no member element, return "nil" zrange (key, start, end) : Returns all elements of the index from start to end (key, start, and end) of the Zset with the name key (the element has been sorted by score from small to large) Zrevrange : Returns the index of all elements from start to end (key, Min, Max) in the Zset with the name key (the element has been sorted by score from large to small): Returns the Zset of the name Key score >= Min and score <= max all elements Zcard (key): Returns the base Zscore (key, Element) of the Zset named key: Returns the zset of element elements in score with the name key Zremrangebyrank (Key, Min, max): Delete all elements Zremrangebyscore (key, Min, max) in Zset rank >= min and rank <= max in the name key : Deletes all elements <= (Zunionstore/zinterstore, Dstkeyn,..., key1, Keyn WEIGHTS,... W1 of score >= min and score WN Max in Zset with name Key Aggre GATE SUm| min| MAX): N Zset are set and intersect, and the last set is saved in Dstkeyn. For the score of each element in the collection, multiply the weight argument to the aggregate before making the operation. 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 sum of all the corresponding elements of the collection, while Min and Max refer to the score of the elements in the result set as the minimum and maximum values for all the corresponding elements of the collection.7, the hash operation of the commandHset (Key, field, value): Add elements to the hash named key Field<->value hget (Key, field): Returns the value hmget of the field corresponding to the hash named key (key , Field1, ..., field N): Returns the value Hmset (key, field1, value1,..., field N, Value N) of the field I in the hash named key: add Element field I to the hash named key <->value I Hincrby (Key, field, integer): Adds the value of field in the hash named key to the integer hexists (Key, field) : There is a domain Hdel (key, field) with key field in the hash named key: Delete the field Hlen (key) with the key in the hash with the name key to return the number of elements in the hash named key Hkeys (key) : Returns all keys Hvals (key) in the 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 key8. PersistentSave: Synchronize data to disk Bgsave: Asynchronously save data to disk Lastsave: Returns the UNIX timestamp Shundown last successfully saved data to disk: Synchronize data to disk, and then turn off services9. Remote Service ControlInfo: Provide server information and statistics Monitor: real-time dump received request slaveof: Change replication Policy settings config: Configure Redis server at run time


Reference: 1.http://www.cnblogs.com/ajun/p/4156484.html

2.http://www.centoscn.com/centos/intermediate/2015/0313/4879.html


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.