|
|
|
@ -117,170 +117,5 @@ Include the following to your dependency list:
|
|
|
|
|
<version>1.1.5</version>
|
|
|
|
|
</dependency>
|
|
|
|
|
|
|
|
|
|
Usage examples
|
|
|
|
|
================================
|
|
|
|
|
####Simple config example
|
|
|
|
|
|
|
|
|
|
// connects to Redis server 127.0.0.1:6379 by default
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
redisson.shutdown();
|
|
|
|
|
|
|
|
|
|
or with initialization by Config object for single server connection
|
|
|
|
|
|
|
|
|
|
Config config = new Config();
|
|
|
|
|
config.useSingleServer()
|
|
|
|
|
.setAddress("127.0.0.1:6379")
|
|
|
|
|
.setConnectionPoolSize(10);
|
|
|
|
|
|
|
|
|
|
Redisson redisson = Redisson.create(config);
|
|
|
|
|
|
|
|
|
|
or master/slave servers connection
|
|
|
|
|
|
|
|
|
|
Config config = new Config();
|
|
|
|
|
config.useMasterSlaveConnection()
|
|
|
|
|
.setMasterAddress("127.0.0.1:6379")
|
|
|
|
|
.addSlaveAddress("127.0.0.1:6389", "127.0.0.1:6332", "127.0.0.1:6419")
|
|
|
|
|
.addSlaveAddress("127.0.0.1:6399");
|
|
|
|
|
|
|
|
|
|
Redisson redisson = Redisson.create(config);
|
|
|
|
|
|
|
|
|
|
for sentinel servers connection
|
|
|
|
|
|
|
|
|
|
Config config = new Config();
|
|
|
|
|
config.useSentinelConnection()
|
|
|
|
|
.setMasterName("mymaster")
|
|
|
|
|
.addSentinelAddress("127.0.0.1:26389", "127.0.0.1:26379")
|
|
|
|
|
.addSentinelAddress("127.0.0.1:26319";
|
|
|
|
|
|
|
|
|
|
Redisson redisson = Redisson.create(config);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
####Distributed Map example
|
|
|
|
|
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
|
|
|
|
|
RMap<String, SomeObject> map = redisson.getMap("anyMap");
|
|
|
|
|
map.put("123", new SomeObject());
|
|
|
|
|
map.putIfAbsent("323", new SomeObject());
|
|
|
|
|
map.remove("123");
|
|
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
redisson.shutdown();
|
|
|
|
|
|
|
|
|
|
####Distributed Set example
|
|
|
|
|
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
|
|
|
|
|
RSet<SomeObject> set = redisson.getSet("anySet");
|
|
|
|
|
set.add(new SomeObject());
|
|
|
|
|
set.remove(new SomeObject());
|
|
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
redisson.shutdown();
|
|
|
|
|
|
|
|
|
|
####Distributed List example
|
|
|
|
|
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
|
|
|
|
|
RList<SomeObject> list = redisson.getList("anyList");
|
|
|
|
|
list.add(new SomeObject());
|
|
|
|
|
list.get(0);
|
|
|
|
|
list.remove(new SomeObject());
|
|
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
redisson.shutdown();
|
|
|
|
|
|
|
|
|
|
####Distributed Queue example
|
|
|
|
|
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
|
|
|
|
|
RQueue<SomeObject> queue = redisson.getQueue("anyQueue");
|
|
|
|
|
queue.add(new SomeObject());
|
|
|
|
|
queue.peek();
|
|
|
|
|
queue.pool();
|
|
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
redisson.shutdown();
|
|
|
|
|
|
|
|
|
|
####Distributed Lock example
|
|
|
|
|
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
|
|
|
|
|
RLock lock = redisson.getLock("anyLock");
|
|
|
|
|
lock.lock();
|
|
|
|
|
lock.unlock();
|
|
|
|
|
|
|
|
|
|
// same as
|
|
|
|
|
|
|
|
|
|
redisson.getLock("anyLock").lock();
|
|
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
redisson.getLock("anyLock").unlock();
|
|
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
redisson.shutdown();
|
|
|
|
|
|
|
|
|
|
####Distributed AtomicLong example
|
|
|
|
|
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
|
|
|
|
|
RAtomicLong atomicLong = redisson.getAtomicLong("anyAtomicLong");
|
|
|
|
|
atomicLong.set(3);
|
|
|
|
|
atomicLong.incrementAndGet();
|
|
|
|
|
atomicLong.get();
|
|
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
redisson.shutdown();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
####Distributed CountDownLatch example
|
|
|
|
|
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
|
|
|
|
|
RCountDownLatch latch = redisson.getCountDownLatch("anyCountDownLatch");
|
|
|
|
|
latch.trySetCount(1);
|
|
|
|
|
latch.await();
|
|
|
|
|
|
|
|
|
|
// in other thread or other JVM
|
|
|
|
|
|
|
|
|
|
RCountDownLatch latch = redisson.getCountDownLatch("anyCountDownLatch");
|
|
|
|
|
latch.countDown();
|
|
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
redisson.shutdown();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
####Distributed Topic example
|
|
|
|
|
|
|
|
|
|
Redisson redisson = Redisson.create();
|
|
|
|
|
|
|
|
|
|
RTopic<SomeObject> topic = redisson.getTopic("anyTopic");
|
|
|
|
|
topic.addListener(new MessageListener<SomeObject>() {
|
|
|
|
|
|
|
|
|
|
public void onMessage(SomeObject message) {
|
|
|
|
|
...
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// in other thread or other JVM
|
|
|
|
|
|
|
|
|
|
RTopic<SomeObject> topic = redisson.getTopic("anyTopic");
|
|
|
|
|
topic.publish(new SomeObject());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
redisson.shutdown();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Read [wiki](https://github.com/mrniko/redisson/wiki) for more Redisson usage details
|
|
|
|
|