All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.darkphoenixs.pool.redis.RedisShardedConnPool Maven / Gradle / Ivy

Go to download

A simple multi-purpose connection pool client (Kafka & Hbase & Redis & RMDB & Socket & Http)

The newest version!
package org.darkphoenixs.pool.redis;

import org.darkphoenixs.pool.ConnectionPool;
import org.darkphoenixs.pool.PoolConfig;
import redis.clients.jedis.JedisShardInfo;
import redis.clients.jedis.ShardedJedis;
import redis.clients.jedis.ShardedJedisPool;
import redis.clients.util.Hashing;

import java.util.List;
import java.util.regex.Pattern;

/**
 * 

Title: RedisShardedConnPool

*

Description: Redis分片连接池

* * @author Victor.Zxy * @version 1.2.3 * @see ConnectionPool * @since 2016 /8/25 */ public class RedisShardedConnPool implements ConnectionPool { private final ShardedJedisPool pool; /** * Instantiates a new Redis sharded conn pool. * * @param poolConfig the pool config * @param shards the shards */ public RedisShardedConnPool(final PoolConfig poolConfig, final List shards) { this(poolConfig, shards, Hashing.MURMUR_HASH); } /** * Instantiates a new Redis sharded conn pool. * * @param poolConfig the pool config * @param shards the shards * @param algo the algo */ public RedisShardedConnPool(final PoolConfig poolConfig, final List shards, final Hashing algo) { this(poolConfig, shards, algo, null); } /** * Instantiates a new Redis sharded conn pool. * * @param poolConfig the pool config * @param shards the shards * @param keyTagPattern the key tag pattern */ public RedisShardedConnPool(final PoolConfig poolConfig, final List shards, final Pattern keyTagPattern) { this(poolConfig, shards, Hashing.MURMUR_HASH, keyTagPattern); } /** * Instantiates a new Redis sharded conn pool. * * @param poolConfig the pool config * @param shards the shards * @param algo the algo * @param keyTagPattern the key tag pattern */ public RedisShardedConnPool(final PoolConfig poolConfig, final List shards, final Hashing algo, final Pattern keyTagPattern) { this.pool = new ShardedJedisPool(poolConfig, shards, algo, keyTagPattern); } @Override public ShardedJedis getConnection() { return pool.getResource(); } @Override public void returnConnection(ShardedJedis conn) { if (conn != null) conn.close(); } @Override public void invalidateConnection(ShardedJedis conn) { if (conn != null) conn.close(); } /** * Close. */ public void close() { pool.close(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy