package client;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.params.SetParams;

public class RedisUtils {


    /**
     * 普通缓存放入并设置时间
     *
     * @param key   键
     * @param value 值
     * @param time  时间(秒) time要大于0 如果time小于等于0 将设置无限期
     * @return true成功 false 失败
     */
    public static boolean set(String key, String value, long time) {
        Jedis jedis = null;
        try {
            if (time > 0) {
                jedis = JedisConnectFactory.getJedis();
                SetParams params = new SetParams();
                params.ex(time);
                jedis.set(key, value,params);
            }
            return true;
        } catch (Exception e) {
            return false;
        }finally {
            jedis.close();
        }
    }
}
