本文整理汇总了Java中redis.clients.jedis.Protocol.DEFAULT_HOST属性的典型用法代码示例。如果您正苦于以下问题:Java Protocol.DEFAULT_HOST属性的具体用法?Java Protocol.DEFAULT_HOST怎么用?Java Protocol.DEFAULT_HOST使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类redis.clients.jedis.Protocol
的用法示例。
在下文中一共展示了Protocol.DEFAULT_HOST属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newJedisPool
/**
* Creates a new {@link JedisPool}.
*
* @param hostAndPort
* @param password
* @param db
* @param timeoutMs
* @return
*/
public static JedisPool newJedisPool(String hostAndPort, String password, int db,
long timeoutMs) {
final int maxTotal = Runtime.getRuntime().availableProcessors();
final int maxIdle = maxTotal / 2;
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxTotal(maxTotal);
poolConfig.setMinIdle(1);
poolConfig.setMaxIdle(maxIdle > 0 ? maxIdle : 1);
poolConfig.setMaxWaitMillis(timeoutMs + 1000);
// poolConfig.setTestOnBorrow(true);
poolConfig.setTestWhileIdle(true);
String[] tokens = hostAndPort.split(":");
String host = tokens.length > 0 ? tokens[0] : Protocol.DEFAULT_HOST;
int port = tokens.length > 1 ? Integer.parseInt(tokens[1]) : Protocol.DEFAULT_PORT;
JedisPool jedisPool = new JedisPool(poolConfig, host, port, (int) timeoutMs, password, db);
return jedisPool;
}
示例2: newJedisPool
/**
* Creates a new {@link JedisPool}.
*
* @param hostAndPort
* @param password
* @param db
* @param timeoutMs
* @return
* @since 0.5.0
*/
public static JedisPool newJedisPool(String hostAndPort, String password, int db,
long timeoutMs) {
final int maxTotal = Runtime.getRuntime().availableProcessors();
final int maxIdle = maxTotal / 2;
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxTotal(maxTotal);
poolConfig.setMinIdle(1);
poolConfig.setMaxIdle(maxIdle > 0 ? maxIdle : 1);
poolConfig.setMaxWaitMillis(timeoutMs);
// poolConfig.setTestOnBorrow(true);
poolConfig.setTestWhileIdle(true);
String[] tokens = hostAndPort.split(":");
String host = tokens.length > 0 ? tokens[0] : Protocol.DEFAULT_HOST;
int port = tokens.length > 1 ? Integer.parseInt(tokens[1]) : Protocol.DEFAULT_PORT;
JedisPool jedisPool = new JedisPool(poolConfig, host, port, Protocol.DEFAULT_TIMEOUT,
password, db);
return jedisPool;
}
示例3: newShardedJedisPool
/**
* Create a new {@link ShardedJedisPool}.
*
* @param poolConfig
* format {@code host1:port1,host2:port2,...}, default Redis port is used if not
* specified
* @param password
* @param timeoutMs
* @return
*/
public static ShardedJedisPool newShardedJedisPool(JedisPoolConfig poolConfig,
String hostsAndPorts, String password, int timeoutMs) {
List<JedisShardInfo> shards = new ArrayList<>();
String[] hapList = hostsAndPorts.split("[,;\\s]+");
for (String hostAndPort : hapList) {
String[] tokens = hostAndPort.split(":");
String host = tokens.length > 0 ? tokens[0] : Protocol.DEFAULT_HOST;
int port = tokens.length > 1 ? Integer.parseInt(tokens[1]) : Protocol.DEFAULT_PORT;
JedisShardInfo shardInfo = new JedisShardInfo(host, port, timeoutMs);
shardInfo.setPassword(password);
shards.add(shardInfo);
}
ShardedJedisPool jedisPool = new ShardedJedisPool(poolConfig, shards);
return jedisPool;
}
示例4: setupPool
@BeforeClass
public static void setupPool() {
POOL = new JedisPool(new GenericObjectPoolConfig(),
Protocol.DEFAULT_HOST,
Protocol.DEFAULT_PORT,
Protocol.DEFAULT_TIMEOUT,
null,
5);
}
示例5: newJedisCluster
/**
* Creates a new {@link JedisCluster}.
*
* @param hostsAndPorts
* format {@code host1:port1,host2:port2...}
* @param password
* @param timeoutMs
* @return
*/
public static JedisCluster newJedisCluster(String hostsAndPorts, String password,
long timeoutMs) {
final int maxTotal = Runtime.getRuntime().availableProcessors();
final int maxIdle = maxTotal / 2;
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxTotal(maxTotal);
poolConfig.setMinIdle(1);
poolConfig.setMaxIdle(maxIdle > 0 ? maxIdle : 1);
poolConfig.setMaxWaitMillis(timeoutMs + 1000);
// poolConfig.setTestOnBorrow(true);
poolConfig.setTestWhileIdle(true);
Set<HostAndPort> clusterNodes = new HashSet<>();
String[] hapList = hostsAndPorts.split("[,;\\s]+");
for (String hostAndPort : hapList) {
String[] tokens = hostAndPort.split(":");
String host = tokens.length > 0 ? tokens[0] : Protocol.DEFAULT_HOST;
int port = tokens.length > 1 ? Integer.parseInt(tokens[1]) : Protocol.DEFAULT_PORT;
clusterNodes.add(new HostAndPort(host, port));
}
JedisCluster jedisCluster = new JedisCluster(clusterNodes, (int) timeoutMs, (int) timeoutMs,
DEFAULT_MAX_ATTEMPTS, password, poolConfig);
return jedisCluster;
}
示例6: newJedisPool
/**
* Creates a new {@link ShardedJedisPool}.
*
* @param hostsAndPorts
* format {@code host1:port1,host2:port2...}
* @param password
* @param timeoutMs
* @return
*/
public static ShardedJedisPool newJedisPool(String hostsAndPorts, String password,
long timeoutMs) {
final int maxTotal = Runtime.getRuntime().availableProcessors();
final int maxIdle = maxTotal / 2;
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxTotal(maxTotal);
poolConfig.setMinIdle(1);
poolConfig.setMaxIdle(maxIdle > 0 ? maxIdle : 1);
poolConfig.setMaxWaitMillis(timeoutMs + 1000);
// poolConfig.setTestOnBorrow(true);
poolConfig.setTestWhileIdle(true);
List<JedisShardInfo> shards = new ArrayList<>();
String[] hapList = hostsAndPorts.split("[,;\\s]+");
for (String hostAndPort : hapList) {
String[] tokens = hostAndPort.split(":");
String host = tokens.length > 0 ? tokens[0] : Protocol.DEFAULT_HOST;
int port = tokens.length > 1 ? Integer.parseInt(tokens[1]) : Protocol.DEFAULT_PORT;
JedisShardInfo shardInfo = new JedisShardInfo(host, port, (int) timeoutMs);
shardInfo.setPassword(password);
shards.add(shardInfo);
}
ShardedJedisPool jedisPool = new ShardedJedisPool(poolConfig, shards);
return jedisPool;
}
示例7: newJedisCluster
/**
* Create a new {@link JedisCluster}.
*
* @param poolConfig
* format {@code host1:port1,host2:port2,...}, default Redis port is used if not
* specified
* @param password
* @param timeoutMs
* @param maxAttempts
* @return
*/
public static JedisCluster newJedisCluster(JedisPoolConfig poolConfig, String hostsAndPorts,
String password, int timeoutMs, int maxAttempts) {
Set<HostAndPort> clusterNodes = new HashSet<>();
String[] hapList = hostsAndPorts.split("[,;\\s]+");
for (String hostAndPort : hapList) {
String[] tokens = hostAndPort.split(":");
String host = tokens.length > 0 ? tokens[0] : Protocol.DEFAULT_HOST;
int port = tokens.length > 1 ? Integer.parseInt(tokens[1]) : Protocol.DEFAULT_PORT;
clusterNodes.add(new HostAndPort(host, port));
}
JedisCluster jedisCluster = new JedisCluster(clusterNodes, timeoutMs, timeoutMs,
maxAttempts, password, poolConfig);
return jedisCluster;
}
示例8: JaRedisPool
public JaRedisPool() {
this(Protocol.DEFAULT_HOST, Protocol.DEFAULT_PORT);
}
示例9: setHost
public void setHost(String host) {
if (host == null || "".equals(host)) {
host = Protocol.DEFAULT_HOST;
}
this.host = host;
}
示例10: newJedisPool
/**
* Create a new {@link JedisPool}.
*
* @param poolConfig
* @param hostAndPort
* format {@code host:port} or {@code host}, default Redis port is used if not
* specified
* @param password
* @param db
* @param timeoutMs
* @return
*/
public static JedisPool newJedisPool(JedisPoolConfig poolConfig, String hostAndPort,
String password, int db, int timeoutMs) {
String[] tokens = hostAndPort.split(":");
String host = tokens.length > 0 ? tokens[0] : Protocol.DEFAULT_HOST;
int port = tokens.length > 1 ? Integer.parseInt(tokens[1]) : Protocol.DEFAULT_PORT;
JedisPool jedisPool = new JedisPool(
poolConfig != null ? poolConfig : defaultJedisPoolConfig(), host, port, timeoutMs,
password, db);
return jedisPool;
}