Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the design method of Jedis and ShardedJedis

2025-02-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what is the design method of Jedis and ShardedJedis". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the design method of Jedis and ShardedJedis".

Jedis design

As the recommended java language redis client, Jedis is abstracted into three parts:

Object pool design: Pool,JedisPool,GenericObjectPool,BasePoolableObjectFactory,JedisFactory

User-oriented redis operation encapsulation: BinaryJedisCommands,JedisCommands,BinaryJedis,Jedis

Operation encapsulation for redis server: Commands,Client,BinaryClient,Connection,Protocol

The class design drawings are as follows:

For more information about common-pool, please see: http://macrochen.iteye.com/blog/320077

The other classes are designed to do the following:

The class name is responsible for Pool abstract Jedis object pool operation, and entrusts the operation to GenericObjectPoolJedisPool implementation Pool and provides JedisFactory factory JedisFactory implementation BasePoolableObjectFactory, provides creation and destruction of Jedis methods BinaryJedisCommands abstract client-oriented Redis commands; key,value is serialized byte array JedisCommands abstract Redis commands for client-oriented operations The key,valueBinaryJedis implementation BinaryJedisCommands interface of String type is provided, and the actual operation is delegated to the ClientJedis implementation JedisCommands interface, and the operation is delegated to the ClientCommands abstract Redis operation interface to provide the key,value operation of String type; the Redis connection is abstracted by Jedis call Connection Including host,port,pass,socket,inputstream,outputstream,protocol completing communication with Redis server Protocol abstracts Redis protocol processing BinaryClient inherits Connection class, encapsulates key,value operation based on Byte [] Client inherits BinaryClient and implements Commands, and analyzes the implementation of operation ShardedJedis based on String type in the upper layer.

ShardedJedis is a distributed Redis cluster client based on consistent hashing algorithm. The design of ShardedJedis is divided into the following parts:

Object pool design: Pool,ShardedJedisPool,ShardedJedisFactory

User-oriented operation encapsulation: BinaryShardedJedis,BinaryShardedJedis

Consistent hash implementation: Sharded

With regard to ShardedJedis design, the design details of Jedis are ignored. The design class diagram is as follows:

With regard to ShardedJedis class diagram design, object pooling and the following details of Jedis design are omitted:

Class name responsibility Sharded

The partition design and design idea based on consistent hash algorithm are abstracted.

Partition redis servers based on hash algorithm

Maintain the Jedis client of each Redis server

Provide a partition method based on Key; provide a ShardKeyTag implementation

BinaryShardedJedis is similar to BinaryJedis in that BinaryJedisCommands provides key,value operations based on Byte [] ShardedJedis is similar to Jedis, and JedisCommands provides Sharded consistent hashes of String-based key,value operations.

The shared consistent hash adopts the following scheme:

Redis server node partition: each server node is divided into 160virtual nodes using hash algorithm (partition weight can be configured)

TreeMap storage will be used to divide virtual nodes.

Use LinkedHashMap storage for the physical connection of each Redis server

Use the same hash algorithm for Key or KeyTag, then get the key hash worth node from TreeMap and store it in the nearest node; when the hash value of key is greater than the maximum value of virtual node hash, store it in the first virtual node

Sharded uses two hash algorithms: MD5 and MurmurHash; the default is 64-bit MurmurHash algorithm. If you are interested, you can study that MurmurHash is an efficient, low-collision hash algorithm.

Thank you for your reading, the above is the content of "what is the design method of Jedis and ShardedJedis". After the study of this article, I believe you have a deeper understanding of what the design method of Jedis and ShardedJedis is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report