generated from root/miduo_server
兼容老环境提交
parent
83937647a4
commit
501a37d37b
|
@ -41,7 +41,6 @@ public class IAPManagerController {
|
||||||
String sig = map.get("sig");
|
String sig = map.get("sig");
|
||||||
String[] serverParam = map.get("channel_id").split("-");
|
String[] serverParam = map.get("channel_id").split("-");
|
||||||
|
|
||||||
String orderId = serverParam[serverParam.length-7];
|
|
||||||
int gameServer = Integer.parseInt(serverParam[serverParam.length-5]);
|
int gameServer = Integer.parseInt(serverParam[serverParam.length-5]);
|
||||||
int userId = Integer.parseInt(serverParam[serverParam.length-4]);
|
int userId = Integer.parseInt(serverParam[serverParam.length-4]);
|
||||||
int goodsId = Integer.parseInt(serverParam[serverParam.length-3]);
|
int goodsId = Integer.parseInt(serverParam[serverParam.length-3]);
|
||||||
|
|
|
@ -8,6 +8,10 @@ import org.springframework.stereotype.Component;
|
||||||
public class CUserDaoImpl implements CUserDao {
|
public class CUserDaoImpl implements CUserDao {
|
||||||
@Override
|
@Override
|
||||||
public String findUserInfo(int serverId, int userId) {
|
public String findUserInfo(int serverId, int userId) {
|
||||||
return RedisUtil.getInstence().getObject(serverId+":CUser_ServerInfo", Integer.toString(userId),String.class, -1);
|
String userInfo = RedisUtil.getInstence().getObject(serverId+":CUser_ServerInfo", Integer.toString(userId),String.class, -1);
|
||||||
|
if (userInfo==null){
|
||||||
|
userInfo = RedisUtil.getInstence().getOldObject(serverId+":CUser_ServerInfo", Integer.toString(userId),String.class, -1);
|
||||||
|
}
|
||||||
|
return userInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,9 @@ public class RedisUtil {
|
||||||
private final static String Disconnected = "Disconnected_";
|
private final static String Disconnected = "Disconnected_";
|
||||||
|
|
||||||
private StringRedisTemplate redisObjectTemplate;
|
private StringRedisTemplate redisObjectTemplate;
|
||||||
|
|
||||||
|
private StringRedisTemplate oldRedisObjectTemplate;
|
||||||
|
|
||||||
private RedisUtil() {
|
private RedisUtil() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +58,7 @@ public class RedisUtil {
|
||||||
try {
|
try {
|
||||||
//initStringCacheDb(0, redisProperties);
|
//initStringCacheDb(0, redisProperties);
|
||||||
initUserCacheDb(0,redisProperties);
|
initUserCacheDb(0,redisProperties);
|
||||||
|
initOldUserCacheDb();
|
||||||
LOGGER.info("redis init ..");
|
LOGGER.info("redis init ..");
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -64,6 +68,60 @@ public class RedisUtil {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initOldUserCacheDb() {
|
||||||
|
//实例化链接工厂
|
||||||
|
JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
|
||||||
|
//设置host
|
||||||
|
connectionFactory.setHostName("redis.test.ysj.db");
|
||||||
|
//设置端口
|
||||||
|
connectionFactory.setPort(50000);
|
||||||
|
// 分库
|
||||||
|
connectionFactory.setDatabase(0);
|
||||||
|
//设置密码
|
||||||
|
connectionFactory.setPassword("ysj@0912");
|
||||||
|
// 设置参数
|
||||||
|
JedisPoolConfig config = new JedisPoolConfig();
|
||||||
|
//连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true
|
||||||
|
config.setBlockWhenExhausted(true);
|
||||||
|
//设置的逐出策略类名, 默认DefaultEvictionPolicy(当连接超过最大空闲时间,或连接数超过最大空闲连接数)
|
||||||
|
config.setEvictionPolicyClassName("org.apache.commons.pool2.impl.DefaultEvictionPolicy");
|
||||||
|
//是否启用pool的jmx管理功能, 默认true
|
||||||
|
config.setJmxEnabled(true);
|
||||||
|
//MBean ObjectName = new ObjectName("org.apache.commons.pool2:type=GenericObjectPool,name=" + "pool" + i); 默 认为"pool", JMX不熟,具体不知道是干啥的...默认就好.
|
||||||
|
config.setJmxNamePrefix("pool");
|
||||||
|
//是否启用后进先出, 默认true
|
||||||
|
config.setLifo(true);
|
||||||
|
//最大空闲连接数, 默认8个
|
||||||
|
config.setMaxIdle(8);
|
||||||
|
//最大连接数, 默认8个
|
||||||
|
config.setMaxTotal(1000);
|
||||||
|
//获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1
|
||||||
|
config.setMaxWaitMillis(-1);
|
||||||
|
//逐出连接的最小空闲时间 默认1800000毫秒(30分钟)
|
||||||
|
config.setMinEvictableIdleTimeMillis(1800000);
|
||||||
|
//最小空闲连接数, 默认0
|
||||||
|
config.setMinIdle(0);
|
||||||
|
//每次逐出检查时 逐出的最大数目 如果为负数就是 : 1/abs(n), 默认3
|
||||||
|
config.setNumTestsPerEvictionRun(3);
|
||||||
|
//对象空闲多久后逐出, 当空闲时间>该值 且 空闲连接>最大空闲数 时直接逐出,不再根据MinEvictableIdleTimeMillis判断 (默认逐出策略)
|
||||||
|
config.setSoftMinEvictableIdleTimeMillis(1800000);
|
||||||
|
//在获取连接的时候检查有效性, 默认false
|
||||||
|
config.setTestOnBorrow(false);
|
||||||
|
//在空闲时检查有效性, 默认false
|
||||||
|
config.setTestWhileIdle(false);
|
||||||
|
//逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认-1
|
||||||
|
config.setTimeBetweenEvictionRunsMillis(-1);
|
||||||
|
|
||||||
|
connectionFactory.setPoolConfig(config);
|
||||||
|
|
||||||
|
//初始化connectionFactory
|
||||||
|
connectionFactory.afterPropertiesSet();
|
||||||
|
//实例化
|
||||||
|
oldRedisObjectTemplate = new StringRedisTemplate(connectionFactory);
|
||||||
|
// redisObjectTemplate.setConnectionFactory(connectionFactory);
|
||||||
|
oldRedisObjectTemplate.afterPropertiesSet();
|
||||||
|
}
|
||||||
|
|
||||||
private void initUserCacheDb(int dbIndex, RedisProperties redisProperties) {
|
private void initUserCacheDb(int dbIndex, RedisProperties redisProperties) {
|
||||||
//实例化链接工厂
|
//实例化链接工厂
|
||||||
JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
|
JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
|
||||||
|
@ -138,6 +196,32 @@ public class RedisUtil {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Object
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public <T> T getOldObject(String type, String key, Class<T> clazz, int expireTime) {
|
||||||
|
try {
|
||||||
|
String valueStr = oldRedisObjectTemplate.opsForValue().get(type + RedisUserKey.Delimiter_colon + key);
|
||||||
|
if (valueStr == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if(expireTime > 0){
|
||||||
|
oldRedisObjectTemplate.expire(type+key, expireTime, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
return gson.fromJson(valueStr, clazz);
|
||||||
|
} catch (RedisConnectionFailureException e) {
|
||||||
|
LOGGER.error("------------------Redis 连接失败------------------");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void delHash(String type, int key, String mapId) {
|
public void delHash(String type, int key, String mapId) {
|
||||||
redisObjectTemplate.opsForHash().delete(type+":"+key, mapId);
|
redisObjectTemplate.opsForHash().delete(type+":"+key, mapId);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue