Java Code Examples for redis.clients.jedis.ShardedJedisPipeline#set()
The following examples show how to use
redis.clients.jedis.ShardedJedisPipeline#set() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedisExample.java From java-platform with Apache License 2.0 | 6 votes |
public void testShardPipelined() {// 0.127秒 JedisShardInfo jedis = new JedisShardInfo("120.25.241.144", 6379); jedis.setPassword("b840fc02d52404542994"); List<JedisShardInfo> shards = Arrays.asList(jedis); ShardedJedis sharding = new ShardedJedis(shards); ShardedJedisPipeline pipeline = sharding.pipelined(); long start = System.currentTimeMillis(); for (int i = 0; i < 1000; i++) { pipeline.set("n" + i, "n" + i); System.out.println(i); } pipeline.syncAndReturnAll(); long end = System.currentTimeMillis(); System.out.println("共花费:" + (end - start) / 1000.0 + "秒"); sharding.disconnect(); try { Closeables.close(sharding, true); } catch (IOException e) { e.printStackTrace(); } }
Example 2
Source File: JedisApiTest.java From easyooo-framework with Apache License 2.0 | 6 votes |
/** * 分布式直连异步调用 * 耗时: * 0.866 seconds * 0.892 seconds */ @Test @Ignore public void testShardpipelined() { List<JedisShardInfo> shards = Arrays.asList( new JedisShardInfo("localhost",6379), new JedisShardInfo("localhost",6379)); ShardedJedis sharding = new ShardedJedis(shards); ShardedJedisPipeline pipeline = sharding.pipelined(); long start = System.currentTimeMillis(); for (int i = 0; i < 100000; i++) { pipeline.set("sp" + i, "p" + i); } List<Object> results = pipeline.syncAndReturnAll(); long end = System.currentTimeMillis(); System.out.println("Pipelined@Sharing SET: " + ((end - start)/1000.0) + " seconds"); sharding.disconnect(); sharding.close(); }
Example 3
Source File: JedisApiTest.java From easyooo-framework with Apache License 2.0 | 6 votes |
/** * 分布式连接池异步调用 * 0.452 seconds * 0.43 seconds */ @Test @Ignore public void testShardPipelinedPool() { List<JedisShardInfo> shards = Arrays.asList( new JedisShardInfo("localhost",6379), new JedisShardInfo("localhost",6379)); ShardedJedisPool pool = new ShardedJedisPool(new JedisPoolConfig(), shards); ShardedJedis one = pool.getResource(); ShardedJedisPipeline pipeline = one.pipelined(); long start = System.currentTimeMillis(); for (int i = 0; i < COUNTER; i++) { pipeline.set("sppn" + i, "n" + i); } List<Object> results = pipeline.syncAndReturnAll(); long end = System.currentTimeMillis(); pool.returnResource(one); logger.info("Pipelined@Pool SET: " + ((end - start)/1000.0) + " seconds"); pool.destroy(); }
Example 4
Source File: ShardedJedisPipelineTest.java From cachecloud with Apache License 2.0 | 5 votes |
@Test public void pipeline() throws UnsupportedEncodingException { ShardedJedisPipeline p = jedis.pipelined(); p.set("foo", "bar"); p.get("foo"); List<Object> results = p.syncAndReturnAll(); assertEquals(2, results.size()); assertEquals("OK", results.get(0)); assertEquals("bar", results.get(1)); }
Example 5
Source File: RedisExample.java From java-platform with Apache License 2.0 | 5 votes |
public void testShardPipelinnedPool() {// 0.124秒 JedisShardInfo jedis = new JedisShardInfo("120.25.241.144", 6379); jedis.setPassword("b840fc02d52404542994"); List<JedisShardInfo> shards = Arrays.asList(jedis); ShardedJedisPool pool = new ShardedJedisPool(new JedisPoolConfig(), shards); ShardedJedis sharding = pool.getResource(); ShardedJedisPipeline pipeline = sharding.pipelined(); long start = System.currentTimeMillis(); for (int i = 0; i < 1000; i++) { pipeline.set("n" + i, "n" + i); System.out.println(i); } pipeline.syncAndReturnAll(); long end = System.currentTimeMillis(); System.out.println("共花费:" + (end - start) / 1000.0 + "秒"); sharding.disconnect(); pool.destroy(); try { Closeables.close(sharding, true); Closeables.close(pool, true); } catch (IOException e) { e.printStackTrace(); } }
Example 6
Source File: DefaultRedisTransactionCallback.java From easyooo-framework with Apache License 2.0 | 5 votes |
@Override public void doCallback(ShardedJedisPipeline p) { for (Command cmd : redisCommands) { switch (cmd.getOp()) { case SET: p.set(cmd.getCacheKey(), cmd.getCacheValue()); break; case MOD: p.set(cmd.getCacheKey(), cmd.getCacheValue()); break; case DEL: p.del(cmd.getCacheKey()); break; case ADD_MEMBERS: p.sadd(cmd.getCacheGroupKey(), cmd.getGroupValues()); break; case DEL_MEMBERS: p.srem(cmd.getCacheGroupKey(), cmd.getGroupValues()); break; case SETS: String[] keyvalues = cmd.getKeyvalues(); for (int i = 0; i < keyvalues.length; i+=2) { p.set(keyvalues[i], keyvalues[i+1]); } default: break; } } }