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

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

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

Jedis.<init>介绍

暂无

代码示例

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

@Override
public Jedis createResource() {
 return new Jedis(this);
}

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

protected Jedis create(JedisShardInfo shard) {
 return new Jedis(shard);
}

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

public JedisSentinelConnection(String host, int port) {
  this(new Jedis(host, port));
}

代码示例来源:origin: Dreampie/Resty

private Jedis getJedis() {
 Jedis jedis = null;
 if (pool != null && pool instanceof JedisPool) {
  jedis = (Jedis) pool.getResource();
 }
 //hp[0] is hostname,hp[1] is port,hp[2] is the password of redis
 if (jedis == null) {
  String[] hp = host.split(":");
  jedis = new Jedis(hp[0], Integer.parseInt(hp[1]), timeout);
  if (hp.length >= 3) {
   jedis.auth(hp[2]);
  }
 }
 return jedis;
}

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

j = new Jedis(host, port);

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

protected Jedis getJedis(RedisNode node) {
  Jedis jedis = new Jedis(node.getHost(), node.getPort());
  if (StringUtils.hasText(clientName)) {
    jedis.clientSetname(clientName);
  }
  return jedis;
}

代码示例来源: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: 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

private Jedis createJedis() {
  if (providedShardInfo) {
    return new Jedis(getShardInfo());
  }
  Jedis jedis = new Jedis(getHostName(), getPort(), getConnectTimeout(), getReadTimeout(), isUseSsl(),
      clientConfiguration.getSslSocketFactory().orElse(null), //
      clientConfiguration.getSslParameters().orElse(null), //
      clientConfiguration.getHostnameVerifier().orElse(null));
  Client client = jedis.getClient();
  getRedisPassword().map(String::new).ifPresent(client::setPassword);
  client.setDb(getDatabase());
  return jedis;
}

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

jedis = new Jedis(hap.getHost(), hap.getPort());

代码示例来源:origin: testcontainers/testcontainers-java

public Jedis getJedis() {
    return new Jedis(getContainerIpAddress(), getMappedPort(6379));
  }
}

代码示例来源:origin: caoxinyu/RedisClient

public void execute() {
  server = service.listById(id);
  this.jedis = new Jedis(server.getHost(), Integer.parseInt(server.getPort()), timeout);
  if(server.getPassword() != null && server.getPassword().length() > 0)
    jedis.auth(server.getPassword());
  
  runCommand();
  
  jedis.close();
}

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

private void initializeSlotsCache(Set<HostAndPort> startNodes, GenericObjectPoolConfig poolConfig) {
 for (HostAndPort hostAndPort : startNodes) {
  Jedis jedis = new Jedis(hostAndPort.getHost(), hostAndPort.getPort());
  try {
   cache.discoverClusterNodesAndSlots(jedis);
   break;
  } catch (JedisConnectionException e) {
   // try next nodes
  } finally {
   if (jedis != null) {
    jedis.close();
   }
  }
 }
 for (HostAndPort node : startNodes) {
  cache.setNodeIfNotExist(node);
 }
}

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

private Jedis getActiveSentinel() {
  Assert.isTrue(RedisConfiguration.isSentinelConfiguration(configuration), "SentinelConfig must not be null!");
  for (RedisNode node : ((SentinelConfiguration) configuration).getSentinels()) {
    Jedis jedis = new Jedis(node.getHost(), node.getPort(), getConnectTimeout(), getReadTimeout());
    if (jedis.ping().equalsIgnoreCase("pong")) {
      potentiallySetClientName(jedis);
      return jedis;
    }
  }
  throw new InvalidDataAccessResourceUsageException("No Sentinel found");
}

代码示例来源:origin: testcontainers/testcontainers-java

@Before
public void setupClients() {
  for (int i = 0; i < 3; i++) {
    String name = String.format("redis_%d", i + 1);
    clients[i] = new Jedis(environment.getServiceHost(name, REDIS_PORT), environment.getServicePort(name, REDIS_PORT));
  }
}

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

public Jedis getNewJedis(String channel, int timeout) {
  Jedis jedis = getJedis(channel);
  try {
    String host = jedis.getClient().getHost();
    int port = jedis.getClient().getPort();
    Jedis newJedis = new Jedis(host, port, timeout);
    String pong = newJedis.ping();
    if (pong == null || !pong.equals("PONG")) {
      throw new JedisException("SubPubCluster:jedis is not ping !");
    }
    return newJedis;
  } finally {
    releaseConnection(jedis);
  }
}

代码示例来源: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: 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: testcontainers/testcontainers-java

@Test
public void simpleTest() {
  Jedis jedis = new Jedis(getEnvironment().getServiceHost("redis_1", REDIS_PORT), getEnvironment().getServicePort("redis_1", REDIS_PORT));
  jedis.incr("test");
  jedis.incr("test");
  jedis.incr("test");
  assertEquals("A redis instance defined in compose can be used in isolation", "3", jedis.get("test"));
}

代码示例来源:origin: testcontainers/testcontainers-java

@Test
public void secondTest() {
  // used in manual checking for cleanup in between tests
  Jedis jedis = new Jedis(getEnvironment().getServiceHost("redis_1", REDIS_PORT), getEnvironment().getServicePort("redis_1", REDIS_PORT));
  jedis.incr("test");
  jedis.incr("test");
  jedis.incr("test");
  assertEquals("Tests use fresh container instances", "3", jedis.get("test"));
  // if these end up using the same container one of the test methods will fail.
  // However, @Rule creates a separate DockerComposeContainer instance per test, so this just shouldn't happen
}

相关文章

Jedis类方法