Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9
-
Upload
nikita-koksharov -
Category
Engineering
-
view
214 -
download
0
Transcript of Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9
![Page 1: Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9](https://reader033.fdocuments.in/reader033/viewer/2022050811/58743c4d1a28ab0e6c8b5b0d/html5/thumbnails/1.jpg)
Java data structures powered by Redis. Introduction to Redisson
Nikita KoksharovFounder of
![Page 2: Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9](https://reader033.fdocuments.in/reader033/viewer/2022050811/58743c4d1a28ab0e6c8b5b0d/html5/thumbnails/2.jpg)
WHY REDISSON? WHY DO WE NEED ANOTHER REDIS CLIENT?
![Page 3: Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9](https://reader033.fdocuments.in/reader033/viewer/2022050811/58743c4d1a28ab0e6c8b5b0d/html5/thumbnails/3.jpg)
COMMUNITY ORIENTEDOPEN SOURCE (APACHE LICENCE)
![Page 4: Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9](https://reader033.fdocuments.in/reader033/viewer/2022050811/58743c4d1a28ab0e6c8b5b0d/html5/thumbnails/4.jpg)
DISTRIBUTED COLLECTIONS
▸ Map *▸ MultiMap *▸ LocalCachedMap▸ Set *▸ SortedSet▸ ScoredSortedSet▸ LexSortedSet▸ List* Supports individual element eviction
▸ Queue▸ Deque▸ BlockingQueue▸ BlockingDeque▸ BoundedBlockingQueue▸ BlockingFairQueue▸ DelayedQueue
![Page 5: Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9](https://reader033.fdocuments.in/reader033/viewer/2022050811/58743c4d1a28ab0e6c8b5b0d/html5/thumbnails/5.jpg)
MAP
ConcurrentMap<Integer, MyObject> map = new ConcurrentHashMap<>();
map.put(20, new MyObject("oldobj"));
map.putIfAbsent(20, new MyObject("newobj"));
map.containsKey(1);
![Page 6: Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9](https://reader033.fdocuments.in/reader033/viewer/2022050811/58743c4d1a28ab0e6c8b5b0d/html5/thumbnails/6.jpg)
REDISSON MAP
ConcurrentMap<Integer, MyObject> map = redisson.getMap("someMap");
map.put(20, new MyObject("oldobj"));
map.putIfAbsent(20, new MyObject("newobj"));
map.containsKey(1);
![Page 7: Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9](https://reader033.fdocuments.in/reader033/viewer/2022050811/58743c4d1a28ab0e6c8b5b0d/html5/thumbnails/7.jpg)
REDISSON MAP EVICTION
RMapCache<Integer, String> map = redisson.getMapCache("someMap");
map.put(20, "oldobj", 20, TimeUnit.MINUTES);
map.containsKey(4);
map.putIfAbsent(2, "oldobj", 5, TimeUnit.SECONDS);
![Page 8: Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9](https://reader033.fdocuments.in/reader033/viewer/2022050811/58743c4d1a28ab0e6c8b5b0d/html5/thumbnails/8.jpg)
REDISSON SET
Set<String> set = redisson.getSet("someSet");
set.add("value");
set.contains("value");
set.remove("value");
![Page 9: Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9](https://reader033.fdocuments.in/reader033/viewer/2022050811/58743c4d1a28ab0e6c8b5b0d/html5/thumbnails/9.jpg)
REDISSON BLOCKINGQUEUE
BlockingQueue<MyObj> queue = redisson.getSet("someSet");
set.add(new MyObj("value"));
MyObj obj = queue.peek();
MyObj obj = queue.poll(10, TimeUnit.MINUTES);
![Page 10: Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9](https://reader033.fdocuments.in/reader033/viewer/2022050811/58743c4d1a28ab0e6c8b5b0d/html5/thumbnails/10.jpg)
DISTRIBUTED LOCKS AND SYNCHRONIZERS
▸ Lock▸ FairLock▸ RedLock▸ MultiLock▸ ReadWriteLock▸ Semaphore▸ PermitExpirableSemaphore▸ CountDownLatch▸ Phaser (Planned)
![Page 11: Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9](https://reader033.fdocuments.in/reader033/viewer/2022050811/58743c4d1a28ab0e6c8b5b0d/html5/thumbnails/11.jpg)
REDISSON LOCK
RLock lock = redisson.getLock("lock");
lock.lock();
// or
lock.lock(10, TimeUnit.MINUTES);
//…
lock.unlock();
![Page 12: Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9](https://reader033.fdocuments.in/reader033/viewer/2022050811/58743c4d1a28ab0e6c8b5b0d/html5/thumbnails/12.jpg)
▸ Bucket (Object Holder)▸ BinaryStream (Input & Output Stream)▸ Geo (Geospatial Object Holder)▸ BitSet▸ AtomicLong▸ AtomicDouble▸ Topic (Pub/Sub)▸ BloomFilter▸ HyperLogLog
DISTRIBUTED OBJECTS
![Page 13: Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9](https://reader033.fdocuments.in/reader033/viewer/2022050811/58743c4d1a28ab0e6c8b5b0d/html5/thumbnails/13.jpg)
REDISSON PUB/SUB
RTopic<SomeMessage> topic = redisson.getTopic("someTopic");
topic.addListener(new MessageListener<SomeMessage>() {
@Override
public void onMessage(String channel, SomeMessage message) {
System.out.println(message);
}
});
// in other thread or other JVM
RTopic<SomeMessage> topic = redisson.getTopic(" someTopic");
topic.publish(new SomeMessage("new message"));
![Page 14: Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9](https://reader033.fdocuments.in/reader033/viewer/2022050811/58743c4d1a28ab0e6c8b5b0d/html5/thumbnails/14.jpg)
INTERGRATION WITH FRAMEWORKS
▸ Spring Cache▸ Hibernate Cache▸ JCache API (JSR-107) implementation▸ Tomcat Session Manager▸ Spring Session
![Page 15: Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9](https://reader033.fdocuments.in/reader033/viewer/2022050811/58743c4d1a28ab0e6c8b5b0d/html5/thumbnails/15.jpg)
CONNECTION MODES
▸ Replicated nodes *▸ Cluster nodes *▸ Sentinel nodes▸ Master with Slave nodes▸ Single node
* Also supports AWS ElastiCache and Azure Redis Cache
![Page 16: Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9](https://reader033.fdocuments.in/reader033/viewer/2022050811/58743c4d1a28ab0e6c8b5b0d/html5/thumbnails/16.jpg)
DATA SERIALIZATION
▸ Jackson JSON▸ Avro▸ Smile▸ CBOR▸ MsgPack▸ Snappy▸ Kryo▸ FST▸ LZ4▸ JDK Serialization
![Page 17: Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9](https://reader033.fdocuments.in/reader033/viewer/2022050811/58743c4d1a28ab0e6c8b5b0d/html5/thumbnails/17.jpg)
HOW TO START
// 1. Create config object
Config = new Config();
config.useClusterServers()
.addNodeAddress("myserver.com:7000", "myserver.com:7001");
// 2. Create Redisson instance
RedissonClient redisson = Redisson.create(config);
// 3. Get object you need
Map<String, String> map = redisson.getMap("myMap");
![Page 18: Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9](https://reader033.fdocuments.in/reader033/viewer/2022050811/58743c4d1a28ab0e6c8b5b0d/html5/thumbnails/18.jpg)
ASYNCHRONOUS COMMAND EXECUTION
RMapAsync<Integer, String> map = redisson.getMap("someMap");
Future<String> putIfFuture = map.putIfAbsentAsync(20, "object");
Future<String> getFuture = map.getAsync(20);
getFuture.addListener(new FutureListener<Boolean>() {
@Override
public void operationComplete(Future<Boolean> future)
throws Exception {
//…
}
});
![Page 19: Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9](https://reader033.fdocuments.in/reader033/viewer/2022050811/58743c4d1a28ab0e6c8b5b0d/html5/thumbnails/19.jpg)
REACTIVE COMMAND EXECUTION
RedissonReactive redisson = Redisson.createReactive(config);
RMapReactive<Integer, String> map = redisson.getMap("someMap");
Publisher<String> putRes = map.put(20, "object");
Publisher<String> value = map.getAsync(20);
![Page 20: Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9](https://reader033.fdocuments.in/reader033/viewer/2022050811/58743c4d1a28ab0e6c8b5b0d/html5/thumbnails/20.jpg)
LOW-LEVEL REDIS CLIENT
RedisClient client = new RedisClient("localhost", 6379);RedisConnection conn = client.connect();
Future<RedisConnection> connFuture = client.connectAsync();
conn.sync(StringCodec.INSTANCE, RedisCommands.SET, "key", "value");
Future<String> res = conn.async(StringCodec.INSTANCE, RedisCommands.GET, "key");
![Page 21: Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9](https://reader033.fdocuments.in/reader033/viewer/2022050811/58743c4d1a28ab0e6c8b5b0d/html5/thumbnails/21.jpg)
USED BY
▸ Electronic Arts▸ Baidu▸ Infor▸ New Relic Synthetics▸ Singtel▸ Crimson Hexagon▸ Brookhaven National
Laboratory▸ Netflix Dyno client▸ 武林Q传▸ Monits
▸ Ocous▸ Invaluable▸ Clover▸ Apache Karaf Decanter▸ Atmosphere Framework▸ BrandsEye▸ Datorama▸ BrightCloud▸ Azar▸ Snapfish…
![Page 22: Java data structures powered by Redis. Introduction to Redisson @ Redis Lightning Talks, May 9](https://reader033.fdocuments.in/reader033/viewer/2022050811/58743c4d1a28ab0e6c8b5b0d/html5/thumbnails/22.jpg)
THANK YOU!
http://redisson.org