mirror of
https://gitee.com/dromara/MaxKey.git
synced 2025-12-06 17:08:29 +08:00
缓存优化
This commit is contained in:
parent
fb6e9d9424
commit
4c89c8d77a
@ -81,7 +81,7 @@ public class RedisConnection {
|
|||||||
public void setex(String key,long seconds, String value){
|
public void setex(String key,long seconds, String value){
|
||||||
_logger.trace("setex key {} ..." , key);
|
_logger.trace("setex key {} ..." , key);
|
||||||
if(seconds==0){
|
if(seconds==0){
|
||||||
conn.setex(key, RedisConnectionFactory.DEFAULT_CONFIG.DEFAULT_LIFETIME, value);
|
conn.setex(key, RedisDefaultConfig.DEFAULT_LIFETIME, value);
|
||||||
}else{
|
}else{
|
||||||
conn.setex(key, seconds, value);
|
conn.setex(key, seconds, value);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,47 +27,6 @@ import redis.clients.jedis.JedisPoolConfig;
|
|||||||
public class RedisConnectionFactory {
|
public class RedisConnectionFactory {
|
||||||
private static final Logger _logger = LoggerFactory.getLogger(RedisConnectionFactory.class);
|
private static final Logger _logger = LoggerFactory.getLogger(RedisConnectionFactory.class);
|
||||||
|
|
||||||
public static class DEFAULT_CONFIG {
|
|
||||||
/**
|
|
||||||
* Redis默认服务器IP
|
|
||||||
*/
|
|
||||||
public static final String DEFAULT_ADDRESS = "127.0.0.1";
|
|
||||||
/**
|
|
||||||
* Redis默认端口号
|
|
||||||
*/
|
|
||||||
public static final int DEFAULT_PORT = 6379;
|
|
||||||
/**
|
|
||||||
* 访问密码
|
|
||||||
*/
|
|
||||||
public static final String DEFAULT_AUTH = "admin";
|
|
||||||
/**
|
|
||||||
* 可用连接实例的最大数目,默认值为8;<br>
|
|
||||||
* 如果赋值为-1,则表示不限制;如果pool已经分配了maxActive个jedis实例,则此时pool的状态为exhausted(耗尽)。
|
|
||||||
**/
|
|
||||||
public static final int DEFAULT_MAX_ACTIVE = 5000;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 控制一个pool最多有多少个状态为idle(空闲的)的jedis实例,默认值也是8。
|
|
||||||
*/
|
|
||||||
public static final int DEFAULT_MAX_IDLE = 5000;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 等待可用连接的最大时间,单位毫秒,默认值为-1,表示永不超时。如果超过等待时间,则直接抛出JedisConnectionException;
|
|
||||||
*/
|
|
||||||
public static final int DEFAULT_MAX_WAIT_MILLIS = 10000;
|
|
||||||
|
|
||||||
public static final int DEFAULT_TIMEOUT = 10000;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 在borrow一个jedis实例时,是否提前进行validate操作;如果为true,则得到的jedis实例均是可用的;
|
|
||||||
*/
|
|
||||||
public static final boolean DEFAULT_TEST_ON_BORROW = true;
|
|
||||||
/**
|
|
||||||
* 默认过期时间
|
|
||||||
*/
|
|
||||||
public static final long DEFAULT_LIFETIME = 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
JedisPoolConfig poolConfig;
|
JedisPoolConfig poolConfig;
|
||||||
|
|
||||||
private JedisPool jedisPool = null;
|
private JedisPool jedisPool = null;
|
||||||
@ -86,13 +45,13 @@ public class RedisConnectionFactory {
|
|||||||
_logger.debug("init Jedis Pool .");
|
_logger.debug("init Jedis Pool .");
|
||||||
try {
|
try {
|
||||||
if (this.hostName == null || hostName.equals("")) {
|
if (this.hostName == null || hostName.equals("")) {
|
||||||
hostName = DEFAULT_CONFIG.DEFAULT_ADDRESS;
|
hostName = RedisDefaultConfig.DEFAULT_ADDRESS;
|
||||||
}
|
}
|
||||||
if (port == 0) {
|
if (port == 0) {
|
||||||
port = DEFAULT_CONFIG.DEFAULT_PORT;
|
port = RedisDefaultConfig.DEFAULT_PORT;
|
||||||
}
|
}
|
||||||
if (timeOut == 0) {
|
if (timeOut == 0) {
|
||||||
timeOut = DEFAULT_CONFIG.DEFAULT_TIMEOUT;
|
timeOut = RedisDefaultConfig.DEFAULT_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.password == null || this.password.equals("")) {
|
if (this.password == null || this.password.equals("")) {
|
||||||
|
|||||||
@ -0,0 +1,42 @@
|
|||||||
|
package org.dromara.maxkey.persistence.redis;
|
||||||
|
|
||||||
|
public class RedisDefaultConfig {
|
||||||
|
/**
|
||||||
|
* Redis默认服务器IP
|
||||||
|
*/
|
||||||
|
public static final String DEFAULT_ADDRESS = "127.0.0.1";
|
||||||
|
/**
|
||||||
|
* Redis默认端口号
|
||||||
|
*/
|
||||||
|
public static final int DEFAULT_PORT = 6379;
|
||||||
|
/**
|
||||||
|
* 访问密码
|
||||||
|
*/
|
||||||
|
public static final String DEFAULT_AUTH = "admin";
|
||||||
|
/**
|
||||||
|
* 可用连接实例的最大数目,默认值为8;<br>
|
||||||
|
* 如果赋值为-1,则表示不限制;如果pool已经分配了maxActive个jedis实例,则此时pool的状态为exhausted(耗尽)。
|
||||||
|
**/
|
||||||
|
public static final int DEFAULT_MAX_ACTIVE = 5000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 控制一个pool最多有多少个状态为idle(空闲的)的jedis实例,默认值也是8。
|
||||||
|
*/
|
||||||
|
public static final int DEFAULT_MAX_IDLE = 5000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 等待可用连接的最大时间,单位毫秒,默认值为-1,表示永不超时。如果超过等待时间,则直接抛出JedisConnectionException;
|
||||||
|
*/
|
||||||
|
public static final int DEFAULT_MAX_WAIT_MILLIS = 10000;
|
||||||
|
|
||||||
|
public static final int DEFAULT_TIMEOUT = 10000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在borrow一个jedis实例时,是否提前进行validate操作;如果为true,则得到的jedis实例均是可用的;
|
||||||
|
*/
|
||||||
|
public static final boolean DEFAULT_TEST_ON_BORROW = true;
|
||||||
|
/**
|
||||||
|
* 默认过期时间
|
||||||
|
*/
|
||||||
|
public static final long DEFAULT_LIFETIME = 600;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user