當前位置: 首頁>>代碼示例>>Java>>正文


Java Jedis.clientSetname方法代碼示例

本文整理匯總了Java中redis.clients.jedis.Jedis.clientSetname方法的典型用法代碼示例。如果您正苦於以下問題:Java Jedis.clientSetname方法的具體用法?Java Jedis.clientSetname怎麽用?Java Jedis.clientSetname使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在redis.clients.jedis.Jedis的用法示例。


在下文中一共展示了Jedis.clientSetname方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: scriptExistsWithBrokenConnection

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Test
public void scriptExistsWithBrokenConnection() {
  Jedis deadClient = new Jedis(jedis.getClient().getHost(), jedis.getClient().getPort());
  deadClient.auth("foobared");

  deadClient.clientSetname("DEAD");

  ClientKillerUtil.killClient(deadClient, "DEAD");

  // sure, script doesn't exist, but it's just for checking connection
  try {
    deadClient.scriptExists("abcdefg");
  } catch (JedisConnectionException e) {
    // ignore it
  }

  assertEquals(true, deadClient.getClient().isBroken());

  deadClient.close();
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:21,代碼來源:ScriptingCommandsTest.java

示例2: makeObject

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public PooledObject<Jedis> makeObject() throws Exception {
    final HostAndPort hostAndPort = this.hostAndPort.get();
    JaRedis.Builder builder = new JaRedis.Builder();
    builder
            .host(hostAndPort.getHost())
            .port(hostAndPort.getPort())
            .connectionTimeout(connectionTimeout)
            .soTimeout(soTimeout);
    Jedis jedis = builder.build();
    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);
}
 
開發者ID:YanXs,項目名稱:nighthawk,代碼行數:28,代碼來源:JaRedisFactory.java

示例3: tagClient

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public static void tagClient(Jedis j, String name) {
  j.clientSetname(name);
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:4,代碼來源:ClientKillerUtil.java

示例4: testAvoidLeaksUponDisconnect

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
 * Test for "Issue - BinaryShardedJedis.disconnect() may occur memory leak". You can find more
 * detailed information at https://github.com/xetorthio/jedis/issues/808
 * @throws InterruptedException
 */
@Test
public void testAvoidLeaksUponDisconnect() throws InterruptedException {
  List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(2);
  // 6379
  JedisShardInfo shard1 = new JedisShardInfo(redis1.getHost(), redis1.getPort());
  shard1.setPassword("foobared");
  shards.add(shard1);
  // 6380
  JedisShardInfo shard2 = new JedisShardInfo(redis2.getHost(), redis2.getPort());
  shard2.setPassword("foobared");
  shards.add(shard2);

  @SuppressWarnings("resource")
  ShardedJedis shardedJedis = new ShardedJedis(shards);
  // establish the connection for two redis servers
  shardedJedis.set("a", "bar");
  JedisShardInfo ak = shardedJedis.getShardInfo("a");
  assertEquals(shard2, ak);
  shardedJedis.set("b", "bar1");
  JedisShardInfo bk = shardedJedis.getShardInfo("b");
  assertEquals(shard1, bk);

  // We set a name to the instance so it's easy to find it
  Iterator<Jedis> it = shardedJedis.getAllShards().iterator();
  Jedis deadClient = it.next();
  deadClient.clientSetname("DEAD");

  ClientKillerUtil.killClient(deadClient, "DEAD");

  assertEquals(true, deadClient.isConnected());
  assertEquals(false, deadClient.getClient().getSocket().isClosed());
  assertEquals(false, deadClient.getClient().isBroken()); // normal - not found

  shardedJedis.disconnect();

  assertEquals(false, deadClient.isConnected());
  assertEquals(true, deadClient.getClient().getSocket().isClosed());
  assertEquals(true, deadClient.getClient().isBroken());

  Jedis jedis2 = it.next();
  assertEquals(false, jedis2.isConnected());
  assertEquals(true, jedis2.getClient().getSocket().isClosed());
  assertEquals(false, jedis2.getClient().isBroken());

}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:51,代碼來源:ShardedJedisTest.java


注:本文中的redis.clients.jedis.Jedis.clientSetname方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。