I am using Spring 2.1.1 and Redis 4.0.1. I have configured two node computers one with IP:192.168.20.40
with master configuration and other with IP:192.168.20.55
with slave configuration. I am running Springboot application using jedis (not using spring-jedis) on two systems, different conditions are occuring-
@Bean
public JedisSentinelPool jedisSentinelPool() {
Set<String> sentinels=new HashSet<>();
sentinels.add("192.168.20.40:26379");
sentinels.add("192.168.20.55:26379");
JedisSentinelPool jedisSentinelPool=new JedisSentinelPool("mymaster", sentinels);
return jedisSentinelPool;
}
- When running application on master node(redis configured with master) data get entred in cache.
- When running application on slave node(redis configured with slave),exception occured - (i.) I am able to get the jedis object from sentinel pool but unable to store data into the redis with exception "redis.clients.jedis.exceptions.JedisDataException: READONLY You can't write against a read only slave."
When running application on another server(192.168.20.33), and redis server are hosted on "IP:192.168.20.40" & "IP:192.168.20.55" , then my application is unable to get the jedis object from sentinel pool-
public String addToCache(@PathVariable("cacheName") String cacheName, HttpEntity<String> httpEntity, @PathVariable("key") String key) { try (Jedis jedis = jedisPool.getResource();) { long dataToEnter = jedis.hset(cacheName.getBytes(), key.getBytes(), httpEntity.getBody().getBytes()); if (dataToEnter == 0) log.info("data existed in cache {} get updated ",cacheName); else log.info("new data inserted in cache {}",cacheName); } catch (Exception e) { System.out.println(e); } return httpEntity.getBody(); }
any input would be appreciable.