Lakshitha Samod
Lakshitha Samod

Reputation: 391

Why does Redis existsById method sometimes return false under high load or concurrent access even though the key exists?

I’m facing an issue with Redis when checking if a key exists using CrudRepository.existsById(). Under normal conditions, everything works fine, and the key exists in Redis, but the problem arises under high request load or concurrent access.

Redis Service:

@Service
public class RedisService {

    private final SessionRedisDataRepository sessionRedisDataRepository;

    public RedisService(SessionRedisDataRepository sessionRedisDataRepository) {
        this.sessionRedisDataRepository = sessionRedisDataRepository;
    }


    public boolean isKeyExists(String key) {
        return sessionRedisDataRepository.existsById(key);
    }
}

Redis Repository:

public interface SessionRedisDataRepository extends CrudRepository<SessionRedisData, String> { 
}

Session Data Class:

@RedisHash(value = "SessionData", timeToLive = 3600L)
public class SessionRedisData implements Serializable {
    @Id
    private String sessionId;
}

When multiple requests come in at the same time or under high load, the isKeyExists method sometimes returns false even though the key exists in Redis.

What could be the underlying cause of this issue with existsById in this case and what are the fixes?

Upvotes: 0

Views: 30

Answers (0)

Related Questions