There was a big joke today. A redis was placed behind the cluster for session unification. In the past, the verification codes placed locally on Android and ios were no longer available, so they were going to be placed in redis for unified management. But I set the key to be the same as the jsessionid in the session, resulting in an error. so awkward
The code of redis on the following, as a save
package com.rsxxjs.util.session;
import com.rsxxjs.util.common.ConfigUtil;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
/**
* @Title RedisClient
* @Description redis
* @date August 9, 2017
*/
public class RedisClient {
public static JedisPool jedisPool; // Pool management jedis link pool
static {
//read related configuration
int maxActive = 1000;
int maxIdle = 20;
int maxWait = 3000;
String ip =ConfigUtil.getProperty("redis.ip");
int port = 6379;
JedisPoolConfig config = new JedisPoolConfig();
//Set the maximum number of connections
config.setMaxTotal(maxActive);
//Set the maximum idle number
config.setMaxIdle(maxIdle);
//set timeout
config.setMaxWaitMillis(maxWait);
//Initialize the connection pool
jedisPool = new JedisPool(config, ip, port);
}
/**
* Set the string content to the cache
* @param key key
* @param value value
* @return
* @throws Exception
*/
public static boolean set(String key,String value) throws Exception{
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
jedis.set(key, value);
return true;
} catch (Exception e) {
e.printStackTrace ();
return false;
}finally{
if(jedis!=null){
jedis.close();
}
}
}
/**
* Delete the object in the cache, according to the key
* @param key
* @return
*/
public static boolean del(String key){
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
jedis.del(key);
return true;
} catch (Exception e) {
e.printStackTrace ();
return false;
}finally{
if(jedis!=null){
jedis.close();
}
}
}
/**
* Get content by key
* @param key
* @return
*/
public static Object get(String key){
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
Object value = jedis.get(key);
return value;
} catch (Exception e) {
e.printStackTrace ();
return false;
}finally{
if(jedis!=null){
jedis.close();
}
}
}
}
The following is used by configutils to read configuration files
package com.rsxxjs.util.common;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Properties;
/**
*@description 读取配置文件工具类
*/
public class ConfigUtil
{
@SuppressWarnings("rawtypes")
private static HashMap messages = new HashMap();
private static Properties props = new Properties();
/**
* @param args
*/
static
{
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream is = null;
is = classLoader.getResourceAsStream("properties/common-config.properties");
if (is != null)
{
try
{
props.load(is);
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
is.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
@SuppressWarnings("unchecked")
public static String getProperty(String key)
{
String msg = (String)messages.get(key);
if (msg == null)
{
String pros = props.getProperty(key);
if( pros != null)
{
messages.put(key,pros);
}
msg = pros;
}
return msg;
}
}