I have 1 master and 2 slaves. First I'm writining info replication
to get infromation. If I'm on slave, I try to coonect to master with redis-cli -h ip-redis-master -a password
. Can I automatize this? For example: redis-cli -h $(info replication | cut -d ip-addr-master) -a password
. Is it possible?
Asked
Active
Viewed 1,659 times
0

igaro4ak337
- 55
- 9
-
what you want is just connect to master automatically? – baozilaji Sep 08 '21 at 08:01
-
@baozilaji because it's my task – igaro4ak337 Sep 08 '21 at 08:11
-
I'm not sure what you want to do yet. – baozilaji Sep 08 '21 at 08:29
-
@baozilaji Yes I want to automatically connect to master – igaro4ak337 Sep 08 '21 at 14:35
-
So, you want to get the master's host automatically by the info replication command, and using that to connect the master? – baozilaji Sep 09 '21 at 02:31
-
@baozilaji maybe somehow differently – igaro4ak337 Sep 09 '21 at 06:31
1 Answers
0
Maybe you want this:
redis-cli -h `redis-cli info replication|grep master_host|awk -F':' '{print $2}'|awk -F'\r' '{print $1}'` -a master-password

baozilaji
- 304
- 1
- 10
-
Thanks for help but when I started this command I have error: `Could not connect to Redis at -p:6379: Name or service not known`. – igaro4ak337 Sep 09 '21 at 06:56
-
-
-
Yes, `Could not connect to Redis at -a:6379: Name or service not known` – igaro4ak337 Sep 09 '21 at 08:41
-
maybe you need to handle this problem step by step: 1、make sure that you can get the master ip info by this command ``` redis-cli info replication | grep master_host ``` 2、remeber the host info and try to connect to master manually ``` redis-cli -h ip -a pass ``` 3、if everything is ok, then maybe you need to check is there any invisible character in the result of redis-cli info replication, run this: ``` $(redis-cli info replication|grep master_host|awk -F':' '{print $2}') ``` – baozilaji Sep 09 '21 at 08:56