Added support for password protected redis server

master
Edward M. Kagan 5 years ago
parent 89567d17dc
commit 7baf5895f8

@ -32,27 +32,33 @@ public class JedisProccessor {
@Record(ExecutionTime.RUNTIME_INIT) @Record(ExecutionTime.RUNTIME_INIT)
@BuildStep @BuildStep
void build(JedisRecorder recorder, BuildProducer<ServiceStartBuildItem> serviceStart, BeanContainerBuildItem beanContainer, ShutdownContextBuildItem shutdownContext) { void build(JedisRecorder recorder, BuildProducer<ServiceStartBuildItem> serviceStart,
BeanContainerBuildItem beanContainer, ShutdownContextBuildItem shutdownContext) {
System.out.println("JedisProccessor - build"); System.out.println("JedisProccessor - build");
// BuildProducer<ReflectiveClassBuildItem> reflectiveClassBuildItemBuildProducer) { // BuildProducer<ReflectiveClassBuildItem>
// reflectiveClassBuildItemBuildProducer.produce(new ReflectiveClassBuildItem(false, false, BaseGenericObjectPool.class.getName())); // reflectiveClassBuildItemBuildProducer) {
// reflectiveClassBuildItemBuildProducer.produce(new ReflectiveClassBuildItem(false, false, DefaultEvictionPolicy.class.getName())); // reflectiveClassBuildItemBuildProducer.produce(new
// ReflectiveClassBuildItem(false, false,
// BaseGenericObjectPool.class.getName()));
// reflectiveClassBuildItemBuildProducer.produce(new
// ReflectiveClassBuildItem(false, false,
// DefaultEvictionPolicy.class.getName()));
recorder.initialize(config, beanContainer.getValue(), shutdownContext); recorder.initialize(config, beanContainer.getValue(), shutdownContext);
serviceStart.produce(new ServiceStartBuildItem("jedis")); serviceStart.produce(new ServiceStartBuildItem("jedis"));
} }
// @BuildStep // @BuildStep
// SubstrateProxyDefinitionBuildItem httpProxies() { // SubstrateProxyDefinitionBuildItem httpProxies() {
// return new SubstrateProxyDefinitionBuildItem(MBeanServer.class.getName(), // return new SubstrateProxyDefinitionBuildItem(MBeanServer.class.getName(),
// MBeanServerConnection.class.getName(), // MBeanServerConnection.class.getName(),
// KeyedObjectPool.class.getName(), // KeyedObjectPool.class.getName(),
// KeyedPooledObjectFactory.class.getName(), // KeyedPooledObjectFactory.class.getName(),
// ObjectPool.class.getName(), // ObjectPool.class.getName(),
// PooledObject.class.getName(), // PooledObject.class.getName(),
// PooledObjectFactory.class.getName(), // PooledObjectFactory.class.getName(),
// SwallowedExceptionListener.class.getName(), // SwallowedExceptionListener.class.getName(),
// TrackedUse.class.getName(), // TrackedUse.class.getName(),
// UsageTracking.class.getName()); // UsageTracking.class.getName());
// } // }
} }

@ -35,4 +35,10 @@ public class JedisConfig {
@ConfigItem(defaultValue = "true") @ConfigItem(defaultValue = "true")
public boolean log; public boolean log;
/**
* Cluster access password
*/
@ConfigItem(defaultValue = "")
public String password;
} }

@ -10,6 +10,7 @@ import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisShardInfo; import redis.clients.jedis.JedisShardInfo;
import redis.clients.jedis.ShardedJedisPool; import redis.clients.jedis.ShardedJedisPool;
import redis.clients.jedis.Jedis; import redis.clients.jedis.Jedis;
import redis.clients.jedis.Protocol;
import redis.clients.jedis.ShardedJedis; import redis.clients.jedis.ShardedJedis;
/** /**
@ -31,29 +32,40 @@ public class JedisSupport {
poolConfig.setTestOnBorrow(true); poolConfig.setTestOnBorrow(true);
poolConfig.setMaxWaitMillis(config.maxWait); poolConfig.setMaxWaitMillis(config.maxWait);
poolConfig.setMaxTotal(config.poolMax); poolConfig.setMaxTotal(config.poolMax);
// poolConfig.setJmxEnabled(false); // poolConfig.setJmxEnabled(false);
poolConfig.setJmxEnabled(true); poolConfig.setJmxEnabled(true);
if (config.shards.contains(",")) { if (config.shards.contains(",")) {
List<JedisShardInfo> jedisShards = Arrays.stream(config.shards.split(",")).map(uri -> { List<JedisShardInfo> jedisShards = Arrays.stream(config.shards.split(",")).map(uri -> {
return new JedisShardInfo(URI.create(uri)); JedisShardInfo jedisShardInfo = new JedisShardInfo(URI.create(uri));
if (config.password.length() > 0) {
jedisShardInfo.setPassword(config.password);
}
return jedisShardInfo;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
this.shardedJedisPool = new ShardedJedisPool(poolConfig, jedisShards); this.shardedJedisPool = new ShardedJedisPool(poolConfig, jedisShards);
} else { } else {
this.jedisPool = new JedisPool(poolConfig, URI.create(config.shards)); URI server = URI.create(config.shards);
if (config.password.length() > 0) {
this.jedisPool = new JedisPool(poolConfig, server.getHost(), server.getPort(), Protocol.DEFAULT_TIMEOUT,
config.password);
} else {
this.jedisPool = new JedisPool(poolConfig, server);
}
} }
} }
public ShardedJedis sharedContext () { public ShardedJedis sharedContext() {
return shardedJedisPool.getResource(); return shardedJedisPool.getResource();
} }
public Jedis context () { public Jedis context() {
return jedisPool.getResource(); return jedisPool.getResource();
} }
public void shutdown() { public void shutdown() {
// redisRuntime.shutdown(); // redisRuntime.shutdown();
} }
} }

Loading…
Cancel
Save