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

Jedis use-pool Pool (version 2je 9)

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

First create a thread pool:

Public voidRedisPool () {

If (Const.jedisPoolCommon==null) {

JedisPoolConfig config = new JedisPoolConfig ()

/ / maximum number of connections. Default is 8.

Config.setMaxTotal (redisPoolMaxActive)

/ / maximum number of idle connections. Default is 8.

Config.setMaxIdle (redisPoolMaxIdle)

/ / the maximum number of milliseconds to wait for a connection

Config.setMaxWaitMillis (100000)

/ / minimum number of idle connections. Default is 0

Config.setMinIdle (redisPoolMinIdle)

/ / whether to block when the connection is exhausted. False reports an exception and ture blocks until it times out. Default is true.

Config.setBlockWhenExhausted (true)

Config.setTestOnBorrow (TEST_ON_BORROW)

Const.jedisPoolCommon = new JedisPool (config,host,port,timeout,password)

}

}

Tool usage pool:

/ * *

Add the list as an example @ param k@param v

, /

Public void rightPush (String KJS string v) {

Jedis jedis = null

Try {

Jedis=Const.jedisPoolCommon.getResource ()

Jedis.select (commdbIndex)

Jedis.rpush (KBI v)

} catch (Exception ex) {

Logger.error ("rightPush exception" + ex)

} finally {

If (jedished invalid null) {/ / close recycling to thread pool

Jedis.close ()

}

}

}

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

Internet Technology

Wechat

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

12
Report