The R&D department has a wide and random selection of clients, and the branches it relies on are not uniform. It feels like Baidu uses it directly when it arrives, or changes it when a function is satisfied, without considering the usage of other groups and centralized maintenance.
The other is that if it is the basic component of the company's pom scaffolding, it is necessary to consider whether it should be unified into one or multiple coexisting problems. Now there are two considerations: if the performance is not a big problem, it is recommended to unify it into one; If multiple clients need to coexist, there should be at least 2 clients.
Step 2 compare
The only officially recommended java clients are Jedis, lettuce and Redisson, so this analysis only focuses on these three.
2. 1. Overview
Jedis: the Java implementation client of Redis provides comprehensive support for Redis commands.
lettuce: Lettuce is a scalable thread-safe Redis client for synchronous, asynchronous and reactive usage. Multiple threads may share one connection if they avoid blocking and transactional operations such as BLPOP and MULTI /EXEC. Lettuce is built with netty. Supports advanced Redis features such as Sentinel, Cluster, Pipelining, Auto-Reconnect and Redis data models.
Redison: Redisson is a Java In-Memory Data Grid based on Rediss. It not only provides a series of distributed Java common objects, but also provides many distributed services. Including (Bitset, Set, MultiMap, Sorted Set, Map, List, Queue, Blocking Queue, Deque, Blocking Deque, Semaphore, Lock, Atomic Long, Countdown Latch, Publish/subscribe, Bloom Filter, Remote Service, Spring Cache, Executor Service, Live Object Service, Scheduler Service) Redisson provides the simplest and most convenient way to use Redis. The purpose of Redisson is to promote the user's Separation of Concern about Redis, so that users can concentrate more on dealing with business logic.
Lettuce: Look directly at official website's: /detail.html? id=9 108
The above test results are relatively old, and no performance test results with the participation of the three are found.
I didn't benchmark the performance of the three, mainly because of aimless and targeted conditions (the number of concurrency, the amount of data, the size range of instruction kv), so it is difficult to do quantitative and comparable benchmark tests (mainly because I am lazy).
2.3.Function
Jedis: provides comprehensive support for redis native instructions, with weak upper-layer encapsulation, very low support for cluster features and almost no advanced features.
Lettuce: Advanced redis client, supporting various modes of redis connection and operation, with few advanced features.
Redisson: Advanced redis client, which supports various modes of Redis connection and operation, while providing a lot of practical functions.
Jedis and lettuce have no functions, so they are simple operations, and even distributed locks need to be implemented by themselves, so let's talk about the advanced functions of Redisson first, and occasionally compare Jedis and lettuce in the middle.
1.
Redisson is an object-based operation, and different advanced encoding methods can be used for key objects and value objects:
JsonJacksonCodec、AvroJacksonCodec、SmileJacksonCodec、CborJacksonCodec、MsgPackJacksonCodec、IonJacksonCodec、KryoCodec、SerializationCodec、FstCodec、LZ4Codec、SnappyCodec、CompositeCodec
And four basic coding methods:
JsonJacksonMapCodec、StringCodec、LongCodec、ByteArrayCodec
Jedis operation is only for byte arrays, and lettuce supports four types: ByteArrayCodec, StringCodec, CipherCodec and CompressionCodec.
On-demand use, no coding comparison.
2. Distributed collection.
Split the large Set and distribute it evenly to all nodes, including set, Map, BitSet, Bloom Filter, Spring Cache and Hibernate Cache, and support local cache. (Only for Professional Edition) Distributed Lock.
Various distributed locks: ReentrantLock, FairLock, interlocking MultiLock, RedLock, ReadWriteLock, Semaphore semaphore, expired semaphore PermitExpirableSemaphore, and counter CountDownLatch.
3.RPC
4. Distributed scheduling task service
5. distributed MR
6. Support for complex multidimensional object structures and object references
7. Cluster pipeline
Lettuce also supports it.
Jedis doesn't support it. jedis doesn't even support multi-key (distributed in different nodes) operations.
8. Affairs
Provides the implementation of XA Transactions standard, which can be integrated into Spring. (Only Professional Edition can be used)
9. Cluster management tools
(Only Professional Edition can be used)
10. Current limiter
Distributed current limiting tool (with timeout function).
1 1. Self-increasing/distributed ID
12.BloomFilter
13. Delay queue
2.4. Selection
Spring first used Jedis as the client by default, but later it was changed to Lettuce. Compared with lettuce, lettuce has obvious characteristics of asynchronism and thread safety, and the bottom layer is netty killer as the communication layer, which has better performance than Jedis's thread insecurity+connection pool.
Redisson is superior to the other two because of its powerful functions and object-oriented design.
According to our business needs:
1. Current limiting
2. Distributed lock
Step 3 cache
4.GID generation
5. Delay queue
6.lua script
7. Request for merger
Redisson can be satisfied, in fact, just using Redisson as the client of Spring is enough.
Personal inclination lettuce+Redisson.