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


Java ShardedJedis.set方法代碼示例

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


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

示例1: checkCloseable

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
@Test
public void checkCloseable() {
  List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
  shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort()));
  shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort()));
  shards.get(0).setPassword("foobared");
  shards.get(1).setPassword("foobared");

  ShardedJedis jedisShard = new ShardedJedis(shards);
  try {
    jedisShard.set("shard_closeable", "true");
  } finally {
    jedisShard.close();
  }

  for (Jedis jedis : jedisShard.getAllShards()) {
    assertTrue(!jedis.isConnected());
  }
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:20,代碼來源:ShardedJedisTest.java

示例2: checkResourceIsCloseable

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
@Test
public void checkResourceIsCloseable() throws URISyntaxException {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);

  List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
  shards.add(new JedisShardInfo(new URI("redis://:[email protected]:6380")));
  shards.add(new JedisShardInfo(new URI("redis://:[email protected]:6379")));

  ShardedJedisPool pool = new ShardedJedisPool(config, shards);

  ShardedJedis jedis = pool.getResource();
  try {
    jedis.set("hello", "jedis");
  } finally {
    jedis.close();
  }

  ShardedJedis jedis2 = pool.getResource();
  try {
    assertEquals(jedis, jedis2);
  } finally {
    jedis2.close();
  }
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:27,代碼來源:ShardedJedisPoolTest.java

示例3: set

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
/**
 * 設置單個值
 *
 * @param key   鍵
 * @param value 值
 * @return 結果
 */
public String set(String key, String value, int timeout) {
    String result = null;
    ShardedJedis shardedJedis = shardedJedisPool.getResource();

    if (shardedJedis == null) {
        return null;
    }
    try {
        result = shardedJedis.set(key, value);
        if (0 != timeout) {
            shardedJedis.expire(key, timeout);
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    } finally {
        shardedJedis.close();
    }
    return result;
}
 
開發者ID:peng9627,項目名稱:hall,代碼行數:27,代碼來源:RedisClientTemplate.java

示例4: setnx

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
/**
 * 從 Redis 2.6.12 版本開始, SET 命令的行為可以通過一係列參數來修改:
 * EX second :設置鍵的過期時間為 second 秒。 SET key value EX second 效果等同於 SETEX key second value 。
 * PX millisecond :設置鍵的過期時間為 millisecond 毫秒。 SET key value PX millisecond 效果等同於 PSETEX key millisecond value 。
 * NX :隻在鍵不存在時,才對鍵進行設置操作。 SET key value NX 效果等同於 SETNX key value 。
 * XX :隻在鍵已經存在時,才對鍵進行設置操作。
 *
 * @param key
 * @param value
 * @param milliseconds
 * @return
 */
public boolean setnx(String key, String value, long milliseconds) {
	ShardedJedis redis = null;
	try {
		redis = pool.getResource();
		key = getKeyAll(key);
		//nx|xx ex|px  seconds|milliseconds
		String result = redis.set(key, value, "nx", "px", milliseconds);
		return "OK".equalsIgnoreCase(result);
	} catch (RuntimeException e) {
		logger.error("redis setex(String key, int seconds, String value):", e);
		return false;
	} finally {
		redis.close();
	}
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:28,代碼來源:RedisCacheClient.java

示例5: shardedPipeline

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
@Test
public void shardedPipeline() {
  List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
  shards.add(new JedisShardInfo(redis1.getHost(), redis1.getPort()));
  shards.add(new JedisShardInfo(redis2.getHost(), redis2.getPort()));
  shards.get(0).setPassword("foobared");
  shards.get(1).setPassword("foobared");
  ShardedJedis jedis = new ShardedJedis(shards);

  final List<String> keys = getKeysDifferentShard(jedis);
  jedis.set(keys.get(0), "a");
  jedis.set(keys.get(1), "b");

  assertNotSame(jedis.getShard(keys.get(0)), jedis.getShard(keys.get(1)));

  List<Object> results = jedis.pipelined(new ShardedJedisPipeline() {
    public void execute() {
      get(keys.get(0));
      get(keys.get(1));
    }
  });

  List<Object> expected = new ArrayList<Object>(2);
  expected.add(SafeEncoder.encode("a"));
  expected.add(SafeEncoder.encode("b"));

  assertEquals(2, results.size());
  assertArrayEquals(SafeEncoder.encode("a"), (byte[]) results.get(0));
  assertArrayEquals(SafeEncoder.encode("b"), (byte[]) results.get(1));
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:31,代碼來源:ShardedJedisTest.java

示例6: checkConnections

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
@Test
public void checkConnections() {
  ShardedJedisPool pool = new ShardedJedisPool(new GenericObjectPoolConfig(), shards);
  ShardedJedis jedis = pool.getResource();
  jedis.set("foo", "bar");
  assertEquals("bar", jedis.get("foo"));
  pool.returnResource(jedis);
  pool.destroy();
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:10,代碼來源:ShardedJedisPoolTest.java

示例7: checkCloseableConnections

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
@Test
public void checkCloseableConnections() throws Exception {
  ShardedJedisPool pool = new ShardedJedisPool(new GenericObjectPoolConfig(), shards);
  ShardedJedis jedis = pool.getResource();
  jedis.set("foo", "bar");
  assertEquals("bar", jedis.get("foo"));
  pool.returnResource(jedis);
  pool.close();
  assertTrue(pool.isClosed());
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:11,代碼來源:ShardedJedisPoolTest.java

示例8: checkConnectionWithDefaultPort

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
@Test
public void checkConnectionWithDefaultPort() {
  ShardedJedisPool pool = new ShardedJedisPool(new GenericObjectPoolConfig(), shards);
  ShardedJedis jedis = pool.getResource();
  jedis.set("foo", "bar");
  assertEquals("bar", jedis.get("foo"));
  pool.returnResource(jedis);
  pool.destroy();
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:10,代碼來源:ShardedJedisPoolTest.java

示例9: checkJedisIsReusedWhenReturned

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
@Test
public void checkJedisIsReusedWhenReturned() {
  ShardedJedisPool pool = new ShardedJedisPool(new GenericObjectPoolConfig(), shards);
  ShardedJedis jedis = pool.getResource();
  jedis.set("foo", "0");
  pool.returnResource(jedis);

  jedis = pool.getResource();
  jedis.incr("foo");
  pool.returnResource(jedis);
  pool.destroy();
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:13,代碼來源:ShardedJedisPoolTest.java

示例10: checkPoolOverflow

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
@Test(expected = JedisException.class)
public void checkPoolOverflow() {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);

  ShardedJedisPool pool = new ShardedJedisPool(config, shards);

  ShardedJedis jedis = pool.getResource();
  jedis.set("foo", "0");

  ShardedJedis newJedis = pool.getResource();
  newJedis.incr("foo");
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:15,代碼來源:ShardedJedisPoolTest.java

示例11: returnResourceShouldResetState

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
@Test
public void returnResourceShouldResetState() throws URISyntaxException {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);

  List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
  shards.add(new JedisShardInfo(new URI("redis://:[email protected]:6380")));
  shards.add(new JedisShardInfo(new URI("redis://:[email protected]:6379")));

  ShardedJedisPool pool = new ShardedJedisPool(config, shards);

  ShardedJedis jedis = pool.getResource();
  jedis.set("pipelined", String.valueOf(0));
  jedis.set("pipelined2", String.valueOf(0));

  ShardedJedisPipeline pipeline = jedis.pipelined();

  pipeline.incr("pipelined");
  pipeline.incr("pipelined2");

  jedis.resetState();

  pipeline = jedis.pipelined();
  pipeline.incr("pipelined");
  pipeline.incr("pipelined2");
  List<Object> results = pipeline.syncAndReturnAll();

  assertEquals(2, results.size());
  pool.returnResource(jedis);
  pool.destroy();
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:33,代碼來源:ShardedJedisPoolTest.java

示例12: set

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
@Override
public boolean set(final String key, final String value, final int expire) {
	checkParameters(key, value);
	final ShardedJedis jedis = getJedis();
	final String result = jedis.set(key, value);
	jedis.expire(key, expire);
	returnResource(jedis);
	return SUCCESS.equalsIgnoreCase(result);
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:10,代碼來源:RedisServiceImpl.java

示例13: setSeq

import redis.clients.jedis.ShardedJedis; //導入方法依賴的package包/類
public void setSeq(String address, Long value){
    if (value == null) {
        return;
    }
    ShardedJedis jedis = null;
    try {
        jedis = pool.getResource();
        jedis.set(seqAddressPrefix + address, value.toString());
    } catch (Exception e) {
        LOGGER.error("", e);
    } finally {
        pool.returnResource(jedis);
    }
}
 
開發者ID:bubicn,項目名稱:bubichain-sdk-java,代碼行數:15,代碼來源:RedisClient.java

示例14: testAvoidLeaksUponDisconnect

import redis.clients.jedis.ShardedJedis; //導入方法依賴的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.ShardedJedis.set方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。