ShardedJedisPool详解

来源:互联网 时间:1970-01-01


ShardedJedisPool类有四个构造函数

 public ShardedJedisPool(final GenericObjectPoolConfig poolConfig, List<JedisShardInfo> shards) { this(poolConfig, shards, Hashing.MURMUR_HASH); } public ShardedJedisPool(final GenericObjectPoolConfig poolConfig, List<JedisShardInfo> shards, Hashing algo) { this(poolConfig, shards, algo, null); } public ShardedJedisPool(final GenericObjectPoolConfig poolConfig, List<JedisShardInfo> shards, Pattern keyTagPattern) { this(poolConfig, shards, Hashing.MURMUR_HASH, keyTagPattern); } public ShardedJedisPool(final GenericObjectPoolConfig poolConfig, List<JedisShardInfo> shards, Hashing algo, Pattern keyTagPattern) { super(poolConfig, new ShardedJedisFactory(shards, algo, keyTagPattern)); }

其实,最后都是调用父类的构造函数

super(poolConfig, new ShardedJedisFactory(shards, algo, keyTagPattern));

输入参数说明:

final GenericObjectPoolConfig poolConfig:pool的一些设置(maxTotal、maxIdle、minIdle)List<JedisShardInfo> shards:为Redis实例的IP、端口以及超时时间等信息Hashing algo:根据Key计算hash值,从而决定具体存入那个Redis实例Pattern keyTagPattern:Key标签模式,默认是取{}中内容去计算对应Hash值,当key='{key1_0}_0_0'时,**此时将根据’key1_0'来计算对应hash值,而不是根据{key1_0}_0_0来计算hash值**,从而决定将存入到哪个Redis实例中,如果需要将数据进行排序,将要利用这个构造函数,因为只有将需要排序的数据存入同一个Redis实例中,排序才是准确的。



相关阅读:
Top