Reputation: 1
I am using AWS Elasticache Redis cluster with Clustered mode enabled. My current cluster configuration is having 1 node group & 2 nodes within the group. As good as having 1 master and 2 slave nodes.
I am using redisTemplate to perform the cache operation like below:
redisTample.execute(new SessionCallback<Void>() {
@Override
public Void execute(RedisOperations ops) {
ops.opsForValue().set(key, Object, TTL, TimeUnit.SECONDS);
//verify that the key is created or not
if(Boolean.TRUE.equals(ops.hasKey(key)) {
logger.info("Key is present. In slot: {}", redissonClient.getKeys().getSlot(key));
}
}
});
Once the above code gets executed, I see the log line Key is present with the slot information. And then when I try to check the value of this key, the value is null sometimes!
Object obj = ops.opsForValue().get(key); //obj is null here
Note: It does not return NULL value always. Can someone help me here what is going on?
I am trying to add the key-value to redis cache, but the value is coming as null sometimes.
Upvotes: 0
Views: 540
Reputation: 10763
It's because of replication lag between Redis master and slave nodes. You can resolve it if you set Redisson readMode
setting to master
Upvotes: 0