takeStaminaMap) {
+ this.takeStaminaMap = takeStaminaMap;
+ }
+
+ public String getCaptainId() {
+ return captainId;
+ }
+
+ public void setCaptainId(String captainId) {
+ this.captainId = captainId;
+ }
+
+ public int getSkipNewer() {
+ return skipNewer;
+ }
+
+ public void setSkipNewer(int skipNewer) {
+ this.skipNewer = skipNewer;
+ }
+
+ public int getCumLoginTime() {
+ return CumLoginTime;
+ }
+
+ public void setCumLoginTime(int cumLoginTime) {
+ CumLoginTime = cumLoginTime;
+ }
+
+ public int getOnline() {
+ return online;
+ }
+
+ public void setOnline(int online) {
+ this.online = online;
+ }
+
+ public int getDrawDailyTime() {
+ return drawDailyTime;
+ }
+
+ public void setDrawDailyTime(int drawDailyTime) {
+ this.drawDailyTime = drawDailyTime;
+ }
+
+ public int getDrawDailyState() {
+ return drawDailyState;
+ }
+
+ public void setDrawDailyState(int drawDailyState) {
+ this.drawDailyState = drawDailyState;
+ }
+
+ public int getIsPrivilege() {
+ return isPrivilege;
+ }
+
+ public void setIsPrivilege(int isPrivilege) {
+ this.isPrivilege = isPrivilege;
+ }
+
+ public long getPrivilegedLoginTime() {
+ return privilegedLoginTime;
+ }
+
+ public void setPrivilegedLoginTime(long privilegedLoginTime) {
+ this.privilegedLoginTime = privilegedLoginTime;
+ }
+
+ public int getRecall() {
+ return recall;
+ }
+
+ public void setRecall(int recall) {
+ this.recall = recall;
+ }
+
+ public int getCumulativeRecharge() {
+ return cumulativeRecharge;
+ }
+
+ public void setCumulativeRecharge(int cumulativeRecharge) {
+ this.cumulativeRecharge = cumulativeRecharge;
+ }
+
+ public int getSkinGold() {
+ return skinGold;
+ }
+
+ public void setSkinGold(int skinGold) {
+ this.skinGold = skinGold;
+ }
+
+ public int getHead() {
+ return head;
+ }
+
+ public void setHead(int head) {
+ this.head = head;
+ }
+
+ public int getHeadFrame() {
+ return headFrame;
+ }
+
+ public void setHeadFrame(int headFrame) {
+ this.headFrame = headFrame;
+ }
+
+ public String getClientVersion() {
+ return clientVersion;
+ }
+
+ public void setClientVersion(String clientVersion) {
+ this.clientVersion = clientVersion;
+ }
+
+ public long getRecNoticeTime() {
+ return recNoticeTime;
+ }
+
+ public void setRecNoticeTime(long recNoticeTime) {
+ this.recNoticeTime = recNoticeTime;
+ }
+
+ public String getCoreAddress() {
+ return coreAddress;
+ }
+
+ public void setCoreAddress(String coreAddress) {
+ this.coreAddress = coreAddress;
+ }
+}
diff --git a/src/main/java/com/jmfy/redisProperties/RedisAutoConfiguration.java b/src/main/java/com/jmfy/redisProperties/RedisAutoConfiguration.java
new file mode 100644
index 0000000..ca71b9a
--- /dev/null
+++ b/src/main/java/com/jmfy/redisProperties/RedisAutoConfiguration.java
@@ -0,0 +1,24 @@
+package com.jmfy.redisProperties;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * Created by Administrator on 2016/3/17.
+ */
+@Configuration(value = "redisAutoConfiguration")
+@EnableConfigurationProperties(RedisProperties.class)
+public class RedisAutoConfiguration {
+
+ @Autowired
+ private com.jmfy.redisProperties.RedisProperties RedisProperties;
+
+ public com.jmfy.redisProperties.RedisProperties getRedisProperties() {
+ return RedisProperties;
+ }
+
+ public void setRedisProperties(com.jmfy.redisProperties.RedisProperties RedisProperties) {
+ RedisProperties = RedisProperties;
+ }
+}
diff --git a/src/main/java/com/jmfy/redisProperties/RedisProperties.java b/src/main/java/com/jmfy/redisProperties/RedisProperties.java
new file mode 100644
index 0000000..9b0bb10
--- /dev/null
+++ b/src/main/java/com/jmfy/redisProperties/RedisProperties.java
@@ -0,0 +1,189 @@
+package com.jmfy.redisProperties;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * Created by Administrator on 2016/3/17.
+ */
+@ConfigurationProperties(prefix = "spring.redis")
+public class RedisProperties {
+
+ private String host;
+
+ private int port;
+
+ private String password;
+
+ private int expireTime; // 过期时间,单位分钟
+ private int database ;
+ //连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true
+ private boolean blockWhenExhausted;
+ //是否启用pool的jmx管理功能, 默认true
+ private boolean jmxEnabled;
+ //是否启用后进先出, 默认true
+ private boolean lifo;
+ //最大空闲连接数, 默认8个
+ private int maxIdle;
+ //最大连接数, 默认8个
+ private int maxTotal;
+ //获取连接时的最大等待毫秒数(如果设置为阻塞时BlockWhenExhausted),如果超时就抛异常, 小于零:阻塞不确定的时间, 默认-1
+ private int maxWaitMillis;
+ //逐出连接的最小空闲时间 默认1800000毫秒(30分钟)
+ private long minEvictableIdleTimeMillis;
+ //最小空闲连接数, 默认0
+ private int minIdle;
+ //每次逐出检查时 逐出的最大数目 如果为负数就是 : 1/abs(n), 默认3
+ private int numTestsPerEvictionRun;
+ //对象空闲多久后逐出, 当空闲时间>该值 且 空闲连接>最大空闲数 时直接逐出,不再根据MinEvictableIdleTimeMillis判断 (默认逐出策略)
+ private long softMinEvictableIdleTimeMillis;
+ //在获取连接的时候检查有效性, 默认false
+ private boolean testOnBorrow;
+ //在空闲时检查有效性, 默认false
+ private boolean testWhileIdle;
+ //逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认-1
+ private int timeBetweenEvictionRunsMillis;
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public int getExpireTime() {
+ return expireTime;
+ }
+
+ public void setExpireTime(int expireTime) {
+ this.expireTime = expireTime;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public boolean isBlockWhenExhausted() {
+ return blockWhenExhausted;
+ }
+
+ public void setBlockWhenExhausted(boolean blockWhenExhausted) {
+ this.blockWhenExhausted = blockWhenExhausted;
+ }
+
+ public boolean isJmxEnabled() {
+ return jmxEnabled;
+ }
+
+ public void setJmxEnabled(boolean jmxEnabled) {
+ this.jmxEnabled = jmxEnabled;
+ }
+
+ public boolean isLifo() {
+ return lifo;
+ }
+
+ public void setLifo(boolean lifo) {
+ this.lifo = lifo;
+ }
+
+ public int getMaxIdle() {
+ return maxIdle;
+ }
+
+ public void setMaxIdle(int maxIdle) {
+ this.maxIdle = maxIdle;
+ }
+
+ public int getMaxTotal() {
+ return maxTotal;
+ }
+
+ public void setMaxTotal(int maxTotal) {
+ this.maxTotal = maxTotal;
+ }
+
+ public int getMaxWaitMillis() {
+ return maxWaitMillis;
+ }
+
+ public void setMaxWaitMillis(int maxWaitMillis) {
+ this.maxWaitMillis = maxWaitMillis;
+ }
+
+ public long getMinEvictableIdleTimeMillis() {
+ return minEvictableIdleTimeMillis;
+ }
+
+ public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {
+ this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
+ }
+
+ public int getMinIdle() {
+ return minIdle;
+ }
+
+ public void setMinIdle(int minIdle) {
+ this.minIdle = minIdle;
+ }
+
+ public int getNumTestsPerEvictionRun() {
+ return numTestsPerEvictionRun;
+ }
+
+ public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
+ this.numTestsPerEvictionRun = numTestsPerEvictionRun;
+ }
+
+ public long getSoftMinEvictableIdleTimeMillis() {
+ return softMinEvictableIdleTimeMillis;
+ }
+
+ public void setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis) {
+ this.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;
+ }
+
+ public boolean isTestOnBorrow() {
+ return testOnBorrow;
+ }
+
+ public void setTestOnBorrow(boolean testOnBorrow) {
+ this.testOnBorrow = testOnBorrow;
+ }
+
+ public boolean isTestWhileIdle() {
+ return testWhileIdle;
+ }
+
+ public void setTestWhileIdle(boolean testWhileIdle) {
+ this.testWhileIdle = testWhileIdle;
+ }
+
+ public int getTimeBetweenEvictionRunsMillis() {
+ return timeBetweenEvictionRunsMillis;
+ }
+
+ public void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis) {
+ this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
+ }
+
+ public int getDatabase() {
+ return database;
+ }
+
+ public void setDatabase(int database) {
+ this.database = database;
+ }
+}
diff --git a/src/main/java/com/jmfy/redisProperties/RedisUserKey.java b/src/main/java/com/jmfy/redisProperties/RedisUserKey.java
new file mode 100644
index 0000000..325ce32
--- /dev/null
+++ b/src/main/java/com/jmfy/redisProperties/RedisUserKey.java
@@ -0,0 +1,34 @@
+package com.jmfy.redisProperties;
+
+public class RedisUserKey {
+
+ public final static String Delimiter_colon = ":";
+ public final static String Delimiter_len = "|";
+ public final static String Delimiter_code = "#";
+ public final static String CUser_Key = "CUser_Key";
+ public final static String CItem_Key = "CItem_Key";
+ public final static String KICK_Old_key = "Kick_Old_Key";
+ public final static String CMail_Key = "CMail_Key";
+ public final static String Barage_Key = "Barage_Key";
+ public final static String Title_Key = "Title_Key";
+ public final static String Clear_Chat_Key = "Clear_Chat_Key";
+ public final static String SendAllSVR_key = "SendAllSVR_key";
+ public final static String Clight_Key = "Clight_Key";
+ public final static String Notice_key = "Notice_key";
+ public final static String HeroRandSwitch = "HeroRandSwitch";
+ public final static String Server_GM = "Server_GM";
+ /** value key:roleUid,value:CBanInfo*/
+ public final static String CBanInfo_Key = "CBanInfo_Key";
+
+ public final static String BlackList_key = "BlackList_key";
+ public final static String UserInfo_key = "UserInfo_key";
+ public final static String CTeam_Pos_Key = "CTeam_Pos_Key";
+ /**
+ * hash key:roleUid,hashKey:heroUid,value:cHero
+ */
+ public final static String CHero_Key = "CHero_Key";
+
+ public final static String Shero_Rand_Switch = "Shero_Rand_Switch";
+ public final static String Shero_Rand_Template = "Shero_Rand_Template";
+ public final static String Login_Server_Info = "Login_Server_Info";
+}
diff --git a/src/main/java/com/jmfy/util/RedisUtil.java b/src/main/java/com/jmfy/util/RedisUtil.java
new file mode 100644
index 0000000..fc68ef3
--- /dev/null
+++ b/src/main/java/com/jmfy/util/RedisUtil.java
@@ -0,0 +1,282 @@
+package com.jmfy.util;
+
+import com.google.gson.Gson;
+import com.jmfy.redisProperties.RedisProperties;
+import com.jmfy.redisProperties.RedisUserKey;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.data.redis.RedisConnectionFailureException;
+import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import redis.clients.jedis.JedisPoolConfig;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+
+/**
+ * 用来储存返回改前端的respose的实体 当断线重连时下次请求直接返回缓存中的数据
+ *
+ * 添加储存玩家常用数据
+ */
+public class RedisUtil {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(RedisUtil.class);
+
+ private static String separator = "_";
+
+ private final static String Disconnected = "Disconnected_";
+
+ private StringRedisTemplate redisObjectTemplate;
+ private RedisUtil() {
+ }
+
+ private static RedisUtil redisUtil;
+ private Gson gson = new Gson();
+ public static RedisUtil getInstence() {
+ if (redisUtil == null) {
+ redisUtil = InnerClass.SINGLETON;
+ }
+ return redisUtil;
+ }
+
+ public Set getKeys(String key) {
+ return redisObjectTemplate.keys("*"+key+ "*");
+ }
+
+
+ private static class InnerClass {
+ private static final RedisUtil SINGLETON = new RedisUtil();
+ }
+
+ public void init(RedisProperties redisProperties) {
+ try {
+ //initStringCacheDb(0, redisProperties);
+ initUserCacheDb(0,redisProperties);
+ LOGGER.info("redis init ..");
+
+ } catch (Exception e) {
+ LOGGER.error("------------------Redis 未启动------------------");
+ }
+
+
+ }
+
+ private void initUserCacheDb(int dbIndex, RedisProperties redisProperties) {
+ //实例化链接工厂
+ JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
+ //设置host
+ connectionFactory.setHostName(redisProperties.getHost());
+ //设置端口
+ connectionFactory.setPort(redisProperties.getPort());
+ // 分库
+ connectionFactory.setDatabase(dbIndex);
+ //设置密码
+ connectionFactory.setPassword(redisProperties.getPassword());
+ // 设置参数
+ 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();
+ //实例化
+ redisObjectTemplate = new StringRedisTemplate(connectionFactory);
+// redisObjectTemplate.setConnectionFactory(connectionFactory);
+ redisObjectTemplate.afterPropertiesSet();
+ }
+ /**
+ * 获取Object
+ *
+ * @param key
+ * @return
+ */
+ public T getObject(String type, String key, Class clazz, int expireTime) {
+ try {
+ String valueStr = redisObjectTemplate.opsForValue().get(type + RedisUserKey.Delimiter_colon + key);
+ if (valueStr == null) {
+ return null;
+ }
+ if(expireTime > 0){
+ redisObjectTemplate.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) {
+ redisObjectTemplate.opsForHash().delete(type+":"+key, mapId);
+ }
+ /**
+ * 更新Object
+ *
+ * @param key
+ * @param value
+ */
+ public void putObject(String type, String key, T value, int expireTime) {
+ try {
+ String valueStr = gson.toJson(value);
+ redisObjectTemplate.opsForValue().set(type + RedisUserKey.Delimiter_colon + key, valueStr);
+ if (expireTime > 0) {
+ redisObjectTemplate.expire(type + RedisUserKey.Delimiter_colon + key, expireTime, TimeUnit.SECONDS);
+ }
+ } catch (RedisConnectionFailureException e) {
+ LOGGER.error("------------------Redis 连接失败------------------");
+ delObject(type, key);
+ return;
+ }
+ }
+ /**
+ * 更新Map某hashKey
+ *
+ * @param type
+ * @param key
+ * @param mapKey
+ * @param value
+ */
+ public void putMapEntry(String type, String key, String mapKey, T value, int expireTime) {
+ try {
+ String valueStr = gson.toJson(value);
+ redisObjectTemplate.opsForHash().put(type + RedisUserKey.Delimiter_colon + key, mapKey, valueStr);
+ if (expireTime > 0) {
+ redisObjectTemplate.expire(type + RedisUserKey.Delimiter_colon + key, expireTime, TimeUnit.SECONDS);
+ }
+ } catch (RedisConnectionFailureException e) {
+ LOGGER.error("------------------Redis 连接失败------------------");
+ delObject(type, key);
+ }
+ }
+ /**
+ * 删除Map中某hashKey值
+ *
+ * @param type
+ * @param key
+ * @param mapKey
+ */
+ public void delMapKey(String type, String key, String... mapKey) {
+ try {
+ redisObjectTemplate.opsForHash().delete(type + RedisUserKey.Delimiter_colon + key, mapKey);
+ } catch (RedisConnectionFailureException e) {
+ LOGGER.error("------------------Redis 连接失败------------------");
+ }
+ }
+ /**
+ * 删除Object
+ *
+ * @param type
+ * @param key
+ */
+ public void delObject(String type, String key) {
+ try {
+ redisObjectTemplate.delete(type + RedisUserKey.Delimiter_colon + key);
+ } catch (RedisConnectionFailureException e) {
+ LOGGER.error("------------------Redis 连接失败------------------");
+ } catch (Exception e) {
+ redisObjectTemplate.delete(type + RedisUserKey.Delimiter_colon + key);
+ }
+ }
+ /**
+ * 获取Map
+ *
+ * @param key
+ * @return
+ */
+ public Map getMap(String key, Class clazz,int expireTime) {
+ try {
+ Map reslut = new HashMap<>();
+ Map