Refine search
protected void shutdownRedisson() { if (redisson != null) { redisson.shutdown(); } }
public RMap<String, Object> getMap(String sessionId) { String separator = keyPrefix == null || keyPrefix.isEmpty() ? "" : ":"; String name = keyPrefix + separator + "redisson:tomcat_session:" + sessionId; return redisson.getMap(name, new CompositeCodec(StringCodec.INSTANCE, redisson.getConfig().getCodec())); }
public RedissonPriorityQueue(CommandExecutor commandExecutor, String name, RedissonClient redisson) { super(commandExecutor, name, redisson); this.commandExecutor = commandExecutor; comparatorHolder = redisson.getBucket(getComparatorKeyName(), StringCodec.INSTANCE); lock = redisson.getLock("redisson_sortedset_lock:{" + getName() + "}"); loadComparator(); }
protected RedissonSortedSet(CommandExecutor commandExecutor, String name, RedissonClient redisson) { super(commandExecutor, name); this.commandExecutor = commandExecutor; this.redisson = redisson; comparatorHolder = redisson.getBucket(getComparatorKeyName(), StringCodec.INSTANCE); lock = redisson.getLock("redisson_sortedset_lock:{" + getName() + "}"); list = (RedissonList<V>) redisson.getList(getName()); loadComparator(); }
public static void main(String[] args) throws InterruptedException { // connects to 127.0.0.1:6379 by default RedissonClient redisson = Redisson.create(); CountDownLatch latch = new CountDownLatch(1); RTopic topic = redisson.getTopic("topic2"); topic.addListener(String.class, new MessageListener<String>() { @Override public void onMessage(CharSequence channel, String msg) { latch.countDown(); } }); topic.publish("msg"); latch.await(); redisson.shutdown(); }
public static void main(String[] args) { RedissonClient redisson = Redisson.create(); RBucket<String> bucket = redisson.getBucket("test"); bucket.set("123"); boolean isUpdated = bucket.compareAndSet("123", "4934"); String prevObject = bucket.getAndSet("321"); boolean isSet = bucket.trySet("901"); long objectSize = bucket.size(); // set with expiration bucket.set("value", 10, TimeUnit.SECONDS); boolean isNewSet = bucket.trySet("nextValue", 10, TimeUnit.SECONDS); redisson.shutdown(); }
public static void main(String[] args) { // connects to 127.0.0.1:6379 by default RedissonClient server = Redisson.create(); RedissonClient client = Redisson.create(); try { server.getRemoteService().register(RemoteInterface.class, new RemoteImpl()); RemoteInterface service = client.getRemoteService().get(RemoteInterface.class); service.myMethod(21L); } finally { client.shutdown(); server.shutdown(); } }
public static void main(String[] args) { // connects to 127.0.0.1:6379 by default RedissonClient redisson = Redisson.create(); RAtomicLong atomicLong = redisson.getAtomicLong("myLong"); atomicLong.getAndDecrement(); atomicLong.getAndIncrement(); atomicLong.addAndGet(10L); atomicLong.compareAndSet(29, 412); atomicLong.decrementAndGet(); atomicLong.incrementAndGet(); atomicLong.getAndAdd(302); atomicLong.getAndDecrement(); atomicLong.getAndIncrement(); redisson.shutdown(); }
public static void main(String[] args) { // connects to 127.0.0.1:6379 by default RedissonClient redisson = Redisson.create(); RAtomicDouble atomicDouble = redisson.getAtomicDouble("myDouble"); atomicDouble.getAndDecrement(); atomicDouble.getAndIncrement(); atomicDouble.addAndGet(10.323); atomicDouble.compareAndSet(29.4, 412.91); atomicDouble.decrementAndGet(); atomicDouble.incrementAndGet(); atomicDouble.getAndAdd(302.00); atomicDouble.getAndDecrement(); atomicDouble.getAndIncrement(); redisson.shutdown(); }
public RedissonSession(String keyPrefix) { this.delegate = new MapSession(); map = redisson.getMap(keyPrefix + delegate.getId(), new CompositeCodec(StringCodec.INSTANCE, redisson.getConfig().getCodec())); principalName = resolvePrincipal(delegate); Map<String, Object> newMap = new HashMap<String, Object>(3); newMap.put("session:creationTime", delegate.getCreationTime()); newMap.put("session:lastAccessedTime", delegate.getLastAccessedTime()); newMap.put("session:maxInactiveInterval", delegate.getMaxInactiveIntervalInSeconds()); map.putAll(newMap); updateExpiration(); String channelName = getEventsChannelName(delegate.getId()); RTopic topic = redisson.getTopic(channelName, StringCodec.INSTANCE); topic.publish(delegate.getId()); }
public RTopic getTopic() { String separator = keyPrefix == null || keyPrefix.isEmpty() ? "" : ":"; final String name = keyPrefix + separator + "redisson:tomcat_session_updates:" + ((Context) getContainer()).getName(); return redisson.getTopic(name); }
@Override public void run() { Codec codec; try { codec = (Codec) objectCodecClass.getConstructor().newInstance(); } catch (Exception e) { throw new IllegalStateException(e); } Injector.inject(mapper, redisson); RCollector<KOut, VOut> collector = new Collector<KOut, VOut>(codec, redisson, collectorMapName, workersAmount, timeout); for (String objectName : objectNames) { RMap<KIn, VIn> map = null; if (RMapCache.class.isAssignableFrom(objectClass)) { map = redisson.getMapCache(objectName, codec); } else { map = redisson.getMap(objectName, codec); } for (Entry<KIn, VIn> entry : map.entrySet()) { if (Thread.currentThread().isInterrupted()) { return; } mapper.map(entry.getKey(), entry.getValue(), collector); } } }
@Override public RedisSentinelConnection getSentinelConnection() { if (!redisson.getConfig().isSentinelConfig()) { throw new InvalidDataAccessResourceUsageException("Redisson is not in Sentinel mode"); } SentinelConnectionManager manager = ((SentinelConnectionManager)((Redisson)redisson).getConnectionManager()); for (RedisClient client : manager.getSentinels()) { org.redisson.client.RedisConnection connection = client.connect(); try { String res = connection.sync(RedisCommands.PING); if ("pong".equalsIgnoreCase(res)) { return new RedissonSentinelConnection(connection); } } catch (Exception e) { log.warn("Can't connect to " + client, e); connection.closeAsync(); } } throw new InvalidDataAccessResourceUsageException("Sentinels are not found"); }
private Object executeCollator() throws ExecutionException, Exception { if (collator == null) { if (timeout > 0) { redisson.getMap(resultMapName).clearExpire(); } return null; } Callable<Object> collatorTask = new CollatorTask<KOut, VOut, Object>(redisson, collator, resultMapName, objectCodecClass); long timeSpent = System.currentTimeMillis() - startTime; if (isTimeoutExpired(timeSpent)) { throw new MapReduceTimeoutException(); } if (timeout > 0) { ExecutorService executor = ((Redisson) redisson).getConnectionManager().getExecutor(); java.util.concurrent.Future<?> collatorFuture = executor.submit(collatorTask); try { return collatorFuture.get(timeout - timeSpent, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { return null; } catch (TimeoutException e) { collatorFuture.cancel(true); throw new MapReduceTimeoutException(); } } else { return collatorTask.call(); } }
protected RMapCache<Object, Object> getMapCache(String name, CacheConfig config) { if (codec != null) { return redisson.getMapCache(name, codec); } return redisson.getMapCache(name); }
@Override public Long resolve(Class value, RId id, String idFieldName, RedissonClient redisson) { return redisson.getAtomicLong(this.getClass().getCanonicalName() + "{" + value.getCanonicalName() + "}:" + idFieldName) .incrementAndGet(); }
@Override public CommandAsyncExecutor enableRedissonReferenceSupport(RedissonClient redisson) { if (redisson != null) { this.redisson = redisson; enableRedissonReferenceSupport(redisson.getConfig()); this.redissonReactive = null; this.redissonRx = null; } return this; }
@Override public final String type(final String key) { RType type = redissonClient.getKeys().getType(key); if (type == null) { return null; } return type.getClass().getName(); }
private void awaitResultAsync(final RemoteInvocationOptions optionsCopy, final RemotePromise<Object> result, final String ackName, final RFuture<RRemoteServiceResponse> responseFuture) { RFuture<Boolean> deleteFuture = redisson.getBucket(ackName).deleteAsync(); deleteFuture.addListener(new FutureListener<Boolean>() { @Override public void operationComplete(Future<Boolean> future) throws Exception { if (!future.isSuccess()) { result.tryFailure(future.cause()); return; } awaitResultAsync(optionsCopy, result, responseFuture); } }); }