本文整理汇总了Java中redis.clients.jedis.Protocol.DEFAULT_PORT属性的典型用法代码示例。如果您正苦于以下问题:Java Protocol.DEFAULT_PORT属性的具体用法?Java Protocol.DEFAULT_PORT怎么用?Java Protocol.DEFAULT_PORT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类redis.clients.jedis.Protocol
的用法示例。
在下文中一共展示了Protocol.DEFAULT_PORT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: JaRedisPool
public JaRedisPool(final String host) {
URI uri = URI.create(host);
if (JedisURIHelper.isValid(uri)) {
String h = uri.getHost();
int port = uri.getPort();
String password = JedisURIHelper.getPassword(uri);
int database = JedisURIHelper.getDBIndex(uri);
this.internalPool = new GenericObjectPool<>(new JaRedisFactory(h, port,
Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, password, database, null),
new GenericObjectPoolConfig());
} else {
this.internalPool = new GenericObjectPool<>(new JaRedisFactory(host,
Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, null,
Protocol.DEFAULT_DATABASE, null), new GenericObjectPoolConfig());
}
}
示例2: createPool
private static JedisPool createPool(GenericObjectPoolConfig redisPoolConfig,
String connection,
int timeout) {
URI redisConnection = URI.create(connection);
String host = redisConnection.getHost();
int port = redisConnection.getPort() == -1 ? Protocol.DEFAULT_PORT : redisConnection.getPort();
String path = redisConnection.getPath();
if (StringUtils.isEmpty(path)) {
path = "/" + String.valueOf(Protocol.DEFAULT_DATABASE);
}
int database = Integer.parseInt(path.split("/", 2)[1]);
String password = null;
if (redisConnection.getUserInfo() != null) {
password = redisConnection.getUserInfo().split(":", 2)[1];
}
if (redisPoolConfig == null) {
redisPoolConfig = new GenericObjectPoolConfig();
}
return new JedisPool(redisPoolConfig, host, port, timeout, password, database, null);
}
示例3: 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;
}
示例4: 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;
}
示例5: 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);
jedis = new Jedis(host, port);
jedis.connect();
String password = props.getProperty(PASSWORD_PROPERTY);
if (password != null) {
jedis.auth(password);
}
}
示例6: create
@Override
public GelfSender create(GelfSenderConfiguration configuration) throws IOException {
String graylogHost = configuration.getHost();
URI hostUri = URI.create(graylogHost);
int port = hostUri.getPort();
if (port <= 0) {
port = configuration.getPort();
}
if (port <= 0) {
port = Protocol.DEFAULT_PORT;
}
if (hostUri.getFragment() == null || hostUri.getFragment().trim().equals("")) {
throw new IllegalArgumentException("Redis URI must specify fragment");
}
if (hostUri.getHost() == null) {
throw new IllegalArgumentException("Redis URI must specify host");
}
Pool<Jedis> pool = RedisSenderPoolProvider.getJedisPool(hostUri, port);
return new GelfREDISSender(pool, hostUri.getFragment(), configuration.getErrorReporter());
}
示例7: 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;
}
示例8: RedisPool
public RedisPool(final String host) {
URI uri = URI.create(host);
if (uri.getScheme() != null && uri.getScheme().equals("redis")) {
String h = uri.getHost();
int port = uri.getPort();
String password = JedisURIHelper.getPassword(uri);
int database = 0;
Integer dbIndex = JedisURIHelper.getDBIndex(uri);
if (dbIndex != null) {
database = dbIndex.intValue();
}
this.internalPool = new GenericObjectPool<BinaryJedis>(
new BinaryJedisFactory(h, port, Protocol.DEFAULT_TIMEOUT,
password, database, null),
new GenericObjectPoolConfig());
} else {
this.internalPool = new GenericObjectPool<BinaryJedis>(new BinaryJedisFactory(
host, Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT,
null, Protocol.DEFAULT_DATABASE, null),
new GenericObjectPoolConfig());
}
}
示例9: connectWithShardInfo
@Test
public void connectWithShardInfo() {
JedisShardInfo shardInfo = new JedisShardInfo("localhost", Protocol.DEFAULT_PORT);
shardInfo.setPassword("foobared");
Jedis jedis = new Jedis(shardInfo);
jedis.get("foo");
}
示例10: activateService
@Override
public void activateService()
throws Exception
{
configuration.refresh();
RedisEntityStoreConfiguration config = configuration.get();
String host = config.host().get() == null ? DEFAULT_HOST : config.host().get();
int port = config.port().get() == null ? Protocol.DEFAULT_PORT : config.port().get();
int timeout = config.timeout().get() == null ? Protocol.DEFAULT_TIMEOUT : config.timeout().get();
String password = config.password().get();
int database = config.database().get() == null ? Protocol.DEFAULT_DATABASE : config.database().get();
pool = new JedisPool( new JedisPoolConfig(), host, port, timeout, password, database );
}
示例11: setupPool
@BeforeClass
public static void setupPool() {
POOL = new JedisPool(new GenericObjectPoolConfig(),
Protocol.DEFAULT_HOST,
Protocol.DEFAULT_PORT,
Protocol.DEFAULT_TIMEOUT,
null,
5);
}
示例12: buildHostAndPort
@Nonnull
public static HostAndPort buildHostAndPort(@Nonnull String host) {
checkNotNull(host);
int index = host.indexOf(":");
return index == -1 ? new HostAndPort(host, Protocol.DEFAULT_PORT) :
new HostAndPort(host.substring(0, index), Integer.parseInt(host.substring(index + 1)));
}
示例13: createPool
private static void createPool(String prop, String charset){
if(pool == null){
LOG.debug("Jedis pool is not exist, lock and create pool.");
lock.lock();
if(pool!=null){
lock.unlock();
}
try {
Map<String, String> conf = PropertiesUtil.read(prop, charset);
String host = conf.get("redis.server");
String confPort = conf.get("redis.server.port");
int port = (confPort==null || "".equals(confPort))?Protocol.DEFAULT_PORT:Integer.valueOf(confPort);
JedisPoolConfig config =new JedisPoolConfig();
//TODO config by properties
pool = new JedisPool(config, host, port);
} catch (IOException e) {
LOG.error("Error occurred when create jedis pool.", e);
}finally{
lock.unlock();
}
}
}
示例14: 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;
}
示例15: 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;
}