-
Notifications
You must be signed in to change notification settings - Fork 52
RedisConnectionPool
业余布道师 edited this page Nov 21, 2016
·
7 revisions
Use the RedisConnectionPool need instantiate PoolConfig
and Properties
For example, the following
/* poolConfig */
PoolConfig config = new PoolConfig();
config.setMaxTotal(20);
config.setMaxIdle(5);
config.setMaxWaitMillis(1000);
config.setTestOnBorrow(true);
/* properties */
Properties props = new Properties();
props.setProperty("address", "localhost:6379");
props.setProperty("connectionTimeout", "2000");
props.setProperty("soTimeout", "2000");
props.setProperty("clientName", "Your client name");
/* connection pool */
RedisConnectionPool pool = new RedisConnectionPool(config, props);
/* pool getConnection */
Jedis jedis = pool.getConnection();
...
/* pool returnConnection */
pool.returnConnection(jedis);
Also provides Master-Slave pool see RedisSentinelConnPool, Sharded pool see RedisShardedConnPool, Cluster pool see RedisClusterConnPool, more configs see the Configuration wiki.