redisson 应用(二)

Map

RMap map = redisson.getMap("anyMap");
SomeObject prevObject = map.put("123", new SomeObject());
SomeObject currentObject = map.putIfAbsent("323", new SomeObject());
SomeObject obj = map.remove("123");

Set

List

Queue

Delayed Queue

延时队列可以实现一些需要延时处理的数据存储,比如延时发送邮件等.

RBlockingQueue blockingQueue = redisson.getBlockingQueue("blockingQueue");
        RDelayedQueue delayedQueue = redisson.getDelayedQueue(blockingQueue);
        delayedQueue.offer("msg1", 10, TimeUnit.SECONDS);
        delayedQueue.offer("msg2", 1, TimeUnit.MINUTES);

        try {
            String msg1 = blockingQueue.poll(15, TimeUnit.SECONDS);
            LOGGER.debug("msg is {}", msg1);
            String msg2 = blockingQueue.poll(2, TimeUnit.SECONDS);
            LOGGER.debug("msg is {}", msg2);
        }catch (InterruptedException e) {
            e.printStackTrace();
        }

Priority Queue 优先队列

Stream 流

Ring Buffer 有限缓冲区

缓存区满了,之后前面的数据将被丢弃

TransferQueue

这个队列的offer方法会阻塞生产者直到有消费者消费了数据。同时提供了tryOffer方法和可以超时的tryOffer。

Time Series 时间序列

你可能感兴趣的:(redisson 应用(二))