java连接redis数据库获取数据
时间:2021-07-01 10:21:17
帮助过:19人阅读
com.alibaba.fastjson.JSON;
import redis.clients.jedis.Jedis;
import com.alibaba.fastjson.JSONObject;
import java.util.HashMap;
import com.google.gson.*
;
import java.util.Map;
import java.util.Set;
public class redis {
public static void getTokens(String ip,
int port, String password){
Jedis jedis =
new Jedis(ip, port);
// 密码
jedis.auth(password);
System.out.println("连接成功"
);
// 获取钻石app utoken
// 第几个库表
int index = 0
;
jedis.select(index);
// 根据 hash获取值
String va = jedis.hget("VERIFYCODE:SMS",""
);
// 解析json值
System.out.println(va);
JSONObject jo = JSON.parseObject(
new String(va));
System.out.println(va);
String json_value = jo.getString("ttoken"
);
String clientSide = jo.getString("clientSide"
);
// 解析字典值
Gson gson =
new Gson();
Map map =
new HashMap<String, Object>
();
map =
gson.fromJson(clientSide, map.getClass());
System.out.println(map);
String name = (String) map.get("name"
);
String version = (String) map.get("version"
);
String osVersion = (String) map.get("osVersion"
);
String buildId = (String) map.get("buildId"
);
// 获取请求头
String head = name + "/" + version + "(build:" + buildId + ":" + osVersion + ")"
;
System.out.println(head);
// 获取企业后台 msid
int indexse = 0
;
jedis.select(indexse);
Set<String> vase = jedis.keys("BACKSTAGE:OAUTH:LOGIN:SESSION:"+"*"
);
String user = "autotest"
;
System.out.println(vase);
for (String all_seid : vase){
String seid =
jedis.get(all_seid);
if (seid.equals(user)){
System.out.println(all_seid);
String seid_value = all_seid.substring(30, 66
);
System.out.println(seid_value);
}
}
// 获取sass后台 msid
String value = jedis.get("SAAS:LOGIN:STK:test"
);
System.out.println(value);
}
public static void main(String[] args) {
getTokens("ip", port, "password"
);
}
}
java连接redis数据库获取数据
标签:oid 成功 ali ide fast hashmap 数据库 buildid public