Conflicts:
	build.gradle
master
gaojie 2019-01-29 18:24:35 +08:00
commit d8d3d0e870
5 changed files with 26 additions and 22 deletions

View File

@ -21,4 +21,5 @@ dependencies {
compile group: 'redis.clients', name: 'jedis', version: '2.9.0'
compile group: 'com.alibaba', name: 'fastjson', version: '1.2.47'
compile group: 'jcifs', name: 'jcifs', version: '1.3.17'
compile group: 'com.google.code.gson', name: 'gson', version: '2.2.4'
}

View File

@ -68,6 +68,7 @@ public class GetServerListController extends HttpServlet {
DBObject res = new BasicDBObject();
res.put("server_id", entry.getKey());
res.put("login_time", entry.getValue().getLoginTime());
res.put("level", entry.getValue().getLevel());
myServerList.add(res);
}
DBObject resp = new BasicDBObject();

View File

@ -1,24 +1,14 @@
package com.ljsd.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ljsd.pojo.UserServerInfo;
import com.ljsd.redis.RedisKey;
import com.ljsd.util.BaseGlobal;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.util.JSON;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class ServerListController extends HttpServlet{
private String message;

View File

@ -1,8 +1,11 @@
package com.ljsd.pojo;
public class UserServerInfo {
private long loginTime;
private int level;
public long getLoginTime() {
return loginTime;
}
@ -10,4 +13,12 @@ public class UserServerInfo {
public void setLoginTime(long loginTime) {
this.loginTime = loginTime;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
}

View File

@ -1,12 +1,13 @@
package com.ljsd.redis;
import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import java.util.*;
public class RedisApp {
private final static String Delimiter_colon = ":";
private RedisUtil redisUtil = new RedisUtil();
private Gson gson = new Gson();
private String areaId = "0";
public RedisApp() {
@ -24,7 +25,7 @@ public class RedisApp {
/***************************************普通键值对操作***************************************/
//设置键值
public <K, T> void set(final String type, final K key, T value, final int seconds, boolean withServerId) throws Exception {
String strValue = JSON.toJSONString(value);
String strValue = gson.toJson(value);
String fullKey = getKey(type, key, withServerId);
if (seconds <= 0) {
redisUtil.set(fullKey, strValue);
@ -45,7 +46,7 @@ public class RedisApp {
if (strValue == null) {
return null;
}
return JSON.parseObject(strValue, clazz);
return gson.fromJson(strValue,clazz);
}
public <K, T> T get(final String type, final K key, final Class<T> clazz, final int seconds) throws Exception {
@ -87,7 +88,7 @@ public class RedisApp {
Map<String, String> map = new HashMap<String, String>();
for (Map.Entry<K, T> entry : mapValues.entrySet()) {
String strKey = String.valueOf(entry.getKey());
String strValue = JSON.toJSONString(entry.getValue());
String strValue = gson.toJson(entry.getValue());
map.put(strKey, strValue);
}
return map;
@ -119,7 +120,7 @@ public class RedisApp {
public <K, T> void hset(final String type, final K key, final String field, final T value, int seconds,
boolean withServerId) throws Exception {
String fullKey = getKey(type, key, withServerId);
String strValue = JSON.toJSONString(value);
String strValue = gson.toJson(value);
redisUtil.hset(fullKey, field, strValue, seconds);
}
@ -131,7 +132,7 @@ public class RedisApp {
private <T> Map<String, T> converClassMap(final Map<String, String> mapValues, final Class<T> valueClazz) {
Map<String, T> map = new HashMap<>();
for (Map.Entry<String, String> entry : mapValues.entrySet()) {
T value = JSON.parseObject(entry.getValue(), valueClazz);
T value = gson.fromJson(entry.getValue(), valueClazz);
map.put(entry.getKey(), value);
}
return map;
@ -160,7 +161,7 @@ public class RedisApp {
if (listStrs == null || listStrs.size() <= 0) {
return null;
}
return JSON.parseObject(listStrs.get(0), clazz);
return gson.fromJson(listStrs.get(0), clazz);
}
public <K, SK, T> T hmget(final String type, final K key, final SK field, final Class<T> clazz, int seconds) throws Exception {
@ -185,7 +186,7 @@ public class RedisApp {
String fullKey = getKey(type, key, withServerId);
String[] strValues = new String[strings.length];
for (int i = 0; i < strings.length; i++) {
strValues[i] = JSON.toJSONString(strings[i]);
strValues[i] = gson.toJson(strings[i]);
}
return redisUtil.lpush(fullKey, seconds, strValues);
}
@ -205,7 +206,7 @@ public class RedisApp {
public <K, T> T rpop(final String type, final K key, final Class<T> clazz, boolean withServerId) throws Exception {
String fullKey = getKey(type, key, withServerId);
String strValue = redisUtil.rpop(fullKey);
return JSON.parseObject(strValue, clazz);
return gson.fromJson(strValue, clazz);
}
public <K, T> T rpop(final String type, final K key, final Class<T> clazz) throws Exception {
@ -222,7 +223,7 @@ public class RedisApp {
redisUtil.rpop(fullKey);
}
}
String strValue = JSON.toJSONString(value);
String strValue = gson.toJson(value);
return redisUtil.lpush(fullKey, seconds, strValue);
}
@ -234,7 +235,7 @@ public class RedisApp {
private <T> List<T> converClassList(final List<String> listValues, final Class<T> clazz) {
List<T> list = new ArrayList<>();
for (String strValue : listValues) {
T value = JSON.parseObject(strValue, clazz);
T value = gson.fromJson(strValue, clazz);
list.add(value);
}