com.github.yoojia.web.Redis.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of next-web-redis Show documentation
Show all versions of next-web-redis Show documentation
NextWebKotlin: A Servlet 3+ based micro web framework written in Kotlin
package com.github.yoojia.web
import redis.clients.jedis.Jedis
/**
* @author Yoojia Chen ([email protected])
* @since 2.16
*/
object Redis {
/**
* 获取一个Redis/Jedis资源
*/
@JvmStatic fun getResource(): Jedis {
return RedisPlugin.CONNECTION.resource
}
@JvmStatic fun auto(action: (redis: Jedis)->T) : T {
return once(action)
}
@JvmStatic fun once(action: (redis: Jedis)->T) : T {
val redis = getResource()
try {
return action.invoke(redis)
}finally {
redis.close()
}
}
}