use of org.redisson.micronaut.cache.RedissonSyncCache in project redisson by redisson.
the class RedissonCacheTest method testCache.
@Test
public void testCache() throws InterruptedException {
Map<String, Object> map = new HashMap<>();
map.put("redisson.threads", "10");
map.put("redisson.single-server-config.address", "redis://127.0.0.1:6379");
// map.put("redisson.clusterServersConfig.scanInterval", "3333");
// map.put("redisson.clusterServersConfig.nodeAddresses", Arrays.asList("redis://127.0.0.2:6379","redis://127.0.0.3:6379"));
map.put("redisson.caches.test.expire-after-write", "10s");
map.put("redisson.caches.test.expire-after-access", "3s");
ApplicationContext ac = ApplicationContext.run(map);
RedissonClient client = ac.getBean(RedissonClient.class);
assertThat(client).isNotNull();
RedissonSyncCache cache = ac.getBean(RedissonSyncCache.class, Qualifiers.byName("test"));
cache.put(1, 2);
Thread.sleep(3500);
assertThat(cache.get(1, Integer.class).isPresent()).isFalse();
cache.put(3, 4);
Thread.sleep(2000);
cache.get(3, Integer.class);
Thread.sleep(2000);
assertThat(cache.get(3, Integer.class).isPresent()).isTrue();
}
use of org.redisson.micronaut.cache.RedissonSyncCache in project redisson by redisson.
the class RedissonFactory method cache.
@EachBean(RedissonCacheConfiguration.class)
public RedissonSyncCache cache(@Parameter RedissonCacheConfiguration configuration, RedissonClient redisson, ConversionService<?> conversionService, @Named(TaskExecutors.IO) ExecutorService executorService) {
Codec codec = Optional.ofNullable(configuration.getCodec()).orElse(redisson.getConfig().getCodec());
if (configuration.getExpireAfterAccess().toMillis() != 0 || configuration.getExpireAfterWrite().toMillis() != 0 || configuration.getMaxSize() != 0) {
RMapCache<Object, Object> mapCache = redisson.getMapCache(configuration.getName(), codec);
return new RedissonSyncCache(conversionService, mapCache, mapCache, executorService, configuration);
}
RMap<Object, Object> map = redisson.getMap(configuration.getName(), codec);
return new RedissonSyncCache(conversionService, null, map, executorService, configuration);
}
Aggregations