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

com.github.yoojia.web.Redis.kt Maven / Gradle / Ivy

There is a newer version: 3.0.5-alpha
Show newest version
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()
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy