Created
July 22, 2013 07:35
-
-
Save lotusk/6051962 to your computer and use it in GitHub Desktop.
这里的 jedisPool 如果不先搞成父类就无法调用 returnBrokenResource方法.
为什么,,why 类似这样的情况有无其他方法
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.zhisuo.redis | |
import redis.clients.jedis.Jedis | |
import redis.clients.jedis.JedisPool | |
import redis.clients.jedis.BinaryJedis | |
import redis.clients.util.Pool | |
/** | |
* 基本redis访问 | |
*/ | |
class Sedis(val jedisPool: JedisPool) { | |
def withJedisClient[T](body: Jedis => T): T = { | |
val jedis: Jedis = jedisPool.getResource | |
try { | |
body(jedis) | |
}catch{ | |
case ex:Exception=> | |
jedisPool.asInstanceOf[Pool[Jedis]].returnBrokenResource(jedis) | |
throw ex | |
} | |
finally { | |
jedisPool.returnResourceObject(jedis) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment