功能比较: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序列化或上述任何编解码器。

相关推荐
phantomsee4 分钟前
Redis学习系列之——高并发应用的缓存问题(二)
redis·redisson
程序员JerrySUN24 分钟前
Linux 文件系统实现层详解:原理、结构与驱动衔接
android·linux·运维·数据库·redis·嵌入式硬件
间彧4 小时前
RedisTemplate介绍与使用
java·redis
L_qingting4 小时前
Redis 主从复制
数据库·redis·缓存
代码老y6 小时前
在百亿流量面前,让“不存在”无处遁形——Redis 缓存穿透的极限攻防实录
数据库·redis·缓存
陈小唬7 小时前
Docker 拉取镜像并离线迁移至云桌面指南(以Redis为例)
redis·docker·容器
武子康8 小时前
大数据-42 Redis 发布/订阅详解:机制、弱事务性与实际风险分析
大数据·redis·后端
骑驴看星星a8 小时前
WebAPIs基本认知,DOM基础介绍
java·linux·javascript·人工智能·redis·深度学习·机器学习
Dajiaonew8 小时前
Redis主从同步原理(全量复制、增量复制)
数据库·redis·缓存
秋恬意10 小时前
redis红锁
数据库·redis·缓存