Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are redis put get get evict async? #3121

Closed
abhinavbansal19961996 opened this issue Mar 19, 2025 · 1 comment
Closed

Are redis put get get evict async? #3121

abhinavbansal19961996 opened this issue Mar 19, 2025 · 1 comment
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@abhinavbansal19961996
Copy link

abhinavbansal19961996 commented Mar 19, 2025

We are having a spring boot application and we are using redis 7.x version, cluster mode disabled.
spring-boot-starter-data-redis: 3.4.3

Configuration
  public CacheManager cacheManager(RedisConnectionFactory connectionFactory) {
    log.info("Initializing Redis cache manager");
    var cacheRegions = redisCacheConfig.getCacheRegions();

    var cacheConfigurations =
        cacheRegions.stream()
            .filter(CacheConfig::cachesThatHaveTTl)
            .collect(
                toMap(
                    RedisCacheConfig.Cache::getRegion,
                    cache ->
                        RedisCacheConfiguration.defaultCacheConfig()
                            .entryTtl(ofSeconds(cache.getTtl()))));

    return builder(connectionFactory)
        .withInitialCacheConfigurations(cacheConfigurations)
        .enableStatistics()
        .transactionAware()
        .build();
  }

We have a API which perform put--->get--->get---->evict (Below method). When we hit this API. On redis server logs (Using redis-cli monitor) we found that, first two gets called, then evict and at last put and its intermittent. Is it async? How can it happen in async way? I thought above operation waits for each other to complete.
Important Note: I am using @transactional


  public void put(String cacheName, String key, Object value) {
    Cache cache = cacheManager.getCache(cacheName);
    if (nonNull(cache)) {
      cache.put(key, value);
      // Increment cache update counter
      registerUpdate(cacheName);
    }
  }

  public Object get(String cacheName, String key) {
    Cache cache = cacheManager.getCache(cacheName);
    if (nonNull(cache)) {
      Cache.ValueWrapper valueWrapper = cache.get(key);
      if (nonNull(valueWrapper)) {
        registerHit(cacheName);
        return valueWrapper.get();
      } else {
        // Increment cache miss counter
        registerMiss(cacheName);
      }
    }
    return null;
  }
  public void evict(String cacheName, String key) {
    Cache cache = cacheManager.getCache(cacheName);
    if (nonNull(cache)) {
      cache.evictIfPresent(key);
      registerEvict(cacheName);
    }
  }

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 19, 2025
@abhinavbansal19961996
Copy link
Author

We can close this. I found the reason
https://docs.spring.io/spring-data/redis/reference/redis/transactions.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

2 participants