forked from Archives/Athou_commafeed
enable redis connections with ACLs
This commit is contained in:
@@ -125,6 +125,8 @@ logging:
|
|||||||
redis:
|
redis:
|
||||||
host: localhost
|
host: localhost
|
||||||
port: 6379
|
port: 6379
|
||||||
|
# username is only required when using ACLs
|
||||||
|
username:
|
||||||
password:
|
password:
|
||||||
timeout: 2000
|
timeout: 2000
|
||||||
database: 0
|
database: 0
|
||||||
|
|||||||
@@ -130,6 +130,8 @@ logging:
|
|||||||
redis:
|
redis:
|
||||||
host: localhost
|
host: localhost
|
||||||
port: 6379
|
port: 6379
|
||||||
|
# username is only required when using ACLs
|
||||||
|
username:
|
||||||
password:
|
password:
|
||||||
timeout: 2000
|
timeout: 2000
|
||||||
database: 0
|
database: 0
|
||||||
|
|||||||
@@ -114,7 +114,7 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<transformers>
|
<transformers>
|
||||||
<transformer
|
<transformer
|
||||||
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
|
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
|
||||||
<transformer
|
<transformer
|
||||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
<mainClass>com.commafeed.CommaFeedApplication</mainClass>
|
<mainClass>com.commafeed.CommaFeedApplication</mainClass>
|
||||||
@@ -387,7 +387,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>redis.clients</groupId>
|
<groupId>redis.clients</groupId>
|
||||||
<artifactId>jedis</artifactId>
|
<artifactId>jedis</artifactId>
|
||||||
<version>2.7.2</version>
|
<version>4.3.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sun.mail</groupId>
|
<groupId>com.sun.mail</groupId>
|
||||||
|
|||||||
@@ -1,27 +1,53 @@
|
|||||||
package com.commafeed.backend.cache;
|
package com.commafeed.backend.cache;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import redis.clients.jedis.DefaultJedisClientConfig;
|
||||||
|
import redis.clients.jedis.HostAndPort;
|
||||||
|
import redis.clients.jedis.JedisClientConfig;
|
||||||
import redis.clients.jedis.JedisPool;
|
import redis.clients.jedis.JedisPool;
|
||||||
import redis.clients.jedis.JedisPoolConfig;
|
import redis.clients.jedis.JedisPoolConfig;
|
||||||
import redis.clients.jedis.Protocol;
|
import redis.clients.jedis.Protocol;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Getter
|
@Getter
|
||||||
public class RedisPoolFactory {
|
public class RedisPoolFactory {
|
||||||
private final String host = "localhost";
|
|
||||||
private final int port = Protocol.DEFAULT_PORT;
|
|
||||||
private String password;
|
|
||||||
private final int timeout = Protocol.DEFAULT_TIMEOUT;
|
|
||||||
private final int database = Protocol.DEFAULT_DATABASE;
|
|
||||||
|
|
||||||
private final int maxTotal = 500;
|
@JsonProperty
|
||||||
|
private String host = "localhost";
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
private int port = Protocol.DEFAULT_PORT;
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
private int timeout = Protocol.DEFAULT_TIMEOUT;
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
private int database = Protocol.DEFAULT_DATABASE;
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
private int maxTotal = 500;
|
||||||
|
|
||||||
public JedisPool build() {
|
public JedisPool build() {
|
||||||
JedisPoolConfig config = new JedisPoolConfig();
|
JedisPoolConfig poolConfig = new JedisPoolConfig();
|
||||||
config.setMaxTotal(maxTotal);
|
poolConfig.setMaxTotal(maxTotal);
|
||||||
|
|
||||||
return new JedisPool(config, host, port, timeout, StringUtils.trimToNull(password), database);
|
JedisClientConfig clientConfig = DefaultJedisClientConfig.builder()
|
||||||
|
.user(username)
|
||||||
|
.password(password)
|
||||||
|
.timeoutMillis(timeout)
|
||||||
|
.database(database)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
return new JedisPool(poolConfig, new HostAndPort(host, port), clientConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user