@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; } } }
@Test public void pipelineResponse() { jedis.set("string", "foo"); jedis.lpush("list", "foo"); jedis.hset("hash", "foo", "bar"); jedis.zadd("zset", 1, "foo"); jedis.sadd("set", "foo"); ShardedJedisPipeline p = jedis.pipelined(); Response<String> string = p.get("string"); Response<String> list = p.lpop("list"); Response<String> hash = p.hget("hash", "foo"); Response<Set<String>> zset = p.zrange("zset", 0, -1); Response<String> set = p.spop("set"); Response<Boolean> blist = p.exists("list"); Response<Double> zincrby = p.zincrby("zset", 1, "foo"); Response<Long> zcard = p.zcard("zset"); p.lpush("list", "bar"); Response<List<String>> lrange = p.lrange("list", 0, -1); Response<Map<String, String>> hgetAll = p.hgetAll("hash"); p.sadd("set", "foo"); Response<Set<String>> smembers = p.smembers("set"); Response<Set<Tuple>> zrangeWithScores = p.zrangeWithScores("zset", 0, -1); p.sync(); assertEquals("foo", string.get()); assertEquals("foo", list.get()); assertEquals("bar", hash.get()); assertEquals("foo", zset.get().iterator().next()); assertEquals("foo", set.get()); assertFalse(blist.get()); assertEquals(new Double(2), zincrby.get()); assertEquals(new Long(1), zcard.get()); assertEquals(1, lrange.get().size()); assertNotNull(hgetAll.get().get("foo")); assertEquals(1, smembers.get().size()); assertEquals(1, zrangeWithScores.get().size()); }