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:
Usage: redis-cli [OPTIONS] [cmd [arg [arg...]
-H <Host ip address>. The default value is 127.0.0.1.
-P <port>. The default value is 6379.
-A <password>: If redis is locked, the password must be passed.
-- Help: displays help information.
Through the introduction of rendis-cli usage, connecting to 101 on 103 should be simple:
[Root @ bkjia001 ~] # 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.
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.
[Root @ bkjia003 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.
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.
[Root @ bkjia003 utils] # vim/etc/redis/6379. conf
Find # requirepass foobared and remove the comment #, and replace foobared with your own password: hi, coder
Requirepass "hi, coder"
After saving the configuration file, restart the redis service.
[Root @ bkjia003 utils] #/etc/init. d/redis_6379 stop
Stopping...
Waiting for Redis to shutdown...
Redis stopped
[Root @ bkjia003 utils] #/etc/init. d/redis_6379 start
Starting Redis server...