Skip to content

Commit

Permalink
Change GenericObjectPoolConfig to JedisPoolConfig, add timeBetweenEvi…
Browse files Browse the repository at this point in the history
…ctionRuns and minEvictableIdleTime properties (#31)

Co-authored-by: jkolenko <[email protected]>
  • Loading branch information
TPXL and iconomi-support authored Dec 31, 2021
1 parent 350578c commit 1ce5de4
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/main/java/com/cwbase/logback/RedisAppender.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import ch.qos.logback.core.UnsynchronizedAppenderBase;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.Protocol;

public class RedisAppender extends UnsynchronizedAppenderBase<ILoggingEvent> {
Expand All @@ -28,6 +29,8 @@ public class RedisAppender extends UnsynchronizedAppenderBase<ILoggingEvent> {
int timeout = Protocol.DEFAULT_TIMEOUT;
String password = null;
int database = Protocol.DEFAULT_DATABASE;
int timeBetweenEvictionRuns = 30000; //default in JedisPoolConfig
int minEvictableIdleTime = 60000; //default in JedisPoolConfig

public RedisAppender() {
jsonlayout = new JSONEventLayout();
Expand Down Expand Up @@ -203,11 +206,29 @@ public void setLayout(Layout<ILoggingEvent> layout) {
this.layout = layout;
}

public int getTimeBetweenEvictionRuns() {
return timeBetweenEvictionRuns;
}

public void setTimeBetweenEvictionRuns(int timeBetweenEvictionRuns) {
this.timeBetweenEvictionRuns = timeBetweenEvictionRuns;
}

public int getMinEvictableIdleTime() {
return minEvictableIdleTime;
}

public void setMinEvictableIdleTime(int minEvictableIdleTime) {
this.minEvictableIdleTime = minEvictableIdleTime;
}

@Override
public void start() {
super.start();
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
GenericObjectPoolConfig config = new JedisPoolConfig();
config.setTestOnBorrow(true);
config.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRuns);
config.setMinEvictableIdleTimeMillis(minEvictableIdleTime);
pool = new JedisPool(config, host, port, timeout, password, database);
}

Expand Down

0 comments on commit 1ce5de4

Please sign in to comment.