完成redisson分布式容器的文档阅读
This commit is contained in:
@@ -1176,4 +1176,39 @@ buffer.add(6);
|
|||||||
- tryTransfer会非阻塞的添加元素,当存在消费者调用poll获取当前元素时,该方法会将元素交给消费者,否则返回false。
|
- tryTransfer会非阻塞的添加元素,当存在消费者调用poll获取当前元素时,该方法会将元素交给消费者,否则返回false。
|
||||||
- transfer会阻塞等待,直到有消费者线程来获取该元素
|
- transfer会阻塞等待,直到有消费者线程来获取该元素
|
||||||
> 当调用阻塞版本trasfer之后,直到该transfer返回,其他线程无法向TransferQueue中添加元素。
|
> 当调用阻塞版本trasfer之后,直到该transfer返回,其他线程无法向TransferQueue中添加元素。
|
||||||
|
```java
|
||||||
|
RTransferQueue<String> queue = redisson.getTransferQueue("myCountDownLatch");
|
||||||
|
|
||||||
|
queue.transfer("data");
|
||||||
|
// or try transfer immediately
|
||||||
|
queue.tryTransfer("data");
|
||||||
|
// or try transfer up to 10 seconds
|
||||||
|
queue.tryTransfer("data", 10, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
// in other thread or JVM
|
||||||
|
|
||||||
|
queue.take();
|
||||||
|
// or
|
||||||
|
queue.poll();
|
||||||
|
```
|
||||||
|
### Time Series
|
||||||
|
基于Redis的TimeSeries允许按照Timestamp来存储值,并且支持为entry设置ttl。
|
||||||
|
TimeSeries的使用如下所示:
|
||||||
|
```java
|
||||||
|
RTimeSeries<String> ts = redisson.getTimeSeries("myTimeSeries");
|
||||||
|
|
||||||
|
ts.add(201908110501, "10%");
|
||||||
|
ts.add(201908110502, "30%");
|
||||||
|
ts.add(201908110504, "10%");
|
||||||
|
ts.add(201908110508, "75%");
|
||||||
|
|
||||||
|
// entry time-to-live is 10 hours
|
||||||
|
ts.add(201908110510, "85%", 10, TimeUnit.HOURS);
|
||||||
|
ts.add(201908110510, "95%", 10, TimeUnit.HOURS);
|
||||||
|
|
||||||
|
String value = ts.get(201908110508);
|
||||||
|
ts.remove(201908110508);
|
||||||
|
|
||||||
|
Collection<String> values = ts.pollFirst(2);
|
||||||
|
Collection<String> range = ts.range(201908110501, 201908110508);
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user