功能比较:Redisson vs Jedis

Redis最流行的两个Java客户端库是Redisson和Jedis。Redisson提供内存中的数据网格功能,支持Redis的各种分布式对象和服务。另一方面,Jedis是一个更轻量级的产品,它缺乏其他库的某些功能。

如果你正在为Redis寻找一个Java客户端库,你可能会想Redisson和Jedis的优缺点。在本文中,我们将比较和对比Redisson和Jedis提供的不同功能。

一 、分布式集合

|-----------------|----------|---------------------|
| | Redisson | Jedis |
| Map | √ | plain commands only |
| Multimap | √ | × |
| Set | √ | plain commands only |
| List | √ | plain commands only |
| Queue | √ | plain commands only |
| Deque | √ | plain commands only |
| SortedSet | √ | × |
| ScoredSortedSet | √ | plain commands only |
| PriorityQueue | √ | × |
| PriorityDeque | √ | × |
| DelayedQueue | √ | × |
| Stream | √ | plain commands only |
| RingBuffer | √ | × |
| TransferQueue | √ | × |
| TimeSeries | √ | × |

Redisson实现了许多不同的Java对象,包括分布式集合。这些Redisson对象帮助Java程序员使用他们在Java中习惯的许多熟悉的数据结构。

Redisson中的分布式集合列表包括:

  • Map
  • Multimap
  • Set
  • List
  • Queue
  • Deque
  • SortedSet
  • ScoredSortedSet
  • PriorityQueue
  • PriorityDeque
  • DelayedQueue
  • Stream
  • RingBuffer

另一方面,Jedis对Redis中分布式集合的支持要少得多。

只有Jedis中的普通命令才支持以下对象:

  • Map
  • Multimap
  • Set
  • List
  • Queue
  • Deque
  • ScoredSortedSet

二、分布式锁和同步器

|----------------|----------|-------|
| | Redisson | Jedis |
| Lock | √ | × |
| Semaphore | √ | × |
| CountDownLatch | √ | × |
| FairLock | √ | × |
| MultiLock | √ | × |
| ReadWriteLock | √ | × |

当处理分布式系统时,锁和同步的问题变得更加复杂,因为不同的客户端位于不同的机器上。

幸运的是,Redisson支持一些常见的Java锁和同步器用于分布式计算,例如:

  • Lock
  • Semaphore
  • CountDownLatch
  • FairLock
  • MultiLock

然而,Jedis在Redis中不支持任何这些锁和同步器。这意味着您必须自己处理这个问题,从而使开发过程更加复杂。

三、分布式对象

|----------------------------|----------|---------------------|
| | Redisson | Jedis |
| Object holder | √ | plain commands only |
| AtomicLong | √ | plain commands only |
| LongAdder | √ | × |
| DoubleAdder | √ | × |
| Publish/Subscribe | √ | plain commands only |
| Reliable Publish/Subscribe | √ | × |
| Id Generator | √ | × |
| AtomicDouble | √ | plain commands only |
| Geospatial | √ | plain commands only |
| BitSet | √ | plain commands only |
| BloomFilter | √ | × |
| BinaryStream | √ | × |
| HyperLogLog | √ | plain commands only |
| RateLimiter | √ | × |

除了分布式集合、锁和同步器,Redisson还在Java中为Redis实现了各种其他分布式对象:

  • ObjectHolder
  • AtomicLong
  • Publish/Subscribe
  • AtomicDouble
  • Geospatial
  • BitSet
  • BloomFilter
  • BinaryStream
  • HyperLogLog

在上面的分布式对象中,Jedis根本不支持BloomFilter或BinaryStream对象。仅通过普通命令支持列表中的其他对象。

四、高级缓存支持

|-----------------------------------------------|----------|-------|
| | Redisson | Jedis |
| JCache API | √ | × |
| JCache API with near cache (up to 45x faster) | √ | × |
| Near Cache | √ | × |
| Read-through strategy support | √ | × |
| Write-through strategy support | √ | × |
| Write-behind strategy support | √ | × |

只有Redisson具有各种高级缓存功能。例如,Redisson支持三种不同的缓存策略:读通、写通和写后。Redisson还有一个JCache API和一个近缓存,用于保存从远程缓存中提取的对象的本地副本。然而,Jedis没有开箱即用地支持上述任何功能。

五、Transactions

|------------------|----------|-------|
| | Redisson | Jedis |
| Transactions API | √ | × |

六、API architecture

|---------------------------|----------|-------|
| | Redisson | Jedis |
| Instance thread-safety | √ | × |
| Asynchronous interface | √ | × |
| Reactive stream interface | √ | × |
| RxJava3 interface | √ | × |

Redisson包括对实例线程安全、异步接口、Reactive Streams API和RxJava3 API的支持。然而,杰迪斯完全缺乏这种支持。

七、Distributed services

|-------------------|----------|-------|
| | Redisson | Jedis |
| ExecutorService | √ | × |
| MapReduce | √ | × |
| SchedulerService | √ | × |
| RemoteService | √ | × |
| LiveObjectService | √ | × |

Redisson支持Java中的各种分布式服务:

  • ExecutorService
  • MapReduce
  • SchedulerService
  • RemoteService
  • LiveObjectService

不幸的是,Jedis不支持这些分布式服务。

八、与框架的集成

|---------------------------------------------------|----------|-------|
| | Redisson | Jedis |
| Spring Cache | √ | × |
| Spring Cache with near cache (up to 45x faster) | √ | × |
| Hibernate Cache | √ | × |
| Hibernate Cache with near cache (up to 5x faster) | √ | × |
| MyBatis Cache | √ | × |
| MyBatis Cache with near cache (up to 45x faster) | √ | × |
| Tomcat Session Manager | √ | × |
| Spring Session | √ | × |

Jedis包括对SpringSession和SpringCache框架的支持。除了这两个框架之外,Redisson还支持Hibernate Cache和Tomcat会话管理器。

九、Security

|----------------|----------|-------|
| | Redisson | Jedis |
| Authentication | √ | × |
| SSL support | √ | × |

好消息是,Jedis和Redisson都包含关键的安全功能,如身份验证和SSL支持。

十、自定义数据序列化

|--------------------------|----------|-------|
| | Redisson | Jedis |
| JSON codec | √ | × |
| JDK Serialization | √ | × |
| Avro codec | √ | × |
| Smile codec | √ | × |
| CBOR codec | √ | × |
| | | × |
| MsgPack codec | √ | × |
| Kryo codec | √ | × |
| FST codec | √ | × |
| LZ4 compression codec | √ | × |
| Snappy compression codec | √ | × |

Redisson支持Java序列化API,以及各种编解码器:

  • JSON
  • FST
  • JDK Serialization
  • CBOR
  • MsgPack
  • Kryo
  • Avro
  • Smile
  • LZ4 compression
  • Snappy compression

不幸的是,Jedis不支持JDK序列化或上述任何编解码器。

相关推荐
笨蛋不要掉眼泪1 小时前
Spring Boot + RedisTemplate 数据结构的基础操作
java·数据结构·spring boot·redis·wpf
知识即是力量ol1 小时前
深度解析:基于 JWT + Redis 白名单的双令牌高安全认证架构
redis·安全·架构
陌上丨1 小时前
什么是Redis的大Key和热Key?项目中一般是怎么解决的?
数据库·redis·缓存
编程彩机2 小时前
互联网大厂Java面试:从分布式事务到微服务优化的技术场景解读
java·spring boot·redis·微服务·面试·kafka·分布式事务
Moshow郑锴2 小时前
Spring Boot Data API 与 Redis 集成:KPI/图表/表格查询的缓存优化方案
spring boot·redis·缓存
TracyCoder1232 小时前
Redis 进阶之路:探秘事务、Lua 与特殊数据结构
数据结构·redis·lua
小毅&Nora3 小时前
# 【后端】【Redis】③ Redis 8队列全解:从“快递分拣站“到“智能配送系统“,一文彻底掌握队列机制
redis·bootstrap·队列
三水不滴3 小时前
SpringBoot+Caffeine+Redis实现多级缓存
spring boot·redis·笔记·缓存
indexsunny3 小时前
互联网大厂Java面试实战:从Spring Boot到Kafka的技术与业务场景解析
java·spring boot·redis·面试·kafka·技术栈·microservices
笨蛋不要掉眼泪3 小时前
Redis持久化解析:RDB和AOF的对比
前端·javascript·redis