Remotely connect to redis and lock redis. Assume that the two redis servers have ip addresses 192.168.1.101 and 192.168.1.103 respectively. How can I access redis on redis 101 through redis-cli on redis 103? Before remotely connecting to redis 103, let's talk about several key parameters of redis-cli: www.2cto.com usage: redis-cli [OPTIONS] [cmd [arg [arg ..
Remotely connect to redis and lock redis. Assume that the two redis servers have ip addresses 192.168.1.101 and 192.168.1.103 respectively. How can I access redis on redis 101 through redis-cli on redis 103? Before remotely connecting to redis 103, let's talk about several key parameters of redis-cli: www.2cto.com usage: redis-cli [OPTIONS] [cmd [arg [arg ..
Connect to redis remotely and lock redis
Assume that the two redis servers have ip addresses 192.168.1.101 and 192.168.1.103 respectively. How can I access redis on redis 101 through redis-cli on redis 103? Before remotely connecting to redis 103, let's talk about several key parameters of redis-cli:
Www.2cto.com
Usage: redis-cli [OPTIONS] [cmd [arg [arg...]
-H <主机ip> The default value is 127.0.0.1.
-P <端口> The default value is 6379.
- <密码> If redis locks, you need to pass the password
-- Help: displays help information.
Through the introduction of rendis-cli usage, connecting to 101 on 103 should be simple:
[Plain]
[Root @ xsf001 ~] # Redis-cli-h 192.168.1.103-p 6379
Redis 192.168.1.103: 6379>
Set each string value user.1.name = zhangsan for 101 on 103.
[Plain]
Redis 192.168.1.103: 6379> set user.1.name zhangsan
OK
If OK is displayed, the setting is successful. Then, log on to MySQL 103 directly to see if this value can be obtained.
[Plain]
[Root @ xsf003 utils] # redis-cli
Redis 127.0.0.1: 6379> get user.1.name
"Zhangsan"
It is indeed zhangsan, which means that the redis server on 101 is connected to the redis server on 103. Of course, there are basic conditions for successful connection to port 103, and port 101 on port 103 can be used for communication. Www.2cto.com
It is very dangerous for everyone to connect to the redis server. We need to set a password for redis on 103. How should we set it? We need to edit the redis configuration file/etc/redis/6379. conf.
[Plain]
[Root @ xsf003 utils] # vim/etc/redis/6379. conf
Find # requirepass foobared and remove the comment #, and replace foobared with your own password: hi, coder
[Plain]
Requirepass "hi, coder"
After saving the configuration file, restart the redis service.
[Plain]
[Root @ xsf003 utils] #/etc/init. d/redis_6379 stop
Stopping...
Waiting for Redis to shutdown...
Redis stopped
[Root @ xsf003 utils] #/etc/init. d/redis_6379 start
Starting Redis server...
Connect to MySQL 101 and obtain the user.1.name value.
[Plain]
[Root @ xsf001 ~] # Redis-cli-h 192.168.1.103-p 6379
Redis 192.168.1.103: 6379> get user.1.name
(Error) ERR operation not permitted
Redis 192.168.1.103: 6379>
Why is it an error? Of course, the password is not passed during connection 103, and the system exits and reconnects.
[Plain]
Redis 192.168.1.103: 6379> quit
[Root @ xsf001 ~] # Redis-cli-h 192.168.1.103-p 6379-a "hi, coder"
Redis 192.168.1.103: 6379> get user.1.name
"Zhangsan"
If you see zhangsan, the connection is successful.