package com.wly.game.common.redis;
import com.wly.game.common.context.ApplicationContext;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import java.io.FileReader;
import java.util.Collections;
import java.util.Properties;
/**
* Redis 工具类
*
* @author jinghan94@126.com
*/
public class RedisUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(RedisUtils.class);
private static final Long RELEASE_SUCCESS = 1L;
private static final String LOCK_SUCCESS = "OK";
private static final String SET_IF_NOT_EXIST = "NX";
private static final String SET_WITH_EXPIRE_TIME = "EX";
private static final String RELEASE_LOCK_SCRIPT = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end";
/**
* Redis服务器IP
*/
private static String IP = "";
/**
* Redis的端口号
*/
private static int PORT = 6379;
/**
* redis password 值
*/
private static String password = "";
private static JedisPool jedisPool = null;
/**
* 初始化Redis连接池
*/
private static void initialPool() {
try {
Properties props = new Properties();
try {
//加载配置文件
props.load(new FileReader(ApplicationContext.getServerFile()));
IP = props.getProperty("redis.ip");
password = props.getProperty("redis.password");
PORT = Integer.valueOf(props.getProperty("redis.port"));
} catch (Exception e) {
LOGGER.error("加载文件[{}]失败,请检查后再启动", ApplicationContext.getServerFile());
System.exit