作用:RBucket桶可存储任意对象,可在高并发场景下进行唯一更新。
示例:创建20个线程并发更新桶对象,只有一个执行了更新操作。
先添加redisson的依赖。
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>3.20.0</version>
</dependency>
public static void main(String[] args) {
Config config = new Config();
config.useSingleServer()
.setAddress("redis://localhost:6379")
.setPassword("123456");
RedissonClient client = Redisson.create(config);
RCountDownLatch countDownLatch = client.getCountDownLatch("countDownLatch");
countDownLatch.trySetCount(20);
RBucket<String> bucket = client.getBucket("bucket");
bucket.set("桶测试"+1);
String oldValue=bucket.get();
ExecutorService executorService= Executors.newFixedT

最低0.47元/天 解锁文章
1843

被折叠的 条评论
为什么被折叠?



