redis主從配置
阿新 • • 發佈:2017-11-03
獲取 slave jedis eof spa col tin on() 127.0.0.1
機器ip:192.168.233.8
主redis:
./src/redis-server ./redis.conf
從redis:
./src/redis-server ./redis.conf
修改 redis.conf 文件:
port 6380
slaveof 192.168.233.8 6379
哨兵:
./src/redis-sentinel ./sentinel.conf
修改 sentinel.conf 文件:
sentinel monitor mymaster 192.168.233.8 6379 1
這樣配置後,應用程序先詢問哨兵,獲取主redis信息,然後連接redis。
@Configuration publicclass Config { @Bean public RedisConnectionFactory jedisConnectionFactory() { RedisSentinelConfiguration sentinelConfig = new RedisSentinelConfiguration().master("mymaster").sentinel("192.168.233.8", 26379); // .sentinel("127.0.0.1", 26380); return new JedisConnectionFactory(sentinelConfig); } }
redis主從配置