use of redis.clients.jedis.JedisCluster in project duangframework by tcrct.
the class AbstractRedisClient method call.
public <T> T call(JedisAction cacheAction) {
T result = null;
if (!isCluster()) {
Jedis jedis = JedisPoolUtils.getJedis();
try {
result = (T) cacheAction.execute(jedis);
} catch (Exception e) {
// JedisPoolUtils.returnBrokenResource(jedis);
logger.warn(e.getMessage(), e);
}
// finally {
// JedisPoolUtils.returnResource(jedis);
// }
} else {
JedisCluster jedisCluster = JedisClusterPoolUtils.getJedisCluster();
result = (T) cacheAction.execute(jedisCluster);
}
return result;
}
use of redis.clients.jedis.JedisCluster in project duangframework by tcrct.
the class JedisClusterPoolUtils method createJedisPool.
/**
* 建立连接池 真实环境,一般把配置参数缺抽取出来。
*/
private static void createJedisPool() {
try {
String[] ipArray = getClusterIps();
if (ToolsKit.isEmpty(ipArray)) {
throw new EmptyNullException("ipArray is null");
}
// 只给集群里一个实例就可以
Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
for (int i = 0; i < ipArray.length; i++) {
String[] items = ipArray[i].split(":");
jedisClusterNodes.add(new HostAndPort(items[0], Integer.parseInt(items[1])));
}
// 配置信息
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(10000);
config.setMaxIdle(500);
config.setMinIdle(100);
config.setMaxWaitMillis(5000);
config.setTestOnBorrow(true);
config.setTestOnReturn(true);
jedisCluster = new JedisCluster(jedisClusterNodes, config);
if (null != jedisCluster) {
logger.warn("Connent Redis Cluster: " + ToolsKit.toJsonString(jedisClusterNodes) + " is Success...");
}
} catch (Exception e) {
e.printStackTrace();
logger.info("初始化 redis 出错啦...");
}
}
use of redis.clients.jedis.JedisCluster in project oxCore by GluuFederation.
the class RedisClusterProvider method create.
public void create() {
try {
LOG.debug("Starting RedisClusterProvider ... configuration:" + getRedisConfiguration());
JedisPoolConfig poolConfig = createPoolConfig();
String password = redisConfiguration.getPassword();
if (redisConfiguration.getUseSSL()) {
RedisProviderFactory.setSSLSystemProperties(redisConfiguration);
pool = new JedisCluster(hosts(getRedisConfiguration().getServers()), redisConfiguration.getConnectionTimeout(), redisConfiguration.getSoTimeout(), redisConfiguration.getMaxRetryAttempts(), password, UUID.randomUUID().toString(), poolConfig, true);
} else {
pool = new JedisCluster(hosts(getRedisConfiguration().getServers()), redisConfiguration.getConnectionTimeout(), redisConfiguration.getSoTimeout(), redisConfiguration.getMaxRetryAttempts(), password, poolConfig);
}
testConnection();
LOG.debug("RedisClusterProvider started.");
} catch (Exception e) {
LOG.error("Failed to start RedisClusterProvider.", e);
throw new IllegalStateException("Error starting RedisClusterProvider", e);
}
}
use of redis.clients.jedis.JedisCluster in project YCSB by brianfrankcooper.
the class RedisClient method init.
public void init() throws DBException {
Properties props = getProperties();
int port;
String portString = props.getProperty(PORT_PROPERTY);
if (portString != null) {
port = Integer.parseInt(portString);
} else {
port = Protocol.DEFAULT_PORT;
}
String host = props.getProperty(HOST_PROPERTY);
boolean clusterEnabled = Boolean.parseBoolean(props.getProperty(CLUSTER_PROPERTY));
if (clusterEnabled) {
Set<HostAndPort> jedisClusterNodes = new HashSet<>();
jedisClusterNodes.add(new HostAndPort(host, port));
jedis = new JedisCluster(jedisClusterNodes);
} else {
String redisTimeout = props.getProperty(TIMEOUT_PROPERTY);
if (redisTimeout != null) {
jedis = new Jedis(host, port, Integer.parseInt(redisTimeout));
} else {
jedis = new Jedis(host, port);
}
((Jedis) jedis).connect();
}
String password = props.getProperty(PASSWORD_PROPERTY);
if (password != null) {
((BasicCommands) jedis).auth(password);
}
}
use of redis.clients.jedis.JedisCluster in project tech by ffyyhh995511.
the class JedisClusterService method get.
public String get(String key) throws IOException {
String res = null;
JedisCluster jedisCluster = null;
try {
jedisCluster = new JedisCluster(jedisClusterNodes, poolConfig);
res = jedisCluster.get(key);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (jedisCluster != null) {
jedisCluster.close();
}
}
return res;
}
Aggregations