0

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;
}
  1. When running application on master node(redis configured with master) data get entred in cache.
  2. 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."
  3. 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.

Michal Kania
  • 609
  • 11
  • 24
  • If connecting to a cluster with sentinel, you need not worry which node behind the sentinel is master or slave. The sentinel will pick the up the master node at that moment for writes (or reads). Can you elaborate what do you mean by "running application on slave node" or "running application on master node"? – shane Oct 17 '19 at 19:31

1 Answers1

0

Can you please check you redis configuration file (redis.conf). It should have read-only mode enabled by default. You need to change the read only mode to false.

Rmahajan
  • 1,311
  • 1
  • 14
  • 23