Redisson的用法

https://github.com/redisson/redisson

Redisson作为一个分布式缓存的一个解决方案,在redis的基础上加入了提供分布式对象


通用对象桶(Object Bucket)、二进制流(Binary Stream)、地理空间对象桶(Geospatial Bucket)、BitSet、原子整长形(AtomicLong)、原子双精度浮点数(AtomicDouble)、话题(订阅分发)、 布隆过滤器(Bloom Filter)和基数估计算法(HyperLogLog)

提供分布式集合
映射(Map)、多值映射(Multimap)、集(Set)、列表(List)、有序集(SortedSet)、计分排序集(ScoredSortedSet)、字典排序集(LexSortedSet)、列队(Queue)、双端队列(Deque)、阻塞队列(Blocking Queue)、有界阻塞列队(Bounded Blocking Queue)、 阻塞双端列队(Blocking Deque)、阻塞公平列队(Blocking Fair Queue)、延迟列队(Delayed Queue)、优先队列(Priority Queue)和优先双端队列(Priority Deque)

提供分布式锁和同步器
可重入锁(Reentrant Lock)、公平锁(Fair Lock)、联锁(MultiLock)、 红锁(RedLock)、读写锁(ReadWriteLock)、信号量(Semaphore)、可过期性信号量(PermitExpirableSemaphore)和闭锁(CountDownLatch)

提供分布式服务
分布式远程服务(Remote Service, RPC)、分布式实时对象(Live Object)服务、分布式执行服务(Executor Service)、分布式调度任务服务(Scheduler Service)和分布式映射归纳服务(MapReduce)

分布式对象的用法

RAtomicLong rAtomicLong = redisson.getAtomicLong("key");
rAtomicLong.set(1223L);
rAtomicLong.expire(d,TimeUnit.DAYS);

 

redissonClient.getBucket("key").set(object, 40, TimeUnit.MINUTES);

分布式锁

RLock rLock = redisson.getLock("key");
try {
 rLock.lock();
} catch (Exception e) {
} finally {
    rLock.unlock();
}

批量

RBatch batch = redisson.createBatch();
batch.getBucket("key").setAsync(object);
batch.atomic().retryAttempts(3).execute();

 

你可能感兴趣的:(springCloud,redis)