redis.clients.jedis.Jedis.connect()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(6.2k)|赞(0)|评价(0)|浏览(222)

本文整理了Java中redis.clients.jedis.Jedis.connect()方法的一些代码示例,展示了Jedis.connect()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Jedis.connect()方法的具体详情如下:
包路径:redis.clients.jedis.Jedis
类名称:Jedis
方法名:connect

Jedis.connect介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-data-redis

/**
 * Do what ever is required to establish the connection to redis.
 *
 * @param jedis
 */
protected void doInit(Jedis jedis) {
  jedis.connect();
}

代码示例来源:origin: brianfrankcooper/YCSB

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 {
  jedis = new Jedis(host, port);
  ((Jedis) jedis).connect();
 }
 String password = props.getProperty(PASSWORD_PROPERTY);
 if (password != null) {
  ((BasicCommands) jedis).auth(password);
 }
}

代码示例来源:origin: sohutv/cachecloud

@Override
public Long publish(final String channel, final String message) {
 checkIsInMultiOrPipeline();
 connect();
 client.publish(channel, message);
 return client.getIntegerReply();
}

代码示例来源:origin: mpusher/mpush

/**
 * Returns a Jedis instance to be used as a Redis connection. The instance can be newly created or retrieved from a
 * pool.
 */
protected Jedis fetchJedisConnector() {
  try {
    if (pool != null) {
      return pool.getResource();
    }
    Jedis jedis = new Jedis(getShardInfo());
    // force initialization (see Jedis issue #82)
    jedis.connect();
    return jedis;
  } catch (Exception ex) {
    throw new RuntimeException("Cannot get Jedis connection", ex);
  }
}

代码示例来源:origin: spring-projects/spring-data-redis

@Override
protected boolean isActive(RedisNode node) {
  Jedis temp = null;
  try {
    temp = getJedis(node);
    temp.connect();
    return temp.ping().equalsIgnoreCase("pong");
  } catch (Exception e) {
    return false;
  } finally {
    if (temp != null) {
      temp.disconnect();
      temp.close();
    }
  }
}

代码示例来源:origin: zendesk/maxwell

logger.warn("lost connection to server, trying to reconnect...", e);
  jedis.disconnect();
  jedis.connect();
} else {
  this.failedMessageCount.inc();

代码示例来源:origin: sohutv/cachecloud

@Override
public PooledObject<Jedis> makeObject() throws Exception {
 final HostAndPort hostAndPort = this.hostAndPort.get();
 final Jedis jedis = new Jedis(hostAndPort.getHost(), hostAndPort.getPort(), connectionTimeout,
   soTimeout);
 try {
  jedis.connect();
  if (null != this.password) {
   jedis.auth(this.password);
  }
  if (database != 0) {
   jedis.select(database);
  }
  if (clientName != null) {
   jedis.clientSetname(clientName);
  }
 } catch (JedisException je) {
  jedis.close();
  throw je;
 }
 return new DefaultPooledObject<Jedis>(jedis);
}

代码示例来源:origin: spring-projects/spring-data-redis

/**
 * Returns a Jedis instance to be used as a Redis connection. The instance can be newly created or retrieved from a
 * pool.
 *
 * @return Jedis instance ready for wrapping into a {@link RedisConnection}.
 */
protected Jedis fetchJedisConnector() {
  try {
    if (getUsePool() && pool != null) {
      return pool.getResource();
    }
    Jedis jedis = createJedis();
    // force initialization (see Jedis issue #82)
    jedis.connect();
    potentiallySetClientName(jedis);
    return jedis;
  } catch (Exception ex) {
    throw new RedisConnectionFailureException("Cannot get Jedis connection", ex);
  }
}

代码示例来源:origin: zendesk/maxwell

public MaxwellRedisProducer(MaxwellContext context, String redisPubChannel, String redisListKey, String redisType) {
  super(context);
  channel = redisPubChannel;
  listkey = redisListKey;
  redistype = redisType;
  jedis = new Jedis(context.getConfig().redisHost, context.getConfig().redisPort);
  jedis.connect();
  if (context.getConfig().redisAuth != null) {
    jedis.auth(context.getConfig().redisAuth);
  }
  if (context.getConfig().redisDatabase > 0) {
    jedis.select(context.getConfig().redisDatabase);
  }
}

代码示例来源:origin: Impetus/Kundera

connection.connect();
return connection;

代码示例来源:origin: org.springframework.data/spring-data-redis

/**
 * Do what ever is required to establish the connection to redis.
 *
 * @param jedis
 */
protected void doInit(Jedis jedis) {
  jedis.connect();
}

代码示例来源:origin: hltfbk/Excitement-Open-Platform

protected void initRedis(String host,int port) {
  JedisPool pool = new JedisPool(new JedisPoolConfig(), host,port);
  jedis = pool.getResource();
  jedis.connect();
  jedis.getClient().setTimeoutInfinite();
  jedis.flushAll();
}
protected UnlimitedMemoryBasedCountableIdentifiableStorage() {

代码示例来源:origin: org.tinygroup/org.tinygroup.jedis

private static boolean testFailJedis(Jedis j) {
  try {
    j.disconnect();
    j.connect();
    if (j.ping().equals("PONG")) {
      return true;
    }
  } catch (Exception e) {
  }
  return false;
}

代码示例来源:origin: org.apache.apex/malhar-contrib

@Override
public void connect() throws IOException
{
 jedis = new Jedis(host, port,timeOut);
 jedis.connect();
 jedis.select(dbIndex);
}

代码示例来源:origin: io.digdag/digdag-standards

@Override
public ParamServerClientConnection getConnection()
{
  Jedis redisClient = new Jedis(host, port, ssl);
  if (password.isPresent()) {
    redisClient.auth(password.get());
  }
  redisClient.connect();
  return new RedisServerClientConnection(redisClient);
}

代码示例来源:origin: iipc/openwayback

public Object makeObject() throws Exception {
  final Jedis jedis;
  jedis = new JedisValid(host, port, timeout);
  if (password != null) {
    jedis.getClient().setPassword(password);
  }
  jedis.connect();
  return jedis;
}

代码示例来源:origin: vakinge/jeesuite-libs

public Jedis getRedisClient(){
  Jedis jedis = (Jedis) JedisProviderFactory.getJedisProvider(DLOCK_GROUP_NAME).get();
  if(!jedis.isConnected()){
    jedis.connect();
  }
  return jedis;
}

代码示例来源:origin: org.arquillian.ape/arquillian-ape-nosql-redis

@Override
public void connect(String host, int port, String database, Map<String, Object> customOptions) {
  RedisOptions redisOptions = new RedisOptions(customOptions);
  jedis = new Jedis(host, port, redisOptions.isSsl());
  jedis.connect();
}

代码示例来源:origin: org.netpreserve.openwayback/openwayback-core

public Object makeObject() throws Exception {
  final Jedis jedis;
  jedis = new JedisValid(host, port, timeout);
  if (password != null) {
    jedis.getClient().setPassword(password);
  }
  jedis.connect();
  return jedis;
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-software-nosql

private Jedis getRedisClient(RedisStore redis) {
    int port = redis.getAttribute(RedisStore.REDIS_PORT);
    String host = redis.getAttribute(RedisStore.HOSTNAME);
    Jedis client = new Jedis(host, port);
    client.connect();
    assertTrue(client.isConnected());
    return client;
  }
}

相关文章

Jedis类方法