当前位置: 首页>>代码示例>>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;未经允许,请勿转载。