use of org.redisson.codec.CompositeCodec in project redisson by redisson.
the class RedissonMapCacheTest method testUpdatedListener.
@Test
public void testUpdatedListener() {
RMapCache<Integer, Integer> map = redisson.getMapCache("simple");
map.put(1, 1);
checkUpdatedListener(map, 1, 3, 1, () -> map.put(1, 3));
map.put(10, 1);
checkUpdatedListener(map, 10, 2, 1, () -> map.put(10, 2, 2, TimeUnit.SECONDS));
map.put(2, 1);
checkUpdatedListener(map, 2, 5, 1, () -> map.fastPut(2, 5));
map.put(13, 1);
checkUpdatedListener(map, 13, 2, 1, () -> map.fastPut(13, 2, 2, TimeUnit.SECONDS));
map.put(14, 1);
checkUpdatedListener(map, 14, 2, 1, () -> map.replace(14, 2));
checkUpdatedListener(map, 14, 3, 2, () -> map.replace(14, 2, 3));
map.destroy();
RMapCache<Integer, Integer> map2 = redisson.getMapCache("simple2", new CompositeCodec(redisson.getConfig().getCodec(), IntegerCodec.INSTANCE));
map2.put(5, 1);
checkUpdatedListener(map2, 5, 4, 1, () -> map2.addAndGet(5, 3));
map2.destroy();
}
use of org.redisson.codec.CompositeCodec in project redisson by redisson.
the class RedissonSessionRepository method loadSession.
private MapSession loadSession(String sessionId) {
RMap<String, Object> map = redisson.getMap(keyPrefix + sessionId, new CompositeCodec(StringCodec.INSTANCE, redisson.getConfig().getCodec()));
Set<Entry<String, Object>> entrySet = map.readAllEntrySet();
if (entrySet.isEmpty()) {
return null;
}
MapSession delegate = new MapSession(sessionId);
for (Entry<String, Object> entry : entrySet) {
if ("session:creationTime".equals(entry.getKey())) {
delegate.setCreationTime(Instant.ofEpochMilli((Long) entry.getValue()));
} else if ("session:lastAccessedTime".equals(entry.getKey())) {
delegate.setLastAccessedTime(Instant.ofEpochMilli((Long) entry.getValue()));
} else if ("session:maxInactiveInterval".equals(entry.getKey())) {
delegate.setMaxInactiveInterval(Duration.ofSeconds((Long) entry.getValue()));
} else if (entry.getKey().startsWith(SESSION_ATTR_PREFIX)) {
delegate.setAttribute(entry.getKey().substring(SESSION_ATTR_PREFIX.length()), entry.getValue());
}
}
return delegate;
}
use of org.redisson.codec.CompositeCodec in project redisson by redisson.
the class AsyncRemoteProxy method cancelExecution.
private void cancelExecution(RemoteInvocationOptions optionsCopy, boolean mayInterruptIfRunning, RemotePromise<Object> remotePromise, String cancelRequestMapName) {
RMap<String, RemoteServiceCancelRequest> canceledRequests = new RedissonMap<>(new CompositeCodec(StringCodec.INSTANCE, codec, codec), commandExecutor, cancelRequestMapName, null, null, null);
canceledRequests.fastPutAsync(remotePromise.getRequestId().toString(), new RemoteServiceCancelRequest(mayInterruptIfRunning, false));
canceledRequests.expireAsync(60, TimeUnit.SECONDS);
// subscribe for async result if it's not expected before
if (!optionsCopy.isResultExpected()) {
RemoteInvocationOptions options = new RemoteInvocationOptions(optionsCopy);
options.expectResultWithin(60, TimeUnit.SECONDS);
CompletionStage<RRemoteServiceResponse> responseFuture = pollResponse(options.getExecutionTimeoutInMillis(), remotePromise.getRequestId(), false);
awaitResultAsync(options, remotePromise, responseFuture);
}
}
use of org.redisson.codec.CompositeCodec in project redisson by redisson.
the class RedissonSessionStore method getMap.
public RMap<CharSequence, Object> getMap(String sessionId) {
String keyPrefix = sessionConfiguration.getKeyPrefix();
String separator = keyPrefix == null || keyPrefix.isEmpty() ? "" : ":";
String name = keyPrefix + separator + SESSION_PREFIX + sessionId;
return redisson.getMap(name, new CompositeCodec(StringCodec.INSTANCE, getCodec(), getCodec()));
}
use of org.redisson.codec.CompositeCodec in project redisson by redisson.
the class RedissonLocalCachedMapTest method testAddAndGet.
@Test
public void testAddAndGet() throws InterruptedException {
RLocalCachedMap<Integer, Integer> map = redisson.getLocalCachedMap("getAll", new CompositeCodec(redisson.getConfig().getCodec(), IntegerCodec.INSTANCE), LocalCachedMapOptions.defaults());
Map<Integer, Integer> cache = map.getCachedMap();
map.put(1, 100);
Integer res = map.addAndGet(1, 12);
assertThat(cache.size()).isEqualTo(1);
assertThat(res).isEqualTo(112);
res = map.get(1);
assertThat(res).isEqualTo(112);
RMap<Integer, Double> map2 = redisson.getLocalCachedMap("getAll2", new CompositeCodec(redisson.getConfig().getCodec(), DoubleCodec.INSTANCE), LocalCachedMapOptions.defaults());
map2.put(1, new Double(100.2));
Double res2 = map2.addAndGet(1, new Double(12.1));
assertThat(res2).isEqualTo(112.3);
res2 = map2.get(1);
assertThat(res2).isEqualTo(112.3);
RMap<String, Integer> mapStr = redisson.getLocalCachedMap("mapStr", new CompositeCodec(redisson.getConfig().getCodec(), IntegerCodec.INSTANCE), LocalCachedMapOptions.defaults());
assertThat(mapStr.put("1", 100)).isNull();
assertThat(mapStr.addAndGet("1", 12)).isEqualTo(112);
assertThat(mapStr.get("1")).isEqualTo(112);
assertThat(cache.size()).isEqualTo(1);
}
Aggregations