From 29a86109e9edaa94f4b4d079d3327f2867e069d3 Mon Sep 17 00:00:00 2001 From: Bryan Keller Date: Wed, 16 Dec 2020 05:25:21 -0800 Subject: [PATCH 1/7] Jedis binary API parity with string API --- .../connectionpool/CompressionOperation.java | 5 + .../dyno/connectionpool/Connection.java | 5 + .../MultiKeyCompressionOperation.java | 5 + .../impl/HostConnectionPoolImpl.java | 1 + .../impl/lb/TokenAwareSelection.java | 64 +- .../impl/ConnectionPoolImplTest.java | 4 + .../impl/HostConnectionPoolImplTest.java | 4 + .../redis/CustomTokenSupplierExample.java | 4 +- .../dyno/demo/redis/DynoJedisDemo.java | 32 +- .../dyno/jedis/DynoDualWriterClient.java | 694 +-- .../dyno/jedis/DynoDualWriterPipeline.java | 5 + .../netflix/dyno/jedis/DynoJedisClient.java | 3817 +++++------------ .../netflix/dyno/jedis/DynoJedisPipeline.java | 2415 ++++------- .../dyno/jedis/JedisConnectionFactory.java | 5 + .../netflix/dyno/jedis/CompressionTest.java | 2 +- .../redisson/RedissonConnectionFactory.java | 4 + 16 files changed, 2393 insertions(+), 4673 deletions(-) diff --git a/dyno-core/src/main/java/com/netflix/dyno/connectionpool/CompressionOperation.java b/dyno-core/src/main/java/com/netflix/dyno/connectionpool/CompressionOperation.java index 901b5e92..886bd283 100644 --- a/dyno-core/src/main/java/com/netflix/dyno/connectionpool/CompressionOperation.java +++ b/dyno-core/src/main/java/com/netflix/dyno/connectionpool/CompressionOperation.java @@ -23,4 +23,9 @@ public interface CompressionOperation extends Operation { String compressValue(String value, ConnectionContext ctx); String decompressValue(String value, ConnectionContext ctx); + + byte[] compressValue(byte[] value, ConnectionContext ctx); + + byte[] decompressValue(byte[] value, ConnectionContext ctx); + } diff --git a/dyno-core/src/main/java/com/netflix/dyno/connectionpool/Connection.java b/dyno-core/src/main/java/com/netflix/dyno/connectionpool/Connection.java index 4389083d..ce6c9f2f 100644 --- a/dyno-core/src/main/java/com/netflix/dyno/connectionpool/Connection.java +++ b/dyno-core/src/main/java/com/netflix/dyno/connectionpool/Connection.java @@ -54,6 +54,11 @@ public interface Connection { */ public void open() throws DynoException; + /** + * Reset connection before adding back to pool. + */ + public void reset(); + /** * Can be used by clients to indicate connection exception. * This can be analyzed by connection pools later diff --git a/dyno-core/src/main/java/com/netflix/dyno/connectionpool/MultiKeyCompressionOperation.java b/dyno-core/src/main/java/com/netflix/dyno/connectionpool/MultiKeyCompressionOperation.java index d19973db..518e5f45 100644 --- a/dyno-core/src/main/java/com/netflix/dyno/connectionpool/MultiKeyCompressionOperation.java +++ b/dyno-core/src/main/java/com/netflix/dyno/connectionpool/MultiKeyCompressionOperation.java @@ -13,4 +13,9 @@ public interface MultiKeyCompressionOperation extends Operation { String[] compressMultiKeyValue(ConnectionContext ctx, String... value); String decompressValue(ConnectionContext ctx, String value); + + byte[][] compressMultiKeyValue(ConnectionContext ctx, byte[]... value); + + byte[] decompressValue(ConnectionContext ctx, byte[] value); + } \ No newline at end of file diff --git a/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/HostConnectionPoolImpl.java b/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/HostConnectionPoolImpl.java index 826833fe..3496b840 100644 --- a/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/HostConnectionPoolImpl.java +++ b/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/HostConnectionPoolImpl.java @@ -346,6 +346,7 @@ public boolean returnConnection(Connection connection) { return closeConnection(connection); } else { // Add the given connection back to the pool + connection.reset(); availableConnections.add(connection); return false; } diff --git a/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/lb/TokenAwareSelection.java b/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/lb/TokenAwareSelection.java index ae0a6857..c67037a6 100644 --- a/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/lb/TokenAwareSelection.java +++ b/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/lb/TokenAwareSelection.java @@ -15,6 +15,13 @@ ******************************************************************************/ package com.netflix.dyno.connectionpool.impl.lb; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + import com.netflix.dyno.connectionpool.BaseOperation; import com.netflix.dyno.connectionpool.HashPartitioner; import com.netflix.dyno.connectionpool.HostConnectionPool; @@ -25,13 +32,8 @@ import com.netflix.dyno.connectionpool.impl.hash.Murmur1HashPartitioner; import com.netflix.dyno.connectionpool.impl.utils.CollectionUtils; import com.netflix.dyno.connectionpool.impl.utils.CollectionUtils.Transform; -import org.apache.commons.lang3.StringUtils; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; +import org.apache.commons.lang3.StringUtils; /** * Concrete implementation of the {@link HostSelectionStrategy} interface using @@ -92,7 +94,7 @@ public HostConnectionPool getPoolForOperation(BaseOperation op, Strin if (hashtag == null || hashtag.isEmpty()) { hToken = this.getTokenForKey(key); } else { - String hashValue = StringUtils.substringBetween(key, Character.toString(hashtag.charAt(0)), Character.toString(hashtag.charAt(1))); + String hashValue = getHashValue(key, hashtag); hToken = this.getTokenForKey(hashValue); } @@ -108,9 +110,15 @@ public HostConnectionPool getPoolForOperation(BaseOperation op, Strin } else { // the key is binary byte[] binaryKey = op.getBinaryKey(); - hToken = this.getTokenForKey(binaryKey); + if (hashtag == null || hashtag.isEmpty()) { + hToken = this.getTokenForKey(binaryKey); + } else { + byte[] hashValue = getHashValue(binaryKey, hashtag); + hToken = this.getTokenForKey(hashValue); + } + if (hToken == null) { - throw new NoAvailableHostsException("Token not found for key " + binaryKey.toString()); + throw new NoAvailableHostsException("Token not found for key " + Arrays.toString(binaryKey)); } hostPool = tokenPools.get(hToken.getToken()); @@ -124,6 +132,44 @@ public HostConnectionPool getPoolForOperation(BaseOperation op, Strin } + public static String getHashValue(String key, String hashtag) { + if (key == null || hashtag == null || hashtag.length() < 2) { + throw new RuntimeException( + "Hash value calculation not possible for key: " + key + ", hashtag: " + hashtag); + } + return StringUtils.substringBetween( + key, Character.toString(hashtag.charAt(0)), Character.toString(hashtag.charAt(1)) + ); + } + + public static byte[] getHashValue(byte[] key, String hashtag) { + if (key == null || hashtag == null || hashtag.length() < 2) { + throw new RuntimeException( + "Hash value calculation not possible for key: " + Arrays.toString(key) + ", hashtag: " + hashtag); + } + + char startChar = hashtag.charAt(0); + char endChar = hashtag.charAt(1); + + int s = -1; + int e = -1; + boolean sFound = false; + for (int i = 0; i < key.length; i++) { + if (key[i] == startChar && !sFound) { + s = i; + sFound = true; + } + if (key[i] == endChar && sFound) { + e = i; + break; + } + } + if (s > -1 && e > -1 && e != s + 1) { + return Arrays.copyOfRange(key, s + 1, e); + } + return key; + } + @Override public Map, BaseOperation> getPoolsForOperationBatch( Collection> ops) throws NoAvailableHostsException { diff --git a/dyno-core/src/test/java/com/netflix/dyno/connectionpool/impl/ConnectionPoolImplTest.java b/dyno-core/src/test/java/com/netflix/dyno/connectionpool/impl/ConnectionPoolImplTest.java index d629008d..fc9b5c59 100644 --- a/dyno-core/src/test/java/com/netflix/dyno/connectionpool/impl/ConnectionPoolImplTest.java +++ b/dyno-core/src/test/java/com/netflix/dyno/connectionpool/impl/ConnectionPoolImplTest.java @@ -113,6 +113,10 @@ public Host getHost() { public void open() throws DynoException { } + @Override + public void reset() { + } + @Override public DynoConnectException getLastException() { return ex; diff --git a/dyno-core/src/test/java/com/netflix/dyno/connectionpool/impl/HostConnectionPoolImplTest.java b/dyno-core/src/test/java/com/netflix/dyno/connectionpool/impl/HostConnectionPoolImplTest.java index 52e8d927..b9fac4e6 100644 --- a/dyno-core/src/test/java/com/netflix/dyno/connectionpool/impl/HostConnectionPoolImplTest.java +++ b/dyno-core/src/test/java/com/netflix/dyno/connectionpool/impl/HostConnectionPoolImplTest.java @@ -84,6 +84,10 @@ public Host getHost() { public void open() throws DynoException { } + @Override + public void reset() { + } + @Override public DynoConnectException getLastException() { return ex; diff --git a/dyno-demo/src/main/java/com/netflix/dyno/demo/redis/CustomTokenSupplierExample.java b/dyno-demo/src/main/java/com/netflix/dyno/demo/redis/CustomTokenSupplierExample.java index 10e8917b..42f6f0ad 100644 --- a/dyno-demo/src/main/java/com/netflix/dyno/demo/redis/CustomTokenSupplierExample.java +++ b/dyno-demo/src/main/java/com/netflix/dyno/demo/redis/CustomTokenSupplierExample.java @@ -93,8 +93,8 @@ public void runSimpleTest() throws Exception { } // read for (int i = 0; i < 10; i++) { - OperationResult result = client.d_get("" + i); - System.out.println("Key: " + i + ", Value: " + result.getResult() + " " + result.getNode()); + String result = client.get("" + i); + System.out.println("Key: " + i + ", Value: " + result); } } diff --git a/dyno-demo/src/main/java/com/netflix/dyno/demo/redis/DynoJedisDemo.java b/dyno-demo/src/main/java/com/netflix/dyno/demo/redis/DynoJedisDemo.java index 68e56500..f40dbef8 100644 --- a/dyno-demo/src/main/java/com/netflix/dyno/demo/redis/DynoJedisDemo.java +++ b/dyno-demo/src/main/java/com/netflix/dyno/demo/redis/DynoJedisDemo.java @@ -248,16 +248,16 @@ public void runSimpleTest() throws Exception { } // read for (int i = 0; i < numKeys; i++) { - OperationResult result = client.d_get("DynoClientTest-" + i); - System.out.println("Reading Key: " + i + ", Value: " + result.getResult() + " " + result.getNode()); + String result = client.get("DynoClientTest-" + i); + System.out.println("Reading Key: " + i + ", Value: " + result); } // read from shadow cluster if (shadowClusterClient != null) { // read for (int i = 0; i < numKeys; i++) { - OperationResult result = shadowClusterClient.d_get("DynoClientTest-" + i); - System.out.println("Reading Key: " + i + ", Value: " + result.getResult() + " " + result.getNode()); + String result = shadowClusterClient.get("DynoClientTest-" + i); + System.out.println("Reading Key: " + i + ", Value: " + result); } } } @@ -285,10 +285,10 @@ public void runSimpleDualWriterPipelineTest() { // read System.out.println("Reading keys from dual writer pipeline client"); for (int i = 0; i < numKeys; i++) { - OperationResult result = client.d_hget("DynoClientTest", "DynoClientTest-" + i); - System.out.println("Reading Key: DynoClientTest/" + i + ", Value: " + result.getResult() + " " + result.getNode()); - result = client.d_hget("DynoClientTest-1", "DynoClientTest-" + i); - System.out.println("Reading Key: DynoClientTest-1/" + i + ", Value: " + result.getResult() + " " + result.getNode()); + String result = client.hget("DynoClientTest", "DynoClientTest-" + i); + System.out.println("Reading Key: DynoClientTest/" + i + ", Value: " + result); + result = client.hget("DynoClientTest-1", "DynoClientTest-" + i); + System.out.println("Reading Key: DynoClientTest-1/" + i + ", Value: " + result); } // read from shadow cluster @@ -296,10 +296,10 @@ public void runSimpleDualWriterPipelineTest() { if (shadowClusterClient != null) { // read for (int i = 0; i < numKeys; i++) { - OperationResult result = shadowClusterClient.d_hget("DynoClientTest", "DynoClientTest-" + i); - System.out.println("Reading Key: DynoClientTest/" + i + ", Value: " + result.getResult() + " " + result.getNode()); - result = shadowClusterClient.d_hget("DynoClientTest-1", "DynoClientTest-" + i); - System.out.println("Reading Key: DynoClientTest-1/" + i + ", Value: " + result.getResult() + " " + result.getNode()); + String result = shadowClusterClient.hget("DynoClientTest", "DynoClientTest-" + i); + System.out.println("Reading Key: DynoClientTest/" + i + ", Value: " + result); + result = shadowClusterClient.hget("DynoClientTest-1", "DynoClientTest-" + i); + System.out.println("Reading Key: DynoClientTest-1/" + i + ", Value: " + result); } } @@ -337,8 +337,8 @@ public void runBinaryKeyTest() throws Exception { System.out.println("Writing Key: " + new String(overallKey, Charset.forName("UTF-8"))); // read - OperationResult result = client.d_get(newKey); - System.out.println("Reading Key: " + new String(newKey, Charset.forName("UTF-8")) + ", Value: " + result.getResult().toString() + " " + result.getNode()); + byte[] result = client.get(newKey); + System.out.println("Reading Key: " + new String(newKey, Charset.forName("UTF-8")) + ", Value: " + Arrays.toString(result)); } @@ -361,9 +361,9 @@ public void runSimpleTestWithHashtag() throws Exception { } // read for (int i = 0; i < numKeys; i++) { - OperationResult result = client.d_get(i + "-{bar}"); + String result = client.get(i + "-{bar}"); System.out.println( - "Reading Key: " + i + "-{bar}" + " , Value: " + result.getResult() + " " + result.getNode()); + "Reading Key: " + i + "-{bar}" + " , Value: " + result); } } diff --git a/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoDualWriterClient.java b/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoDualWriterClient.java index d6aa1726..17877bfd 100644 --- a/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoDualWriterClient.java +++ b/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoDualWriterClient.java @@ -15,17 +15,25 @@ */ package com.netflix.dyno.jedis; +import com.netflix.dyno.connectionpool.CompressionOperation; +import com.netflix.dyno.connectionpool.ConnectionContext; import com.netflix.dyno.connectionpool.ConnectionPool; import com.netflix.dyno.connectionpool.ConnectionPoolMonitor; +import com.netflix.dyno.connectionpool.MultiKeyCompressionOperation; import com.netflix.dyno.connectionpool.OperationResult; +import com.netflix.dyno.connectionpool.exception.DynoException; import com.netflix.dyno.connectionpool.impl.ConnectionPoolImpl; import com.netflix.dyno.contrib.DynoOPMonitor; +import com.netflix.dyno.jedis.operation.BaseKeyOperation; +import com.netflix.dyno.jedis.operation.MultiKeyOperation; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import redis.clients.jedis.Jedis; import redis.clients.jedis.ScanParams; import redis.clients.jedis.ScanResult; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Set; @@ -35,6 +43,7 @@ import java.util.concurrent.Future; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; /** * Client that provides 'dual-write' functionality. This is useful when clients wish to move from one dynomite @@ -44,6 +53,10 @@ */ public class DynoDualWriterClient extends DynoJedisClient { + + // FIXME: not all write commands are shadowed + + private static final Logger logger = LoggerFactory.getLogger(DynoDualWriterClient.class); private static ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); @@ -106,7 +119,7 @@ public DynoDualWriterPipeline pipelined() { shadowClient.getConnPool(), dial); } - private Future> writeAsync(final String key, Callable> func) { + private Future writeAsync(final String key, Callable func) { if (sendShadowRequest(key)) { try { return executor.submit(func); @@ -124,7 +137,7 @@ private Future> writeAsync(final String key, Callable Future> writeAsync(final byte[] key, Callable> func) { + private Future writeAsync(final byte[] key, Callable func) { if (sendShadowRequest(key)) { try { return executor.submit(func); @@ -139,7 +152,6 @@ private Future> writeAsync(final byte[] key, CallableIs NOT idle @@ -205,611 +217,641 @@ public void setRange(int range) { //----------------------------- JEDIS COMMANDS -------------------------------------- - @Override - public Long append(final String key, final String value) { - return this.d_append(key, value).getResult(); - } @Override - public OperationResult d_append(final String key, final String value) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_append(key, value); - } - }); - - return DynoDualWriterClient.super.d_append(key, value); + public Long append(final String key, final String value) { + writeAsync(key, () -> shadowClient.append(key, value)); + return DynoDualWriterClient.super.append(key, value); } @Override - public OperationResult d_hmset(final String key, final Map hash) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_hmset(key, hash); - } - }); + public String hmset(final String key, final Map hash) { + writeAsync(key, () -> shadowClient.hmset(key, hash)); - return DynoDualWriterClient.super.d_hmset(key, hash); + return DynoDualWriterClient.super.hmset(key, hash); } @Override public Long sadd(final String key, final String... members) { - return this.d_sadd(key, members).getResult(); - } + writeAsync(key, () -> shadowClient.sadd(key, members)); - @Override - public OperationResult d_sadd(final String key, final String... members) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_sadd(key, members); - } - }); - - return DynoDualWriterClient.super.d_sadd(key, members); + return DynoDualWriterClient.super.sadd(key, members); } @Override public Long hset(final String key, final String field, final String value) { - return this.d_hset(key, field, value).getResult(); - } - - @Override - public OperationResult d_hset(final String key, final String field, final String value) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_hset(key, field, value); - } - }); + writeAsync(key, () -> shadowClient.hset(key, field, value)); - return DynoDualWriterClient.super.d_hset(key, field, value); + return DynoDualWriterClient.super.hset(key, field, value); } @Override public String set(final String key, final String value) { - return this.d_set(key, value).getResult(); - } + writeAsync(key, () -> shadowClient.set(key, value)); - @Override - public OperationResult d_set(final String key, final String value) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_set(key, value); - } - }); - - return DynoDualWriterClient.super.d_set(key, value); + return DynoDualWriterClient.super.set(key, value); } @Override public String setex(final String key, int seconds, String value) { - return this.d_setex(key, seconds, value).getResult(); - } - - @Override - public OperationResult d_setex(final String key, final Integer seconds, final String value) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_setex(key, seconds, value); - } - }); - - return DynoDualWriterClient.super.d_setex(key, seconds, value); + writeAsync(key, () -> shadowClient.setex(key, seconds, value)); + return DynoDualWriterClient.super.setex(key, seconds, value); } @Override public Long del(final String key) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_del(key); - } - }); + writeAsync(key, () -> shadowClient.del(key)); return DynoDualWriterClient.super.del(key); } @Override public Long expire(final String key, final int seconds) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_expire(key, seconds); - } - }); + writeAsync(key, () -> shadowClient.expire(key, seconds)); return DynoDualWriterClient.super.expire(key, seconds); } @Override public Long expireAt(final String key, final long unixTime) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_expireAt(key, unixTime); - } - }); + writeAsync(key, () -> shadowClient.expireAt(key, unixTime)); return DynoDualWriterClient.super.expireAt(key, unixTime); } @Override public String getSet(final String key, final String value) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_getSet(key, value); - } - }); + writeAsync(key, () -> shadowClient.getSet(key, value)); return DynoDualWriterClient.super.getSet(key, value); } @Override public Long hdel(final String key, final String... fields) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_hdel(key, fields); - } - }); + writeAsync(key, () -> shadowClient.hdel(key, fields)); return DynoDualWriterClient.super.hdel(key); } @Override public Long hincrBy(final String key, final String field, final long value) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_hincrBy(key, field, value); - } - }); + writeAsync(key, () -> shadowClient.hincrBy(key, field, value)); return DynoDualWriterClient.super.hincrBy(key, field, value); } @Override public Double hincrByFloat(final String key, final String field, final double value) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_hincrByFloat(key, field, value); - } - }); + writeAsync(key, () -> shadowClient.hincrByFloat(key, field, value)); return DynoDualWriterClient.super.hincrByFloat(key, field, value); } @Override public Long hsetnx(final String key, final String field, final String value) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_hsetnx(key, field, value); - } - }); + writeAsync(key, () -> shadowClient.hsetnx(key, field, value)); return DynoDualWriterClient.super.hsetnx(key, field, value); } @Override public Long incr(final String key) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_incr(key); - } - }); + writeAsync(key, () -> shadowClient.incr(key)); return DynoDualWriterClient.super.incr(key); } @Override public Long incrBy(final String key, final long delta) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_incrBy(key, delta); - } - }); + writeAsync(key, () -> shadowClient.incrBy(key, delta)); return DynoDualWriterClient.super.incrBy(key, delta); } @Override public Double incrByFloat(final String key, final double increment) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_incrByFloat(key, increment); - } - }); + writeAsync(key, () -> shadowClient.incrByFloat(key, increment)); return DynoDualWriterClient.super.incrByFloat(key, increment); } @Override public String lpop(final String key) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_lpop(key); - } - }); + writeAsync(key, () -> shadowClient.lpop(key)); return DynoDualWriterClient.super.lpop(key); } @Override public Long lpush(final String key, final String... values) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_lpush(key, values); - } - }); + writeAsync(key, () -> shadowClient.lpush(key, values)); return DynoDualWriterClient.super.lpush(key, values); } @Override public Long lrem(final String key, final long count, final String value) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_lrem(key, count, value); - } - }); + writeAsync(key, () -> shadowClient.lrem(key, count, value)); return DynoDualWriterClient.super.lrem(key, count, value); } @Override public String lset(final String key, final long count, final String value) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_lset(key, count, value); - } - }); + writeAsync(key, () -> shadowClient.lset(key, count, value)); return DynoDualWriterClient.super.lset(key, count, value); } @Override public String ltrim(final String key, final long start, final long end) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_ltrim(key, start, end); - } - }); + writeAsync(key, () -> shadowClient.ltrim(key, start, end)); return DynoDualWriterClient.super.ltrim(key, start, end); } @Override public Long persist(final String key) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_persist(key); - } - }); + writeAsync(key, () -> shadowClient.persist(key)); return DynoDualWriterClient.super.persist(key); } @Override public Long pexpireAt(final String key, final long millisecondsTimestamp) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_pexpireAt(key, millisecondsTimestamp); - } - }); + writeAsync(key, () -> shadowClient.pexpireAt(key, millisecondsTimestamp)); return DynoDualWriterClient.super.pexpireAt(key, millisecondsTimestamp); } @Override public Long pttl(final String key) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_pttl(key); - } - }); + writeAsync(key, () -> shadowClient.pttl(key)); return DynoDualWriterClient.super.pttl(key); } @Override public String rename(final String oldkey, final String newkey) { - writeAsync(oldkey, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_rename(oldkey, oldkey); - } - }); + writeAsync(oldkey, () -> shadowClient.rename(oldkey, oldkey)); return DynoDualWriterClient.super.rename(oldkey, oldkey); } @Override public String rpop(final String key) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_rpop(key); - } - }); + writeAsync(key, () -> shadowClient.rpop(key)); return DynoDualWriterClient.super.rpop(key); } @Override public Long scard(final String key) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_scard(key); - } - }); + writeAsync(key, () -> shadowClient.scard(key)); return DynoDualWriterClient.super.scard(key); } @Override public Boolean setbit(final String key, final long offset, final boolean value) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_setbit(key, offset, value); - } - }); + writeAsync(key, () -> shadowClient.setbit(key, offset, value)); return DynoDualWriterClient.super.setbit(key, offset, value); } @Override public Boolean setbit(final String key, final long offset, final String value) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_setbit(key, offset, value); - } - }); + writeAsync(key, () -> shadowClient.setbit(key, offset, value)); return DynoDualWriterClient.super.setbit(key, offset, value); } @Override public Long setnx(final String key, final String value) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_setnx(key, value); - } - }); + writeAsync(key, () -> shadowClient.setnx(key, value)); return DynoDualWriterClient.super.setnx(key, value); } @Override public Long setrange(final String key, final long offset, final String value) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_setrange(key, offset, value); - } - }); + writeAsync(key, () -> shadowClient.setrange(key, offset, value)); return DynoDualWriterClient.super.setrange(key, offset, value); } @Override public Set smembers(final String key) { - writeAsync(key, new Callable>>() { - @Override - public OperationResult> call() throws Exception { - return shadowClient.d_smembers(key); - } - }); + writeAsync(key, () -> shadowClient.smembers(key)); return DynoDualWriterClient.super.smembers(key); } @Override public Long smove(final String srckey, final String dstkey, final String member) { - writeAsync(srckey, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_smove(srckey, dstkey, member); - } - }); + writeAsync(srckey, () -> shadowClient.smove(srckey, dstkey, member)); return DynoDualWriterClient.super.smove(srckey, dstkey, member); } @Override public List sort(final String key) { - writeAsync(key, new Callable>>() { - @Override - public OperationResult> call() throws Exception { - return shadowClient.d_sort(key); - } - }); + writeAsync(key, () -> shadowClient.sort(key)); return DynoDualWriterClient.super.sort(key); } @Override public String spop(final String key) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_spop(key); - } - }); + writeAsync(key, () -> shadowClient.spop(key)); return DynoDualWriterClient.super.spop(key); } @Override public Long srem(final String key, final String... members) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_srem(key, members); - } - }); + writeAsync(key, () -> shadowClient.srem(key, members)); return DynoDualWriterClient.super.srem(key, members); } @Override public ScanResult sscan(final String key, final String cursor) { - writeAsync(key, new Callable>>() { - @Override - public OperationResult> call() throws Exception { - return shadowClient.d_sscan(key, cursor); - } - }); + writeAsync(key, () -> shadowClient.sscan(key, cursor)); return DynoDualWriterClient.super.sscan(key, cursor); } @Override public ScanResult sscan(final String key, final String cursor, final ScanParams params) { - writeAsync(key, new Callable>>() { - @Override - public OperationResult> call() throws Exception { - return shadowClient.d_sscan(key, cursor, params); - } - }); + writeAsync(key, () -> shadowClient.sscan(key, cursor, params)); return DynoDualWriterClient.super.sscan(key, cursor, params); } @Override public Long ttl(final String key) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_ttl(key); - } - }); + writeAsync(key, () -> shadowClient.ttl(key)); return DynoDualWriterClient.super.ttl(key); } @Override public Long zadd(final String key, final double score, final String member) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_zadd(key, score, member); - } - }); + writeAsync(key, () -> shadowClient.zadd(key, score, member)); return DynoDualWriterClient.super.zadd(key, score, member); } @Override public Long zadd(final String key, final Map scoreMembers) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_zadd(key, scoreMembers); - } - }); + writeAsync(key, () -> shadowClient.zadd(key, scoreMembers)); return DynoDualWriterClient.super.zadd(key, scoreMembers); } @Override public Double zincrby(final String key, final double score, final String member) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_zincrby(key, score, member); - } - }); + writeAsync(key, () -> shadowClient.zincrby(key, score, member)); return DynoDualWriterClient.super.zincrby(key, score, member); } @Override public Long zrem(final String key, final String... member) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_zrem(key, member); - } - }); + writeAsync(key, () -> shadowClient.zrem(key, member)); return DynoDualWriterClient.super.zrem(key, member); } @Override public List blpop(final int timeout, final String key) { - writeAsync(key, new Callable>>() { - @Override - public OperationResult> call() throws Exception { - return shadowClient.d_blpop(timeout, key); - } - }); + writeAsync(key, () -> shadowClient.blpop(timeout, key)); return DynoDualWriterClient.super.blpop(timeout, key); } @Override public List brpop(final int timeout, final String key) { - writeAsync(key, new Callable>>() { - @Override - public OperationResult> call() throws Exception { - return shadowClient.d_brpop(timeout, key); - } - }); + writeAsync(key, () -> shadowClient.brpop(timeout, key)); return DynoDualWriterClient.super.brpop(timeout, key); } + /******************* Jedis Dual write for binary commands **************/ + @Override + public Long append(final byte[] key, final byte[] value) { + writeAsync(key, () -> shadowClient.append(key, value)); + + return DynoDualWriterClient.super.append(key, value); + } + + @Override + public String hmset(final byte[] key, final Map hash) { + writeAsync(key, () -> shadowClient.hmset(key, hash)); + + return DynoDualWriterClient.super.hmset(key, hash); + } + + @Override + public Long sadd(final byte[] key, final byte[]... members) { + writeAsync(key, () -> shadowClient.sadd(key, members)); + + return DynoDualWriterClient.super.sadd(key, members); + + } + + @Override + public Long hset(final byte[] key, final byte[] field, final byte[] value) { + writeAsync(key, () -> shadowClient.hset(key, field, value)); + + return DynoDualWriterClient.super.hset(key, field, value); + } + @Override public String set(final byte[] key, final byte[] value) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_set(key, value); - } - }); + writeAsync(key, () -> shadowClient.set(key, value)); return DynoDualWriterClient.super.set(key, value); } @Override - public String setex(final byte[] key, final int seconds, final byte[] value) { - writeAsync(key, new Callable>() { - @Override - public OperationResult call() throws Exception { - return shadowClient.d_setex(key, seconds, value); - } - }); + public String setex(final byte[] key, int seconds, byte[] value) { + writeAsync(key, () -> shadowClient.setex(key, seconds, value)); return DynoDualWriterClient.super.setex(key, seconds, value); } + @Override + public Long del(final byte[] key) { + writeAsync(key, () -> shadowClient.del(key)); + + return DynoDualWriterClient.super.del(key); + } + + @Override + public Long expire(final byte[] key, final int seconds) { + writeAsync(key, () -> shadowClient.expire(key, seconds)); + + return DynoDualWriterClient.super.expire(key, seconds); + } + + @Override + public Long expireAt(final byte[] key, final long unixTime) { + writeAsync(key, () -> shadowClient.expireAt(key, unixTime)); + + return DynoDualWriterClient.super.expireAt(key, unixTime); + } + + @Override + public byte[] getSet(final byte[] key, final byte[] value) { + writeAsync(key, () -> shadowClient.getSet(key, value)); + + return DynoDualWriterClient.super.getSet(key, value); + } + + @Override + public Long hdel(final byte[] key, final byte[]... fields) { + writeAsync(key, () -> shadowClient.hdel(key, fields)); + + return DynoDualWriterClient.super.hdel(key); + } + + @Override + public Long hincrBy(final byte[] key, final byte[] field, final long value) { + writeAsync(key, () -> shadowClient.hincrBy(key, field, value)); + + return DynoDualWriterClient.super.hincrBy(key, field, value); + } + + @Override + public Double hincrByFloat(final byte[] key, final byte[] field, final double value) { + writeAsync(key, () -> shadowClient.hincrByFloat(key, field, value)); + + return DynoDualWriterClient.super.hincrByFloat(key, field, value); + } + + @Override + public Long hsetnx(final byte[] key, final byte[] field, final byte[] value) { + writeAsync(key, () -> shadowClient.hsetnx(key, field, value)); + + return DynoDualWriterClient.super.hsetnx(key, field, value); + } + + @Override + public Long incr(final byte[] key) { + writeAsync(key, () -> shadowClient.incr(key)); + + return DynoDualWriterClient.super.incr(key); + } + + @Override + public Long incrBy(final byte[] key, final long delta) { + writeAsync(key, () -> shadowClient.incrBy(key, delta)); + + return DynoDualWriterClient.super.incrBy(key, delta); + } + + @Override + public Double incrByFloat(final byte[] key, final double increment) { + writeAsync(key, () -> shadowClient.incrByFloat(key, increment)); + + return DynoDualWriterClient.super.incrByFloat(key, increment); + } + + @Override + public byte[] lpop(final byte[] key) { + writeAsync(key, () -> shadowClient.lpop(key)); + + return DynoDualWriterClient.super.lpop(key); + } + + @Override + public Long lpush(final byte[] key, final byte[]... values) { + writeAsync(key, () -> shadowClient.lpush(key, values)); + + return DynoDualWriterClient.super.lpush(key, values); + } + + @Override + public Long lrem(final byte[] key, final long count, final byte[] value) { + writeAsync(key, () -> shadowClient.lrem(key, count, value)); + + return DynoDualWriterClient.super.lrem(key, count, value); + } + + @Override + public String lset(final byte[] key, final long count, final byte[] value) { + writeAsync(key, () -> shadowClient.lset(key, count, value)); + + return DynoDualWriterClient.super.lset(key, count, value); + } + + @Override + public String ltrim(final byte[] key, final long start, final long end) { + writeAsync(key, () -> shadowClient.ltrim(key, start, end)); + + return DynoDualWriterClient.super.ltrim(key, start, end); + } + + @Override + public Long persist(final byte[] key) { + writeAsync(key, () -> shadowClient.persist(key)); + + return DynoDualWriterClient.super.persist(key); + } + + @Override + public Long pexpireAt(final byte[] key, final long millisecondsTimestamp) { + writeAsync(key, () -> shadowClient.pexpireAt(key, millisecondsTimestamp)); + + return DynoDualWriterClient.super.pexpireAt(key, millisecondsTimestamp); + } + + @Override + public Long pttl(final byte[] key) { + writeAsync(key, () -> shadowClient.pttl(key)); + + return DynoDualWriterClient.super.pttl(key); + } + + @Override + public String rename(final byte[] oldkey, final byte[] newkey) { + writeAsync(oldkey, () -> shadowClient.rename(oldkey, oldkey)); + + return DynoDualWriterClient.super.rename(oldkey, oldkey); + } + + @Override + public byte[] rpop(final byte[] key) { + writeAsync(key, () -> shadowClient.rpop(key)); + + return DynoDualWriterClient.super.rpop(key); + } + + @Override + public Long scard(final byte[] key) { + writeAsync(key, () -> shadowClient.scard(key)); + + return DynoDualWriterClient.super.scard(key); + } + + @Override + public Boolean setbit(final byte[] key, final long offset, final boolean value) { + writeAsync(key, () -> shadowClient.setbit(key, offset, value)); + + return DynoDualWriterClient.super.setbit(key, offset, value); + } + + @Override + public Boolean setbit(final byte[] key, final long offset, final byte[] value) { + writeAsync(key, () -> shadowClient.setbit(key, offset, value)); + + return DynoDualWriterClient.super.setbit(key, offset, value); + } + + @Override + public Long setnx(final byte[] key, final byte[] value) { + writeAsync(key, () -> shadowClient.setnx(key, value)); + + return DynoDualWriterClient.super.setnx(key, value); + } + + @Override + public Long setrange(final byte[] key, final long offset, final byte[] value) { + writeAsync(key, () -> shadowClient.setrange(key, offset, value)); + + return DynoDualWriterClient.super.setrange(key, offset, value); + } + + @Override + public Set smembers(final byte[] key) { + writeAsync(key, () -> shadowClient.smembers(key)); + + return DynoDualWriterClient.super.smembers(key); + } + + @Override + public Long smove(final byte[] srckey, final byte[] dstkey, final byte[] member) { + writeAsync(srckey, () -> shadowClient.smove(srckey, dstkey, member)); + + return DynoDualWriterClient.super.smove(srckey, dstkey, member); + } + + @Override + public List sort(final byte[] key) { + writeAsync(key, () -> shadowClient.sort(key)); + + return DynoDualWriterClient.super.sort(key); + } + + @Override + public byte[] spop(final byte[] key) { + writeAsync(key, () -> shadowClient.spop(key)); + + return DynoDualWriterClient.super.spop(key); + } + + @Override + public Long srem(final byte[] key, final byte[]... members) { + writeAsync(key, () -> shadowClient.srem(key, members)); + + return DynoDualWriterClient.super.srem(key, members); + } + + @Override + public ScanResult sscan(final byte[] key, final byte[] cursor) { + writeAsync(key, () -> shadowClient.sscan(key, cursor)); + + return DynoDualWriterClient.super.sscan(key, cursor); + } + + @Override + public ScanResult sscan(final byte[] key, final byte[] cursor, final ScanParams params) { + writeAsync(key, () -> shadowClient.sscan(key, cursor, params)); + + return DynoDualWriterClient.super.sscan(key, cursor, params); + } + + @Override + public Long ttl(final byte[] key) { + writeAsync(key, () -> shadowClient.ttl(key)); + + return DynoDualWriterClient.super.ttl(key); + } + + @Override + public Long zadd(final byte[] key, final double score, final byte[] member) { + writeAsync(key, () -> shadowClient.zadd(key, score, member)); + + return DynoDualWriterClient.super.zadd(key, score, member); + } + + @Override + public Long zadd(final byte[] key, final Map scoreMembers) { + writeAsync(key, () -> shadowClient.zadd(key, scoreMembers)); + + return DynoDualWriterClient.super.zadd(key, scoreMembers); + } + + @Override + public Double zincrby(final byte[] key, final double score, final byte[] member) { + writeAsync(key, () -> shadowClient.zincrby(key, score, member)); + + return DynoDualWriterClient.super.zincrby(key, score, member); + } + + @Override + public Long zrem(final byte[] key, final byte[]... member) { + writeAsync(key, () -> shadowClient.zrem(key, member)); + + return DynoDualWriterClient.super.zrem(key, member); + } + } diff --git a/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoDualWriterPipeline.java b/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoDualWriterPipeline.java index f5ab8162..819ce99f 100644 --- a/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoDualWriterPipeline.java +++ b/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoDualWriterPipeline.java @@ -38,6 +38,11 @@ * dynomite clusters. */ public class DynoDualWriterPipeline extends DynoJedisPipeline { + + + // FIXME: not all write commands are shadowed + + private static final org.slf4j.Logger logger = LoggerFactory.getLogger(DynoDualWriterPipeline.class); private static ExecutorService executor = Executors.newSingleThreadExecutor(); private final ConnectionPoolImpl connPool; diff --git a/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoJedisClient.java b/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoJedisClient.java index 7813a53d..bdebc66e 100644 --- a/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoJedisClient.java +++ b/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoJedisClient.java @@ -17,6 +17,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Strings; + import com.netflix.discovery.DiscoveryClient; import com.netflix.discovery.EurekaClient; import com.netflix.dyno.connectionpool.CompressionOperation; @@ -72,6 +73,7 @@ import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; import static com.netflix.dyno.connectionpool.ConnectionPoolConfiguration.CompressionStrategy; @@ -149,6 +151,10 @@ private CompressionValueOperation(String k, OpName o) { super(k, o); } + private CompressionValueOperation(byte[] k, OpName o) { + super(k, o); + } + /** * Compresses the value based on the threshold defined by * {@link ConnectionPoolConfiguration#getValueCompressionThreshold()} @@ -177,6 +183,26 @@ public String compressValue(String value, ConnectionContext ctx) { return result; } + @Override + public byte[] compressValue(byte[] value, ConnectionContext ctx) { + byte[] result = value; + int thresholdBytes = connPool.getConfiguration().getValueCompressionThreshold(); + + try { + // prefer speed over accuracy here so rather than using + // getBytes() to get the actual size + // just estimate using 2 bytes per character + if ((2 * value.length) > thresholdBytes) { + result = ZipUtils.compressBytesNonBase64(value); + ctx.setMetadata("compression", true); + } + } catch (IOException e) { + Logger.warn( + "UNABLE to compress [" + value + "] for key [" + getStringKey() + "]; sending value uncompressed"); + } + + return result; + } @Override public String decompressValue(String value, ConnectionContext ctx) { try { @@ -191,6 +217,20 @@ public String decompressValue(String value, ConnectionContext ctx) { return value; } + @Override + public byte[] decompressValue(byte[] value, ConnectionContext ctx) { + try { + if (ZipUtils.isCompressed(value)) { + ctx.setMetadata("decompression", true); + return ZipUtils.decompressBytesNonBase64(value); + } + } catch (IOException e) { + Logger.warn("Unable to decompress value [" + Arrays.toString(value) + "]"); + } + + return value; + } + } /** @@ -250,6 +290,38 @@ public String[] compressMultiKeyValue(ConnectionContext ctx, String... keyValues return (String[]) newItems.toArray(); } + @Override + public byte[][] compressMultiKeyValue(ConnectionContext ctx, byte[]... keyValues) { + List items = Arrays.asList(keyValues); + List newItems = new ArrayList<>(); + + for (int i = 0; i < items.size(); i++) { + /* + * byte[]... keyValues is a List of keys and values. + * The value always comes second and this is the one + * we want to compress. + */ + if (i % 2 == 0) { + byte[] value = items.get(i); + + try { + if ((2 * value.length) > connPool.getConfiguration().getValueCompressionThreshold()) { + newItems.add(i, ZipUtils.compressBytesNonBase64(value)); + ctx.setMetadata("compression", true); + } + + } catch (IOException e) { + Logger.warn( + "UNABLE to compress [" + Arrays.toString(value) + "] for key [" + + Arrays.toString(getBinaryKey()) + "]; sending value uncompressed"); + } + } else { + newItems.add(items.get(i)); + } + } + return (byte[][]) newItems.toArray(); + } + @Override public String decompressValue(ConnectionContext ctx, String value) { try { @@ -264,6 +336,20 @@ public String decompressValue(ConnectionContext ctx, String value) { return value; } + @Override + public byte[] decompressValue(ConnectionContext ctx, byte[] value) { + try { + if (ZipUtils.isCompressed(value)) { + ctx.setMetadata("decompression", true); + return ZipUtils.decompressBytesNonBase64(value); + } + } catch (IOException e) { + Logger.warn("Unable to decompress value [" + value + "]"); + } + + return value; + } + } public TopologyView getTopologyView() { @@ -274,93 +360,127 @@ public OperationResult moduleCommand(JedisGenericOperation handler) { return connPool.executeWithFailover(handler); } - @Override - public Long append(final String key, final String value) { - return d_append(key, value).getResult(); + protected T execOp(String key, OpName opName, Function fn) { + return connPool.executeWithFailover(new BaseKeyOperation(key, opName) { + @Override + public T execute(Jedis client, ConnectionContext state) throws DynoException { + return fn.apply(client); + } + }).getResult(); } - public OperationResult d_append(final String key, final String value) { - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.APPEND) { + protected T execOp(byte[] key, OpName opName, Function fn) { + return connPool.executeWithFailover(new BaseKeyOperation(key, opName) { @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.append(key, value); + public T execute(Jedis client, ConnectionContext state) throws DynoException { + return fn.apply(client); } - }); + }).getResult(); } - @Override - public Long decr(final String key) { - return d_decr(key).getResult(); + protected T execMultiOp(String[] keys, OpName opName, Function fn) { + return connPool.executeWithFailover(new MultiKeyOperation(Arrays.asList(keys), opName) { + @Override + public T execute(Jedis client, ConnectionContext state) throws DynoException { + return fn.apply(client); + } + }).getResult(); } - public OperationResult d_decr(final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.DECR) { - + protected T execMultiOp(byte[][] keys, OpName opName, Function fn) { + return connPool.executeWithFailover(new MultiKeyOperation(Arrays.asList(keys), opName) { @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.decr(key); + public T execute(Jedis client, ConnectionContext state) throws DynoException { + return fn.apply(client); } - - }); + }).getResult(); } - @Override - public Long decrBy(final String key, final long delta) { - return d_decrBy(key, delta).getResult(); + @FunctionalInterface + interface CompressionFunction { + T apply(Jedis jedis, ConnectionContext state, CompressionOperation op); } - public OperationResult d_decrBy(final String key, final Long delta) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.DECRBY) { - + protected T execCompressOp(String key, OpName opName, + CompressionFunction fn) { + return connPool.executeWithFailover(new CompressionValueOperation(key, opName) { @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.decrBy(key, delta); + public T execute(final Jedis client, final ConnectionContext state) throws DynoException { + return fn.apply(client, state, this); } + }).getResult(); + } - }); + protected T execCompressOp(byte[] key, OpName opName, + CompressionFunction fn) { + return connPool.executeWithFailover(new CompressionValueOperation(key, opName) { + @Override + public T execute(final Jedis client, final ConnectionContext state) throws DynoException { + return fn.apply(client, state, this); + } + }).getResult(); } - @Override - public Long del(final String key) { - return d_del(key).getResult(); + @FunctionalInterface + interface MultiKeyCompressionFunction { + T apply(Jedis jedis, ConnectionContext state, MultiKeyCompressionOperation op); } - @Override - public Long unlink(String key) { - return d_unlink(key).getResult(); + protected T execCompressMultiOp(String[] keys, OpName opName, + MultiKeyCompressionFunction fn) { + return connPool.executeWithFailover(new CompressionValueMultiKeyOperation(Arrays.asList(keys), opName) { + @Override + public T execute(final Jedis client, final ConnectionContext state) throws DynoException { + return fn.apply(client, state, this); + } + }).getResult(); } - public OperationResult d_unlink(String key) { - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.UNLINK) { + protected T execCompressMultiOp(byte[][] keys, OpName opName, + MultiKeyCompressionFunction fn) { + return connPool.executeWithFailover(new CompressionValueMultiKeyOperation(Arrays.asList(keys), opName) { @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.unlink(key); + public T execute(final Jedis client, final ConnectionContext state) throws DynoException { + return fn.apply(client, state, this); } + }).getResult(); + } - }); + + /******************* Jedis String Commands **************/ + + @Override + public Long append(final String key, final String value) { + return execOp(key, OpName.APPEND, client -> client.append(key, value)); } - public OperationResult d_del(final String key) { + @Override + public Long decr(final String key) { + return execOp(key, OpName.DECR, client -> client.decr(key)); + } - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.DEL) { + @Override + public Long decrBy(final String key, final long delta) { + return execOp(key, OpName.DECRBY, client -> client.decrBy(key, delta)); + } - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.del(key); - } + @Override + public Long del(final String key) { + return execOp(key, OpName.DEL, client -> client.del(key)); + } - }); + @Override + public Long unlink(String key) { + return execOp(key, OpName.UNLINK, client -> client.unlink(key)); } public byte[] dump(final String key) { - return d_dump(key).getResult(); + return execOp(key, OpName.DUMP, client -> client.dump(key)); } @Override public String restore(String key, int ttl, byte[] serializedValue) { - throw new UnsupportedOperationException("not yet implemented"); + return execOp(key, OpName.RESTORE, client -> client.restore(key, ttl, serializedValue)); } @Override @@ -368,83 +488,27 @@ public String restoreReplace(String key, int ttl, byte[] serializedValue) { throw new UnsupportedOperationException("not yet implemented"); } - public OperationResult d_dump(final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.DUMP) { - - @Override - public byte[] execute(Jedis client, ConnectionContext state) { - return client.dump(key); - } - - }); - } - @Override public Boolean exists(final String key) { - return d_exists(key).getResult(); - } - - public OperationResult d_exists(final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.EXISTS) { - - @Override - public Boolean execute(Jedis client, ConnectionContext state) { - return client.exists(key); - } - - }); + return execOp(key, OpName.EXISTS, client -> client.exists(key)); } @Override public Long expire(final String key, final int seconds) { - return d_expire(key, seconds).getResult(); - } - - public OperationResult d_expire(final String key, final int seconds) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.EXPIRE) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.expire(key, seconds); - } - }); + return execOp(key, OpName.EXPIRE, client -> client.expire(key, seconds)); } @Override public Long expireAt(final String key, final long unixTime) { - return d_expireAt(key, unixTime).getResult(); - } - - public OperationResult d_expireAt(final String key, final long unixTime) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.EXPIREAT) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.expireAt(key, unixTime); - } - - }); + return execOp(key, OpName.EXPIREAT, client -> client.expireAt(key, unixTime)); } @Override public Object eval(String script, int keyCount, String... params) { - return d_eval(script, keyCount, params).getResult(); - } - - public OperationResult d_eval(final String script, final int keyCount, final String... params) { if (keyCount == 0) { throw new DynoException("Need at least one key in script"); } - return connPool.executeWithFailover(new BaseKeyOperation(params[0], OpName.EVAL) { - @Override - public Object execute(Jedis client, ConnectionContext state) { - return client.eval(script, keyCount, params); - } - }); + return execOp(params[0], OpName.EVAL, client -> client.eval(script, keyCount, params)); } @Override @@ -460,19 +524,10 @@ public Object eval(String script) { @Override public Object evalsha(String sha1, int keyCount, String... params) { - return d_evalsha(sha1, keyCount, params).getResult(); - } - - public OperationResult d_evalsha(String sha1, int keyCount, String... params) { if (keyCount == 0) { throw new DynoException("Need at least one key in script"); } - return connPool.executeWithFailover(new BaseKeyOperation(params[0], OpName.EVALSHA) { - @Override - public Object execute(Jedis client, ConnectionContext state) { - return client.evalsha(sha1, keyCount, params); - } - }); + return execOp(params[0], OpName.EVALSHA, client -> client.evalsha(sha1, keyCount, params)); } @Override @@ -488,337 +543,140 @@ public Object evalsha(String sha1) { @Override public Boolean scriptExists(String sha1) { - return d_scriptExists(sha1).getResult(); - } - - public OperationResult d_scriptExists(String sha1) { - return connPool.executeWithFailover(new BaseKeyOperation(sha1, OpName.SCRIPT_EXISTS) { - @Override - public Boolean execute(Jedis client, ConnectionContext state) throws DynoException { - return client.scriptExists(sha1); - } - }); + return execOp(sha1, OpName.SCRIPT_EXISTS, client -> client.scriptExists(sha1)); } @Override public List scriptExists(String... sha1) { - return scriptExists(sha1); + throw new UnsupportedOperationException("not yet implemented"); } @Override public String scriptLoad(String script) { - return d_scriptLoad(script).getResult(); - } - - public OperationResult d_scriptLoad(final String script) { - return connPool.executeWithFailover(new BaseKeyOperation(script, OpName.SCRIPT_LOAD) { - @Override - public String execute(Jedis client, ConnectionContext state) throws DynoException { - return client.scriptLoad(script); - } - }); + return execOp(script, OpName.SCRIPT_LOAD, client -> client.scriptLoad(script)); } public String scriptFlush() { - return d_scriptFlush().getResult(); - } - - public OperationResult d_scriptFlush() { - return connPool.executeWithFailover(new BaseKeyOperation("", OpName.SCRIPT_FLUSH) { - @Override - public String execute(Jedis client, ConnectionContext state) throws DynoException { - return client.scriptFlush(); - } - }); + return execOp("", OpName.SCRIPT_FLUSH, client -> client.scriptFlush()); } public String scriptKill() { - return d_scriptKill().getResult(); - } - - public OperationResult d_scriptKill() { - return connPool.executeWithFailover(new BaseKeyOperation("", OpName.SCRIPT_KILL) { - @Override - public String execute(Jedis client, ConnectionContext state) throws DynoException { - return client.scriptKill(); - } - }); + return execOp("", OpName.SCRIPT_KILL, client -> client.scriptKill()); } @Override public String get(final String key) { - return d_get(key).getResult(); - } - - public OperationResult d_get(final String key) { - if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.GET) { - @Override - public String execute(Jedis client, ConnectionContext state) throws DynoException { - return client.get(key); - } - }); + return execOp(key, OpName.GET, client -> client.get(key)); } else { - return connPool.executeWithFailover(new CompressionValueOperation(key, OpName.GET) { - @Override - public String execute(final Jedis client, final ConnectionContext state) throws DynoException { - return decompressValue(client.get(key), state); - } - }); + return execCompressOp(key, OpName.GET, (client, state, op) -> op.decompressValue(client.get(key), state)); } } @Override public Boolean getbit(final String key, final long offset) { - return d_getbit(key, offset).getResult(); - } - - public OperationResult d_getbit(final String key, final Long offset) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.GETBIT) { - - @Override - public Boolean execute(Jedis client, ConnectionContext state) { - return client.getbit(key, offset); - } - - }); + return execOp(key, OpName.GETBIT, client -> client.getbit(key, offset)); } @Override public String getrange(final String key, final long startOffset, final long endOffset) { - return d_getrange(key, startOffset, endOffset).getResult(); - } - - public OperationResult d_getrange(final String key, final Long startOffset, final Long endOffset) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.GETRANGE) { - - @Override - public String execute(Jedis client, ConnectionContext state) { - return client.getrange(key, startOffset, endOffset); - } - - }); + return execOp(key, OpName.GETRANGE, client -> client.getrange(key, startOffset, endOffset)); } @Override public String getSet(final String key, final String value) { - return d_getSet(key, value).getResult(); - } - - public OperationResult d_getSet(final String key, final String value) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.GETSET) { - @Override - public String execute(Jedis client, ConnectionContext state) throws DynoException { - return client.getSet(key, value); - } - }); + return execOp(key, OpName.GETSET, client -> client.getSet(key, value)); } else { - return connPool.executeWithFailover(new CompressionValueOperation(key, OpName.GETSET) { - @Override - public String execute(Jedis client, ConnectionContext state) throws DynoException { - return decompressValue(client.getSet(key, compressValue(value, state)), state); - } - }); + return execCompressOp( + key, + OpName.GETSET, + (client, state, op) -> op.decompressValue(client.getSet(key, op.compressValue(value, state)), state) + ); } } @Override public Long hdel(final String key, final String... fields) { - return d_hdel(key, fields).getResult(); - } - - public OperationResult d_hdel(final String key, final String... fields) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.HDEL) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.hdel(key, fields); - } - - }); + return execOp(key, OpName.HDEL, client -> client.hdel(key, fields)); } @Override public Boolean hexists(final String key, final String field) { - return d_hexists(key, field).getResult(); - } - - public OperationResult d_hexists(final String key, final String field) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.HEXISTS) { - - @Override - public Boolean execute(Jedis client, ConnectionContext state) { - return client.hexists(key, field); - } - - }); + return execOp(key, OpName.HEXISTS, client -> client.hexists(key, field)); } @Override public String hget(final String key, final String field) { - return d_hget(key, field).getResult(); - } - - public OperationResult d_hget(final String key, final String field) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.HGET) { - @Override - public String execute(Jedis client, ConnectionContext state) throws DynoException { - return client.hget(key, field); - } - }); + return execOp(key, OpName.HGET, client -> client.hget(key, field)); } else { - return connPool.executeWithFailover(new CompressionValueOperation(key, OpName.HGET) { - @Override - public String execute(final Jedis client, final ConnectionContext state) throws DynoException { - return decompressValue(client.hget(key, field), state); - } - }); + return execCompressOp( + key, + OpName.HGET, + (client, state, op) -> op.decompressValue(client.hget(key, field), state) + ); } } @Override public Map hgetAll(final String key) { - return d_hgetAll(key).getResult(); - } - - public OperationResult> d_hgetAll(final String key) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.HGETALL) { - @Override - public Map execute(Jedis client, ConnectionContext state) throws DynoException { - return client.hgetAll(key); - } - }); + return execOp(key, OpName.HGETALL, client -> client.hgetAll(key)); } else { - return connPool - .executeWithFailover(new CompressionValueOperation>(key, OpName.HGETALL) { - @Override - public Map execute(final Jedis client, final ConnectionContext state) { - return CollectionUtils.transform(client.hgetAll(key), - new CollectionUtils.MapEntryTransform() { - @Override - public String get(String key, String val) { - return decompressValue(val, state); - } - }); - } - }); + return execCompressOp( + key, + OpName.HGETALL, + (client, state, op) -> CollectionUtils.transform(client.hgetAll(key), + (key1, val) -> op.decompressValue(val, state)) + ); } } @Override public Long hincrBy(final String key, final String field, final long value) { - return d_hincrBy(key, field, value).getResult(); - } - - public OperationResult d_hincrBy(final String key, final String field, final long value) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.HINCRBY) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.hincrBy(key, field, value); - } - - }); + return execOp(key, OpName.HINCRBY, client -> client.hincrBy(key, field, value)); } /* not supported by RedisPipeline 2.7.3 */ public Double hincrByFloat(final String key, final String field, final double value) { - return d_hincrByFloat(key, field, value).getResult(); - } - - public OperationResult d_hincrByFloat(final String key, final String field, final double value) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.HINCRBYFLOAT) { - - @Override - public Double execute(Jedis client, ConnectionContext state) { - return client.hincrByFloat(key, field, value); - } - - }); + return execOp(key, OpName.HINCRBYFLOAT, client -> client.hincrByFloat(key, field, value)); } @Override public Long hsetnx(final String key, final String field, final String value) { - return d_hsetnx(key, field, value).getResult(); - } - - public OperationResult d_hsetnx(final String key, final String field, final String value) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.HSETNX) { - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.hsetnx(key, field, value); - } - - }); + return execOp(key, OpName.HSETNX, client -> client.hsetnx(key, field, value)); } else { - return connPool.executeWithFailover(new CompressionValueOperation(key, OpName.HSETNX) { - @Override - public Long execute(final Jedis client, final ConnectionContext state) throws DynoException { - return client.hsetnx(key, field, compressValue(value, state)); - } - }); + return execCompressOp( + key, + OpName.HSETNX, + (client, state, op) -> client.hsetnx(key, field, op.compressValue(value, state)) + ); } } @Override public Set hkeys(final String key) { - return d_hkeys(key).getResult(); - } - - public OperationResult> d_hkeys(final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.HKEYS) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.hkeys(key); - } - - }); + return execOp(key, OpName.HKEYS, client -> client.hkeys(key)); } @Override public ScanResult> hscan(final String key, final String cursor) { - return d_hscan(key, cursor).getResult(); - } - - public OperationResult>> d_hscan(final String key, final String cursor) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return connPool.executeWithFailover( - new BaseKeyOperation>>(key, OpName.HSCAN) { - @Override - public ScanResult> execute(Jedis client, ConnectionContext state) { - return client.hscan(key, cursor); - } - }); + return execOp(key, OpName.HSCAN, client -> client.hscan(key, cursor)); } else { - return connPool.executeWithFailover( - new CompressionValueOperation>>(key, OpName.HSCAN) { - @Override - public ScanResult> execute(final Jedis client, - final ConnectionContext state) { - return new ScanResult<>(cursor, new ArrayList(CollectionUtils.transform( - client.hscan(key, cursor).getResult(), - new CollectionUtils.Transform, Map.Entry>() { - @Override - public Map.Entry get(Map.Entry entry) { - entry.setValue(decompressValue(entry.getValue(), state)); - return entry; - } - }))); - } - }); + return execCompressOp( + key, + OpName.HSCAN, + (client, state, op) -> + new ScanResult<>(cursor, new ArrayList(CollectionUtils.transform( + client.hscan(key, cursor).getResult(), + entry -> { + entry.setValue(op.decompressValue(entry.getValue(), state)); + return entry; + }))) + ); } } @@ -854,393 +712,151 @@ public ScanResult execute(final Jedis client, final ConnectionContext st @Override public Long hlen(final String key) { - return d_hlen(key).getResult(); - } - - public OperationResult d_hlen(final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.HLEN) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.hlen(key); - } - - }); + return execOp(key, OpName.HLEN, client -> client.hlen(key)); } @Override public List hmget(final String key, final String... fields) { - return d_hmget(key, fields).getResult(); - } - - public OperationResult> d_hmget(final String key, final String... fields) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.HMGET) { - @Override - public List execute(Jedis client, ConnectionContext state) { - return client.hmget(key, fields); - } - }); + return execOp(key, OpName.HMGET, client -> client.hmget(key, fields)); } else { - return connPool.executeWithFailover(new CompressionValueOperation>(key, OpName.HMGET) { - @Override - public List execute(final Jedis client, final ConnectionContext state) throws DynoException { - return new ArrayList(CollectionUtils.transform(client.hmget(key, fields), - new CollectionUtils.Transform() { - @Override - public String get(String s) { - return decompressValue(s, state); - } - })); - } - }); + return execCompressOp( + key, + OpName.HMGET, + (client, state, op) -> + new ArrayList<>(CollectionUtils.transform(client.hmget(key, fields), + s -> op.decompressValue(s, state))) + ); } } @Override public String hmset(final String key, final Map hash) { - return d_hmset(key, hash).getResult(); - } - - public OperationResult d_hmset(final String key, final Map hash) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.HMSET) { - @Override - public String execute(Jedis client, ConnectionContext state) { - return client.hmset(key, hash); - } - }); + return execOp(key, OpName.HMSET, client -> client.hmset(key, hash)); } else { - return connPool.executeWithFailover(new CompressionValueOperation(key, OpName.HMSET) { - @Override - public String execute(final Jedis client, final ConnectionContext state) throws DynoException { - return client.hmset(key, CollectionUtils.transform(hash, - new CollectionUtils.MapEntryTransform() { - @Override - public String get(String key, String val) { - return compressValue(val, state); - } - })); - } - }); + return execCompressOp( + key, + OpName.HMSET, + (client, state, op) -> + client.hmset(key, CollectionUtils.transform(hash, (key1, val) -> op.compressValue(val, state))) + ); } } @Override public Long hset(final String key, final String field, final String value) { - return d_hset(key, field, value).getResult(); + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.HSET, client -> client.hset(key, field, value)); + } else { + return execCompressOp( + key, + OpName.HSET, + (client, state, op) -> client.hset(key, field, op.compressValue(value, state)) + ); + } } @Override public Long hset(String key, Map hash) { - throw new UnsupportedOperationException("not yet implemented"); - } - - public OperationResult d_hset(final String key, final String field, final String value) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.HSET) { - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.hset(key, field, value); - } - - }); + return execOp(key, OpName.HSET, client -> client.hset(key, hash)); } else { - return connPool.executeWithFailover(new CompressionValueOperation(key, OpName.HSET) { - @Override - public Long execute(final Jedis client, final ConnectionContext state) throws DynoException { - return client.hset(key, field, compressValue(value, state)); - } - }); + throw new UnsupportedOperationException("not yet implemented"); } } @Override public List hvals(final String key) { - return d_hvals(key).getResult(); - } - - public OperationResult> d_hvals(final String key) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.HVALS) { - @Override - public List execute(Jedis client, ConnectionContext state) { - return client.hvals(key); - } - - }); + return execOp(key, OpName.HVALS, client -> client.hvals(key)); } else { - return connPool.executeWithFailover(new CompressionValueOperation>(key, OpName.HVALS) { - @Override - public List execute(final Jedis client, final ConnectionContext state) throws DynoException { - return new ArrayList(CollectionUtils.transform(client.hvals(key), - new CollectionUtils.Transform() { - @Override - public String get(String s) { - return decompressValue(s, state); - } - })); - } - }); + return execCompressOp( + key, + OpName.HVALS, + (client, state, op) -> + new ArrayList<>(CollectionUtils.transform(client.hvals(key), s -> op.decompressValue(s, state))) + ); } } @Override public Long incr(final String key) { - return d_incr(key).getResult(); - } - - public OperationResult d_incr(final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.INCR) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.incr(key); - } - - }); + return execOp(key, OpName.INCR, client -> client.incr(key)); } @Override public Long incrBy(final String key, final long delta) { - return d_incrBy(key, delta).getResult(); - } - - public OperationResult d_incrBy(final String key, final Long delta) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.INCRBY) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.incrBy(key, delta); - } - - }); + return execOp(key, OpName.INCRBY, client -> client.incrBy(key, delta)); } public Double incrByFloat(final String key, final double increment) { - return d_incrByFloat(key, increment).getResult(); - } - - public OperationResult d_incrByFloat(final String key, final Double increment) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.INCRBYFLOAT) { - - @Override - public Double execute(Jedis client, ConnectionContext state) { - return client.incrByFloat(key, increment); - } - - }); + return execOp(key, OpName.INCRBYFLOAT, client -> client.incrByFloat(key, increment)); } @Override public String lindex(final String key, final long index) { - return d_lindex(key, index).getResult(); - } - - public OperationResult d_lindex(final String key, final Long index) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.LINDEX) { - - @Override - public String execute(Jedis client, ConnectionContext state) { - return client.lindex(key, index); - } - - }); + return execOp(key, OpName.LINDEX, client -> client.lindex(key, index)); } @Override public Long linsert(final String key, final ListPosition where, final String pivot, final String value) { - return d_linsert(key, where, pivot, value).getResult(); - } - - public OperationResult d_linsert(final String key, final ListPosition where, final String pivot, - final String value) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.LINSERT) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.linsert(key, where, pivot, value); - } - }); + return execOp(key, OpName.LINSERT, client -> client.linsert(key, where, pivot, value)); } @Override public Long llen(final String key) { - return d_llen(key).getResult(); - } - - public OperationResult d_llen(final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.LLEN) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.llen(key); - } - - }); + return execOp(key, OpName.LLEN, client -> client.llen(key)); } @Override public String lpop(final String key) { - return d_lpop(key).getResult(); - } - - public OperationResult d_lpop(final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.LPOP) { - - @Override - public String execute(Jedis client, ConnectionContext state) { - return client.lpop(key); - } - - }); + return execOp(key, OpName.LPOP, client -> client.lpop(key)); } @Override public Long lpush(final String key, final String... values) { - return d_lpush(key, values).getResult(); - } - - public OperationResult d_lpush(final String key, final String... values) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.LPUSH) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.lpush(key, values); - } - - }); + return execOp(key, OpName.LPUSH, client -> client.lpush(key, values)); } @Override public Long lpushx(final String key, final String... values) { - return d_lpushx(key, values).getResult(); - } - - public OperationResult d_lpushx(final String key, final String... values) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.LPUSHX) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.lpushx(key, values); - } - - }); + return execOp(key, OpName.LPUSHX, client -> client.lpushx(key, values)); } @Override public List lrange(final String key, final long start, final long end) { - return d_lrange(key, start, end).getResult(); - } - - public OperationResult> d_lrange(final String key, final Long start, final Long end) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.LRANGE) { - - @Override - public List execute(Jedis client, ConnectionContext state) { - return client.lrange(key, start, end); - } - - }); + return execOp(key, OpName.LRANGE, client -> client.lrange(key, start, end)); } @Override public Long lrem(final String key, final long count, final String value) { - return d_lrem(key, count, value).getResult(); - } - - public OperationResult d_lrem(final String key, final Long count, final String value) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.LREM) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.lrem(key, count, value); - } - - }); + return execOp(key, OpName.LREM, client -> client.lrem(key, count, value)); } @Override public String lset(final String key, final long index, final String value) { - return d_lset(key, index, value).getResult(); - } - - public OperationResult d_lset(final String key, final Long index, final String value) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.LSET) { - - @Override - public String execute(Jedis client, ConnectionContext state) { - return client.lset(key, index, value); - } - - }); + return execOp(key, OpName.LSET, client -> client.lset(key, index, value)); } @Override public String ltrim(final String key, final long start, final long end) { - return d_ltrim(key, start, end).getResult(); - } - - public OperationResult d_ltrim(final String key, final long start, final long end) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.LTRIM) { - - @Override - public String execute(Jedis client, ConnectionContext state) { - return client.ltrim(key, start, end); - } - - }); + return execOp(key, OpName.LTRIM, client -> client.ltrim(key, start, end)); } @Override public Long persist(final String key) { - return d_persist(key).getResult(); - } - - public OperationResult d_persist(final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.PERSIST) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.persist(key); - } - - }); + return execOp(key, OpName.PERSIST, client -> client.persist(key)); } + @Override public Long pexpireAt(final String key, final long millisecondsTimestamp) { - return d_pexpireAt(key, millisecondsTimestamp).getResult(); - } - - public OperationResult d_pexpireAt(final String key, final Long millisecondsTimestamp) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.PEXPIREAT) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.pexpireAt(key, millisecondsTimestamp); - } - - }); + return execOp(key, OpName.PEXPIREAT, client -> client.pexpireAt(key, millisecondsTimestamp)); } + @Override public Long pttl(final String key) { - return d_pttl(key).getResult(); + return execOp(key, OpName.PTTL, client -> client.pttl(key)); } @Override @@ -1248,221 +864,71 @@ public Long touch(String key) { throw new UnsupportedOperationException("not yet implemented"); } - public OperationResult d_pttl(final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.PTTL) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.pttl(key); - } - - }); - } - @Override public String rename(String oldkey, String newkey) { - return d_rename(oldkey, newkey).getResult(); - } - - public OperationResult d_rename(final String oldkey, final String newkey) { - - return connPool.executeWithFailover(new BaseKeyOperation(oldkey, OpName.RENAME) { - - @Override - public String execute(Jedis client, ConnectionContext state) { - return client.rename(oldkey, newkey); - } - - }); + return execOp(oldkey, OpName.RENAME, client -> client.rename(oldkey, newkey)); } @Override public Long renamenx(String oldkey, String newkey) { - return d_renamenx(oldkey, newkey).getResult(); - } - - public OperationResult d_renamenx(final String oldkey, final String newkey) { - - return connPool.executeWithFailover(new BaseKeyOperation(oldkey, OpName.RENAMENX) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.renamenx(oldkey, newkey); - } - - }); + return execOp(oldkey, OpName.RENAMENX, client -> client.renamenx(oldkey, newkey)); } public String restore(final String key, final Integer ttl, final byte[] serializedValue) { - return d_restore(key, ttl, serializedValue).getResult(); - } - - public OperationResult d_restore(final String key, final Integer ttl, final byte[] serializedValue) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.RESTORE) { - - @Override - public String execute(Jedis client, ConnectionContext state) { - return client.restore(key, ttl, serializedValue); - } - - }); + return execOp(key, OpName.RESTORE, client -> client.restore(key, ttl, serializedValue)); } + @Override public String rpop(final String key) { - return d_rpop(key).getResult(); - } - - public OperationResult d_rpop(final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.RPOP) { - - @Override - public String execute(Jedis client, ConnectionContext state) { - return client.rpop(key); - } - - }); + return execOp(key, OpName.RPOP, client -> client.rpop(key)); } + @Override public String rpoplpush(final String srckey, final String dstkey) { - return d_rpoplpush(srckey, dstkey).getResult(); - } - - public OperationResult d_rpoplpush(final String srckey, final String dstkey) { - - return connPool.executeWithFailover(new BaseKeyOperation(srckey, OpName.RPOPLPUSH) { - - @Override - public String execute(Jedis client, ConnectionContext state) { - return client.rpoplpush(srckey, dstkey); - } - - }); + return execOp(srckey, OpName.RPOPLPUSH, client -> client.rpoplpush(srckey, dstkey)); } + @Override public Long rpush(final String key, final String... values) { - return d_rpush(key, values).getResult(); - } - - public OperationResult d_rpush(final String key, final String... values) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.RPUSH) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.rpush(key, values); - } - - }); + return execOp(key, OpName.RPUSH, client -> client.rpush(key, values)); } @Override public Long rpushx(final String key, final String... values) { - return d_rpushx(key, values).getResult(); - } - - public OperationResult d_rpushx(final String key, final String... values) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.RPUSHX) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.rpushx(key, values); - } - - }); + return execOp(key, OpName.RPUSHX, client -> client.rpushx(key, values)); } @Override public Long sadd(final String key, final String... members) { - return d_sadd(key, members).getResult(); - } - - public OperationResult d_sadd(final String key, final String... members) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.SADD) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.sadd(key, members); - } - - }); + return execOp(key, OpName.SADD, client -> client.sadd(key, members)); } @Override public Long scard(final String key) { - return d_scard(key).getResult(); - } - - public OperationResult d_scard(final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.SCARD) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.scard(key); - } - - }); + return execOp(key, OpName.SCARD, client -> client.scard(key)); } + @Override public Set sdiff(final String... keys) { - return d_sdiff(keys).getResult(); - } - - public OperationResult> d_sdiff(final String... keys) { - - return connPool.executeWithFailover(new BaseKeyOperation>(keys[0], OpName.SDIFF) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.sdiff(keys); - } - - }); + return execOp(keys[0], OpName.SDIFF, client -> client.sdiff(keys)); } + @Override public Long sdiffstore(final String dstkey, final String... keys) { - return d_sdiffstore(dstkey, keys).getResult(); - } - - public OperationResult d_sdiffstore(final String dstkey, final String... keys) { - - return connPool.executeWithFailover(new BaseKeyOperation(dstkey, OpName.SDIFFSTORE) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.sdiffstore(dstkey, keys); - } - - }); + return execOp(dstkey, OpName.SDIFFSTORE, client -> client.sdiffstore(dstkey, keys)); } @Override public String set(final String key, final String value) { - return d_set(key, value).getResult(); - } - - public OperationResult d_set(final String key, final String value) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.SET) { - @Override - public String execute(Jedis client, ConnectionContext state) throws DynoException { - return client.set(key, value); - } - }); + return execOp(key, OpName.SET, client -> client.set(key, value)); } else { - return connPool.executeWithFailover(new CompressionValueOperation(key, OpName.SET) { - @Override - public String execute(final Jedis client, final ConnectionContext state) throws DynoException { - return client.set(key, compressValue(value, state)); - } - }); + return execCompressOp( + key, + OpName.SET, + (client, state, op) -> client.set(key, op.compressValue(value, state)) + ); } - } @Deprecated @@ -1470,11 +936,6 @@ public String execute(final Jedis client, final ConnectionContext state) throws * use {@link set(String, String, SetParams)} instead */ public String set(final String key, final String value, final String nxxx, final String expx, final long time) { - return d_set(key, value, nxxx, expx, time).getResult(); - } - - public OperationResult d_set(final String key, final String value, final String nxxx, final String expx, - final long time) { SetParams setParams = SetParams.setParams(); if (nxxx.equalsIgnoreCase("NX")) { setParams.nx(); @@ -1487,1160 +948,373 @@ public OperationResult d_set(final String key, final String value, final setParams.px(time); } - return d_set(key, value, setParams); + return set(key, value, setParams); } + @Override public String set(final String key, final String value, final SetParams setParams) { - return d_set(key, value, setParams).getResult(); - } - - public OperationResult d_set(final String key, final String value, final SetParams setParams) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.SET) { - @Override - public String execute(Jedis client, ConnectionContext state) throws DynoException { - return client.set(key, value, setParams); - } - }); + return execOp(key, OpName.SET, client -> client.set(key, value, setParams)); else { - return connPool.executeWithFailover(new CompressionValueOperation(key, OpName.SET) { - @Override - public String execute(final Jedis client, final ConnectionContext state) throws DynoException { - return client.set(key, compressValue(value, state), setParams); - } - }); + return execCompressOp( + key, + OpName.SET, + (client, state, op) -> client.set(key, op.compressValue(value, state), setParams) + ); } } @Override public Boolean setbit(final String key, final long offset, final boolean value) { - return d_setbit(key, offset, value).getResult(); - } - - public OperationResult d_setbit(final String key, final Long offset, final Boolean value) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.SETBIT) { - - @Override - public Boolean execute(Jedis client, ConnectionContext state) { - return client.setbit(key, offset, value); - } - - }); + return execOp(key, OpName.SETBIT, client -> client.setbit(key, offset, value)); } @Override public Boolean setbit(final String key, final long offset, final String value) { - return d_setbit(key, offset, value).getResult(); - } - - public OperationResult d_setbit(final String key, final Long offset, final String value) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.SETBIT) { - - @Override - public Boolean execute(Jedis client, ConnectionContext state) { - return client.setbit(key, offset, value); - } - - }); + return execOp(key, OpName.SETBIT, client -> client.setbit(key, offset, value)); } @Override public String setex(final String key, final int seconds, final String value) { - return d_setex(key, seconds, value).getResult(); - } - - public OperationResult d_setex(final String key, final Integer seconds, final String value) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.SETEX) { - @Override - public String execute(Jedis client, ConnectionContext state) throws DynoException { - return client.setex(key, seconds, value); - } - }); + return execOp(key, OpName.SETEX, client -> client.setex(key, seconds, value)); } else { - return connPool.executeWithFailover(new CompressionValueOperation(key, OpName.SETEX) { - @Override - public String execute(final Jedis client, final ConnectionContext state) throws DynoException { - return client.setex(key, seconds, compressValue(value, state)); - } - }); + return execCompressOp( + key, + OpName.SETEX, + (client, state, op) -> client.setex(key, seconds, op.compressValue(value, state)) + ); } } @Override public String psetex(final String key, final long milliseconds, final String value) { - return d_psetex(key, milliseconds, value).getResult(); - } - - public OperationResult d_psetex(final String key, final long milliseconds, final String value) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.PSETEX) { - @Override - public String execute(Jedis client, ConnectionContext state) throws DynoException { - return client.psetex(key, milliseconds, value); - } - }); + return execOp(key, OpName.PSETEX, client -> client.psetex(key, milliseconds, value)); } else { - return connPool.executeWithFailover(new CompressionValueOperation(key, OpName.PSETEX) { - @Override - public String execute(final Jedis client, final ConnectionContext state) throws DynoException { - return client.psetex(key, milliseconds, compressValue(value, state)); - } - }); + return execCompressOp( + key, + OpName.PSETEX, + (client, state, op) -> client.psetex(key, milliseconds, op.compressValue(value, state)) + ); } } - @Override public Long setnx(final String key, final String value) { - return d_setnx(key, value).getResult(); - } - - public OperationResult d_setnx(final String key, final String value) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.SETNX) { - @Override - public Long execute(Jedis client, ConnectionContext state) throws DynoException { - return client.setnx(key, value); - } - }); + return execOp(key, OpName.SETNX, client -> client.setnx(key, value)); } else { - return connPool.executeWithFailover(new CompressionValueOperation(key, OpName.SETNX) { - @Override - public Long execute(final Jedis client, final ConnectionContext state) { - return client.setnx(key, compressValue(value, state)); - } - }); + return execCompressOp( + key, + OpName.SETNX, + (client, state, op) -> client.setnx(key, op.compressValue(value, state)) + ); } } @Override public Long setrange(final String key, final long offset, final String value) { - return d_setrange(key, offset, value).getResult(); - } - - public OperationResult d_setrange(final String key, final Long offset, final String value) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.SETRANGE) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.setrange(key, offset, value); - } - - }); + return execOp(key, OpName.SETRANGE, client -> client.setrange(key, offset, value)); } @Override public Boolean sismember(final String key, final String member) { - return d_sismember(key, member).getResult(); - } - - public OperationResult d_sismember(final String key, final String member) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.SISMEMBER) { - - @Override - public Boolean execute(Jedis client, ConnectionContext state) { - return client.sismember(key, member); - } - - }); + return execOp(key, OpName.SISMEMBER, client -> client.sismember(key, member)); } @Override public Set smembers(final String key) { - return d_smembers(key).getResult(); - } - - public OperationResult> d_smembers(final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.SMEMBERS) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.smembers(key); - } - - }); + return execOp(key, OpName.SMEMBERS, client -> client.smembers(key)); } public Long smove(final String srckey, final String dstkey, final String member) { - return d_smove(srckey, dstkey, member).getResult(); - } - - public OperationResult d_smove(final String srckey, final String dstkey, final String member) { - - return connPool.executeWithFailover(new BaseKeyOperation(srckey, OpName.SMOVE) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.smove(srckey, dstkey, member); - } - - }); + return execOp(srckey, OpName.SMOVE, client -> client.smove(srckey, dstkey, member)); } - @Override public List sort(String key) { - return d_sort(key).getResult(); - } - - public OperationResult> d_sort(final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.SORT) { - - @Override - public List execute(Jedis client, ConnectionContext state) { - return client.sort(key); - } - - }); + return execOp(key, OpName.SORT, client -> client.sort(key)); } @Override public List sort(String key, SortingParams sortingParameters) { - return d_sort(key, sortingParameters).getResult(); - } - - public OperationResult> d_sort(final String key, final SortingParams sortingParameters) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.SORT) { - - @Override - public List execute(Jedis client, ConnectionContext state) { - return client.sort(key, sortingParameters); - } - - }); + return execOp(key, OpName.SORT, client -> client.sort(key, sortingParameters)); } @Override public String spop(final String key) { - return d_spop(key).getResult(); - } - - public OperationResult d_spop(final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.SPOP) { - - @Override - public String execute(Jedis client, ConnectionContext state) { - return client.spop(key); - } - - }); + return execOp(key, OpName.SPOP, client -> client.spop(key)); } @Override public Set spop(String key, long count) { - throw new UnsupportedOperationException("not yet implemented"); + return execOp(key, OpName.SPOP, client -> client.spop(key, count)); } @Override public String srandmember(final String key) { - return d_srandmember(key).getResult(); + return execOp(key, OpName.SRANDMEMBER, client -> client.srandmember(key)); } @Override public List srandmember(String key, int count) { - throw new UnsupportedOperationException("not yet implemented"); - } - - public OperationResult d_srandmember(final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.SRANDMEMBER) { - - @Override - public String execute(Jedis client, ConnectionContext state) { - return client.srandmember(key); - } - - }); + return execOp(key, OpName.SRANDMEMBER, client -> client.srandmember(key, count)); } @Override public Long srem(final String key, final String... members) { - return d_srem(key, members).getResult(); - } - - public OperationResult d_srem(final String key, final String... members) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.SREM) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.srem(key, members); - } - - }); + return execOp(key, OpName.SREM, client -> client.srem(key, members)); } @Override public ScanResult sscan(final String key, final String cursor) { - return d_sscan(key, cursor).getResult(); - } - - public OperationResult> d_sscan(final String key, final String cursor) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.SSCAN) { - - @Override - public ScanResult execute(Jedis client, ConnectionContext state) { - return client.sscan(key, cursor); - } - - }); + return execOp(key, OpName.SSCAN, client -> client.sscan(key, cursor)); } @Override public ScanResult sscan(final String key, final String cursor, final ScanParams params) { - return d_sscan(key, cursor, params).getResult(); - } - - public OperationResult> d_sscan(final String key, final String cursor, final ScanParams params) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.SSCAN) { - - @Override - public ScanResult execute(Jedis client, ConnectionContext state) { - return client.sscan(key, cursor, params); - } - - }); + return execOp(key, OpName.SSCAN, client -> client.sscan(key, cursor, params)); } @Override public Long strlen(final String key) { - return d_strlen(key).getResult(); - } - - public OperationResult d_strlen(final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.STRLEN) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.strlen(key); - } - - }); + return execOp(key, OpName.STRLEN, client -> client.strlen(key)); } @Override public String substr(String key, int start, int end) { - return d_substr(key, start, end).getResult(); - } - - public OperationResult d_substr(final String key, final Integer start, final Integer end) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.SUBSTR) { - - @Override - public String execute(Jedis client, ConnectionContext state) { - return client.substr(key, start, end); - } - - }); + return execOp(key, OpName.SUBSTR, client -> client.substr(key, start, end)); } @Override public Long ttl(final String key) { - return d_ttl(key).getResult(); - } - - public OperationResult d_ttl(final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.TTL) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.ttl(key); - } - - }); + return execOp(key, OpName.TTL, client -> client.ttl(key)); } @Override public String type(final String key) { - return d_type(key).getResult(); - } - - public OperationResult d_type(final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.TYPE) { - - @Override - public String execute(Jedis client, ConnectionContext state) { - return client.type(key); - } - - }); + return execOp(key, OpName.TYPE, client -> client.type(key)); } @Override public Long zadd(String key, double score, String member) { - return d_zadd(key, score, member).getResult(); - } - - public OperationResult d_zadd(final String key, final Double score, final String member) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.ZADD) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.zadd(key, score, member); - } - - }); + return execOp(key, OpName.ZADD, client -> client.zadd(key, score, member)); } @Override public Long zadd(String key, Map scoreMembers) { - return d_zadd(key, scoreMembers).getResult(); - } - - public OperationResult d_zadd(final String key, final Map scoreMembers) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.ZADD) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.zadd(key, scoreMembers); - } - - }); + return execOp(key, OpName.ZADD, client -> client.zadd(key, scoreMembers)); } @Override public Long zadd(String key, double score, String member, ZAddParams params) { - return d_zadd(key, score, member, params).getResult(); - } - - public OperationResult d_zadd(final String key, final double score, final String member, - final ZAddParams params) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.ZADD) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.zadd(key, score, member, params); - } - - }); + return execOp(key, OpName.ZADD, client -> client.zadd(key, score, member, params)); } @Override public Long zcard(final String key) { - return d_zcard(key).getResult(); - } - - public OperationResult d_zcard(final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.ZCARD) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.zcard(key); - } - - }); + return execOp(key, OpName.ZCARD, client -> client.zcard(key)); } @Override public Long zcount(final String key, final double min, final double max) { - return d_zcount(key, min, max).getResult(); - } - - public OperationResult d_zcount(final String key, final Double min, final Double max) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.ZCOUNT) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.zcount(key, min, max); - } - - }); + return execOp(key, OpName.ZCOUNT, client -> client.zcount(key, min, max)); } @Override public Long zcount(String key, String min, String max) { - return d_zcount(key, min, max).getResult(); - } - - public OperationResult d_zcount(final String key, final String min, final String max) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.ZCOUNT) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.zcount(key, min, max); - } - - }); + return execOp(key, OpName.ZCOUNT, client -> client.zcount(key, min, max)); } @Override public Double zincrby(final String key, final double score, final String member) { - return d_zincrby(key, score, member).getResult(); - } - - public OperationResult d_zincrby(final String key, final Double score, final String member) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.ZINCRBY) { - - @Override - public Double execute(Jedis client, ConnectionContext state) { - return client.zincrby(key, score, member); - } - - }); + return execOp(key, OpName.ZINCRBY, client -> client.zincrby(key, score, member)); } @Override public Set zrange(String key, long start, long end) { - return d_zrange(key, start, end).getResult(); - } - - public OperationResult> d_zrange(final String key, final Long start, final Long end) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZRANGE) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrange(key, start, end); - } - - }); + return execOp(key, OpName.ZRANGE, client -> client.zrange(key, start, end)); } @Override public Long zrank(final String key, final String member) { - return d_zrank(key, member).getResult(); - } - - public OperationResult d_zrank(final String key, final String member) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.ZRANK) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.zrank(key, member); - } - - }); + return execOp(key, OpName.ZRANK, client -> client.zrank(key, member)); } @Override public Long zrem(String key, String... member) { - return d_zrem(key, member).getResult(); - } - - public OperationResult d_zrem(final String key, final String... member) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.ZREM) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.zrem(key, member); - } - - }); + return execOp(key, OpName.ZREM, client -> client.zrem(key, member)); } @Override public Long zremrangeByRank(final String key, final long start, final long end) { - return d_zremrangeByRank(key, start, end).getResult(); + return execOp(key, OpName.ZREMRANGEBYRANK, client -> client.zremrangeByRank(key, start, end)); } - public OperationResult d_zremrangeByRank(final String key, final Long start, final Long end) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.ZREMRANGEBYRANK) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.zremrangeByRank(key, start, end); - } + @Override + public Long zremrangeByScore(final String key, final double start, final double end) { + return execOp(key, OpName.ZREMRANGEBYSCORE, client -> client.zremrangeByScore(key, start, end)); + } - }); + @Override + public Set zrevrange(String key, long start, long end) { + return execOp(key, OpName.ZREVRANGE, client -> client.zrevrange(key, start, end)); } @Override - public Long zremrangeByScore(final String key, final double start, final double end) { - return d_zremrangeByScore(key, start, end).getResult(); + public Long zrevrank(final String key, final String member) { + return execOp(key, OpName.ZREVRANK, client -> client.zrevrank(key, member)); } - public OperationResult d_zremrangeByScore(final String key, final Double start, final Double end) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.ZREMRANGEBYSCORE) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.zremrangeByScore(key, start, end); - } - - }); - } - - @Override - public Set zrevrange(String key, long start, long end) { - return d_zrevrange(key, start, end).getResult(); - } - - public OperationResult> d_zrevrange(final String key, final Long start, final Long end) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZREVRANGE) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrevrange(key, start, end); - } - - }); - } - - @Override - public Long zrevrank(final String key, final String member) { - return d_zrevrank(key, member).getResult(); - } - - public OperationResult d_zrevrank(final String key, final String member) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.ZREVRANK) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.zrevrank(key, member); - } - - }); - } - - @Override - public Set zrangeWithScores(String key, long start, long end) { - return d_zrangeWithScores(key, start, end).getResult(); - } - - public OperationResult> d_zrangeWithScores(final String key, final Long start, final Long end) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZRANGEWITHSCORES) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrangeWithScores(key, start, end); - } - - }); - } + @Override + public Set zrangeWithScores(String key, long start, long end) { + return execOp(key, OpName.ZRANGEWITHSCORES, client -> client.zrangeWithScores(key, start, end)); + } @Override public Set zrevrangeWithScores(String key, long start, long end) { - return d_zrevrangeWithScores(key, start, end).getResult(); - } - - public OperationResult> d_zrevrangeWithScores(final String key, final Long start, final Long end) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZREVRANGEWITHSCORES) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrevrangeWithScores(key, start, end); - } - - }); + return execOp(key, OpName.ZREVRANGEWITHSCORES, client -> client.zrevrangeWithScores(key, start, end)); } @Override public Double zscore(final String key, final String member) { - return d_zscore(key, member).getResult(); - } - - public OperationResult d_zscore(final String key, final String member) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.ZSCORE) { - - @Override - public Double execute(Jedis client, ConnectionContext state) { - return client.zscore(key, member); - } - - }); + return execOp(key, OpName.ZSCORE, client -> client.zscore(key, member)); } @Override public ScanResult zscan(final String key, final String cursor) { - return d_zscan(key, cursor).getResult(); - } - - public OperationResult> d_zscan(final String key, final String cursor) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZSCAN) { - @Override - public ScanResult execute(Jedis client, ConnectionContext state) { - return client.zscan(key, cursor); - } - - }); + return execOp(key, OpName.ZSCAN, client -> client.zscan(key, cursor)); } @Override public Set zrangeByScore(String key, double min, double max) { - return d_zrangeByScore(key, min, max).getResult(); - } - - public OperationResult> d_zrangeByScore(final String key, final Double min, final Double max) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZRANGEBYSCORE) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrangeByScore(key, min, max); - } - - }); + return execOp(key, OpName.ZRANGEBYSCORE, client -> client.zrangeByScore(key, min, max)); } @Override public Set zrangeByScore(String key, String min, String max) { - return d_zrangeByScore(key, min, max).getResult(); - } - - public OperationResult> d_zrangeByScore(final String key, final String min, final String max) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZRANGEBYSCORE) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrangeByScore(key, min, max); - } - - }); + return execOp(key, OpName.ZRANGEBYSCORE, client -> client.zrangeByScore(key, min, max)); } @Override public Set zrangeByScore(String key, double min, double max, int offset, int count) { - return d_zrangeByScore(key, min, max, offset, count).getResult(); - } - - public OperationResult> d_zrangeByScore(final String key, final Double min, final Double max, - final Integer offset, final Integer count) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZRANGEBYSCORE) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrangeByScore(key, min, max, offset, count); - } - - }); - } - - @Override - public Set zrevrangeByScore(String key, String max, String min) { - return d_zrevrangeByScore(key, max, min).getResult(); - } - - public OperationResult> d_zrevrangeByScore(final String key, final String max, final String min) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZREVRANGEBYSCORE) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrevrangeByScore(key, max, min); - } - - }); + return execOp(key, OpName.ZRANGEBYSCORE, client -> client.zrangeByScore(key, min, max, offset, count)); } @Override public Set zrangeByScore(String key, String min, String max, int offset, int count) { - return d_zrangeByScore(key, min, max, offset, count).getResult(); + return execOp(key, OpName.ZRANGEBYSCORE, client -> client.zrangeByScore(key, min, max, offset, count)); } - public OperationResult> d_zrangeByScore(final String key, final String min, final String max, - final Integer offset, final Integer count) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZRANGEBYSCORE) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrangeByScore(key, min, max, offset, count); - } - - }); + @Override + public Set zrevrangeByScore(String key, String max, String min) { + return execOp(key, OpName.ZREVRANGEBYSCORE, client -> client.zrevrangeByScore(key, max, min)); } @Override public Set zrevrangeByScore(String key, double max, double min, int offset, int count) { - return d_zrevrangeByScore(key, max, min, offset, count).getResult(); - } - - public OperationResult> d_zrevrangeByScore(final String key, final Double max, final Double min, - final Integer offset, final Integer count) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZREVRANGEBYSCORE) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrevrangeByScore(key, max, min, offset, count); - } - - }); + return execOp(key, OpName.ZREVRANGEBYSCORE, client -> client.zrevrangeByScore(key, max, min, offset, count)); } @Override public Set zrevrangeByScore(String key, double max, double min) { - return d_zrevrangeByScore(key, max, min).getResult(); - } - - public OperationResult> d_zrevrangeByScore(final String key, final Double max, final Double min) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZREVRANGEBYSCORE) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrevrangeByScore(key, max, min); - } - - }); + return execOp(key, OpName.ZREVRANGEBYSCORE, client -> client.zrevrangeByScore(key, max, min)); } @Override public Set zrangeByScoreWithScores(String key, double min, double max) { - return d_zrangeByScoreWithScores(key, min, max).getResult(); - } - - public OperationResult> d_zrangeByScoreWithScores(final String key, final Double min, final Double max) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZREVRANGEBYSCORE) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrangeByScoreWithScores(key, min, max); - } - - }); + return execOp(key, OpName.ZRANGEBYSCOREWITHSCORES, client -> client.zrangeByScoreWithScores(key, min, max)); } @Override public Set zrevrangeByScoreWithScores(String key, double max, double min) { - return d_zrevrangeByScoreWithScores(key, min, max).getResult(); - } - - public OperationResult> d_zrevrangeByScoreWithScores(final String key, final Double max, - final Double min) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZREVRANGEBYSCOREWITHSCORES) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrevrangeByScoreWithScores(key, max, min); - } - - }); + return execOp(key, OpName.ZREVRANGEBYSCOREWITHSCORES, client -> client.zrevrangeByScoreWithScores(key, max, min)); } @Override public Set zrangeByScoreWithScores(String key, double min, double max, int offset, int count) { - return d_zrangeByScoreWithScores(key, min, max, offset, count).getResult(); - } - - public OperationResult> d_zrangeByScoreWithScores(final String key, final Double min, final Double max, - final Integer offset, final Integer count) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZRANGEBYSCOREWITHSCORES) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrangeByScoreWithScores(key, min, max, offset, count); - } - - }); + return execOp(key, OpName.ZRANGEBYSCOREWITHSCORES, client -> client.zrangeByScoreWithScores(key, min, max, offset, count)); } @Override public Set zrevrangeByScore(String key, String max, String min, int offset, int count) { - return d_zrevrangeByScore(key, max, min, offset, count).getResult(); - } - - public OperationResult> d_zrevrangeByScore(final String key, final String max, final String min, - final Integer offset, final Integer count) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZREVRANGEBYSCORE) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrevrangeByScore(key, max, min, offset, count); - } - - }); + return execOp(key, OpName.ZREVRANGEBYSCORE, client -> client.zrevrangeByScore(key, max, min, offset, count)); } @Override public Set zrangeByScoreWithScores(String key, String min, String max) { - return d_zrangeByScoreWithScores(key, min, max).getResult(); - } - - public OperationResult> d_zrangeByScoreWithScores(final String key, final String min, final String max) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZRANGEBYSCOREWITHSCORES) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrangeByScoreWithScores(key, min, max); - } - - }); + return execOp(key, OpName.ZRANGEBYSCOREWITHSCORES, client -> client.zrangeByScoreWithScores(key, min, max)); } @Override public Set zrevrangeByScoreWithScores(String key, String max, String min) { - return d_zrevrangeByScoreWithScores(key, max, min).getResult(); - } - - public OperationResult> d_zrevrangeByScoreWithScores(final String key, final String max, - final String min) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZREVRANGEBYSCOREWITHSCORES) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrevrangeByScoreWithScores(key, max, min); - } - - }); + return execOp(key, OpName.ZREVRANGEBYSCOREWITHSCORES, client -> client.zrevrangeByScoreWithScores(key, max, min)); } @Override public Set zrangeByScoreWithScores(String key, String min, String max, int offset, int count) { - return d_zrangeByScoreWithScores(key, min, max, offset, count).getResult(); - } - - public OperationResult> d_zrangeByScoreWithScores(final String key, final String min, final String max, - final Integer offset, final Integer count) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZRANGEBYSCOREWITHSCORES) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrangeByScoreWithScores(key, min, max, offset, count); - } - - }); + return execOp(key, OpName.ZRANGEBYSCOREWITHSCORES, client -> client.zrangeByScoreWithScores(key, min, max, offset, count)); } @Override public Set zrevrangeByScoreWithScores(String key, double max, double min, int offset, int count) { - return d_zrevrangeByScoreWithScores(key, max, min, offset, count).getResult(); - } - - public OperationResult> d_zrevrangeByScoreWithScores(final String key, final Double max, - final Double min, final Integer offset, final Integer count) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZREVRANGEBYSCOREWITHSCORES) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrevrangeByScoreWithScores(key, max, min, offset, count); - } - - }); + return execOp(key, OpName.ZREVRANGEBYSCOREWITHSCORES, client -> client.zrevrangeByScoreWithScores(key, max, min, offset, count)); } @Override public Set zrevrangeByScoreWithScores(String key, String max, String min, int offset, int count) { - return d_zrevrangeByScoreWithScores(key, max, min, offset, count).getResult(); - } - - public OperationResult> d_zrevrangeByScoreWithScores(final String key, final String max, - final String min, final Integer offset, final Integer count) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZREVRANGEBYSCOREWITHSCORES) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrevrangeByScoreWithScores(key, max, min, offset, count); - } - - }); + return execOp(key, OpName.ZREVRANGEBYSCOREWITHSCORES, client -> client.zrevrangeByScoreWithScores(key, max, min, offset, count)); } @Override public Long zremrangeByScore(String key, String start, String end) { - return d_zremrangeByScore(key, start, end).getResult(); + return execOp(key, OpName.ZREMRANGEBYSCORE, client -> client.zremrangeByScore(key, start, end)); } @Override public Long zlexcount(String key, String min, String max) { - return d_zlexcount(key, min, max).getResult(); - } - - public OperationResult d_zlexcount(final String key, final String min, final String max) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.ZLEXCOUNT) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.zlexcount(key, min, max); - } - - }); + return execOp(key, OpName.ZLEXCOUNT, client -> client.zlexcount(key, min, max)); } @Override public Set zrangeByLex(String key, String min, String max) { - return d_zrangeByLex(key, min, max).getResult(); - } - - public OperationResult> d_zrangeByLex(final String key, final String min, final String max) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZRANGEBYLEX) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrangeByLex(key, min, max); - } - - }); + return execOp(key, OpName.ZRANGEBYLEX, client -> client.zrangeByLex(key, min, max)); } @Override public Set zrangeByLex(String key, String min, String max, int offset, int count) { - return d_zrangeByLex(key, min, max, offset, count).getResult(); + return execOp(key, OpName.ZRANGEBYLEX, client -> client.zrangeByLex(key, min, max, offset, count)); } - public OperationResult> d_zrangeByLex(final String key, final String min, final String max, - final int offset, final int count) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZRANGEBYLEX) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrangeByLex(key, min, max, offset, count); - } - - }); - } - - @Override public Long zremrangeByLex(String key, String min, String max) { - return d_zremrangeByLex(key, min, max).getResult(); - } - - public OperationResult d_zremrangeByLex(final String key, final String min, final String max) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.ZREMRANGEBYLEX) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.zremrangeByLex(key, min, max); - } - - }); - } - - - public OperationResult d_zremrangeByScore(final String key, final String start, final String end) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.ZREMRANGEBYSCORE) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.zremrangeByScore(key, start, end); - } - - }); + return execOp(key, OpName.ZREMRANGEBYLEX, client -> client.zremrangeByLex(key, min, max)); } @Override - public List blpop(int timeout, String key) { - return d_blpop(timeout, key).getResult(); - } - - public OperationResult> d_blpop(final int timeout, final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.BLPOP) { - - @Override - public List execute(Jedis client, ConnectionContext state) { - return client.blpop(timeout, key); - } - - }); - } - - @Override - public List brpop(int timeout, String key) { - return d_brpop(timeout, key).getResult(); - } - - public OperationResult> d_brpop(final int timeout, final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.BRPOP) { - - @Override - public List execute(Jedis client, ConnectionContext state) { - return client.brpop(timeout, key); - } - - }); - } - - @Override - public String echo(String string) { - return d_echo(string).getResult(); - } - - public OperationResult d_echo(final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.ECHO) { - - @Override - public String execute(Jedis client, ConnectionContext state) { - return client.echo(key); - } - - }); - } - - @Override - public Long move(String key, int dbIndex) { - return d_move(key, dbIndex).getResult(); - } - - public OperationResult d_move(final String key, final Integer dbIndex) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.MOVE) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.move(key, dbIndex); - } - - }); + public List blpop(int timeout, String key) { + return execOp(key, OpName.BLPOP, client -> client.blpop(timeout, key)); } @Override - public Long bitcount(String key) { - return d_bitcount(key).getResult(); + public List brpop(int timeout, String key) { + return execOp(key, OpName.BRPOP, client -> client.brpop(timeout, key)); } - public OperationResult d_bitcount(final String key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.BITCOUNT) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.bitcount(key); - } + @Override + public String echo(String string) { + return execOp(string, OpName.ECHO, client -> client.echo(string)); + } - }); + @Override + public Long move(String key, int dbIndex) { + return execOp(key, OpName.MOVE, client -> client.move(key, dbIndex)); } + @Override + public Long bitcount(String key) { + return execOp(key, OpName.BITCOUNT, client -> client.bitcount(key)); + } @Override public Long pfadd(String key, String... elements) { @@ -2654,44 +1328,31 @@ public long pfcount(String key) { @Override public Long bitcount(String key, long start, long end) { - return d_bitcount(key, start, end).getResult(); - } - - public OperationResult d_bitcount(final String key, final Long start, final Long end) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.BITCOUNT) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.bitcount(key, start, end); - } - - }); + return execOp(key, OpName.BITCOUNT, client -> client.bitcount(key, start, end)); } /** * MULTI-KEY COMMANDS */ - @Override public List blpop(int timeout, String... keys) { - throw new UnsupportedOperationException("not yet implemented"); + return execMultiOp(keys, OpName.BLPOP, client -> client.blpop(timeout, keys)); } @Override public List brpop(int timeout, String... keys) { - throw new UnsupportedOperationException("not yet implemented"); + return execMultiOp(keys, OpName.BRPOP, client -> client.brpop(timeout, keys)); } @Override - public List blpop(String... args) { - throw new UnsupportedOperationException("not yet implemented"); + public List blpop(String... keys) { + return execMultiOp(keys, OpName.BLPOP, client -> client.blpop(keys)); } @Override - public List brpop(String... args) { - throw new UnsupportedOperationException("not yet implemented"); + public List brpop(String... keys) { + return execMultiOp(keys, OpName.BRPOP, client -> client.brpop(keys)); } @Override @@ -2730,7 +1391,7 @@ public Set execute(Jedis client, ConnectionContext state) throws DynoExc @Override public Long pexpire(String key, long milliseconds) { - throw new UnsupportedOperationException("not yet implemented"); + return execOp(key, OpName.PEXPIRE, client -> client.pexpire(key, milliseconds)); } /** @@ -2744,148 +1405,86 @@ public Long pexpire(String key, long milliseconds) { */ @Override public List mget(String... keys) { - return d_mget(keys).getResult(); - } - - public OperationResult> d_mget(final String... keys) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - - return connPool.executeWithFailover(new MultiKeyOperation>(Arrays.asList(keys), OpName.MGET) { - @Override - public List execute(Jedis client, ConnectionContext state) { - return client.mget(keys); - } - }); + return execMultiOp(keys, OpName.MGET, client -> client.mget(keys)); } else { - return connPool.executeWithFailover( - new CompressionValueMultiKeyOperation>(Arrays.asList(keys), OpName.MGET) { - @Override - public List execute(final Jedis client, final ConnectionContext state) - throws DynoException { - return new ArrayList(CollectionUtils.transform(client.mget(keys), - new CollectionUtils.Transform() { - @Override - public String get(String s) { - return decompressValue(state, s); - } - })); - } - }); + return execCompressMultiOp( + keys, + OpName.MGET, + (client, state, op) -> new ArrayList<>(CollectionUtils.transform(client.mget(keys), + s -> op.decompressValue(state, s))) + ); } } - @Override - public Long exists(String... arg0) { - return d_exists(arg0).getResult(); - } - - public OperationResult d_exists(final String... arg0) { - return connPool.executeWithFailover(new MultiKeyOperation(Arrays.asList(arg0), OpName.EXISTS) { - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.exists(arg0); - } - }); + public Long exists(String... keys) { + return execMultiOp(keys, OpName.EXISTS, client -> client.exists(keys)); } @Override public Long del(String... keys) { - return d_del(keys).getResult(); + return execMultiOp(keys, OpName.DEL, client -> client.del(keys)); } @Override public Long unlink(String... keys) { - throw new UnsupportedOperationException("not yet implemented"); - } - - public OperationResult d_del(final String... keys) { - - return connPool.executeWithFailover(new MultiKeyOperation(Arrays.asList(keys), OpName.DEL) { - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.del(keys); - } - }); + return execMultiOp(keys, OpName.UNLINK, client -> client.unlink(keys)); } - @Override public Long msetnx(String... keysvalues) { - return d_msetnx(keysvalues).getResult(); - } - - public OperationResult d_msetnx(final String... keysvalues) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - - return connPool.executeWithFailover(new MultiKeyOperation(Arrays.asList(keysvalues), OpName.MSETNX) { - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.msetnx(keysvalues); - } - }); + return execMultiOp(keysvalues, OpName.MSETNX, client -> client.msetnx(keysvalues)); } else { - return connPool.executeWithFailover(new CompressionValueMultiKeyOperation(Arrays.asList(keysvalues), OpName.MSETNX) { - @Override - public Long execute(final Jedis client, final ConnectionContext state) { - return client.msetnx(compressMultiKeyValue(state, keysvalues)); - } - }); + return execCompressMultiOp( + keysvalues, + OpName.MSETNX, + (client, state, op) -> client.msetnx(op.compressMultiKeyValue(state, keysvalues)) + ); } } @Override public String mset(String... keysvalues) { - return d_mset(keysvalues).getResult(); - } - - public OperationResult d_mset(final String... keysvalues) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - - return connPool.executeWithFailover(new MultiKeyOperation(Arrays.asList(keysvalues), OpName.MSET) { - @Override - public String execute(Jedis client, ConnectionContext state) { - - return client.mset(keysvalues); - } - }); + return execOp(keysvalues[0], OpName.MSET, client -> client.mset(keysvalues)); } else { - return connPool.executeWithFailover(new CompressionValueMultiKeyOperation(Arrays.asList(keysvalues), OpName.MSET) { - @Override - public String execute(final Jedis client, final ConnectionContext state) { - return client.mset(compressMultiKeyValue(state, keysvalues)); - } - }); + return execCompressMultiOp( + keysvalues, + OpName.MSET, + (client, state, op) -> client.mset(op.compressMultiKeyValue(state, keysvalues)) + ); } } @Override public Set sinter(String... keys) { - throw new UnsupportedOperationException("not yet implemented"); + return execMultiOp(keys, OpName.SINTER, client -> client.sinter(keys)); } public Long sinterstore(final String dstkey, final String... keys) { - throw new UnsupportedOperationException("not yet implemented"); + return execOp(dstkey, OpName.SINTERSTORE, client -> client.sinterstore(dstkey, keys)); } @Override public Long sort(String key, SortingParams sortingParameters, String dstkey) { - throw new UnsupportedOperationException("not yet implemented"); + return execOp(key, OpName.SORT, client -> client.sort(key, sortingParameters, dstkey)); } @Override public Long sort(String key, String dstkey) { - throw new UnsupportedOperationException("not yet implemented"); + return execOp(key, OpName.SORT, client -> client.sort(key, dstkey)); } @Override public Set sunion(String... keys) { - throw new UnsupportedOperationException("not yet implemented"); + return execMultiOp(keys, OpName.SUNION, client -> client.sunion(keys)); } @Override public Long sunionstore(String dstkey, String... keys) { - throw new UnsupportedOperationException("not yet implemented"); + return execOp(dstkey, OpName.SUNIONSTORE, client -> client.sunionstore(dstkey, keys)); } @Override @@ -2894,1247 +1493,1341 @@ public String watch(String... keys) { } @Override - public Long del(byte[]... keys) { + public String unwatch() { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long unlink(byte[]... keys) { + public Long zinterstore(String dstkey, String... sets) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long exists(byte[]... keys) { + public Long zinterstore(String dstkey, ZParams params, String... sets) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public List blpop(int timeout, byte[]... keys) { + public Set zrevrangeByLex(String key, String max, String min) { + return execOp(key, OpName.ZREVRANGEBYLEX, client -> client.zrevrangeByLex(key, max, min)); + } + + @Override + public Set zrevrangeByLex(String key, String max, String min, int offset, int count) { + return execOp(key, OpName.ZREVRANGEBYLEX, client -> client.zrevrangeByLex(key, max, min, offset, count)); + } + + @Override + public Long zunionstore(String dstkey, String... sets) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public List brpop(int timeout, byte[]... keys) { + public Long zunionstore(String dstkey, ZParams params, String... sets) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public List blpop(byte[]... args) { + public String brpoplpush(String source, String destination, int timeout) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public List brpop(byte[]... args) { + public Long publish(String channel, String message) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Set keys(byte[] pattern) { + public void subscribe(JedisPubSub jedisPubSub, String... channels) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public List mget(byte[]... keys) { - return d_mget(keys).getResult(); + public void psubscribe(JedisPubSub jedisPubSub, String... patterns) { + throw new UnsupportedOperationException("not yet implemented"); } - public OperationResult> d_mget(final byte[]... keys) { - if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + @Override + public String randomKey() { + throw new UnsupportedOperationException("not yet implemented"); + } - return connPool.executeWithFailover(new MultiKeyOperation>(Arrays.asList(keys), OpName.MGET) { - @Override - public List execute(Jedis client, ConnectionContext state) { - return client.mget(keys); - } - }); - } else { - return connPool.executeWithFailover( - new CompressionValueMultiKeyOperation>(Arrays.asList(keys), OpName.MGET) { - @Override - public List execute(final Jedis client, final ConnectionContext state) - throws DynoException { - return new ArrayList<>(CollectionUtils.transform(client.mget(keys), - new CollectionUtils.Transform() { - @Override - public byte[] get(byte[] s) { - return decompressValue(state, String.valueOf(s)).getBytes(); - } - })); - } - }); + @Override + public Long bitop(BitOP op, String destKey, String... srcKeys) { + throw new UnsupportedOperationException("not yet implemented"); + } + + /** + * NOT SUPPORTED ! Use {@link #dyno_scan(CursorBasedResult, int, String...)} + * instead. + * + * @param cursor + * @return nothing -- throws UnsupportedOperationException when invoked + * @see #dyno_scan(CursorBasedResult, int, String...) + */ + @Override + public ScanResult scan(String cursor) { + throw new UnsupportedOperationException("Not supported - use dyno_scan(String, CursorBasedResult"); + } + + public CursorBasedResult dyno_scan(String... pattern) { + return this.dyno_scan(10, pattern); + } + + public CursorBasedResult dyno_scan(int count, String... pattern) { + return this.dyno_scan(null, count, pattern); + } + + public CursorBasedResult dyno_scan(CursorBasedResult cursor, int count, String... pattern) { + if (cursor == null) { + // Create a temporary cursor context which will maintain a map of token to rack + cursor = new CursorBasedResultImpl<>(new LinkedHashMap>()); } + final Map> results = new LinkedHashMap<>(); + + List>> opResults = scatterGatherScan(cursor, count, pattern); + for (OperationResult> opResult : opResults) { + results.put(opResult.getNode().getHostAddress(), opResult.getResult()); + } + return new CursorBasedResultImpl<>(results, ((TokenRackMapper) cursor).getTokenRackMap()); } @Override - public String mset(byte[]... keysvalues) { + public String pfmerge(String destkey, String... sourcekeys) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long msetnx(byte[]... keysvalues) { + public long pfcount(String... keys) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public String rename(byte[] oldkey, byte[] newkey) { + public Long touch(String... keys) { throw new UnsupportedOperationException("not yet implemented"); } + @Override - public Long renamenx(byte[] oldkey, byte[] newkey) { + public ScanResult scan(String arg0, ScanParams arg1) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public byte[] rpoplpush(byte[] srckey, byte[] dstkey) { + public Long bitpos(String arg0, boolean arg1) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Set sdiff(byte[]... keys) { + public Long bitpos(String arg0, boolean arg1, BitPosParams arg2) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long sdiffstore(byte[] dstkey, byte[]... keys) { + public Long geoadd(String arg0, Map arg1) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Set sinter(byte[]... keys) { + public Long geoadd(String arg0, double arg1, double arg2, String arg3) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long sinterstore(byte[] dstkey, byte[]... keys) { + public Double geodist(String arg0, String arg1, String arg2) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long smove(byte[] srckey, byte[] dstkey, byte[] member) { + public Double geodist(String arg0, String arg1, String arg2, GeoUnit arg3) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long sort(byte[] key, SortingParams sortingParameters, byte[] dstkey) { + public List geohash(String arg0, String... arg1) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long sort(byte[] key, byte[] dstkey) { + public List geopos(String arg0, String... arg1) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Set sunion(byte[]... keys) { + public List georadius(String arg0, double arg1, double arg2, double arg3, GeoUnit arg4) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long sunionstore(byte[] dstkey, byte[]... keys) { + public List georadiusReadonly(String key, double longitude, double latitude, double radius, GeoUnit unit) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public String watch(byte[]... keys) { + public List georadius(String arg0, double arg1, double arg2, double arg3, GeoUnit arg4, + GeoRadiusParam arg5) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public String unwatch() { + public List georadiusReadonly(String key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long zinterstore(byte[] dstkey, byte[]... sets) { + public List georadiusByMember(String arg0, String arg1, double arg2, GeoUnit arg3) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long zinterstore(byte[] dstkey, ZParams params, byte[]... sets) { + public List georadiusByMemberReadonly(String key, String member, double radius, GeoUnit unit) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long zunionstore(byte[] dstkey, byte[]... sets) { + public List georadiusByMember(String arg0, String arg1, double arg2, GeoUnit arg3, + GeoRadiusParam arg4) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long zunionstore(byte[] dstkey, ZParams params, byte[]... sets) { + public List georadiusByMemberReadonly(String key, String member, double radius, GeoUnit unit, GeoRadiusParam param) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public byte[] brpoplpush(byte[] source, byte[] destination, int timeout) { + public List bitfield(String key, String... arguments) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long publish(byte[] channel, byte[] message) { + public Long hstrlen(String key, String field) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public void subscribe(BinaryJedisPubSub jedisPubSub, byte[]... channels) { + public ScanResult> hscan(String arg0, String arg1, ScanParams arg2) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public void psubscribe(BinaryJedisPubSub jedisPubSub, byte[]... patterns) { + public Long zadd(String arg0, Map arg1, ZAddParams arg2) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public byte[] randomBinaryKey() { + public Double zincrby(String arg0, double arg1, String arg2, ZIncrByParams arg3) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long bitop(BitOP op, byte[] destKey, byte[]... srcKeys) { + public ScanResult zscan(String arg0, String arg1, ScanParams arg2) { throw new UnsupportedOperationException("not yet implemented"); } + /******************* End Jedis String Commands **************/ + + + + /******************* Jedis Binary Commands **************/ + @Override - public String pfmerge(byte[] destkey, byte[]... sourcekeys) { - throw new UnsupportedOperationException("not yet implemented"); + public Long append(final byte[] key, final byte[] value) { + return execOp(key, OpName.APPEND, client -> client.append(key, value)); } @Override - public Long pfcount(byte[]... keys) { - throw new UnsupportedOperationException("not yet implemented"); + public Long decr(final byte[] key) { + return execOp(key, OpName.DECR, client -> client.decr(key)); } @Override - public Long touch(byte[]... keys) { - throw new UnsupportedOperationException("not yet implemented"); + public Long decrBy(final byte[] key, final long delta) { + return execOp(key, OpName.DECRBY, client -> client.decrBy(key, delta)); } @Override - public Long zinterstore(String dstkey, String... sets) { - throw new UnsupportedOperationException("not yet implemented"); + public Long del(final byte[] key) { + return execOp(key, OpName.DEL, client -> client.del(key)); } @Override - public Long zinterstore(String dstkey, ZParams params, String... sets) { + public Long unlink(byte[] key) { + return execOp(key, OpName.UNLINK, client -> client.unlink(key)); + } + + public byte[] dump(final byte[] key) { + return execOp(key, OpName.DUMP, client -> client.dump(key)); + } + + @Override + public String restore(byte[] key, int ttl, byte[] serializedValue) { + return execOp(key, OpName.RESTORE, client -> client.restore(key, ttl, serializedValue)); + } + + @Override + public String restoreReplace(byte[] key, int ttl, byte[] serializedValue) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Set zrevrangeByLex(String key, String max, String min) { - return d_zrevrangeByLex(key, max, min).getResult(); + public Boolean exists(final byte[] key) { + return execOp(key, OpName.EXISTS, client -> client.exists(key)); } - public OperationResult> d_zrevrangeByLex(final String key, final String max, final String min) { + @Override + public Long expire(final byte[] key, final int seconds) { + return execOp(key, OpName.EXPIRE, client -> client.expire(key, seconds)); + } - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZREVRANGEBYLEX) { + @Override + public Long expireAt(final byte[] key, final long unixTime) { + return execOp(key, OpName.EXPIREAT, client -> client.expireAt(key, unixTime)); + } - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrangeByLex(key, max, min); - } + @Override + public byte[] get(final byte[] key) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.GET, client -> client.get(key)); + } else { + return execCompressOp(key, OpName.GET, (client, state, op) -> op.decompressValue(client.get(key), state)); + } + } - }); + @Override + public Boolean getbit(final byte[] key, final long offset) { + return execOp(key, OpName.GETBIT, client -> client.getbit(key, offset)); + } + + @Override + public byte[] getrange(final byte[] key, final long startOffset, final long endOffset) { + return execOp(key, OpName.GETRANGE, client -> client.getrange(key, startOffset, endOffset)); + } + + @Override + public byte[] getSet(final byte[] key, final byte[] value) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.GETSET, client -> client.getSet(key, value)); + } else { + return execCompressOp( + key, + OpName.GETSET, + (client, state, op) -> op.decompressValue(client.getSet(key, op.compressValue(value, state)), state) + ); + } + } + + @Override + public Long hdel(final byte[] key, final byte[]... fields) { + return execOp(key, OpName.HDEL, client -> client.hdel(key, fields)); + } + + @Override + public Boolean hexists(final byte[] key, final byte[] field) { + return execOp(key, OpName.HEXISTS, client -> client.hexists(key, field)); + } + + @Override + public byte[] hget(final byte[] key, final byte[] field) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.HGET, client -> client.hget(key, field)); + } else { + return execCompressOp( + key, + OpName.HGET, + (client, state, op) -> op.decompressValue(client.hget(key, field), state) + ); + } + } + + @Override + public Map hgetAll(final byte[] key) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.HGETALL, client -> client.hgetAll(key)); + } else { + return execCompressOp( + key, + OpName.HGETALL, + (client, state, op) -> CollectionUtils.transform(client.hgetAll(key), + (key1, val) -> op.decompressValue(val, state)) + ); + } } @Override - public Set zrevrangeByLex(String key, String max, String min, int offset, int count) { - return d_zrevrangeByLex(key, max, min, offset, count).getResult(); + public Long hincrBy(final byte[] key, final byte[] field, final long value) { + return execOp(key, OpName.HINCRBY, client -> client.hincrBy(key, field, value)); } - public OperationResult> d_zrevrangeByLex(final String key, final String max, final String min, - final int offset, final int count) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZREVRANGEBYLEX) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.zrangeByLex(key, max, min, offset, count); - } - - }); + /* not supported by RedisPipeline 2.7.3 */ + public Double hincrByFloat(final byte[] key, final byte[] field, final double value) { + return execOp(key, OpName.HINCRBYFLOAT, client -> client.hincrByFloat(key, field, value)); } @Override - public Long zunionstore(String dstkey, String... sets) { - throw new UnsupportedOperationException("not yet implemented"); + public Long hsetnx(final byte[] key, final byte[] field, final byte[] value) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.HSETNX, client -> client.hsetnx(key, field, value)); + } else { + return execCompressOp( + key, + OpName.HSETNX, + (client, state, op) -> client.hsetnx(key, field, op.compressValue(value, state)) + ); + } } @Override - public Long zunionstore(String dstkey, ZParams params, String... sets) { - throw new UnsupportedOperationException("not yet implemented"); + public Set hkeys(final byte[] key) { + return execOp(key, OpName.HKEYS, client -> client.hkeys(key)); } @Override - public String brpoplpush(String source, String destination, int timeout) { - throw new UnsupportedOperationException("not yet implemented"); + public ScanResult> hscan(final byte[] key, final byte[] cursor) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.HSCAN, client -> client.hscan(key, cursor)); + } else { + return execCompressOp( + key, + OpName.HSCAN, + (client, state, op) -> + new ScanResult<>(cursor, new ArrayList(CollectionUtils.transform( + client.hscan(key, cursor).getResult(), + entry -> { + entry.setValue(op.decompressValue(entry.getValue(), state)); + return entry; + }))) + ); + } } @Override - public Long publish(String channel, String message) { - throw new UnsupportedOperationException("not yet implemented"); + public Long hlen(final byte[] key) { + return execOp(key, OpName.HLEN, client -> client.hlen(key)); } @Override - public void subscribe(JedisPubSub jedisPubSub, String... channels) { - throw new UnsupportedOperationException("not yet implemented"); + public List hmget(final byte[] key, final byte[]... fields) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.HMGET, client -> client.hmget(key, fields)); + } else { + return execCompressOp( + key, + OpName.HMGET, + (client, state, op) -> + new ArrayList<>(CollectionUtils.transform(client.hmget(key, fields), + s -> op.decompressValue(s, state))) + ); + } } @Override - public void psubscribe(JedisPubSub jedisPubSub, String... patterns) { - throw new UnsupportedOperationException("not yet implemented"); + public String hmset(final byte[] key, final Map hash) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.HMSET, client -> client.hmset(key, hash)); + } else { + return execCompressOp( + key, + OpName.HMSET, + (client, state, op) -> + client.hmset(key, CollectionUtils.transform(hash, (key1, val) -> op.compressValue(val, state))) + ); + } } @Override - public String randomKey() { - throw new UnsupportedOperationException("not yet implemented"); + public Long hset(final byte[] key, final byte[] field, final byte[] value) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.HSET, client -> client.hset(key, field, value)); + } else { + return execCompressOp( + key, + OpName.HSET, + (client, state, op) -> client.hset(key, field, op.compressValue(value, state)) + ); + } } @Override - public Long bitop(BitOP op, String destKey, String... srcKeys) { - throw new UnsupportedOperationException("not yet implemented"); + public Long hset(byte[] key, Map hash) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.HSET, client -> client.hset(key, hash)); + } else { + throw new UnsupportedOperationException("not yet implemented"); + } } - /******************* Jedis Binary Commands **************/ @Override - public String set(final byte[] key, final byte[] value) { - return d_set(key, value).getResult(); + public List hvals(final byte[] key) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.HVALS, client -> client.hvals(key)); + } else { + return execCompressOp( + key, + OpName.HVALS, + (client, state, op) -> + new ArrayList<>(CollectionUtils.transform(client.hvals(key), s -> op.decompressValue(s, state))) + ); + } } - public OperationResult d_set(final byte[] key, final byte[] value) { - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.SET) { - @Override - public String execute(Jedis client, ConnectionContext state) throws DynoException { - return client.set(key, value); - } - }); + @Override + public Long incr(final byte[] key) { + return execOp(key, OpName.INCR, client -> client.incr(key)); } @Override - public byte[] get(final byte[] key) { - return d_get(key).getResult(); + public Long incrBy(final byte[] key, final long delta) { + return execOp(key, OpName.INCRBY, client -> client.incrBy(key, delta)); } - public OperationResult d_get(final byte[] key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.GET) { - @Override - public byte[] execute(Jedis client, ConnectionContext state) throws DynoException { - return client.get(key); - } - }); + public Double incrByFloat(final byte[] key, final double increment) { + return execOp(key, OpName.INCRBYFLOAT, client -> client.incrByFloat(key, increment)); } @Override - public String setex(final byte[] key, final int seconds, final byte[] value) { - return d_setex(key, seconds, value).getResult(); + public byte[] lindex(final byte[] key, final long index) { + return execOp(key, OpName.LINDEX, client -> client.lindex(key, index)); } - public OperationResult d_setex(final byte[] key, final Integer seconds, final byte[] value) { - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.SETEX) { - @Override - public String execute(Jedis client, ConnectionContext state) throws DynoException { - return client.setex(key, seconds, value); - } - }); + @Override + public Long linsert(final byte[] key, final ListPosition where, final byte[] pivot, final byte[] value) { + return execOp(key, OpName.LINSERT, client -> client.linsert(key, where, pivot, value)); } @Override - public String psetex(byte[] key, long milliseconds, byte[] value) { - return d_psetex(key, milliseconds, value).getResult(); + public Long llen(final byte[] key) { + return execOp(key, OpName.LLEN, client -> client.llen(key)); } - public OperationResult d_psetex(final byte[] key, final Long milliseconds, final byte[] value) { - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.PSETEX) { - @Override - public String execute(Jedis client, ConnectionContext state) throws DynoException { - return client.psetex(key, milliseconds, value); - } - }); + @Override + public byte[] lpop(final byte[] key) { + return execOp(key, OpName.LPOP, client -> client.lpop(key)); } @Override - public String set(final byte[] key, final byte[] value, final SetParams setParams) { - return d_set(key, value, setParams).getResult(); + public Long lpush(final byte[] key, final byte[]... values) { + return execOp(key, OpName.LPUSH, client -> client.lpush(key, values)); } - public OperationResult d_set(final byte[] key, final byte[] value, final SetParams setParams) { - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.SET) { - @Override - public String execute(Jedis client, ConnectionContext state) throws DynoException { - return client.set(key, value, setParams); - } - }); + @Override + public Long lpushx(final byte[] key, final byte[]... values) { + return execOp(key, OpName.LPUSHX, client -> client.lpushx(key, values)); } @Override - public Boolean exists(final byte[] key) { - return d_exists(key).getResult(); + public List lrange(final byte[] key, final long start, final long end) { + return execOp(key, OpName.LRANGE, client -> client.lrange(key, start, end)); } - public OperationResult d_exists(final byte[] key) { - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.EXISTS) { + @Override + public Long lrem(final byte[] key, final long count, final byte[] value) { + return execOp(key, OpName.LREM, client -> client.lrem(key, count, value)); + } - @Override - public Boolean execute(Jedis client, ConnectionContext state) { - return client.exists(key); - } - }); + @Override + public String lset(final byte[] key, final long index, final byte[] value) { + return execOp(key, OpName.LSET, client -> client.lset(key, index, value)); } @Override - public Long persist(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public String ltrim(final byte[] key, final long start, final long end) { + return execOp(key, OpName.LTRIM, client -> client.ltrim(key, start, end)); } @Override - public String type(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public Long persist(final byte[] key) { + return execOp(key, OpName.PERSIST, client -> client.persist(key)); } @Override - public byte[] dump(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public Long pexpireAt(final byte[] key, final long millisecondsTimestamp) { + return execOp(key, OpName.PEXPIREAT, client -> client.pexpireAt(key, millisecondsTimestamp)); } @Override - public String restore(byte[] key, int ttl, byte[] serializedValue) { - throw new UnsupportedOperationException("not yet implemented"); + public Long pttl(final byte[] key) { + return execOp(key, OpName.PTTL, client -> client.pttl(key)); } @Override - public String restoreReplace(byte[] key, int ttl, byte[] serializedValue) { + public Long touch(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long expire(final byte[] key, final int seconds) { - return d_expire(key, seconds).getResult(); + public String rename(byte[] oldkey, byte[] newkey) { + return execOp(oldkey, OpName.RENAME, client -> client.rename(oldkey, newkey)); } - public OperationResult d_expire(final byte[] key, final int seconds) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.EXPIRE) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.expire(key, seconds); - } - }); + @Override + public Long renamenx(byte[] oldkey, byte[] newkey) { + return execOp(oldkey, OpName.RENAMENX, client -> client.renamenx(oldkey, newkey)); } + public String restore(final byte[] key, final Integer ttl, final byte[] serializedValue) { + return execOp(key, OpName.RESTORE, client -> client.restore(key, ttl, serializedValue)); + } @Override - public Long pexpire(byte[] key, final long milliseconds) { - throw new UnsupportedOperationException("not yet implemented"); + public byte[] rpop(final byte[] key) { + return execOp(key, OpName.RPOP, client -> client.rpop(key)); } @Override - public Long expireAt(final byte[] key, final long unixTime) { - return d_expireAt(key, unixTime).getResult(); + public byte[] rpoplpush(final byte[] srckey, final byte[] dstkey) { + return execOp(srckey, OpName.RPOPLPUSH, client -> client.rpoplpush(srckey, dstkey)); } - public OperationResult d_expireAt(final byte[] key, final long unixTime) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.EXPIREAT) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.expireAt(key, unixTime); - } - - }); + @Override + public Long rpush(final byte[] key, final byte[]... values) { + return execOp(key, OpName.RPUSH, client -> client.rpush(key, values)); } @Override - public Long pexpireAt(byte[] key, long millisecondsTimestamp) { - throw new UnsupportedOperationException("not yet implemented"); + public Long rpushx(final byte[] key, final byte[]... values) { + return execOp(key, OpName.RPUSHX, client -> client.rpushx(key, values)); } @Override - public Long ttl(final byte[] key) { - return d_ttl(key).getResult(); + public Long sadd(final byte[] key, final byte[]... members) { + return execOp(key, OpName.SADD, client -> client.sadd(key, members)); } - public OperationResult d_ttl(final byte[] key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.TTL) { + @Override + public Long scard(final byte[] key) { + return execOp(key, OpName.SCARD, client -> client.scard(key)); + } - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.ttl(key); - } + @Override + public Set sdiff(final byte[]... keys) { + return execOp(keys[0], OpName.SDIFF, client -> client.sdiff(keys)); + } - }); + @Override + public Long sdiffstore(final byte[] dstkey, final byte[]... keys) { + return execOp(dstkey, OpName.SDIFFSTORE, client -> client.sdiffstore(dstkey, keys)); } @Override - public Long pttl(byte[] key) { - return d_pttl(key).getResult(); + public String set(final byte[] key, final byte[] value) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.SET, client -> client.set(key, value)); + } else { + return execCompressOp( + key, + OpName.SET, + (client, state, op) -> client.set(key, op.compressValue(value, state)) + ); + } } - public OperationResult d_pttl(final byte[] key) { - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.PTTL) { - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.pttl(key); - } + @Deprecated + /** + * use {@link set(byte[], byte[], SetParams)} instead + */ + public String set(final byte[] key, final byte[] value, final String nxxx, final String expx, final long time) { + SetParams setParams = SetParams.setParams(); + if (nxxx.equalsIgnoreCase("NX")) { + setParams.nx(); + } else if (nxxx.equalsIgnoreCase("XX")) { + setParams.xx(); + } + if (expx.equalsIgnoreCase("EX")) { + setParams.ex((int) time); + } else if (expx.equalsIgnoreCase("PX")) { + setParams.px(time); + } - }); + return d_set(key, value, setParams); } - @Override - public Long touch(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public String set(final byte[] key, final byte[] value, final SetParams setParams) { + return d_set(key, value, setParams); } - @Override - public Boolean setbit(byte[] key, long offset, boolean value) { - throw new UnsupportedOperationException("not yet implemented"); + public String d_set(final byte[] key, final byte[] value, final SetParams setParams) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) + return execOp(key, OpName.SET, client -> client.set(key, value, setParams)); + else { + return execCompressOp( + key, + OpName.SET, + (client, state, op) -> client.set(key, op.compressValue(value, state), setParams) + ); + } } @Override - public Boolean setbit(byte[] key, long offset, byte[] value) { - throw new UnsupportedOperationException("not yet implemented"); + public Boolean setbit(final byte[] key, final long offset, final boolean value) { + return execOp(key, OpName.SETBIT, client -> client.setbit(key, offset, value)); } @Override - public Boolean getbit(byte[] key, long offset) { - throw new UnsupportedOperationException("not yet implemented"); + public Boolean setbit(final byte[] key, final long offset, final byte[] value) { + return execOp(key, OpName.SETBIT, client -> client.setbit(key, offset, value)); } @Override - public Long setrange(byte[] key, long offset, byte[] value) { - throw new UnsupportedOperationException("not yet implemented"); + public String setex(final byte[] key, final int seconds, final byte[] value) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.SETEX, client -> client.setex(key, seconds, value)); + } else { + return execCompressOp( + key, + OpName.SETEX, + (client, state, op) -> client.setex(key, seconds, op.compressValue(value, state)) + ); + } } @Override - public byte[] getrange(byte[] key, long startOffset, long endOffset) { - throw new UnsupportedOperationException("not yet implemented"); + public String psetex(final byte[] key, final long milliseconds, final byte[] value) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.PSETEX, client -> client.psetex(key, milliseconds, value)); + } else { + return execCompressOp( + key, + OpName.PSETEX, + (client, state, op) -> client.psetex(key, milliseconds, op.compressValue(value, state)) + ); + } } @Override - public byte[] getSet(byte[] key, byte[] value) { - throw new UnsupportedOperationException("not yet implemented"); + public Long setnx(final byte[] key, final byte[] value) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.SETNX, client -> client.setnx(key, value)); + } else { + return execCompressOp( + key, + OpName.SETNX, + (client, state, op) -> client.setnx(key, op.compressValue(value, state)) + ); + } } @Override - public Long setnx(byte[] key, byte[] value) { - throw new UnsupportedOperationException("not yet implemented"); + public Long setrange(final byte[] key, final long offset, final byte[] value) { + return execOp(key, OpName.SETRANGE, client -> client.setrange(key, offset, value)); } @Override - public Long decrBy(byte[] key, long integer) { - throw new UnsupportedOperationException("not yet implemented"); + public Boolean sismember(final byte[] key, final byte[] member) { + return execOp(key, OpName.SISMEMBER, client -> client.sismember(key, member)); } @Override - public Long decr(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public Set smembers(final byte[] key) { + return execOp(key, OpName.SMEMBERS, client -> client.smembers(key)); } + public Long smove(final byte[] srckey, final byte[] dstkey, final byte[] member) { + return execOp(srckey, OpName.SMOVE, client -> client.smove(srckey, dstkey, member)); + } @Override - public Long incrBy(byte[] key, long integer) { - throw new UnsupportedOperationException("not yet implemented"); + public List sort(byte[] key) { + return execOp(key, OpName.SORT, client -> client.sort(key)); } @Override - public Double incrByFloat(byte[] key, double value) { - throw new UnsupportedOperationException("not yet implemented"); + public List sort(byte[] key, SortingParams sortingParameters) { + return execOp(key, OpName.SORT, client -> client.sort(key, sortingParameters)); } @Override - public Long incr(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public byte[] spop(final byte[] key) { + return execOp(key, OpName.SPOP, client -> client.spop(key)); } @Override - public Long append(byte[] key, byte[] value) { - throw new UnsupportedOperationException("not yet implemented"); + public Set spop(byte[] key, long count) { + return execOp(key, OpName.SPOP, client -> client.spop(key, count)); } @Override - public byte[] substr(byte[] key, int start, int end) { - throw new UnsupportedOperationException("not yet implemented"); + public byte[] srandmember(final byte[] key) { + return execOp(key, OpName.SRANDMEMBER, client -> client.srandmember(key)); } @Override - public Long hset(final byte[] key, final byte[] field, final byte[] value) { - return d_hset(key, field, value).getResult(); + public List srandmember(byte[] key, int count) { + return execOp(key, OpName.SRANDMEMBER, client -> client.srandmember(key, count)); } @Override - public Long hset(byte[] key, Map hash) { - throw new UnsupportedOperationException("not yet implemented"); + public Long srem(final byte[] key, final byte[]... members) { + return execOp(key, OpName.SREM, client -> client.srem(key, members)); } - public OperationResult d_hset(final byte[] key, final byte[] field, final byte[] value) { - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.HSET) { - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.hset(key, field, value); - } - }); + @Override + public ScanResult sscan(final byte[] key, final byte[] cursor) { + return execOp(key, OpName.SSCAN, client -> client.sscan(key, cursor)); } @Override - public byte[] hget(final byte[] key, final byte[] field) { - return d_hget(key, field).getResult(); + public ScanResult sscan(final byte[] key, final byte[] cursor, final ScanParams params) { + return execOp(key, OpName.SSCAN, client -> client.sscan(key, cursor, params)); } - public OperationResult d_hget(final byte[] key, final byte[] field) { - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.HGET) { - @Override - public byte[] execute(Jedis client, ConnectionContext state) throws DynoException { - return client.hget(key, field); - } - }); + @Override + public Long strlen(final byte[] key) { + return execOp(key, OpName.STRLEN, client -> client.strlen(key)); } @Override - public Long hsetnx(byte[] key, byte[] field, byte[] value) { - throw new UnsupportedOperationException("not yet implemented"); + public byte[] substr(byte[] key, int start, int end) { + return execOp(key, OpName.SUBSTR, client -> client.substr(key, start, end)); } @Override - public String hmset(final byte[] key, final Map hash) { - return d_hmset(key, hash).getResult(); + public Long ttl(final byte[] key) { + return execOp(key, OpName.TTL, client -> client.ttl(key)); } - public OperationResult d_hmset(final byte[] key, final Map hash) { - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.HMSET) { - @Override - public String execute(Jedis client, ConnectionContext state) { - return client.hmset(key, hash); - } - }); + @Override + public String type(final byte[] key) { + return execOp(key, OpName.TYPE, client -> client.type(key)); } @Override - public List hmget(final byte[] key, final byte[]... fields) { - return d_hmget(key, fields).getResult(); + public Long zadd(byte[] key, double score, byte[] member) { + return execOp(key, OpName.ZADD, client -> client.zadd(key, score, member)); } - public OperationResult> d_hmget(final byte[] key, final byte[]... fields) { - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.HMGET) { - @Override - public List execute(Jedis client, ConnectionContext state) { - return client.hmget(key, fields); - } - }); + @Override + public Long zadd(byte[] key, Map scoreMembers) { + return execOp(key, OpName.ZADD, client -> client.zadd(key, scoreMembers)); } @Override - public Long hincrBy(byte[] key, byte[] field, long value) { - throw new UnsupportedOperationException("not yet implemented"); + public Long zadd(byte[] key, double score, byte[] member, ZAddParams params) { + return execOp(key, OpName.ZADD, client -> client.zadd(key, score, member, params)); } @Override - public Double hincrByFloat(byte[] key, byte[] field, double value) { - throw new UnsupportedOperationException("not yet implemented"); + public Long zcard(final byte[] key) { + return execOp(key, OpName.ZCARD, client -> client.zcard(key)); } @Override - public Boolean hexists(byte[] key, byte[] field) { - throw new UnsupportedOperationException("not yet implemented"); + public Long zcount(final byte[] key, final double min, final double max) { + return execOp(key, OpName.ZCOUNT, client -> client.zcount(key, min, max)); } @Override - public Long hdel(final byte[] key, final byte[]... fields) { - return d_hdel(key, fields).getResult(); + public Long zcount(byte[] key, byte[] min, byte[] max) { + return execOp(key, OpName.ZCOUNT, client -> client.zcount(key, min, max)); } - public OperationResult d_hdel(final byte[] key, final byte[]... fields) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.HDEL) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.hdel(key, fields); - } - - }); + @Override + public Double zincrby(final byte[] key, final double score, final byte[] member) { + return execOp(key, OpName.ZINCRBY, client -> client.zincrby(key, score, member)); } @Override - public Long hlen(final byte[] key) { - return d_hlen(key).getResult(); + public Set zrange(byte[] key, long start, long end) { + return execOp(key, OpName.ZRANGE, client -> client.zrange(key, start, end)); } - public OperationResult d_hlen(final byte[] key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.HLEN) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.hlen(key); - } - - }); + @Override + public Long zrank(final byte[] key, final byte[] member) { + return execOp(key, OpName.ZRANK, client -> client.zrank(key, member)); } @Override - public Set hkeys(final byte[] key) { - return d_hkeys(key).getResult(); + public Long zrem(byte[] key, byte[]... member) { + return execOp(key, OpName.ZREM, client -> client.zrem(key, member)); } - public OperationResult> d_hkeys(final byte[] key) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.HKEYS) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.hkeys(key); - } - - }); + @Override + public Long zremrangeByRank(final byte[] key, final long start, final long end) { + return execOp(key, OpName.ZREMRANGEBYRANK, client -> client.zremrangeByRank(key, start, end)); } @Override - public Collection hvals(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public Long zremrangeByScore(final byte[] key, final double start, final double end) { + return execOp(key, OpName.ZREMRANGEBYSCORE, client -> client.zremrangeByScore(key, start, end)); } @Override - public Map hgetAll(final byte[] key) { - return d_hgetAll(key).getResult(); + public Set zrevrange(byte[] key, long start, long end) { + return execOp(key, OpName.ZREVRANGE, client -> client.zrevrange(key, start, end)); } - public OperationResult> d_hgetAll(final byte[] key) { - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.HGETALL) { - @Override - public Map execute(Jedis client, ConnectionContext state) throws DynoException { - return client.hgetAll(key); - } - }); + @Override + public Long zrevrank(final byte[] key, final byte[] member) { + return execOp(key, OpName.ZREVRANK, client -> client.zrevrank(key, member)); } @Override - public Long rpush(byte[] key, byte[]... args) { - throw new UnsupportedOperationException("not yet implemented"); + public Set zrangeWithScores(byte[] key, long start, long end) { + return execOp(key, OpName.ZRANGEWITHSCORES, client -> client.zrangeWithScores(key, start, end)); } @Override - public Long lpush(byte[] key, byte[]... args) { - throw new UnsupportedOperationException("not yet implemented"); + public Set zrevrangeWithScores(byte[] key, long start, long end) { + return execOp(key, OpName.ZREVRANGEWITHSCORES, client -> client.zrevrangeWithScores(key, start, end)); } @Override - public Long llen(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public Double zscore(final byte[] key, final byte[] member) { + return execOp(key, OpName.ZSCORE, client -> client.zscore(key, member)); } @Override - public List lrange(byte[] key, long start, long end) { - throw new UnsupportedOperationException("not yet implemented"); + public ScanResult zscan(final byte[] key, final byte[] cursor) { + return execOp(key, OpName.ZSCAN, client -> client.zscan(key, cursor)); } @Override - public String ltrim(byte[] key, long start, long end) { - throw new UnsupportedOperationException("not yet implemented"); + public Set zrangeByScore(byte[] key, double min, double max) { + return execOp(key, OpName.ZRANGEBYSCORE, client -> client.zrangeByScore(key, min, max)); } @Override - public byte[] lindex(byte[] key, long index) { - throw new UnsupportedOperationException("not yet implemented"); + public Set zrangeByScore(byte[] key, byte[] min, byte[] max) { + return execOp(key, OpName.ZRANGEBYSCORE, client -> client.zrangeByScore(key, min, max)); } @Override - public String lset(byte[] key, long index, byte[] value) { - throw new UnsupportedOperationException("not yet implemented"); + public Set zrangeByScore(byte[] key, double min, double max, int offset, int count) { + return execOp(key, OpName.ZRANGEBYSCORE, client -> client.zrangeByScore(key, min, max, offset, count)); } @Override - public Long lrem(byte[] key, long count, byte[] value) { - throw new UnsupportedOperationException("not yet implemented"); + public Set zrangeByScore(byte[] key, byte[] min, byte[] max, int offset, int count) { + return execOp(key, OpName.ZRANGEBYSCORE, client -> client.zrangeByScore(key, min, max, offset, count)); } @Override - public byte[] lpop(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public Set zrevrangeByScore(byte[] key, byte[] max, byte[] min) { + return execOp(key, OpName.ZREVRANGEBYSCORE, client -> client.zrevrangeByScore(key, max, min)); } @Override - public byte[] rpop(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public Set zrevrangeByScore(byte[] key, double max, double min, int offset, int count) { + return execOp(key, OpName.ZREVRANGEBYSCORE, client -> client.zrevrangeByScore(key, max, min, offset, count)); } @Override - public Long sadd(final byte[] key, final byte[]... members) { - return d_sadd(key, members).getResult(); + public Set zrevrangeByScore(byte[] key, double max, double min) { + return execOp(key, OpName.ZREVRANGEBYSCORE, client -> client.zrevrangeByScore(key, max, min)); } - public OperationResult d_sadd(final byte[] key, final byte[]... members) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.SADD) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.sadd(key, members); - } - - }); + @Override + public Set zrangeByScoreWithScores(byte[] key, double min, double max) { + return execOp(key, OpName.ZRANGEBYSCOREWITHSCORES, client -> client.zrangeByScoreWithScores(key, min, max)); } @Override - public Set smembers(final byte[] key) { - return d_smembers(key).getResult(); + public Set zrevrangeByScoreWithScores(byte[] key, double max, double min) { + return execOp(key, OpName.ZREVRANGEBYSCOREWITHSCORES, client -> client.zrevrangeByScoreWithScores(key, max, min)); } - public OperationResult> d_smembers(final byte[] key) { - - return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.SMEMBERS) { - - @Override - public Set execute(Jedis client, ConnectionContext state) { - return client.smembers(key); - } - }); + @Override + public Set zrangeByScoreWithScores(byte[] key, double min, double max, int offset, int count) { + return execOp(key, OpName.ZRANGEBYSCOREWITHSCORES, client -> client.zrangeByScoreWithScores(key, min, max, offset, count)); } @Override - public Long srem(final byte[] key, final byte[]... members) { - return d_srem(key, members).getResult(); + public Set zrevrangeByScore(byte[] key, byte[] max, byte[] min, int offset, int count) { + return execOp(key, OpName.ZREVRANGEBYSCORE, client -> client.zrevrangeByScore(key, max, min, offset, count)); } - public OperationResult d_srem(final byte[] key, final byte[]... members) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.SREM) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.srem(key, members); - } - - }); + @Override + public Set zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max) { + return execOp(key, OpName.ZRANGEBYSCOREWITHSCORES, client -> client.zrangeByScoreWithScores(key, min, max)); } @Override - public byte[] spop(final byte[] key) { - return d_spop(key).getResult(); + public Set zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min) { + return execOp(key, OpName.ZREVRANGEBYSCOREWITHSCORES, client -> client.zrevrangeByScoreWithScores(key, max, min)); } - public OperationResult d_spop(final byte[] key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.SPOP) { - - @Override - public byte[] execute(Jedis client, ConnectionContext state) { - return client.spop(key); - } - }); + @Override + public Set zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max, int offset, int count) { + return execOp(key, OpName.ZRANGEBYSCOREWITHSCORES, client -> client.zrangeByScoreWithScores(key, min, max, offset, count)); } @Override - public Set spop(byte[] key, long count) { - throw new UnsupportedOperationException("not yet implemented"); + public Set zrevrangeByScoreWithScores(byte[] key, double max, double min, int offset, int count) { + return execOp(key, OpName.ZREVRANGEBYSCOREWITHSCORES, client -> client.zrevrangeByScoreWithScores(key, max, min, offset, count)); } @Override - public Long scard(final byte[] key) { - return d_scard(key).getResult(); + public Set zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min, int offset, int count) { + return execOp(key, OpName.ZREVRANGEBYSCOREWITHSCORES, client -> client.zrevrangeByScoreWithScores(key, max, min, offset, count)); } - public OperationResult d_scard(final byte[] key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.SCARD) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.scard(key); - } - - }); + @Override + public Long zremrangeByScore(byte[] key, byte[] start, byte[] end) { + return execOp(key, OpName.ZREMRANGEBYSCORE, client -> client.zremrangeByScore(key, start, end)); } @Override - public Boolean sismember(byte[] key, byte[] member) { - throw new UnsupportedOperationException("not yet implemented"); + public Long zlexcount(byte[] key, byte[] min, byte[] max) { + return execOp(key, OpName.ZLEXCOUNT, client -> client.zlexcount(key, min, max)); } @Override - public byte[] srandmember(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public Set zrangeByLex(byte[] key, byte[] min, byte[] max) { + return execOp(key, OpName.ZRANGEBYLEX, client -> client.zrangeByLex(key, min, max)); } @Override - public List srandmember(final byte[] key, final int count) { - throw new UnsupportedOperationException("not yet implemented"); + public Set zrangeByLex(byte[] key, byte[] min, byte[] max, int offset, int count) { + return execOp(key, OpName.ZRANGEBYLEX, client -> client.zrangeByLex(key, min, max, offset, count)); } @Override - public Long strlen(final byte[] key) { - return d_strlen(key).getResult(); + public Long zremrangeByLex(byte[] key, byte[] min, byte[] max) { + return execOp(key, OpName.ZREMRANGEBYLEX, client -> client.zremrangeByLex(key, min, max)); } - public OperationResult d_strlen(final byte[] key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.STRLEN) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.strlen(key); - } - - }); + @Override + public byte[] echo(byte[] string) { + return execOp(string, OpName.ECHO, client -> client.echo(string)); } @Override - public Long zadd(byte[] key, double score, byte[] member) { - throw new UnsupportedOperationException("not yet implemented"); + public Long move(byte[] key, int dbIndex) { + return execOp(key, OpName.MOVE, client -> client.move(key, dbIndex)); } @Override - public Long zadd(byte[] key, Map scoreMembers) { - throw new UnsupportedOperationException("not yet implemented"); + public Long bitcount(byte[] key) { + return execOp(key, OpName.BITCOUNT, client -> client.bitcount(key)); } @Override - public Set zrange(byte[] key, long start, long end) { + public Long pfadd(byte[] key, byte[]... elements) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long zrem(byte[] key, byte[]... member) { + public long pfcount(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Double zincrby(byte[] key, double score, byte[] member) { - throw new UnsupportedOperationException("not yet implemented"); + public Long bitcount(byte[] key, long start, long end) { + return execOp(key, OpName.BITCOUNT, client -> client.bitcount(key, start, end)); } + /** + * MULTI-KEY COMMANDS + */ + @Override - public Long zrank(byte[] key, byte[] member) { - throw new UnsupportedOperationException("not yet implemented"); + public List blpop(int timeout, byte[]... keys) { + return execMultiOp(keys, OpName.BLPOP, client -> client.blpop(timeout, keys)); } @Override - public Long zrevrank(byte[] key, byte[] member) { - throw new UnsupportedOperationException("not yet implemented"); + public List brpop(int timeout, byte[]... keys) { + return execMultiOp(keys, OpName.BRPOP, client -> client.brpop(timeout, keys)); } @Override - public Set zrevrange(byte[] key, long start, long end) { - throw new UnsupportedOperationException("not yet implemented"); + public List blpop(byte[]... keys) { + return execMultiOp(keys, OpName.BLPOP, client -> client.blpop(keys)); } @Override - public Set zrangeWithScores(byte[] key, long start, long end) { - throw new UnsupportedOperationException("not yet implemented"); + public List brpop(byte[]... keys) { + return execMultiOp(keys, OpName.BRPOP, client -> client.brpop(keys)); } @Override - public Set zrevrangeWithScores(byte[] key, long start, long end) { + public Set keys(final byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long zcard(final byte[] key) { - return d_zcard(key).getResult(); + public Long pexpire(byte[] key, long milliseconds) { + return execOp(key, OpName.PEXPIRE, client -> client.pexpire(key, milliseconds)); } - public OperationResult d_zcard(final byte[] key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.ZCARD) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.zcard(key); - } - - }); + /** + * Get values for all the keys provided. Returns a list of string values + * corresponding to individual keys. If one of the key is missing, the + * return list has null as its corresponding value. + * + * @param keys: variable list of keys to query + * @return list of string values + * @see mget + */ + @Override + public List mget(byte[]... keys) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execMultiOp(keys, OpName.MGET, client -> client.mget(keys)); + } else { + return execCompressMultiOp( + keys, + OpName.MGET, + (client, state, op) -> new ArrayList<>(CollectionUtils.transform(client.mget(keys), + s -> op.decompressValue(state, s))) + ); + } } @Override - public Double zscore(final byte[] key, final byte[] member) { - return d_zscore(key, member).getResult(); + public Long exists(byte[]... keys) { + return execMultiOp(keys, OpName.EXISTS, client -> client.exists(keys)); } - public OperationResult d_zscore(final byte[] key, final byte[] member) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.ZSCORE) { - - @Override - public Double execute(Jedis client, ConnectionContext state) { - return client.zscore(key, member); - } - - }); + @Override + public Long del(byte[]... keys) { + return execMultiOp(keys, OpName.DEL, client -> client.del(keys)); } @Override - public List sort(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public Long unlink(byte[]... keys) { + return execMultiOp(keys, OpName.UNLINK, client -> client.unlink(keys)); } @Override - public List sort(byte[] key, SortingParams sortingParameters) { - throw new UnsupportedOperationException("not yet implemented"); + public Long msetnx(byte[]... keysvalues) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execMultiOp(keysvalues, OpName.MSETNX, client -> client.msetnx(keysvalues)); + } else { + return execCompressMultiOp( + keysvalues, + OpName.MSETNX, + (client, state, op) -> client.msetnx(op.compressMultiKeyValue(state, keysvalues)) + ); + } } @Override - public Long zcount(byte[] key, double min, double max) { - throw new UnsupportedOperationException("not yet implemented"); + public String mset(byte[]... keysvalues) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(keysvalues[0], OpName.MSET, client -> client.mset(keysvalues)); + } else { + return execCompressMultiOp( + keysvalues, + OpName.MSET, + (client, state, op) -> client.mset(op.compressMultiKeyValue(state, keysvalues)) + ); + } } @Override - public Long zcount(byte[] key, byte[] min, byte[] max) { - throw new UnsupportedOperationException("not yet implemented"); + public Set sinter(byte[]... keys) { + return execMultiOp(keys, OpName.SINTER, client -> client.sinter(keys)); } - @Override - public Set zrangeByScore(byte[] key, double min, double max) { - throw new UnsupportedOperationException("not yet implemented"); + public Long sinterstore(final byte[] dstkey, final byte[]... keys) { + return execOp(dstkey, OpName.SINTERSTORE, client -> client.sinterstore(dstkey, keys)); } @Override - public Set zrangeByScore(byte[] key, byte[] min, byte[] max) { - throw new UnsupportedOperationException("not yet implemented"); + public Long sort(byte[] key, SortingParams sortingParameters, byte[] dstkey) { + return execOp(key, OpName.SORT, client -> client.sort(key, sortingParameters, dstkey)); } @Override - public Set zrevrangeByScore(byte[] key, double max, double min) { - throw new UnsupportedOperationException("not yet implemented"); + public Long sort(byte[] key, byte[] dstkey) { + return execOp(key, OpName.SORT, client -> client.sort(key, dstkey)); } @Override - public Set zrangeByScore(byte[] key, double min, double max, int offset, int count) { - throw new UnsupportedOperationException("not yet implemented"); + public Set sunion(byte[]... keys) { + return execMultiOp(keys, OpName.SUNION, client -> client.sunion(keys)); } @Override - public Set zrevrangeByScore(byte[] key, byte[] max, byte[] min) { - throw new UnsupportedOperationException("not yet implemented"); + public Long sunionstore(byte[] dstkey, byte[]... keys) { + return execOp(dstkey, OpName.SUNIONSTORE, client -> client.sunionstore(dstkey, keys)); } @Override - public Set zrangeByScore(byte[] key, byte[] min, byte[] max, int offset, int count) { + public String watch(byte[]... keys) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Set zrevrangeByScore(byte[] key, double max, double min, int offset, int count) { + public Long zinterstore(byte[] dstkey, byte[]... sets) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Set zrangeByScoreWithScores(byte[] key, double min, double max) { + public Long zinterstore(byte[] dstkey, ZParams params, byte[]... sets) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Set zrevrangeByScoreWithScores(byte[] key, double max, double min) { - throw new UnsupportedOperationException("not yet implemented"); + public Set zrevrangeByLex(byte[] key, byte[] max, byte[] min) { + return execOp(key, OpName.ZREVRANGEBYLEX, client -> client.zrevrangeByLex(key, max, min)); } @Override - public Set zrangeByScoreWithScores(byte[] key, double min, double max, int offset, int count) { - throw new UnsupportedOperationException("not yet implemented"); + public Set zrevrangeByLex(byte[] key, byte[] max, byte[] min, int offset, int count) { + return execOp(key, OpName.ZREVRANGEBYLEX, client -> client.zrevrangeByLex(key, max, min, offset, count)); } @Override - public Set zrevrangeByScore(byte[] key, byte[] max, byte[] min, int offset, int count) { + public Long zunionstore(byte[] dstkey, byte[]... sets) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Set zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max) { + public Long zunionstore(byte[] dstkey, ZParams params, byte[]... sets) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Set zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min) { + public byte[] brpoplpush(byte[] source, byte[] destination, int timeout) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Set zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max, int offset, int count) { + public Long publish(byte[] channel, byte[] message) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Set zrevrangeByScoreWithScores(byte[] key, double max, double min, int offset, int count) { + public void subscribe(BinaryJedisPubSub jedisPubSub, byte[]... channels) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Set zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min, int offset, int count) { + public void psubscribe(BinaryJedisPubSub jedisPubSub, byte[]... patterns) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long zremrangeByRank(byte[] key, long start, long end) { + public byte[] randomBinaryKey() { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long zremrangeByScore(byte[] key, double start, double end) { + public Long bitop(BitOP op, byte[] destKey, byte[]... srcKeys) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long zremrangeByScore(byte[] key, byte[] start, byte[] end) { + public String pfmerge(byte[] destkey, byte[]... sourcekeys) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long zlexcount(final byte[] key, final byte[] min, final byte[] max) { + public Long pfcount(byte[]... keys) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Set zrangeByLex(final byte[] key, final byte[] min, final byte[] max) { + public Long touch(byte[]... keys) { throw new UnsupportedOperationException("not yet implemented"); } + @Override - public Set zrangeByLex(final byte[] key, final byte[] min, final byte[] max, int offset, int count) { + public Long geoadd(byte[] arg0, Map arg1) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Set zrevrangeByLex(final byte[] key, final byte[] max, final byte[] min) { + public Long geoadd(byte[] arg0, double arg1, double arg2, byte[] arg3) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Set zrevrangeByLex(final byte[] key, final byte[] max, final byte[] min, int offset, int count) { + public Double geodist(byte[] arg0, byte[] arg1, byte[] arg2) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long zremrangeByLex(final byte[] key, final byte[] min, final byte[] max) { + public Double geodist(byte[] arg0, byte[] arg1, byte[] arg2, GeoUnit arg3) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long linsert(byte[] key, ListPosition where, byte[] pivot, byte[] value) { + public List geohash(byte[] arg0, byte[]... arg1) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long lpushx(byte[] key, byte[]... arg) { + public List geopos(byte[] arg0, byte[]... arg1) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long rpushx(byte[] key, byte[]... arg) { + public List georadius(byte[] arg0, double arg1, double arg2, double arg3, GeoUnit arg4) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long del(final byte[] key) { - return d_del(key).getResult(); - } - - public OperationResult d_del(final byte[] key) { - - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.DEL) { - - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.del(key); - } - - }); + public List georadiusReadonly(byte[] key, double longitude, double latitude, double radius, GeoUnit unit) { + throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long unlink(byte[] key) { - return d_unlink(key).getResult(); - } - - public OperationResult d_unlink(final byte[] key) { - return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.UNLINK) { - @Override - public Long execute(Jedis client, ConnectionContext state) { - return client.unlink(key); - } - - }); + public List georadius(byte[] arg0, double arg1, double arg2, double arg3, GeoUnit arg4, + GeoRadiusParam arg5) { + throw new UnsupportedOperationException("not yet implemented"); } @Override - public byte[] echo(byte[] arg) { + public List georadiusReadonly(byte[] key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long move(byte[] key, int dbIndex) { + public List georadiusByMember(byte[] arg0, byte[] arg1, double arg2, GeoUnit arg3) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long bitcount(final byte[] key) { + public List georadiusByMemberReadonly(byte[] key, byte[] member, double radius, GeoUnit unit) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long bitcount(final byte[] key, long start, long end) { + public List georadiusByMember(byte[] arg0, byte[] arg1, double arg2, GeoUnit arg3, + GeoRadiusParam arg4) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long pfadd(final byte[] key, final byte[]... elements) { + public List georadiusByMemberReadonly(byte[] key, byte[] member, double radius, GeoUnit unit, GeoRadiusParam param) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public long pfcount(final byte[] key) { + public List bitfield(byte[] key, byte[]... arguments) { throw new UnsupportedOperationException("not yet implemented"); } - /** - * NOT SUPPORTED ! Use {@link #dyno_scan(CursorBasedResult, int, String...)} - * instead. - * - * @param cursor - * @return nothing -- throws UnsupportedOperationException when invoked - * @see #dyno_scan(CursorBasedResult, int, String...) - */ @Override - public ScanResult scan(String cursor) { - throw new UnsupportedOperationException("Not supported - use dyno_scan(String, CursorBasedResult"); - } - - public CursorBasedResult dyno_scan(String... pattern) { - return this.dyno_scan(10, pattern); - } - - public CursorBasedResult dyno_scan(int count, String... pattern) { - return this.dyno_scan(null, count, pattern); - } - - public CursorBasedResult dyno_scan(CursorBasedResult cursor, int count, String... pattern) { - if (cursor == null) { - // Create a temporary cursor context which will maintain a map of token to rack - cursor = new CursorBasedResultImpl<>(new LinkedHashMap>()); - } - final Map> results = new LinkedHashMap<>(); + public Long hstrlen(byte[] key, byte[] field) { + throw new UnsupportedOperationException("not yet implemented"); + } - List>> opResults = scatterGatherScan(cursor, count, pattern); - for (OperationResult> opResult : opResults) { - results.put(opResult.getNode().getHostAddress(), opResult.getResult()); - } - return new CursorBasedResultImpl<>(results, ((TokenRackMapper) cursor).getTokenRackMap()); + @Override + public ScanResult> hscan(byte[] arg0, byte[] arg1, ScanParams arg2) { + throw new UnsupportedOperationException("not yet implemented"); } @Override - public String pfmerge(String destkey, String... sourcekeys) { + public Long zadd(byte[] arg0, Map arg1, ZAddParams arg2) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public long pfcount(String... keys) { + public Double zincrby(byte[] arg0, double arg1, byte[] arg2, ZIncrByParams arg3) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Long touch(String... keys) { + public ScanResult zscan(byte[] arg0, byte[] arg1, ScanParams arg2) { throw new UnsupportedOperationException("not yet implemented"); } + /******************* End Jedis Binary Commands **************/ + + private boolean validHashtag(final String hashtag) { return !Strings.isNullOrEmpty(hashtag) && hashtag.length() == 2; } @@ -4236,8 +2929,8 @@ public Long ehsetnx(final String key, final String field, final String value, fi // If metadata operation failed, remove the data and throw exception if (!zResponse.get().equals(hResponse.get())) { - d_hdel(ehashDataKey, field); - d_zrem(ehashMetadataKey, field); + hdel(ehashDataKey, field); + zrem(ehashMetadataKey, field); throw new DynoException("Metadata inconsistent with data for expireHash: " + ehashDataKey); } return hResponse.get(); @@ -4897,248 +3590,4 @@ public DynoJedisClient build() { } - @Override - public ScanResult scan(String arg0, ScanParams arg1) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public Long geoadd(byte[] arg0, Map arg1) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public Long geoadd(byte[] arg0, double arg1, double arg2, byte[] arg3) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public Double geodist(byte[] arg0, byte[] arg1, byte[] arg2) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public Double geodist(byte[] arg0, byte[] arg1, byte[] arg2, GeoUnit arg3) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public List geohash(byte[] arg0, byte[]... arg1) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public List geopos(byte[] arg0, byte[]... arg1) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public List georadius(byte[] arg0, double arg1, double arg2, double arg3, GeoUnit arg4) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public List georadiusReadonly(byte[] key, double longitude, double latitude, double radius, GeoUnit unit) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public List georadius(byte[] arg0, double arg1, double arg2, double arg3, GeoUnit arg4, - GeoRadiusParam arg5) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public List georadiusReadonly(byte[] key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public List georadiusByMember(byte[] arg0, byte[] arg1, double arg2, GeoUnit arg3) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public List georadiusByMemberReadonly(byte[] key, byte[] member, double radius, GeoUnit unit) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public List georadiusByMember(byte[] arg0, byte[] arg1, double arg2, GeoUnit arg3, - GeoRadiusParam arg4) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public List georadiusByMemberReadonly(byte[] key, byte[] member, double radius, GeoUnit unit, GeoRadiusParam param) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public ScanResult> hscan(byte[] arg0, byte[] arg1) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public ScanResult> hscan(byte[] arg0, byte[] arg1, ScanParams arg2) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public ScanResult sscan(byte[] arg0, byte[] arg1) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public ScanResult sscan(byte[] arg0, byte[] arg1, ScanParams arg2) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public Long zadd(byte[] arg0, Map arg1, ZAddParams arg2) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public Long zadd(byte[] arg0, double arg1, byte[] arg2, ZAddParams arg3) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public Double zincrby(byte[] arg0, double arg1, byte[] arg2, ZIncrByParams arg3) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public ScanResult zscan(byte[] arg0, byte[] arg1) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public ScanResult zscan(byte[] arg0, byte[] arg1, ScanParams arg2) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public List bitfield(byte[] key, byte[]... arguments) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public Long hstrlen(byte[] key, byte[] field) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public Long bitpos(String arg0, boolean arg1) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public Long bitpos(String arg0, boolean arg1, BitPosParams arg2) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public Long geoadd(String arg0, Map arg1) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public Long geoadd(String arg0, double arg1, double arg2, String arg3) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public Double geodist(String arg0, String arg1, String arg2) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public Double geodist(String arg0, String arg1, String arg2, GeoUnit arg3) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public List geohash(String arg0, String... arg1) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public List geopos(String arg0, String... arg1) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public List georadius(String arg0, double arg1, double arg2, double arg3, GeoUnit arg4) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public List georadiusReadonly(String key, double longitude, double latitude, double radius, GeoUnit unit) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public List georadius(String arg0, double arg1, double arg2, double arg3, GeoUnit arg4, - GeoRadiusParam arg5) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public List georadiusReadonly(String key, double longitude, double latitude, double radius, GeoUnit unit, GeoRadiusParam param) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public List georadiusByMember(String arg0, String arg1, double arg2, GeoUnit arg3) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public List georadiusByMemberReadonly(String key, String member, double radius, GeoUnit unit) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public List georadiusByMember(String arg0, String arg1, double arg2, GeoUnit arg3, - GeoRadiusParam arg4) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public List georadiusByMemberReadonly(String key, String member, double radius, GeoUnit unit, GeoRadiusParam param) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public List bitfield(String key, String... arguments) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public Long hstrlen(String key, String field) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public ScanResult> hscan(String arg0, String arg1, ScanParams arg2) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public Long zadd(String arg0, Map arg1, ZAddParams arg2) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public Double zincrby(String arg0, double arg1, String arg2, ZIncrByParams arg3) { - throw new UnsupportedOperationException("not yet implemented"); - } - - @Override - public ScanResult zscan(String arg0, String arg1, ScanParams arg2) { - throw new UnsupportedOperationException("not yet implemented"); - } - } diff --git a/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoJedisPipeline.java b/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoJedisPipeline.java index f796f36f..05141848 100644 --- a/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoJedisPipeline.java +++ b/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoJedisPipeline.java @@ -22,9 +22,11 @@ import com.netflix.dyno.connectionpool.exception.FatalConnectionException; import com.netflix.dyno.connectionpool.exception.NoAvailableHostsException; import com.netflix.dyno.connectionpool.impl.ConnectionPoolImpl; +import com.netflix.dyno.connectionpool.impl.lb.TokenAwareSelection; import com.netflix.dyno.connectionpool.impl.utils.CollectionUtils; import com.netflix.dyno.connectionpool.impl.utils.ZipUtils; import com.netflix.dyno.jedis.JedisConnectionFactory.JedisConnection; +import com.netflix.dyno.jedis.operation.BaseKeyOperation; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -43,11 +45,16 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.stream.Collectors; import static com.netflix.dyno.connectionpool.ConnectionPoolConfiguration.CompressionStrategy; @@ -67,8 +74,9 @@ public class DynoJedisPipeline implements RedisPipeline, BinaryRedisPipeline, Au // the cached row key for the pipeline. all subsequent requests to pipeline // must be the same. this is used to check that. private final AtomicReference theKey = new AtomicReference(null); - private final AtomicReference theBinaryKey = new AtomicReference(null); private final AtomicReference hashtag = new AtomicReference(null); + private final AtomicReference theBinaryKey = new AtomicReference(null); + private final AtomicReference hashtagBinary = new AtomicReference(null); // used for tracking errors private final AtomicReference pipelineEx = new AtomicReference(null); @@ -167,24 +175,51 @@ private void checkHashtag(final String key, final String hashtagValue) { } + private void checkHashtag(final byte[] key, final byte[] hashtagValue) { + if (this.hashtagBinary.get() != null) { + verifyHashtagValue(hashtagValue); + } else { + boolean success = this.hashtagBinary.compareAndSet(null, hashtagValue); + if (!success) { + verifyHashtagValue(hashtagValue); + } else { + pipelined(key); + } + } + + } + /** - * Checks that a pipeline is associated with a single key. Binary keys do not - * support hashtags. + * Checks that a pipeline is associated with a single key. * * @param key */ private void checkKey(final byte[] key) { - if (theBinaryKey.get() != null) { - verifyKey(key); - } else { - boolean success = theBinaryKey.compareAndSet(null, key); - if (!success) { - // someone already beat us to it. that's fine, just verify - // that the key is the same + String hashtag = connPool.getConfiguration().getHashtag(); + if (hashtag == null || hashtag.isEmpty()) { + if (theBinaryKey.get() != null) { verifyKey(key); } else { - pipelined(key); + boolean success = theBinaryKey.compareAndSet(null, key); + if (!success) { + // someone already beat us to it. that's fine, just verify + // that the key is the same + verifyKey(key); + } else { + pipelined(key); + } + } + } else { + /* + * We have a identified a hashtag in the Host object. That means Dynomite has a + * defined hashtag. Producing the hashvalue out of the hashtag and using that as + * a reference to the pipeline + */ + byte[] hashValue = TokenAwareSelection.getHashValue(key, hashtag); + if (hashValue == null || hashValue.length == 0) { + hashValue = key; } + checkHashtag(key, hashValue); } } @@ -221,8 +256,7 @@ private void checkKey(final String key) { * defined hashtag. Producing the hashvalue out of the hashtag and using that as * a reference to the pipeline */ - String hashValue = StringUtils.substringBetween(key, Character.toString(hashtag.charAt(0)), - Character.toString(hashtag.charAt(1))); + String hashValue = TokenAwareSelection.getHashValue(key, hashtag); if (Strings.isNullOrEmpty(hashValue)) { hashValue = key; } @@ -234,9 +268,10 @@ private void checkKey(final String key) { * Verifies binary key with pipeline binary key */ private void verifyKey(final byte[] key) { - if (!theBinaryKey.get().equals(key)) { + if (!Arrays.equals(theBinaryKey.get(), key)) { try { - throw new RuntimeException("Must have same key for Redis Pipeline in Dynomite. This key: " + key); + throw new RuntimeException("Must have same key for Redis Pipeline in Dynomite. This key: " + + Arrays.toString(key)); } finally { discardPipelineAndReleaseConnection(); } @@ -262,7 +297,20 @@ private void verifyHashtagValue(final String hashtagValue) { if (!this.hashtag.get().equals(hashtagValue)) { try { throw new RuntimeException( - "Must have same hashtag for Redis Pipeline in Dynomite. This hashvalue: " + hashtagValue); + "Must have same hashtag for Redis Pipeline in Dynomite. This hashvalue: " + hashtagValue); + } finally { + discardPipelineAndReleaseConnection(); + } + } + } + + private void verifyHashtagValue(final byte[] hashtagValue) { + + if (!Arrays.equals(this.hashtagBinary.get(), hashtagValue)) { + try { + throw new RuntimeException( + "Must have same hashtag for Redis Pipeline in Dynomite. This hashvalue: " + + Arrays.toString(hashtagValue)); } finally { discardPipelineAndReleaseConnection(); } @@ -292,25 +340,45 @@ private byte[] decompressValue(byte[] value) { return value; } - /** - * As long as jdk 7 and below is supported we need to define our own function - * interfaces - */ - private interface Func0 { - R call(); + private String compressValue(String value) { + String result = value; + int thresholdBytes = connPool.getConfiguration().getValueCompressionThreshold(); + + try { + // prefer speed over accuracy here so rather than using + // getBytes() to get the actual size + // just estimate using 2 bytes per character + if ((2 * value.length()) > thresholdBytes) { + result = ZipUtils.compressStringToBase64String(value); + } + } catch (IOException e) { + Logger.warn("UNABLE to compress [" + value + "]; sending value uncompressed"); + } + + return result; + } + + private byte[] compressValue(byte[] value) { + int thresholdBytes = connPool.getConfiguration().getValueCompressionThreshold(); + + if (value.length > thresholdBytes) { + try { + return ZipUtils.compressBytesNonBase64(value); + } catch (IOException e) { + Logger.warn("UNABLE to compress byte array [" + value + "]; sending value uncompressed"); + } + } + + return value; } - public class PipelineResponse extends Response { + public class DecompressPipelineResponse extends Response { private Response response; - public PipelineResponse(Builder b) { + public DecompressPipelineResponse(Response response) { super(BuilderFactory.STRING); - } - - public PipelineResponse apply(Func0> f) { - this.response = f.call(); - return this; + this.response = response; } @Override @@ -320,55 +388,28 @@ public String get() { } - public class PipelineLongResponse extends Response { - private Response response; - - public PipelineLongResponse(Builder b) { - super(b); - } - - public PipelineLongResponse apply(Func0> f) { - this.response = f.call(); - return this; - } - } - - public class PipelineListResponse extends Response> { + public class DecompressPipelineListResponse extends Response> { private Response> response; - public PipelineListResponse(Builder b) { + public DecompressPipelineListResponse(Response> response) { super(BuilderFactory.STRING_LIST); - } - - public PipelineListResponse apply(Func0>> f) { - this.response = f.call(); - return this; + this.response = response; } @Override public List get() { - return new ArrayList( - CollectionUtils.transform(response.get(), new CollectionUtils.Transform() { - @Override - public String get(String s) { - return decompressValue(s); - } - })); + return response.get().stream().map(val -> decompressValue(val)).collect(Collectors.toList()); } } - public class PipelineBinaryResponse extends Response { + public class DecompressPipelineBinaryResponse extends Response { private Response response; - public PipelineBinaryResponse(Builder b) { + public DecompressPipelineBinaryResponse(Response response) { super(BuilderFactory.BYTE_ARRAY); - } - - public PipelineBinaryResponse apply(Func0> f) { - this.response = f.call(); - return this; + this.response = response; } @Override @@ -378,247 +419,137 @@ public byte[] get() { } - public class PipelineMapResponse extends Response> { - - private Response> response; - - public PipelineMapResponse(Builder> b) { - super(BuilderFactory.STRING_MAP); - } - - @Override - public Map get() { - return CollectionUtils.transform(response.get(), - new CollectionUtils.MapEntryTransform() { - @Override - public String get(String key, String val) { - return decompressValue(val); - } - }); - } - } - - public class PipelineBinaryMapResponse extends Response> { - - private Response> response; + public class DecompressPipelineBinaryListResponse extends Response> { - public PipelineBinaryMapResponse(Builder> b) { - super(BuilderFactory.BYTE_ARRAY_MAP); - } + private Response> response; - public PipelineBinaryMapResponse apply(Func0>> f) { - this.response = f.call(); - return this; + public DecompressPipelineBinaryListResponse(Response> response) { + super(BuilderFactory.BYTE_ARRAY_LIST); + this.response = response; } @Override - public Map get() { - return CollectionUtils.transform(response.get(), - new CollectionUtils.MapEntryTransform() { - @Override - public byte[] get(byte[] key, byte[] val) { - return decompressValue(val); - } - }); + public List get() { + return response.get().stream().map(val -> decompressValue(val)).collect(Collectors.toList()); } } - private abstract class PipelineOperation { - - abstract Response execute(Pipeline jedisPipeline) throws DynoException; - - Response execute(final byte[] key, final OpName opName) { - checkKey(key); - return executeOperation(opName); - } - - Response execute(final String key, final OpName opName) { - checkKey(key); - return executeOperation(opName); - } - - Response executeOperation(final OpName opName) { - try { - opMonitor.recordOperation(opName.name()); - return execute(jedisPipeline); - - } catch (JedisConnectionException ex) { - handleConnectionException(ex); - throw ex; - } + protected Response execOp(String key, OpName opName, Supplier> fn) { + checkKey(key); + try { + opMonitor.recordOperation(opName.name()); + return fn.get(); + } catch (JedisConnectionException ex) { + DynoException e = new FatalConnectionException(ex).setAttempt(1); + pipelineEx.set(e); + cpMonitor.incOperationFailure(connection.getHost(), e); + throw ex; } + } - void handleConnectionException(JedisConnectionException ex) { + protected Response execOp(byte[] key, OpName opName, Supplier> fn) { + checkKey(key); + try { + opMonitor.recordOperation(opName.name()); + return fn.get(); + } catch (JedisConnectionException ex) { DynoException e = new FatalConnectionException(ex).setAttempt(1); pipelineEx.set(e); cpMonitor.incOperationFailure(connection.getHost(), e); + throw ex; } } - private abstract class PipelineCompressionOperation extends PipelineOperation { - - /** - * Compresses the value based on the threshold defined by - * {@link ConnectionPoolConfiguration#getValueCompressionThreshold()} - * - * @param value - * @return - */ - public String compressValue(String value) { - String result = value; - int thresholdBytes = connPool.getConfiguration().getValueCompressionThreshold(); + protected String compress(String val) { + return compressValue(val); + } - try { - // prefer speed over accuracy here so rather than using - // getBytes() to get the actual size - // just estimate using 2 bytes per character - if ((2 * value.length()) > thresholdBytes) { - result = ZipUtils.compressStringToBase64String(value); - } - } catch (IOException e) { - Logger.warn("UNABLE to compress [" + value + "]; sending value uncompressed"); - } + protected Map compressMap(Map val) { + Map result = new HashMap<>(); + val.entrySet().stream().forEach(entry -> result.put(entry.getKey(), compressValue(entry.getValue()))); + return result; + } - return result; - } + protected Response decompress(Response val) { + return new DecompressPipelineResponse(val); + } - public byte[] compressValue(byte[] value) { - int thresholdBytes = connPool.getConfiguration().getValueCompressionThreshold(); + protected Response> decompressList(Response> val) { + return new DecompressPipelineListResponse(val); + } - if (value.length > thresholdBytes) { - try { - return ZipUtils.compressBytesNonBase64(value); - } catch (IOException e) { - Logger.warn("UNABLE to compress byte array [" + value + "]; sending value uncompressed"); - } - } + protected byte[] compressBin(byte[] val) { + return compressValue(val); + } - return value; - } + protected Map compressBinMap(Map val) { + Map result = new HashMap<>(); + val.entrySet().stream().forEach(entry -> result.put(entry.getKey(), compressValue(entry.getValue()))); + return result; + } + protected Response decompressBin(Response val) { + return new DecompressPipelineBinaryResponse(val); } - @Override - public Response append(final String key, final String value) { + protected Response> decompressBinList(Response> val) { + return new DecompressPipelineBinaryListResponse(val); + } - return new PipelineOperation() { + /******************* Jedis String Commands **************/ - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.append(key, value); - } - }.execute(key, OpName.APPEND); + @Override + public Response append(final String key, final String value) { + return execOp(key, OpName.APPEND, () -> jedisPipeline.append(key, value)); } @Override public Response> blpop(final String arg) { - - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.blpop(arg); - } - }.execute(arg, OpName.BLPOP); - + return execOp(arg, OpName.BLPOP, () -> jedisPipeline.blpop(arg)); } @Override public Response> brpop(final String arg) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.brpop(arg); - } - }.execute(arg, OpName.BRPOP); - + return execOp(arg, OpName.BRPOP, () -> jedisPipeline.brpop(arg)); } @Override public Response decr(final String key) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.decr(key); - } - }.execute(key, OpName.DECR); + return execOp(key, OpName.DECR, () -> jedisPipeline.decr(key)); } @Override public Response decrBy(final String key, final long integer) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.decrBy(key, integer); - } - }.execute(key, OpName.DECRBY); + return execOp(key, OpName.DECRBY, () -> jedisPipeline.decrBy(key, integer)); } @Override public Response del(final String key) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.del(key); - } - }.execute(key, OpName.DEL); + return execOp(key, OpName.DEL, () -> jedisPipeline.del(key)); } @Override public Response unlink(String key) { - return new PipelineOperation() { - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.unlink(key); - } - }.execute(key, OpName.UNLINK); + return execOp(key, OpName.UNLINK, () -> jedisPipeline.unlink(key)); } @Override public Response echo(final String string) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.echo(string); - } - }.execute(string, OpName.ECHO); + return execOp(string, OpName.ECHO, () -> jedisPipeline.echo(string)); } @Override public Response exists(final String key) { - return new PipelineOperation() { - - @Override - Response execute(final Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.exists(key); - } - }.execute(key, OpName.EXISTS); + return execOp(key, OpName.EXISTS, () -> jedisPipeline.exists(key)); } @Override public Response expire(final String key, final int seconds) { - return new PipelineOperation() { - - @Override - Response execute(final Pipeline jedisPipeline) throws DynoException { - long startTime = System.nanoTime() / 1000; - try { - return jedisPipeline.expire(key, seconds); - } finally { - long duration = System.nanoTime() / 1000 - startTime; - opMonitor.recordSendLatency(OpName.EXPIRE.name(), duration, TimeUnit.MICROSECONDS); - } - } - }.execute(key, OpName.EXPIRE); + return execOp(key, OpName.EXPIRE, () -> jedisPipeline.expire(key, seconds)); } @@ -629,13 +560,7 @@ public Response pexpire(String key, long milliseconds) { @Override public Response expireAt(final String key, final long unixTime) { - return new PipelineOperation() { - - @Override - Response execute(final Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.expireAt(key, unixTime); - } - }.execute(key, OpName.EXPIREAT); + return execOp(key, OpName.EXPIREAT, () -> jedisPipeline.expireAt(key, unixTime)); } @@ -647,238 +572,74 @@ public Response pexpireAt(String key, long millisecondsTimestamp) { @Override public Response get(final String key) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return new PipelineOperation() { - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - long startTime = System.nanoTime() / 1000; - try { - return jedisPipeline.get(key); - } finally { - long duration = System.nanoTime() / 1000 - startTime; - opMonitor.recordSendLatency(OpName.GET.name(), duration, TimeUnit.MICROSECONDS); - } - } - }.execute(key, OpName.GET); + return execOp(key, OpName.GET, () -> jedisPipeline.get(key)); } else { - return new PipelineCompressionOperation() { - @Override - Response execute(final Pipeline jedisPipeline) throws DynoException { - return new PipelineResponse(null).apply(new Func0>() { - @Override - public Response call() { - return jedisPipeline.get(key); - } - }); - } - }.execute(key, OpName.GET); + return execOp(key, OpName.GET, () -> decompress(jedisPipeline.get(key))); } } @Override public Response getbit(final String key, final long offset) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.getbit(key, offset); - } - }.execute(key, OpName.GETBIT); + return execOp(key, OpName.GETBIT, () -> jedisPipeline.getbit(key, offset)); } @Override public Response getrange(final String key, final long startOffset, final long endOffset) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.getrange(key, startOffset, endOffset); - } - }.execute(key, OpName.GETRANGE); + return execOp(key, OpName.GETRANGE, () -> jedisPipeline.getrange(key, startOffset, endOffset)); } @Override public Response getSet(final String key, final String value) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return new PipelineOperation() { - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.getSet(key, value); - } - }.execute(key, OpName.GETSET); + return execOp(key, OpName.GETSET, () -> jedisPipeline.getSet(key, value)); } else { - return new PipelineCompressionOperation() { - @Override - Response execute(final Pipeline jedisPipeline) throws DynoException { - return new PipelineResponse(null).apply(new Func0>() { - @Override - public Response call() { - return jedisPipeline.getSet(key, compressValue(value)); - } - }); - } - }.execute(key, OpName.GETSET); + return execOp(key, OpName.GETSET, () -> decompress(jedisPipeline.getSet(key, compress(value)))); } } @Override public Response hdel(final String key, final String... field) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.hdel(key, field); - } - }.execute(key, OpName.HDEL); + return execOp(key, OpName.HDEL, () -> jedisPipeline.hdel(key, field)); } @Override public Response hexists(final String key, final String field) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.hexists(key, field); - } - }.execute(key, OpName.HEXISTS); + return execOp(key, OpName.HEXISTS, () -> jedisPipeline.hexists(key, field)); } @Override public Response hget(final String key, final String field) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return new PipelineOperation() { - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.hget(key, field); - } - }.execute(key, OpName.HGET); + return execOp(key, OpName.HGET, () -> jedisPipeline.hget(key, field)); } else { - return new PipelineCompressionOperation() { - @Override - Response execute(final Pipeline jedisPipeline) throws DynoException { - return new PipelineResponse(null).apply(new Func0>() { - @Override - public Response call() { - return jedisPipeline.hget(key, field); - } - }); - } - }.execute(key, OpName.HGET); + return execOp(key, OpName.HGET, () -> decompress(jedisPipeline.hget(key, field))); } } - /** - * This method is a BinaryRedisPipeline command which dyno does not yet properly - * support, therefore the interface is not yet implemented. - */ - public Response hget(final byte[] key, final byte[] field) { - if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return new PipelineOperation() { - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.hget(key, field); - } - }.execute(key, OpName.HGET); - } else { - return new PipelineCompressionOperation() { - @Override - Response execute(final Pipeline jedisPipeline) throws DynoException { - return new PipelineBinaryResponse(null).apply(new Func0>() { - @Override - public Response call() { - return jedisPipeline.hget(key, field); - } - }); - } - }.execute(key, OpName.HGET); - } - } - @Override public Response> hgetAll(final String key) { - - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - long startTime = System.nanoTime() / 1000; - try { - return jedisPipeline.hgetAll(key); - } finally { - long duration = System.nanoTime() / 1000 - startTime; - opMonitor.recordSendLatency(OpName.HGETALL.name(), duration, TimeUnit.MICROSECONDS); - } - } - - }.execute(key, OpName.HGETALL); - - } - - public Response> hgetAll(final byte[] key) { - if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return new PipelineOperation>() { - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - long startTime = System.nanoTime() / 1000; - try { - return jedisPipeline.hgetAll(key); - } finally { - long duration = System.nanoTime() / 1000 - startTime; - opMonitor.recordSendLatency(OpName.HGETALL.name(), duration, TimeUnit.MICROSECONDS); - } - } - }.execute(key, OpName.HGETALL); - } else { - return new PipelineCompressionOperation>() { - @Override - Response> execute(final Pipeline jedisPipeline) throws DynoException { - return new PipelineBinaryMapResponse(null).apply(new Func0>>() { - @Override - public Response> call() { - return jedisPipeline.hgetAll(key); - } - }); - } - }.execute(key, OpName.HGETALL); - } + return execOp(key, OpName.HGETALL, () -> jedisPipeline.hgetAll(key)); } @Override public Response hincrBy(final String key, final String field, final long value) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.hincrBy(key, field, value); - } - }.execute(key, OpName.HINCRBY); + return execOp(key, OpName.HINCRBY, () -> jedisPipeline.hincrBy(key, field, value)); } /* not supported by RedisPipeline 2.7.3 */ public Response hincrByFloat(final String key, final String field, final double value) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.hincrByFloat(key, field, value); - } - }.execute(key, OpName.HINCRBYFLOAT); + return execOp(key, OpName.HINCRBYFLOAT, () -> jedisPipeline.hincrByFloat(key, field, value)); } @Override public Response> hkeys(final String key) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.hkeys(key); - } - }.execute(key, OpName.HKEYS); + return execOp(key, OpName.HKEYS, () -> jedisPipeline.hkeys(key)); } @@ -888,170 +649,34 @@ public Response>> hscan(final String key, i @Override public Response hlen(final String key) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.hlen(key); - } - }.execute(key, OpName.HLEN); - - } - - /** - * This method is a BinaryRedisPipeline command which dyno does not yet properly - * support, therefore the interface is not yet implemented. - */ - public Response> hmget(final byte[] key, final byte[]... fields) { - return new PipelineOperation>() { + return execOp(key, OpName.HLEN, () -> jedisPipeline.hlen(key)); - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - long startTime = System.nanoTime() / 1000; - try { - return jedisPipeline.hmget(key, fields); - } finally { - long duration = System.nanoTime() / 1000 - startTime; - opMonitor.recordSendLatency(OpName.HMGET.name(), duration, TimeUnit.MICROSECONDS); - } - } - }.execute(key, OpName.HMGET); } @Override public Response> hmget(final String key, final String... fields) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return new PipelineOperation>() { - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - long startTime = System.nanoTime() / 1000; - try { - return jedisPipeline.hmget(key, fields); - } finally { - long duration = System.nanoTime() / 1000 - startTime; - opMonitor.recordSendLatency(OpName.HMGET.name(), duration, TimeUnit.MICROSECONDS); - } - } - }.execute(key, OpName.HMGET); - } else { - return new PipelineCompressionOperation>() { - @Override - Response> execute(final Pipeline jedisPipeline) throws DynoException { - long startTime = System.nanoTime() / 1000; - try { - return new PipelineListResponse(null).apply(new Func0>>() { - @Override - public Response> call() { - return jedisPipeline.hmget(key, fields); - } - }); - } finally { - long duration = System.nanoTime() / 1000 - startTime; - opMonitor.recordSendLatency(OpName.HMGET.name(), duration, TimeUnit.MICROSECONDS); - } - } - }.execute(key, OpName.HGET); - } - } - - /** - * This method is a BinaryRedisPipeline command which dyno does not yet properly - * support, therefore the interface is not yet implemented since only a few - * binary commands are present. - */ - public Response hmset(final byte[] key, final Map hash) { - if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return new PipelineOperation() { - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - long startTime = System.nanoTime() / 1000; - try { - return jedisPipeline.hmset(key, hash); - } finally { - long duration = System.nanoTime() / 1000 - startTime; - opMonitor.recordSendLatency(OpName.HMSET.name(), duration, TimeUnit.MICROSECONDS); - } - } - }.execute(key, OpName.HMSET); + return execOp(key, OpName.HMGET, () -> jedisPipeline.hmget(key, fields)); } else { - return new PipelineCompressionOperation() { - @Override - Response execute(final Pipeline jedisPipeline) throws DynoException { - return new PipelineResponse(null).apply(new Func0>() { - @Override - public Response call() { - return jedisPipeline.hmset(key, CollectionUtils.transform(hash, - new CollectionUtils.MapEntryTransform() { - @Override - public byte[] get(byte[] key, byte[] val) { - return compressValue(val); - } - })); - } - }); - } - }.execute(key, OpName.HMSET); + return execOp(key, OpName.HMGET, () -> decompressList(jedisPipeline.hmget(key, fields))); } } @Override public Response hmset(final String key, final Map hash) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return new PipelineOperation() { - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - long startTime = System.nanoTime() / 1000; - try { - return jedisPipeline.hmset(key, hash); - } finally { - long duration = System.nanoTime() / 1000 - startTime; - opMonitor.recordSendLatency(OpName.HMSET.name(), duration, TimeUnit.MICROSECONDS); - } - } - }.execute(key, OpName.HMSET); + return execOp(key, OpName.HMSET, () -> jedisPipeline.hmset(key, hash)); } else { - return new PipelineCompressionOperation() { - @Override - Response execute(final Pipeline jedisPipeline) throws DynoException { - return new PipelineResponse(null).apply(new Func0>() { - @Override - public Response call() { - return jedisPipeline.hmset(key, CollectionUtils.transform(hash, - new CollectionUtils.MapEntryTransform() { - @Override - public String get(String key, String val) { - return compressValue(val); - } - })); - } - }); - } - }.execute(key, OpName.HMSET); + return execOp(key, OpName.HMSET, () -> jedisPipeline.hmset(key, compressMap(hash))); } - } @Override public Response hset(final String key, final String field, final String value) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return new PipelineOperation() { - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.hset(key, field, value); - } - }.execute(key, OpName.HSET); + return execOp(key, OpName.HSET, () -> jedisPipeline.hset(key, field, value)); } else { - return new PipelineCompressionOperation() { - @Override - Response execute(final Pipeline jedisPipeline) throws DynoException { - return new PipelineLongResponse(null).apply(new Func0>() { - @Override - public Response call() { - return jedisPipeline.hset(key, field, compressValue(value)); - } - }); - } - }.execute(key, OpName.HSET); + return execOp(key, OpName.HSET, () -> jedisPipeline.hset(key, field, compress(value))); } } @@ -1060,535 +685,224 @@ public Response hset(String key, Map hash) { throw new UnsupportedOperationException("not yet implemented"); } - /** - * This method is a BinaryRedisPipeline command which dyno does not yet properly - * support, therefore the interface is not yet implemented. - */ - public Response hset(final byte[] key, final byte[] field, final byte[] value) { - if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return new PipelineOperation() { - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.hset(key, field, value); - } - }.execute(key, OpName.HSET); - } else { - return new PipelineCompressionOperation() { - @Override - Response execute(final Pipeline jedisPipeline) throws DynoException { - return new PipelineLongResponse(null).apply(new Func0>() { - @Override - public Response call() { - return jedisPipeline.hset(key, field, compressValue(value)); - } - }); - } - }.execute(key, OpName.HSET); - } - } - - @Override - public Response hset(byte[] key, Map hash) { - throw new UnsupportedOperationException("not yet implemented"); - } - @Override public Response hsetnx(final String key, final String field, final String value) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return new PipelineOperation() { - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.hsetnx(key, field, value); - } - }.execute(key, OpName.HSETNX); + return execOp(key, OpName.HSETNX, () -> jedisPipeline.hsetnx(key, field, value)); } else { - return new PipelineCompressionOperation() { - @Override - Response execute(final Pipeline jedisPipeline) throws DynoException { - return new PipelineLongResponse(null).apply(new Func0>() { - @Override - public Response call() { - return jedisPipeline.hsetnx(key, field, compressValue(value)); - } - }); - } - }.execute(key, OpName.HSETNX); + return execOp(key, OpName.HSETNX, () -> jedisPipeline.hsetnx(key, field, compress(value))); } } @Override public Response> hvals(final String key) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return new PipelineOperation>() { - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.hvals(key); - } - }.execute(key, OpName.HVALS); + return execOp(key, OpName.HVALS, () -> jedisPipeline.hvals(key)); } else { - return new PipelineCompressionOperation>() { - @Override - Response> execute(final Pipeline jedisPipeline) throws DynoException { - return new PipelineListResponse(null).apply(new Func0>>() { - @Override - public Response> call() { - return jedisPipeline.hvals(key); - } - }); - } - }.execute(key, OpName.HVALS); + return execOp(key, OpName.HVALS, () -> decompressList(jedisPipeline.hvals(key))); } } @Override public Response incr(final String key) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.incr(key); - } - - }.execute(key, OpName.INCR); + return execOp(key, OpName.INCR, () -> jedisPipeline.incr(key)); } @Override public Response incrBy(final String key, final long integer) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.incrBy(key, integer); - } - - }.execute(key, OpName.INCRBY); + return execOp(key, OpName.INCRBY, () -> jedisPipeline.incrBy(key, integer)); } /* not supported by RedisPipeline 2.7.3 */ public Response incrByFloat(final String key, final double increment) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.incrByFloat(key, increment); - } - - }.execute(key, OpName.INCRBYFLOAT); + return execOp(key, OpName.INCRBYFLOAT, () -> jedisPipeline.incrByFloat(key, increment)); } @Override public Response psetex(String key, long milliseconds, String value) { - return null; + throw new UnsupportedOperationException("not yet implemented"); } @Override public Response lindex(final String key, final long index) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.lindex(key, index); - } - - }.execute(key, OpName.LINDEX); + return execOp(key, OpName.LINDEX, () -> jedisPipeline.lindex(key, index)); } @Override public Response linsert(final String key, final ListPosition where, final String pivot, final String value) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.linsert(key, where, pivot, value); - } - - }.execute(key, OpName.LINSERT); + return execOp(key, OpName.LINSERT, () -> jedisPipeline.linsert(key, where, pivot, value)); } @Override public Response llen(final String key) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.llen(key); - } - - }.execute(key, OpName.LLEN); + return execOp(key, OpName.LLEN, () -> jedisPipeline.llen(key)); } @Override public Response lpop(final String key) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.lpop(key); - } - - }.execute(key, OpName.LPOP); + return execOp(key, OpName.LPOP, () -> jedisPipeline.lpop(key)); } @Override public Response lpush(final String key, final String... string) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.lpush(key, string); - } - - }.execute(key, OpName.LPUSH); + return execOp(key, OpName.LPUSH, () -> jedisPipeline.lpush(key, string)); } @Override public Response lpushx(final String key, final String... string) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.lpushx(key, string); - } - - }.execute(key, OpName.LPUSHX); + return execOp(key, OpName.LPUSHX, () -> jedisPipeline.lpushx(key, string)); } @Override public Response> lrange(final String key, final long start, final long end) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.lrange(key, start, end); - } - - }.execute(key, OpName.LRANGE); + return execOp(key, OpName.LRANGE, () -> jedisPipeline.lrange(key, start, end)); } @Override public Response lrem(final String key, final long count, final String value) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.lrem(key, count, value); - } - - }.execute(key, OpName.LREM); + return execOp(key, OpName.LREM, () -> jedisPipeline.lrem(key, count, value)); } @Override public Response lset(final String key, final long index, final String value) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.lset(key, index, value); - } - - }.execute(key, OpName.LSET); + return execOp(key, OpName.LSET, () -> jedisPipeline.lset(key, index, value)); } @Override public Response ltrim(final String key, final long start, final long end) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.ltrim(key, start, end); - } - - }.execute(key, OpName.LTRIM); + return execOp(key, OpName.LTRIM, () -> jedisPipeline.ltrim(key, start, end)); } @Override public Response move(final String key, final int dbIndex) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.move(key, dbIndex); - } - - }.execute(key, OpName.MOVE); + return execOp(key, OpName.MOVE, () -> jedisPipeline.move(key, dbIndex)); } @Override public Response persist(final String key) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.persist(key); - } - - }.execute(key, OpName.PERSIST); + return execOp(key, OpName.PERSIST, () -> jedisPipeline.persist(key)); } /* not supported by RedisPipeline 2.7.3 */ public Response rename(final String oldkey, final String newkey) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.rename(oldkey, newkey); - } - }.execute(oldkey, OpName.RENAME); + return execOp(oldkey, OpName.RENAME, () -> jedisPipeline.rename(oldkey, newkey)); } /* not supported by RedisPipeline 2.7.3 */ public Response renamenx(final String oldkey, final String newkey) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.renamenx(oldkey, newkey); - } - }.execute(oldkey, OpName.RENAMENX); + return execOp(oldkey, OpName.RENAMENX, () -> jedisPipeline.renamenx(oldkey, newkey)); } @Override public Response rpop(final String key) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.rpop(key); - } - - }.execute(key, OpName.RPOP); + return execOp(key, OpName.RPOP, () -> jedisPipeline.rpop(key)); } @Override public Response rpush(final String key, final String... string) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.rpush(key, string); - } - - }.execute(key, OpName.RPUSH); + return execOp(key, OpName.RPUSH, () -> jedisPipeline.rpush(key, string)); } @Override public Response rpushx(final String key, final String... string) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.rpushx(key, string); - } - - }.execute(key, OpName.RPUSHX); + return execOp(key, OpName.RPUSHX, () -> jedisPipeline.rpushx(key, string)); } @Override public Response sadd(final String key, final String... member) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.sadd(key, member); - } - - }.execute(key, OpName.SADD); + return execOp(key, OpName.SADD, () -> jedisPipeline.sadd(key, member)); } @Override public Response scard(final String key) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.scard(key); - } - - }.execute(key, OpName.SCARD); + return execOp(key, OpName.SCARD, () -> jedisPipeline.scard(key)); } @Override public Response sismember(final String key, final String member) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.sismember(key, member); - } - - }.execute(key, OpName.SISMEMBER); + return execOp(key, OpName.SISMEMBER, () -> jedisPipeline.sismember(key, member)); } @Override public Response set(final String key, final String value) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return new PipelineOperation() { - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - long startTime = System.nanoTime() / 1000; - try { - return jedisPipeline.set(key, value); - } finally { - long duration = System.nanoTime() / 1000 - startTime; - opMonitor.recordSendLatency(OpName.SET.name(), duration, TimeUnit.MICROSECONDS); - } - } - - }.execute(key, OpName.SET); + return execOp(key, OpName.SET, () -> jedisPipeline.set(key, value)); } else { - return new PipelineCompressionOperation() { - @Override - Response execute(final Pipeline jedisPipeline) throws DynoException { - long startTime = System.nanoTime() / 1000; - try { - return new PipelineResponse(null).apply(new Func0>() { - @Override - public Response call() { - return jedisPipeline.set(key, compressValue(value)); - } - }); - } finally { - long duration = System.nanoTime() / 1000 - startTime; - opMonitor.recordSendLatency(OpName.SET.name(), duration, TimeUnit.MICROSECONDS); - } - } - }.execute(key, OpName.SET); + return execOp(key, OpName.SET, () -> jedisPipeline.set(key, compress(value))); } } @Override public Response setbit(final String key, final long offset, final boolean value) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.setbit(key, offset, value); - } - - }.execute(key, OpName.SETBIT); + return execOp(key, OpName.SETBIT, () -> jedisPipeline.setbit(key, offset, value)); } @Override public Response setex(final String key, final int seconds, final String value) { if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { - return new PipelineOperation() { - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.setex(key, seconds, value); - } - }.execute(key, OpName.SETEX); + return execOp(key, OpName.SETEX, () -> jedisPipeline.setex(key, seconds, value)); } else { - return new PipelineCompressionOperation() { - @Override - Response execute(final Pipeline jedisPipeline) throws DynoException { - return new PipelineResponse(null).apply(new Func0>() { - @Override - public Response call() { - return jedisPipeline.setex(key, seconds, compressValue(value)); - } - }); - } - }.execute(key, OpName.SETEX); + return execOp(key, OpName.SETEX, () -> jedisPipeline.setex(key, seconds, compress(value))); } } @Override public Response setnx(final String key, final String value) { - return new PipelineOperation() { - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.setnx(key, value); - } - }.execute(key, OpName.SETNX); + return execOp(key, OpName.SETNX, () -> jedisPipeline.setnx(key, value)); } @Override public Response setrange(final String key, final long offset, final String value) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.setrange(key, offset, value); - } - - }.execute(key, OpName.SETRANGE); + return execOp(key, OpName.SETRANGE, () -> jedisPipeline.setrange(key, offset, value)); } @Override public Response> smembers(final String key) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.smembers(key); - } - - }.execute(key, OpName.SMEMBERS); + return execOp(key, OpName.SMEMBERS, () -> jedisPipeline.smembers(key)); } @Override public Response> sort(final String key) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.sort(key); - } - - }.execute(key, OpName.SORT); + return execOp(key, OpName.SORT, () -> jedisPipeline.sort(key)); } @Override public Response> sort(final String key, final SortingParams sortingParameters) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.sort(key, sortingParameters); - } - - }.execute(key, OpName.SORT); + return execOp(key, OpName.SORT, () -> jedisPipeline.sort(key, sortingParameters)); } @Override public Response spop(final String key) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.spop(key); - } - - }.execute(key, OpName.SPOP); + return execOp(key, OpName.SPOP, () -> jedisPipeline.spop(key)); } @@ -1599,67 +913,33 @@ public Response> spop(final String key, final long count) { @Override public Response srandmember(final String key) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.srandmember(key); - } - - }.execute(key, OpName.SRANDMEMBER); + return execOp(key, OpName.SRANDMEMBER, () -> jedisPipeline.srandmember(key)); } @Override public Response srem(final String key, final String... member) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.srem(key, member); - } - - }.execute(key, OpName.SREM); + return execOp(key, OpName.SREM, () -> jedisPipeline.srem(key, member)); } - /** - * This method is not supported by the BinaryRedisPipeline interface. - */ public Response> sscan(final String key, final int cursor) { throw new UnsupportedOperationException("'SSCAN' cannot be called in pipeline"); } - /** - * This method is not supported by the BinaryRedisPipeline interface. - */ public Response> sscan(final String key, final String cursor) { throw new UnsupportedOperationException("'SSCAN' cannot be called in pipeline"); } @Override public Response strlen(final String key) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.strlen(key); - } - - }.execute(key, OpName.STRLEN); + return execOp(key, OpName.STRLEN, () -> jedisPipeline.strlen(key)); } @Override public Response substr(final String key, final int start, final int end) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.substr(key, start, end); - } - - }.execute(key, OpName.SUBSTR); + return execOp(key, OpName.SUBSTR, () -> jedisPipeline.substr(key, start, end)); } @@ -1670,442 +950,205 @@ public Response touch(String key) { @Override public Response ttl(final String key) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.ttl(key); - } - - }.execute(key, OpName.TTL); + return execOp(key, OpName.TTL, () -> jedisPipeline.ttl(key)); } @Override public Response pttl(String key) { - return new PipelineOperation() { - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.pttl(key); - } - }.execute(key, OpName.PTTL); + return execOp(key, OpName.PTTL, () -> jedisPipeline.pttl(key)); } @Override public Response type(final String key) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.type(key); - } - - }.execute(key, OpName.TYPE); + return execOp(key, OpName.TYPE, () -> jedisPipeline.type(key)); } @Override public Response zadd(final String key, final double score, final String member) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zadd(key, score, member); - } - - }.execute(key, OpName.ZADD); + return execOp(key, OpName.ZADD, () -> jedisPipeline.zadd(key, score, member)); } @Override public Response zadd(final String key, final Map scoreMembers) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zadd(key, scoreMembers); - } - - }.execute(key, OpName.ZADD); + return execOp(key, OpName.ZADD, () -> jedisPipeline.zadd(key, scoreMembers)); } @Override public Response zcard(final String key) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zcard(key); - } - - }.execute(key, OpName.ZCARD); + return execOp(key, OpName.ZCARD, () -> jedisPipeline.zcard(key)); } @Override public Response zcount(final String key, final double min, final double max) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zcount(key, min, max); - } - - }.execute(key, OpName.ZCOUNT); + return execOp(key, OpName.ZCOUNT, () -> jedisPipeline.zcount(key, min, max)); } @Override public Response zcount(String key, String min, String max) { - return new PipelineOperation() { - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zcount(key, min, max); - } - }.execute(key, OpName.ZCOUNT); + return execOp(key, OpName.ZCOUNT, () -> jedisPipeline.zcount(key, min, max)); } @Override public Response zincrby(final String key, final double score, final String member) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zincrby(key, score, member); - } - - }.execute(key, OpName.ZINCRBY); + return execOp(key, OpName.ZINCRBY, () -> jedisPipeline.zincrby(key, score, member)); } @Override public Response> zrange(final String key, final long start, final long end) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zrange(key, start, end); - } - - }.execute(key, OpName.ZRANGE); + return execOp(key, OpName.ZRANGE, () -> jedisPipeline.zrange(key, start, end)); } @Override public Response> zrangeByScore(final String key, final double min, final double max) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zrangeByScore(key, min, max); - } - - }.execute(key, OpName.ZRANGEBYSCORE); + return execOp(key, OpName.ZRANGEBYSCORE, () -> jedisPipeline.zrangeByScore(key, min, max)); } @Override public Response> zrangeByScore(final String key, final String min, final String max) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zrangeByScore(key, min, max); - } - - }.execute(key, OpName.ZRANGEBYSCORE); + return execOp(key, OpName.ZRANGEBYSCORE, () -> jedisPipeline.zrangeByScore(key, min, max)); } @Override public Response> zrangeByScore(final String key, final double min, final double max, final int offset, final int count) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zrangeByScore(key, min, max, offset, count); - } - - }.execute(key, OpName.ZRANGEBYSCORE); + return execOp(key, OpName.ZRANGEBYSCORE, () -> jedisPipeline.zrangeByScore(key, min, max, offset, count)); } @Override public Response> zrangeByScore(String key, String min, String max, int offset, int count) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zrangeByScore(key, min, max, offset, count); - } - - }.execute(key, OpName.ZRANGEBYSCORE); + return execOp(key, OpName.ZRANGEBYSCORE, () -> jedisPipeline.zrangeByScore(key, min, max, offset, count)); } @Override public Response> zrangeByScoreWithScores(final String key, final double min, final double max) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zrangeByScoreWithScores(key, min, max); - } - - }.execute(key, OpName.ZRANGEBYSCOREWITHSCORES); + return execOp(key, OpName.ZRANGEBYSCOREWITHSCORES, () -> jedisPipeline.zrangeByScoreWithScores(key, min, max)); } @Override public Response> zrangeByScoreWithScores(final String key, final double min, final double max, final int offset, final int count) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zrangeByScoreWithScores(key, min, max, offset, count); - } - - }.execute(key, OpName.ZRANGEBYSCOREWITHSCORES); + return execOp(key, OpName.ZRANGEBYSCOREWITHSCORES, () -> jedisPipeline.zrangeByScoreWithScores(key, min, max, offset, count)); } @Override public Response> zrevrangeByScore(final String key, final double max, final double min) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zrevrangeByScore(key, max, min); - } - - }.execute(key, OpName.ZREVRANGEBYSCORE); + return execOp(key, OpName.ZREVRANGEBYSCORE, () -> jedisPipeline.zrevrangeByScore(key, max, min)); } @Override public Response> zrevrangeByScore(final String key, final String max, final String min) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zrevrangeByScore(key, max, min); - } - - }.execute(key, OpName.ZREVRANGEBYSCORE); + return execOp(key, OpName.ZREVRANGEBYSCORE, () -> jedisPipeline.zrevrangeByScore(key, max, min)); } @Override public Response> zrevrangeByScore(final String key, final double max, final double min, final int offset, final int count) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zrevrangeByScore(key, max, min, offset, count); - } - - }.execute(key, OpName.ZREVRANGEBYSCORE); + return execOp(key, OpName.ZREVRANGEBYSCORE, () -> jedisPipeline.zrevrangeByScore(key, max, min, offset, count)); } @Override public Response> zrevrangeByScore(String key, String max, String min, int offset, int count) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zrevrangeByScore(key, max, min, offset, count); - } - - }.execute(key, OpName.ZREVRANGEBYSCORE); + return execOp(key, OpName.ZREVRANGEBYSCORE, () -> jedisPipeline.zrevrangeByScore(key, max, min, offset, count)); } @Override public Response> zrevrangeByScoreWithScores(final String key, final double max, final double min) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zrevrangeByScoreWithScores(key, max, min); - } - - }.execute(key, OpName.ZREVRANGEBYSCOREWITHSCORES); + return execOp(key, OpName.ZREVRANGEBYSCOREWITHSCORES, () -> jedisPipeline.zrevrangeByScoreWithScores(key, max, min)); } @Override public Response> zrevrangeByScoreWithScores(String key, String max, String min) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zrevrangeByScoreWithScores(key, max, min); - } - - }.execute(key, OpName.ZREVRANGEBYSCOREWITHSCORES); + return execOp(key, OpName.ZREVRANGEBYSCOREWITHSCORES, () -> jedisPipeline.zrevrangeByScoreWithScores(key, max, min)); } @Override public Response> zrevrangeByScoreWithScores(final String key, final double max, final double min, final int offset, final int count) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zrevrangeByScoreWithScores(key, max, min, offset, count); - } - - }.execute(key, OpName.ZREVRANGEBYSCOREWITHSCORES); + return execOp(key, OpName.ZREVRANGEBYSCOREWITHSCORES, () -> jedisPipeline.zrevrangeByScoreWithScores(key, max, min, offset, count)); } @Override public Response> zrevrangeByScoreWithScores(String key, String max, String min, int offset, int count) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zrevrangeByScoreWithScores(key, max, min, offset, count); - } - - }.execute(key, OpName.ZREVRANGEBYSCOREWITHSCORES); + return execOp(key, OpName.ZREVRANGEBYSCOREWITHSCORES, () -> jedisPipeline.zrevrangeByScoreWithScores(key, max, min, offset, count)); } @Override public Response> zrangeWithScores(final String key, final long start, final long end) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zrangeWithScores(key, start, end); - } - - }.execute(key, OpName.ZRANGEWITHSCORES); + return execOp(key, OpName.ZRANGEWITHSCORES, () -> jedisPipeline.zrangeWithScores(key, start, end)); } @Override public Response zrank(final String key, final String member) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zrank(key, member); - } - - }.execute(key, OpName.ZRANK); + return execOp(key, OpName.ZRANK, () -> jedisPipeline.zrank(key, member)); } @Override public Response zrem(final String key, final String... member) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zrem(key, member); - } - - }.execute(key, OpName.ZREM); + return execOp(key, OpName.ZREM, () -> jedisPipeline.zrem(key, member)); } @Override public Response zremrangeByRank(final String key, final long start, final long end) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zremrangeByRank(key, start, end); - } - - }.execute(key, OpName.ZREMRANGEBYRANK); + return execOp(key, OpName.ZREMRANGEBYRANK, () -> jedisPipeline.zremrangeByRank(key, start, end)); } @Override public Response zremrangeByScore(final String key, final double start, final double end) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zremrangeByScore(key, start, end); - } - - }.execute(key, OpName.ZREMRANGEBYSCORE); + return execOp(key, OpName.ZREMRANGEBYSCORE, () -> jedisPipeline.zremrangeByScore(key, start, end)); } @Override public Response zremrangeByScore(String key, String min, String max) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zremrangeByScore(key, min, max); - } - - }.execute(key, OpName.ZREMRANGEBYSCORE); + return execOp(key, OpName.ZREMRANGEBYSCORE, () -> jedisPipeline.zremrangeByScore(key, min, max)); } @Override public Response> zrevrange(final String key, final long start, final long end) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zrevrange(key, start, end); - } - - }.execute(key, OpName.ZREVRANGE); + return execOp(key, OpName.ZREVRANGE, () -> jedisPipeline.zrevrange(key, start, end)); } @Override public Response> zrevrangeWithScores(final String key, final long start, final long end) { - return new PipelineOperation>() { - - @Override - Response> execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zrevrangeWithScores(key, start, end); - } - - }.execute(key, OpName.ZREVRANGEWITHSCORES); + return execOp(key, OpName.ZREVRANGEWITHSCORES, () -> jedisPipeline.zrevrangeWithScores(key, start, end)); } @Override public Response zrevrank(final String key, final String member) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zrevrank(key, member); - } - - }.execute(key, OpName.ZREVRANK); + return execOp(key, OpName.ZREVRANK, () -> jedisPipeline.zrevrank(key, member)); } @Override public Response zscore(final String key, final String member) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zscore(key, member); - } - - }.execute(key, OpName.ZSCORE); + return execOp(key, OpName.ZSCORE, () -> jedisPipeline.zscore(key, member)); } - /** - * This method is not supported by the BinaryRedisPipeline interface. - */ public Response> zscan(final String key, final int cursor) { throw new UnsupportedOperationException("'ZSCAN' cannot be called in pipeline"); } @@ -2132,46 +1175,14 @@ public Response zremrangeByLex(String key, String start, String end) { @Override public Response bitcount(final String key) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.bitcount(key); - } - - }.execute(key, OpName.BITCOUNT); + return execOp(key, OpName.BITCOUNT, () -> jedisPipeline.bitcount(key)); } @Override public Response bitcount(final String key, final long start, final long end) { - return new PipelineOperation() { - - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.bitcount(key, start, end); - } + return execOp(key, OpName.BITCOUNT, () -> jedisPipeline.bitcount(key, start, end)); - }.execute(key, OpName.BITCOUNT); - - } - - /**** Binary Operations ****/ - @Override - public Response set(final byte[] key, final byte[] value) { - return new PipelineOperation() { - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - long startTime = System.nanoTime() / 1000; - try { - return jedisPipeline.set(key, value); - } finally { - long duration = System.nanoTime() / 1000 - startTime; - opMonitor.recordSendLatency(OpName.SET.name(), duration, TimeUnit.MICROSECONDS); - } - } - - }.execute(key, OpName.SET); } @Override @@ -2191,26 +1202,21 @@ public Response> bitfield(String key, String... arguments) { @Override public Response hstrlen(String key, String field) { - return new PipelineOperation() { - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.hstrlen(key, field); - } - }.execute(key, OpName.HSTRLEN); + return execOp(key, OpName.HSTRLEN, () -> jedisPipeline.hstrlen(key, field)); } @Override - public Response dump(String key) { + public Response restore(String key, int ttl, byte[] serializedValue) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response restore(String key, int ttl, byte[] serializedValue) { + public Response restoreReplace(String key, int ttl, byte[] serializedValue) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response restoreReplace(String key, int ttl, byte[] serializedValue) { + public Response dump(String key) { throw new UnsupportedOperationException("not yet implemented"); } @@ -2304,699 +1310,729 @@ public Response> georadiusByMemberReadonly(String key, S @Override public Response bitpos(String key, boolean value) { - return null; + throw new UnsupportedOperationException("not yet implemented"); } @Override public Response bitpos(String key, boolean value, BitPosParams params) { - return null; + throw new UnsupportedOperationException("not yet implemented"); } @Override public Response set(String key, String value, SetParams params) { - return null; + throw new UnsupportedOperationException("not yet implemented"); } @Override public Response> srandmember(String key, int count) { - return null; + throw new UnsupportedOperationException("not yet implemented"); } @Override public Response> zrangeByScoreWithScores(String key, String min, String max) { - return null; + throw new UnsupportedOperationException("not yet implemented"); } @Override public Response> zrangeByScoreWithScores(String key, String min, String max, int offset, int count) { - return null; + throw new UnsupportedOperationException("not yet implemented"); } @Override public Response objectRefcount(String key) { - return null; + throw new UnsupportedOperationException("not yet implemented"); } @Override public Response objectEncoding(String key) { - return null; + throw new UnsupportedOperationException("not yet implemented"); } @Override public Response objectIdletime(String key) { - return null; + throw new UnsupportedOperationException("not yet implemented"); } @Override public Response zadd(String key, Map members, ZAddParams params) { - return new PipelineOperation() { + return execOp(key, OpName.ZADD, () -> jedisPipeline.zadd(key, members, params)); + } - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zadd(key, members, params); - } + public Response zadd(final String key, final double score, final String member, final ZAddParams params) { + return execOp(key, OpName.ZADD, () -> jedisPipeline.zadd(key, score, member, params)); + } - }.execute(key, OpName.ZADD); + @Override + public Response zincrby(String arg0, double arg1, String arg2, ZIncrByParams arg3) { + throw new UnsupportedOperationException("not yet implemented"); } - public Response zadd(final String key, final double score, final String member, final ZAddParams params) { - return new PipelineOperation() { + /******************* End Jedis String Commands **************/ - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.zadd(key, score, member, params); - } - }.execute(key, OpName.ZADD); + /******************* Jedis Binary Commands **************/ + @Override + public Response append(final byte[] key, final byte[] value) { + return execOp(key, OpName.APPEND, () -> jedisPipeline.append(key, value)); } + @Override + public Response> blpop(final byte[] arg) { + return execOp(arg, OpName.BLPOP, () -> jedisPipeline.blpop(arg)); + } @Override - public Response zincrby(String arg0, double arg1, String arg2, ZIncrByParams arg3) { - throw new UnsupportedOperationException("not yet implemented"); + public Response> brpop(final byte[] arg) { + return execOp(arg, OpName.BRPOP, () -> jedisPipeline.brpop(arg)); } - public void sync() { - long startTime = System.nanoTime() / 1000; - try { - jedisPipeline.sync(); - opMonitor.recordPipelineSync(); - } catch (JedisConnectionException jce) { - String msg = "Failed sync() to host: " + getHostInfo(); - pipelineEx.set(new FatalConnectionException(msg, jce). - setHost(connection == null ? Host.NO_HOST : connection.getHost())); - cpMonitor.incOperationFailure(connection == null ? null : connection.getHost(), jce); - throw jce; - } finally { - long duration = System.nanoTime() / 1000 - startTime; - opMonitor.recordLatency(duration, TimeUnit.MICROSECONDS); - discardPipeline(false); - releaseConnection(); - } + @Override + public Response decr(final byte[] key) { + return execOp(key, OpName.DECR, () -> jedisPipeline.decr(key)); } - public List syncAndReturnAll() { - long startTime = System.nanoTime() / 1000; - try { - List result = jedisPipeline.syncAndReturnAll(); - opMonitor.recordPipelineSync(); - return result; - } catch (JedisConnectionException jce) { - String msg = "Failed syncAndReturnAll() to host: " + getHostInfo(); - pipelineEx.set(new FatalConnectionException(msg, jce). - setHost(connection == null ? Host.NO_HOST : connection.getHost())); - cpMonitor.incOperationFailure(connection == null ? null : connection.getHost(), jce); - throw jce; - } finally { - long duration = System.nanoTime() / 1000 - startTime; - opMonitor.recordLatency(duration, TimeUnit.MICROSECONDS); - discardPipeline(false); - releaseConnection(); - } + @Override + public Response decrBy(final byte[] key, final long integer) { + return execOp(key, OpName.DECRBY, () -> jedisPipeline.decrBy(key, integer)); } - private void discardPipeline(boolean recordLatency) { - try { - if (jedisPipeline != null) { - long startTime = System.nanoTime() / 1000; - jedisPipeline.sync(); - if (recordLatency) { - long duration = System.nanoTime() / 1000 - startTime; - opMonitor.recordLatency(duration, TimeUnit.MICROSECONDS); - } - jedisPipeline = null; - } - } catch (Exception e) { - Logger.warn(String.format("Failed to discard jedis pipeline, %s", getHostInfo()), e); - } + @Override + public Response del(final byte[] key) { + return execOp(key, OpName.DEL, () -> jedisPipeline.del(key)); + } - private void releaseConnection() { - if (connection != null) { - try { - connection.getContext().reset(); - connection.getParentConnectionPool().returnConnection(connection); - if (pipelineEx.get() != null) { - connPool.getHealthTracker().trackConnectionError(connection.getParentConnectionPool(), - pipelineEx.get()); - pipelineEx.set(null); - } - connection = null; - } catch (Exception e) { - Logger.warn(String.format("Failed to return connection in Dyno Jedis Pipeline, %s", getHostInfo()), e); - } - } + @Override + public Response unlink(byte[] key) { + return execOp(key, OpName.UNLINK, () -> jedisPipeline.unlink(key)); } - public void discardPipelineAndReleaseConnection() { - opMonitor.recordPipelineDiscard(); - discardPipeline(true); - releaseConnection(); + @Override + public Response echo(final byte[] string) { + return execOp(string, OpName.ECHO, () -> jedisPipeline.echo(string)); + } @Override - public void close() throws Exception { - discardPipelineAndReleaseConnection(); + public Response exists(final byte[] key) { + return execOp(key, OpName.EXISTS, () -> jedisPipeline.exists(key)); } - private String getHostInfo() { - if (connection != null && connection.getHost() != null) { - return connection.getHost().toString(); - } + @Override + public Response expire(final byte[] key, final int seconds) { + return execOp(key, OpName.EXPIRE, () -> jedisPipeline.expire(key, seconds)); - return "unknown"; } @Override - public Response append(byte[] key, byte[] value) { + public Response pexpire(byte[] key, long milliseconds) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response> blpop(byte[] arg) { - throw new UnsupportedOperationException("not yet implemented"); + public Response expireAt(final byte[] key, final long unixTime) { + return execOp(key, OpName.EXPIREAT, () -> jedisPipeline.expireAt(key, unixTime)); + } @Override - public Response> brpop(byte[] arg) { + public Response pexpireAt(byte[] key, long millisecondsTimestamp) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response decr(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public Response get(final byte[] key) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.GET, () -> jedisPipeline.get(key)); + } else { + return execOp(key, OpName.GET, () -> decompressBin(jedisPipeline.get(key))); + } + } @Override - public Response decrBy(final byte[] key, final long integer) { - return new PipelineOperation() { + public Response getbit(final byte[] key, final long offset) { + return execOp(key, OpName.GETBIT, () -> jedisPipeline.getbit(key, offset)); - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.decrBy(key, integer); - } - }.execute(key, OpName.DECRBY); } @Override - public Response del(final byte[] key) { - return new PipelineOperation() { + public Response getrange(final byte[] key, final long startOffset, final long endOffset) { + return execOp(key, OpName.GETRANGE, () -> jedisPipeline.getrange(key, startOffset, endOffset)); - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.del(key); - } - }.execute(key, OpName.DEL); } @Override - public Response unlink(byte[] keys) { - return new PipelineOperation() { - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.unlink(keys); - } - }.execute(keys, OpName.UNLINK); + public Response getSet(final byte[] key, final byte[] value) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.GETSET, () -> jedisPipeline.getSet(key, value)); + } else { + return execOp(key, OpName.GETSET, () -> decompressBin(jedisPipeline.getSet(key, compressBin(value)))); + } } @Override - public Response echo(byte[] string) { - throw new UnsupportedOperationException("not yet implemented"); + public Response hdel(final byte[] key, final byte[]... field) { + return execOp(key, OpName.HDEL, () -> jedisPipeline.hdel(key, field)); + } @Override - public Response exists(final byte[] key) { - return new PipelineOperation() { + public Response hexists(final byte[] key, final byte[] field) { + return execOp(key, OpName.HEXISTS, () -> jedisPipeline.hexists(key, field)); - @Override - Response execute(final Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.exists(key); - } - }.execute(key, OpName.EXISTS); } @Override - public Response expire(byte[] key, int seconds) { - throw new UnsupportedOperationException("not yet implemented"); + public Response hget(final byte[] key, final byte[] field) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.HGET, () -> jedisPipeline.hget(key, field)); + } else { + return execOp(key, OpName.HGET, () -> decompressBin(jedisPipeline.hget(key, field))); + } + } @Override - public Response pexpire(byte[] key, long milliseconds) { - throw new UnsupportedOperationException("not yet implemented"); + public Response> hgetAll(final byte[] key) { + return execOp(key, OpName.HGETALL, () -> jedisPipeline.hgetAll(key)); } @Override - public Response expireAt(byte[] key, long unixTime) { - throw new UnsupportedOperationException("not yet implemented"); + public Response hincrBy(final byte[] key, final byte[] field, final long value) { + return execOp(key, OpName.HINCRBY, () -> jedisPipeline.hincrBy(key, field, value)); } - @Override - public Response pexpireAt(byte[] key, long millisecondsTimestamp) { - throw new UnsupportedOperationException("not yet implemented"); + /* not supported by RedisPipeline 2.7.3 */ + public Response hincrByFloat(final byte[] key, final byte[] field, final double value) { + return execOp(key, OpName.HINCRBYFLOAT, () -> jedisPipeline.hincrByFloat(key, field, value)); } @Override - public Response get(final byte[] key) { - return new PipelineOperation() { - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - long startTime = System.nanoTime() / 1000; - try { - return jedisPipeline.get(key); - } finally { - long duration = System.nanoTime() / 1000 - startTime; - opMonitor.recordSendLatency(OpName.GET.name(), duration, TimeUnit.MICROSECONDS); - } - } - }.execute(key, OpName.GET); + public Response> hkeys(final byte[] key) { + return execOp(key, OpName.HKEYS, () -> jedisPipeline.hkeys(key)); + } - @Override - public Response getbit(byte[] key, long offset) { - throw new UnsupportedOperationException("not yet implemented"); + public Response>> hscan(final byte[] key, int cursor) { + throw new UnsupportedOperationException("'HSCAN' cannot be called in pipeline"); } @Override - public Response getSet(final byte[] key, final byte[] value) { - return new PipelineOperation() { - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.getSet(key, value); - } - }.execute(key, OpName.GETSET); + public Response hlen(final byte[] key) { + return execOp(key, OpName.HLEN, () -> jedisPipeline.hlen(key)); + } @Override - public Response getrange(byte[] key, long startOffset, long endOffset) { - throw new UnsupportedOperationException("not yet implemented"); + public Response> hmget(final byte[] key, final byte[]... fields) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.HMGET, () -> jedisPipeline.hmget(key, fields)); + } else { + return execOp(key, OpName.HMGET, () -> decompressBinList(jedisPipeline.hmget(key, fields))); + } } @Override - public Response hdel(byte[] key, byte[]... field) { - throw new UnsupportedOperationException("not yet implemented"); + public Response hmset(final byte[] key, final Map hash) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.HMSET, () -> jedisPipeline.hmset(key, hash)); + } else { + return execOp(key, OpName.HMSET, () -> jedisPipeline.hmset(key, compressBinMap(hash))); + } } @Override - public Response hexists(byte[] key, byte[] field) { - throw new UnsupportedOperationException("not yet implemented"); + public Response hset(final byte[] key, final byte[] field, final byte[] value) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.HSET, () -> jedisPipeline.hset(key, field, value)); + } else { + return execOp(key, OpName.HSET, () -> jedisPipeline.hset(key, field, compressBin(value))); + } } @Override - public Response hincrBy(byte[] key, byte[] field, long value) { + public Response hset(byte[] key, Map hash) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response> hkeys(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public Response hsetnx(final byte[] key, final byte[] field, final byte[] value) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.HSETNX, () -> jedisPipeline.hsetnx(key, field, value)); + } else { + return execOp(key, OpName.HSETNX, () -> jedisPipeline.hsetnx(key, field, compressBin(value))); + } } @Override - public Response hlen(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public Response> hvals(final byte[] key) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.HVALS, () -> jedisPipeline.hvals(key)); + } else { + return execOp(key, OpName.HVALS, () -> decompressBinList(jedisPipeline.hvals(key))); + } + } @Override - public Response hsetnx(byte[] key, byte[] field, byte[] value) { - throw new UnsupportedOperationException("not yet implemented"); + public Response incr(final byte[] key) { + return execOp(key, OpName.INCR, () -> jedisPipeline.incr(key)); + } @Override - public Response> hvals(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public Response incrBy(final byte[] key, final long integer) { + return execOp(key, OpName.INCRBY, () -> jedisPipeline.incrBy(key, integer)); + } - @Override - public Response incr(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + /* not supported by RedisPipeline 2.7.3 */ + public Response incrByFloat(final byte[] key, final double increment) { + return execOp(key, OpName.INCRBYFLOAT, () -> jedisPipeline.incrByFloat(key, increment)); + } @Override - public Response incrBy(byte[] key, long integer) { + public Response psetex(byte[] key, long milliseconds, byte[] value) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response lindex(byte[] key, long index) { - throw new UnsupportedOperationException("not yet implemented"); + public Response lindex(final byte[] key, final long index) { + return execOp(key, OpName.LINDEX, () -> jedisPipeline.lindex(key, index)); + } @Override - public Response linsert(byte[] key, ListPosition where, byte[] pivot, byte[] value) { - throw new UnsupportedOperationException("not yet implemented"); + public Response linsert(final byte[] key, final ListPosition where, final byte[] pivot, final byte[] value) { + return execOp(key, OpName.LINSERT, () -> jedisPipeline.linsert(key, where, pivot, value)); + } @Override - public Response llen(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public Response llen(final byte[] key) { + return execOp(key, OpName.LLEN, () -> jedisPipeline.llen(key)); + } @Override - public Response lpop(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public Response lpop(final byte[] key) { + return execOp(key, OpName.LPOP, () -> jedisPipeline.lpop(key)); + } @Override - public Response lpush(byte[] key, byte[]... string) { - throw new UnsupportedOperationException("not yet implemented"); + public Response lpush(final byte[] key, final byte[]... string) { + return execOp(key, OpName.LPUSH, () -> jedisPipeline.lpush(key, string)); + } @Override - public Response lpushx(byte[] key, byte[]... bytes) { - throw new UnsupportedOperationException("not yet implemented"); + public Response lpushx(final byte[] key, final byte[]... string) { + return execOp(key, OpName.LPUSHX, () -> jedisPipeline.lpushx(key, string)); + } @Override - public Response> lrange(byte[] key, long start, long end) { - throw new UnsupportedOperationException("not yet implemented"); + public Response> lrange(final byte[] key, final long start, final long end) { + return execOp(key, OpName.LRANGE, () -> jedisPipeline.lrange(key, start, end)); + } @Override - public Response lrem(byte[] key, long count, byte[] value) { - throw new UnsupportedOperationException("not yet implemented"); + public Response lrem(final byte[] key, final long count, final byte[] value) { + return execOp(key, OpName.LREM, () -> jedisPipeline.lrem(key, count, value)); + } @Override - public Response lset(byte[] key, long index, byte[] value) { - throw new UnsupportedOperationException("not yet implemented"); + public Response lset(final byte[] key, final long index, final byte[] value) { + return execOp(key, OpName.LSET, () -> jedisPipeline.lset(key, index, value)); + } @Override - public Response ltrim(byte[] key, long start, long end) { - throw new UnsupportedOperationException("not yet implemented"); + public Response ltrim(final byte[] key, final long start, final long end) { + return execOp(key, OpName.LTRIM, () -> jedisPipeline.ltrim(key, start, end)); + } @Override - public Response move(byte[] key, int dbIndex) { - throw new UnsupportedOperationException("not yet implemented"); + public Response move(final byte[] key, final int dbIndex) { + return execOp(key, OpName.MOVE, () -> jedisPipeline.move(key, dbIndex)); + } @Override - public Response persist(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public Response persist(final byte[] key) { + return execOp(key, OpName.PERSIST, () -> jedisPipeline.persist(key)); + } - @Override - public Response rpop(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + /* not supported by RedisPipeline 2.7.3 */ + public Response rename(final byte[] oldkey, final byte[] newkey) { + return execOp(oldkey, OpName.RENAME, () -> jedisPipeline.rename(oldkey, newkey)); + } - @Override - public Response rpush(byte[] key, byte[]... string) { - throw new UnsupportedOperationException("not yet implemented"); + /* not supported by RedisPipeline 2.7.3 */ + public Response renamenx(final byte[] oldkey, final byte[] newkey) { + return execOp(oldkey, OpName.RENAMENX, () -> jedisPipeline.renamenx(oldkey, newkey)); + } @Override - public Response rpushx(byte[] key, byte[]... string) { - throw new UnsupportedOperationException("not yet implemented"); + public Response rpop(final byte[] key) { + return execOp(key, OpName.RPOP, () -> jedisPipeline.rpop(key)); + } @Override - public Response sadd(byte[] key, byte[]... member) { - throw new UnsupportedOperationException("not yet implemented"); + public Response rpush(final byte[] key, final byte[]... string) { + return execOp(key, OpName.RPUSH, () -> jedisPipeline.rpush(key, string)); + } @Override - public Response scard(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public Response rpushx(final byte[] key, final byte[]... string) { + return execOp(key, OpName.RPUSHX, () -> jedisPipeline.rpushx(key, string)); + } @Override - public Response setbit(byte[] key, long offset, byte[] value) { - throw new UnsupportedOperationException("not yet implemented"); + public Response sadd(final byte[] key, final byte[]... member) { + return execOp(key, OpName.SADD, () -> jedisPipeline.sadd(key, member)); + } @Override - public Response setrange(byte[] key, long offset, byte[] value) { - throw new UnsupportedOperationException("not yet implemented"); + public Response scard(final byte[] key) { + return execOp(key, OpName.SCARD, () -> jedisPipeline.scard(key)); + } @Override - public Response setex(final byte[] key, final int seconds, final byte[] value) { - return new PipelineOperation() { - @Override - Response execute(Pipeline jedisPipeline) throws DynoException { - return jedisPipeline.setex(key, seconds, value); - } - }.execute(key, OpName.SETEX); + public Response sismember(final byte[] key, final byte[] member) { + return execOp(key, OpName.SISMEMBER, () -> jedisPipeline.sismember(key, member)); } @Override - public Response setnx(byte[] key, byte[] value) { - throw new UnsupportedOperationException("not yet implemented"); + public Response set(final byte[] key, final byte[] value) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.SET, () -> jedisPipeline.set(key, value)); + } else { + return execOp(key, OpName.SET, () -> jedisPipeline.set(key, compressBin(value))); + } } @Override - public Response> smembers(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public Response setbit(final byte[] key, final long offset, final byte[] value) { + return execOp(key, OpName.SETBIT, () -> jedisPipeline.setbit(key, offset, value)); + } @Override - public Response sismember(byte[] key, byte[] member) { - throw new UnsupportedOperationException("not yet implemented"); + public Response setex(final byte[] key, final int seconds, final byte[] value) { + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.SETEX, () -> jedisPipeline.setex(key, seconds, value)); + } else { + return execOp(key, OpName.SETEX, () -> jedisPipeline.setex(key, seconds, compressBin(value))); + } + } @Override - public Response> sort(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public Response setnx(final byte[] key, final byte[] value) { + return execOp(key, OpName.SETNX, () -> jedisPipeline.setnx(key, value)); } @Override - public Response> sort(byte[] key, SortingParams sortingParameters) { - throw new UnsupportedOperationException("not yet implemented"); + public Response setrange(final byte[] key, final long offset, final byte[] value) { + return execOp(key, OpName.SETRANGE, () -> jedisPipeline.setrange(key, offset, value)); + } @Override - public Response spop(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public Response> smembers(final byte[] key) { + return execOp(key, OpName.SMEMBERS, () -> jedisPipeline.smembers(key)); } @Override - public Response> spop(byte[] key, long count) { - throw new UnsupportedOperationException("not yet implemented"); + public Response> sort(final byte[] key) { + return execOp(key, OpName.SORT, () -> jedisPipeline.sort(key)); + } @Override - public Response srandmember(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public Response> sort(final byte[] key, final SortingParams sortingParameters) { + return execOp(key, OpName.SORT, () -> jedisPipeline.sort(key, sortingParameters)); + } @Override - public Response srem(byte[] key, byte[]... member) { - throw new UnsupportedOperationException("not yet implemented"); + public Response spop(final byte[] key) { + return execOp(key, OpName.SPOP, () -> jedisPipeline.spop(key)); + } @Override - public Response strlen(byte[] key) { + public Response> spop(final byte[] key, final long count) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response substr(byte[] key, int start, int end) { - throw new UnsupportedOperationException("not yet implemented"); + public Response srandmember(final byte[] key) { + return execOp(key, OpName.SRANDMEMBER, () -> jedisPipeline.srandmember(key)); + } @Override - public Response touch(byte[] keys) { - throw new UnsupportedOperationException("not yet implemented"); + public Response srem(final byte[] key, final byte[]... member) { + return execOp(key, OpName.SREM, () -> jedisPipeline.srem(key, member)); + } - @Override - public Response ttl(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + /** + * This method is not supported by the BinaryRedisPipeline interface. + */ + public Response> sscan(final byte[] key, final int cursor) { + throw new UnsupportedOperationException("'SSCAN' cannot be called in pipeline"); } - @Override - public Response pttl(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + /** + * This method is not supported by the BinaryRedisPipeline interface. + */ + public Response> sscan(final byte[] key, final byte[] cursor) { + throw new UnsupportedOperationException("'SSCAN' cannot be called in pipeline"); } @Override - public Response type(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public Response strlen(final byte[] key) { + return execOp(key, OpName.STRLEN, () -> jedisPipeline.strlen(key)); + } @Override - public Response zadd(byte[] key, double score, byte[] member) { - throw new UnsupportedOperationException("not yet implemented"); + public Response substr(final byte[] key, final int start, final int end) { + return execOp(key, OpName.SUBSTR, () -> jedisPipeline.substr(key, start, end)); + } @Override - public Response zadd(byte[] key, double score, byte[] member, ZAddParams params) { + public Response touch(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response zadd(byte[] key, Map scoreMembers) { - throw new UnsupportedOperationException("not yet implemented"); + public Response ttl(final byte[] key) { + return execOp(key, OpName.TTL, () -> jedisPipeline.ttl(key)); + } @Override - public Response zadd(byte[] key, Map scoreMembers, ZAddParams params) { - throw new UnsupportedOperationException("not yet implemented"); + public Response pttl(byte[] key) { + return execOp(key, OpName.PTTL, () -> jedisPipeline.pttl(key)); } @Override - public Response zcard(byte[] key) { - throw new UnsupportedOperationException("not yet implemented"); + public Response type(final byte[] key) { + return execOp(key, OpName.TYPE, () -> jedisPipeline.type(key)); + } @Override - public Response zcount(byte[] key, double min, double max) { - throw new UnsupportedOperationException("not yet implemented"); + public Response zadd(final byte[] key, final double score, final byte[] member) { + return execOp(key, OpName.ZADD, () -> jedisPipeline.zadd(key, score, member)); + } @Override - public Response zcount(byte[] key, byte[] min, byte[] max) { - throw new UnsupportedOperationException("not yet implemented"); + public Response zadd(final byte[] key, final Map scoreMembers) { + return execOp(key, OpName.ZADD, () -> jedisPipeline.zadd(key, scoreMembers)); + } @Override - public Response zincrby(byte[] key, double score, byte[] member) { - throw new UnsupportedOperationException("not yet implemented"); + public Response zcard(final byte[] key) { + return execOp(key, OpName.ZCARD, () -> jedisPipeline.zcard(key)); + } @Override - public Response zincrby(byte[] key, double score, byte[] member, ZIncrByParams params) { - throw new UnsupportedOperationException("not yet implemented"); + public Response zcount(final byte[] key, final double min, final double max) { + return execOp(key, OpName.ZCOUNT, () -> jedisPipeline.zcount(key, min, max)); + } @Override - public Response> zrange(byte[] key, long start, long end) { - throw new UnsupportedOperationException("not yet implemented"); + public Response zcount(byte[] key, byte[] min, byte[] max) { + return execOp(key, OpName.ZCOUNT, () -> jedisPipeline.zcount(key, min, max)); } @Override - public Response> zrangeByScore(byte[] key, double min, double max) { - throw new UnsupportedOperationException("not yet implemented"); + public Response zincrby(final byte[] key, final double score, final byte[] member) { + return execOp(key, OpName.ZINCRBY, () -> jedisPipeline.zincrby(key, score, member)); + } @Override - public Response> zrangeByScore(byte[] key, byte[] min, byte[] max) { - throw new UnsupportedOperationException("not yet implemented"); + public Response> zrange(final byte[] key, final long start, final long end) { + return execOp(key, OpName.ZRANGE, () -> jedisPipeline.zrange(key, start, end)); + } @Override - public Response> zrangeByScore(byte[] key, double min, double max, int offset, int count) { - throw new UnsupportedOperationException("not yet implemented"); + public Response> zrangeByScore(final byte[] key, final double min, final double max) { + return execOp(key, OpName.ZRANGEBYSCORE, () -> jedisPipeline.zrangeByScore(key, min, max)); + } @Override - public Response> zrangeByScore(byte[] key, byte[] min, byte[] max, int offset, int count) { - throw new UnsupportedOperationException("not yet implemented"); + public Response> zrangeByScore(final byte[] key, final byte[] min, final byte[] max) { + return execOp(key, OpName.ZRANGEBYSCORE, () -> jedisPipeline.zrangeByScore(key, min, max)); + } @Override - public Response> zrangeByScoreWithScores(byte[] key, double min, double max) { - throw new UnsupportedOperationException("not yet implemented"); + public Response> zrangeByScore(final byte[] key, final double min, final double max, final int offset, + final int count) { + return execOp(key, OpName.ZRANGEBYSCORE, () -> jedisPipeline.zrangeByScore(key, min, max, offset, count)); + } @Override - public Response> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max) { - throw new UnsupportedOperationException("not yet implemented"); + public Response> zrangeByScore(byte[] key, byte[] min, byte[] max, int offset, int count) { + return execOp(key, OpName.ZRANGEBYSCORE, () -> jedisPipeline.zrangeByScore(key, min, max, offset, count)); } @Override - public Response> zrangeByScoreWithScores(byte[] key, double min, double max, int offset, int count) { - throw new UnsupportedOperationException("not yet implemented"); + public Response> zrangeByScoreWithScores(final byte[] key, final double min, final double max) { + return execOp(key, OpName.ZRANGEBYSCOREWITHSCORES, () -> jedisPipeline.zrangeByScoreWithScores(key, min, max)); + } @Override - public Response> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max, int offset, int count) { - throw new UnsupportedOperationException("not yet implemented"); + public Response> zrangeByScoreWithScores(final byte[] key, final double min, final double max, + final int offset, final int count) { + return execOp(key, OpName.ZRANGEBYSCOREWITHSCORES, () -> jedisPipeline.zrangeByScoreWithScores(key, min, max, offset, count)); + } @Override - public Response> zrevrangeByScore(byte[] key, double max, double min) { - throw new UnsupportedOperationException("not yet implemented"); + public Response> zrevrangeByScore(final byte[] key, final double max, final double min) { + return execOp(key, OpName.ZREVRANGEBYSCORE, () -> jedisPipeline.zrevrangeByScore(key, max, min)); + } @Override - public Response> zrevrangeByScore(byte[] key, byte[] max, byte[] min) { - throw new UnsupportedOperationException("not yet implemented"); + public Response> zrevrangeByScore(final byte[] key, final byte[] max, final byte[] min) { + return execOp(key, OpName.ZREVRANGEBYSCORE, () -> jedisPipeline.zrevrangeByScore(key, max, min)); + } @Override - public Response> zrevrangeByScore(byte[] key, double max, double min, int offset, int count) { - throw new UnsupportedOperationException("not yet implemented"); + public Response> zrevrangeByScore(final byte[] key, final double max, final double min, + final int offset, final int count) { + return execOp(key, OpName.ZREVRANGEBYSCORE, () -> jedisPipeline.zrevrangeByScore(key, max, min, offset, count)); + } @Override public Response> zrevrangeByScore(byte[] key, byte[] max, byte[] min, int offset, int count) { - throw new UnsupportedOperationException("not yet implemented"); + return execOp(key, OpName.ZREVRANGEBYSCORE, () -> jedisPipeline.zrevrangeByScore(key, max, min, offset, count)); } @Override - public Response> zrevrangeByScoreWithScores(byte[] key, double max, double min) { - throw new UnsupportedOperationException("not yet implemented"); + public Response> zrevrangeByScoreWithScores(final byte[] key, final double max, final double min) { + return execOp(key, OpName.ZREVRANGEBYSCOREWITHSCORES, () -> jedisPipeline.zrevrangeByScoreWithScores(key, max, min)); + } @Override public Response> zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min) { - throw new UnsupportedOperationException("not yet implemented"); + return execOp(key, OpName.ZREVRANGEBYSCOREWITHSCORES, () -> jedisPipeline.zrevrangeByScoreWithScores(key, max, min)); } @Override - public Response> zrevrangeByScoreWithScores(byte[] key, double max, double min, int offset, int count) { - throw new UnsupportedOperationException("not yet implemented"); + public Response> zrevrangeByScoreWithScores(final byte[] key, final double max, final double min, + final int offset, final int count) { + return execOp(key, OpName.ZREVRANGEBYSCOREWITHSCORES, () -> jedisPipeline.zrevrangeByScoreWithScores(key, max, min, offset, count)); + } @Override public Response> zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min, int offset, int count) { - throw new UnsupportedOperationException("not yet implemented"); + return execOp(key, OpName.ZREVRANGEBYSCOREWITHSCORES, () -> jedisPipeline.zrevrangeByScoreWithScores(key, max, min, offset, count)); } @Override - public Response> zrangeWithScores(byte[] key, long start, long end) { - throw new UnsupportedOperationException("not yet implemented"); + public Response> zrangeWithScores(final byte[] key, final long start, final long end) { + return execOp(key, OpName.ZRANGEWITHSCORES, () -> jedisPipeline.zrangeWithScores(key, start, end)); + } @Override - public Response zrank(byte[] key, byte[] member) { - throw new UnsupportedOperationException("not yet implemented"); + public Response zrank(final byte[] key, final byte[] member) { + return execOp(key, OpName.ZRANK, () -> jedisPipeline.zrank(key, member)); + } @Override - public Response zrem(byte[] key, byte[]... member) { - throw new UnsupportedOperationException("not yet implemented"); + public Response zrem(final byte[] key, final byte[]... member) { + return execOp(key, OpName.ZREM, () -> jedisPipeline.zrem(key, member)); + } @Override - public Response zremrangeByRank(byte[] key, long start, long end) { - throw new UnsupportedOperationException("not yet implemented"); + public Response zremrangeByRank(final byte[] key, final long start, final long end) { + return execOp(key, OpName.ZREMRANGEBYRANK, () -> jedisPipeline.zremrangeByRank(key, start, end)); + } @Override - public Response zremrangeByScore(byte[] key, double start, double end) { - throw new UnsupportedOperationException("not yet implemented"); + public Response zremrangeByScore(final byte[] key, final double start, final double end) { + return execOp(key, OpName.ZREMRANGEBYSCORE, () -> jedisPipeline.zremrangeByScore(key, start, end)); + } @Override - public Response zremrangeByScore(byte[] key, byte[] start, byte[] end) { - throw new UnsupportedOperationException("not yet implemented"); + public Response zremrangeByScore(byte[] key, byte[] min, byte[] max) { + return execOp(key, OpName.ZREMRANGEBYSCORE, () -> jedisPipeline.zremrangeByScore(key, min, max)); } @Override - public Response> zrevrange(byte[] key, long start, long end) { - throw new UnsupportedOperationException("not yet implemented"); + public Response> zrevrange(final byte[] key, final long start, final long end) { + return execOp(key, OpName.ZREVRANGE, () -> jedisPipeline.zrevrange(key, start, end)); + } @Override - public Response> zrevrangeWithScores(byte[] key, long start, long end) { - throw new UnsupportedOperationException("not yet implemented"); + public Response> zrevrangeWithScores(final byte[] key, final long start, final long end) { + return execOp(key, OpName.ZREVRANGEWITHSCORES, () -> jedisPipeline.zrevrangeWithScores(key, start, end)); + } @Override - public Response zrevrank(byte[] key, byte[] member) { - throw new UnsupportedOperationException("not yet implemented"); + public Response zrevrank(final byte[] key, final byte[] member) { + return execOp(key, OpName.ZREVRANK, () -> jedisPipeline.zrevrank(key, member)); + } @Override - public Response zscore(byte[] key, byte[] member) { - throw new UnsupportedOperationException("not yet implemented"); + public Response zscore(final byte[] key, final byte[] member) { + return execOp(key, OpName.ZSCORE, () -> jedisPipeline.zscore(key, member)); + + } + + /** + * This method is not supported by the BinaryRedisPipeline interface. + */ + public Response> zscan(final byte[] key, final int cursor) { + throw new UnsupportedOperationException("'ZSCAN' cannot be called in pipeline"); } @Override @@ -3015,37 +2051,49 @@ public Response> zrangeByLex(byte[] key, byte[] min, byte[] max, int } @Override - public Response> zrevrangeByLex(byte[] key, byte[] max, byte[] min) { + public Response zremrangeByLex(byte[] key, byte[] start, byte[] end) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response> zrevrangeByLex(byte[] key, byte[] max, byte[] min, int offset, int count) { - throw new UnsupportedOperationException("not yet implemented"); + public Response bitcount(final byte[] key) { + return execOp(key, OpName.BITCOUNT, () -> jedisPipeline.bitcount(key)); + + } + + @Override + public Response bitcount(final byte[] key, final long start, final long end) { + return execOp(key, OpName.BITCOUNT, () -> jedisPipeline.bitcount(key, start, end)); + } @Override - public Response zremrangeByLex(byte[] key, byte[] min, byte[] max) { + public Response pfadd(byte[] key, byte[]... elements) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response bitcount(byte[] key) { + public Response pfcount(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response bitcount(byte[] key, long start, long end) { + public Response> bitfield(byte[] key, byte[]... arguments) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response pfadd(byte[] key, byte[]... elements) { + public Response hstrlen(byte[] key, byte[] field) { + return execOp(key, OpName.HSTRLEN, () -> jedisPipeline.hstrlen(key, field)); + } + + @Override + public Response restore(byte[] key, int ttl, byte[] serializedValue) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response pfcount(byte[] key) { + public Response restoreReplace(byte[] key, int ttl, byte[] serializedValue) { throw new UnsupportedOperationException("not yet implemented"); } @@ -3055,53 +2103,53 @@ public Response dump(byte[] key) { } @Override - public Response restore(byte[] key, int ttl, byte[] serializedValue) { + public Response migrate(String host, int port, byte[] key, int destinationDB, int timeout) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response restoreReplace(byte[] key, int ttl, byte[] serializedValue) { + public Response> zrevrangeByLex(byte[] key, byte[] max, byte[] min) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response migrate(String host, int port, byte[] key, int destinationDB, int timeout) { + public Response> zrevrangeByLex(byte[] key, byte[] max, byte[] min, int offset, int count) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response geoadd(byte[] key, double longitude, double latitude, byte[] member) { + public Response geoadd(byte[] arg0, Map arg1) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response geoadd(byte[] key, Map memberCoordinateMap) { + public Response geoadd(byte[] arg0, double arg1, double arg2, byte[] arg3) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response geodist(byte[] key, byte[] member1, byte[] member2) { + public Response geodist(byte[] arg0, byte[] arg1, byte[] arg2) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response geodist(byte[] key, byte[] member1, byte[] member2, GeoUnit unit) { + public Response geodist(byte[] arg0, byte[] arg1, byte[] arg2, GeoUnit arg3) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response> geohash(byte[] key, byte[]... members) { + public Response> geohash(byte[] arg0, byte[]... arg1) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response> geopos(byte[] key, byte[]... members) { + public Response> geopos(byte[] arg0, byte[]... arg1) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response> georadius(byte[] key, double longitude, double latitude, double radius, - GeoUnit unit) { + public Response> georadius(byte[] arg0, double arg1, double arg2, double arg3, + GeoUnit arg4) { throw new UnsupportedOperationException("not yet implemented"); } @@ -3111,8 +2159,8 @@ public Response> georadiusReadonly(byte[] key, double lo } @Override - public Response> georadius(byte[] key, double longitude, double latitude, double radius, - GeoUnit unit, GeoRadiusParam param) { + public Response> georadius(byte[] arg0, double arg1, double arg2, double arg3, GeoUnit arg4, + GeoRadiusParam arg5) { throw new UnsupportedOperationException("not yet implemented"); } @@ -3122,7 +2170,7 @@ public Response> georadiusReadonly(byte[] key, double lo } @Override - public Response> georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit) { + public Response> georadiusByMember(byte[] arg0, byte[] arg1, double arg2, GeoUnit arg3) { throw new UnsupportedOperationException("not yet implemented"); } @@ -3132,8 +2180,8 @@ public Response> georadiusByMemberReadonly(byte[] key, b } @Override - public Response> georadiusByMember(byte[] key, byte[] member, double radius, GeoUnit unit, - GeoRadiusParam param) { + public Response> georadiusByMember(byte[] arg0, byte[] arg1, double arg2, GeoUnit arg3, + GeoRadiusParam arg4) { throw new UnsupportedOperationException("not yet implemented"); } @@ -3143,32 +2191,32 @@ public Response> georadiusByMemberReadonly(byte[] key, b } @Override - public Response> bitfield(byte[] key, byte[]... elements) { + public Response bitpos(byte[] key, boolean value) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response hstrlen(byte[] key, byte[] field) { + public Response bitpos(byte[] key, boolean value, BitPosParams params) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response bitpos(byte[] key, boolean value) { + public Response set(byte[] key, byte[] value, SetParams params) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response bitpos(byte[] key, boolean value, BitPosParams params) { + public Response> srandmember(byte[] key, int count) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response set(byte[] key, byte[] value, SetParams params) { + public Response> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max) { throw new UnsupportedOperationException("not yet implemented"); } @Override - public Response> srandmember(byte[] key, int count) { + public Response> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max, int offset, int count) { throw new UnsupportedOperationException("not yet implemented"); } @@ -3188,17 +2236,114 @@ public Response objectIdletime(byte[] key) { } @Override - public Response incrByFloat(byte[] key, double increment) { - throw new UnsupportedOperationException("not yet implemented"); + public Response zadd(byte[] key, Map members, ZAddParams params) { + return execOp(key, OpName.ZADD, () -> jedisPipeline.zadd(key, members, params)); + } + + public Response zadd(final byte[] key, final double score, final byte[] member, final ZAddParams params) { + return execOp(key, OpName.ZADD, () -> jedisPipeline.zadd(key, score, member, params)); } @Override - public Response psetex(byte[] key, long milliseconds, byte[] value) { + public Response zincrby(byte[] arg0, double arg1, byte[] arg2, ZIncrByParams arg3) { throw new UnsupportedOperationException("not yet implemented"); } + + /******************* End Jedis Binary Commands **************/ + + + public void sync() { + long startTime = System.nanoTime() / 1000; + try { + jedisPipeline.sync(); + opMonitor.recordPipelineSync(); + } catch (JedisConnectionException jce) { + String msg = "Failed sync() to host: " + getHostInfo(); + pipelineEx.set(new FatalConnectionException(msg, jce). + setHost(connection == null ? Host.NO_HOST : connection.getHost())); + cpMonitor.incOperationFailure(connection == null ? null : connection.getHost(), jce); + throw jce; + } finally { + long duration = System.nanoTime() / 1000 - startTime; + opMonitor.recordLatency(duration, TimeUnit.MICROSECONDS); + discardPipeline(false); + releaseConnection(); + } + } + + public List syncAndReturnAll() { + long startTime = System.nanoTime() / 1000; + try { + List result = jedisPipeline.syncAndReturnAll(); + opMonitor.recordPipelineSync(); + return result; + } catch (JedisConnectionException jce) { + String msg = "Failed syncAndReturnAll() to host: " + getHostInfo(); + pipelineEx.set(new FatalConnectionException(msg, jce). + setHost(connection == null ? Host.NO_HOST : connection.getHost())); + cpMonitor.incOperationFailure(connection == null ? null : connection.getHost(), jce); + throw jce; + } finally { + long duration = System.nanoTime() / 1000 - startTime; + opMonitor.recordLatency(duration, TimeUnit.MICROSECONDS); + discardPipeline(false); + releaseConnection(); + } + } + + private void discardPipeline(boolean recordLatency) { + if (jedisPipeline != null) { + try { + long startTime = System.nanoTime() / 1000; + jedisPipeline.sync(); + if (recordLatency) { + long duration = System.nanoTime() / 1000 - startTime; + opMonitor.recordLatency(duration, TimeUnit.MICROSECONDS); + } + } catch (Exception e) { + Logger.warn(String.format("Failed to discard jedis pipeline, %s", getHostInfo()), e); + } finally { + jedisPipeline = null; + } + } + } + + private void releaseConnection() { + if (connection != null) { + try { + connection.getContext().reset(); + connection.getParentConnectionPool().returnConnection(connection); + if (pipelineEx.get() != null) { + connPool.getHealthTracker().trackConnectionError(connection.getParentConnectionPool(), + pipelineEx.get()); + pipelineEx.set(null); + } + } catch (Exception e) { + Logger.warn(String.format("Failed to return connection in Dyno Jedis Pipeline, %s", getHostInfo()), e); + } finally { + connection = null; + } + } + } + + public void discardPipelineAndReleaseConnection() { + opMonitor.recordPipelineDiscard(); + discardPipeline(true); + releaseConnection(); + } + @Override - public Response hincrByFloat(byte[] key, byte[] field, double increment) { - throw new UnsupportedOperationException("not yet implemented"); + public void close() throws Exception { + discardPipelineAndReleaseConnection(); + } + + private String getHostInfo() { + if (connection != null && connection.getHost() != null) { + return connection.getHost().toString(); + } + + return "unknown"; } + } diff --git a/dyno-jedis/src/main/java/com/netflix/dyno/jedis/JedisConnectionFactory.java b/dyno-jedis/src/main/java/com/netflix/dyno/jedis/JedisConnectionFactory.java index 855140c1..81072aa9 100644 --- a/dyno-jedis/src/main/java/com/netflix/dyno/jedis/JedisConnectionFactory.java +++ b/dyno-jedis/src/main/java/com/netflix/dyno/jedis/JedisConnectionFactory.java @@ -180,6 +180,11 @@ public void open() throws DynoException { } } + @Override + public void reset() { + jedisClient.resetState(); + } + @Override public DynoConnectException getLastException() { return lastDynoException; diff --git a/dyno-jedis/src/test/java/com/netflix/dyno/jedis/CompressionTest.java b/dyno-jedis/src/test/java/com/netflix/dyno/jedis/CompressionTest.java index ed508165..1e376032 100644 --- a/dyno-jedis/src/test/java/com/netflix/dyno/jedis/CompressionTest.java +++ b/dyno-jedis/src/test/java/com/netflix/dyno/jedis/CompressionTest.java @@ -137,7 +137,7 @@ public void testDynoJedis_Hmset_AboveCompressionThreshold() throws IOException { map.put(KEY_1KB, VALUE_1KB); map.put(KEY_3KB, VALUE_3KB); - client.d_hmset("compressionTestKey", map); + client.hmset("compressionTestKey", map); LastOperationMonitor monitor = (LastOperationMonitor) opMonitor; Assert.assertTrue(1 == monitor.getSuccessCount(OpName.HMSET.name(), true)); diff --git a/dyno-redisson/src/main/java/com/netflix/dyno/redisson/RedissonConnectionFactory.java b/dyno-redisson/src/main/java/com/netflix/dyno/redisson/RedissonConnectionFactory.java index 6880e485..6d4fa338 100644 --- a/dyno-redisson/src/main/java/com/netflix/dyno/redisson/RedissonConnectionFactory.java +++ b/dyno-redisson/src/main/java/com/netflix/dyno/redisson/RedissonConnectionFactory.java @@ -124,6 +124,10 @@ public void open() throws DynoException { rConn = client.connectAsync(); } + @Override + public void reset() { + } + @Override public DynoConnectException getLastException() { return lastEx.get(); From ad826d404e1b75198e2090ccf6bfd7398fbb4431 Mon Sep 17 00:00:00 2001 From: Bryan Keller Date: Fri, 18 Dec 2020 10:03:11 -0800 Subject: [PATCH 2/7] Recycle connection if it cannot be reset --- .../connectionpool/impl/HostConnectionPoolImpl.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/HostConnectionPoolImpl.java b/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/HostConnectionPoolImpl.java index 3496b840..72d9257c 100644 --- a/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/HostConnectionPoolImpl.java +++ b/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/HostConnectionPoolImpl.java @@ -346,9 +346,14 @@ public boolean returnConnection(Connection connection) { return closeConnection(connection); } else { // Add the given connection back to the pool - connection.reset(); - availableConnections.add(connection); - return false; + try { + connection.reset(); + availableConnections.add(connection); + return false; + } catch (Exception e) { + recycleConnection(connection); + return true; + } } } finally { monitor.incConnectionReturned(host); From da2f380932549941b85327e772640675a6ee2712 Mon Sep 17 00:00:00 2001 From: Bryan Keller Date: Mon, 11 Jan 2021 08:57:38 -0800 Subject: [PATCH 3/7] Reset Jedis state before calling quit() --- .../main/java/com/netflix/dyno/jedis/JedisConnectionFactory.java | 1 + 1 file changed, 1 insertion(+) diff --git a/dyno-jedis/src/main/java/com/netflix/dyno/jedis/JedisConnectionFactory.java b/dyno-jedis/src/main/java/com/netflix/dyno/jedis/JedisConnectionFactory.java index 81072aa9..510ce221 100644 --- a/dyno-jedis/src/main/java/com/netflix/dyno/jedis/JedisConnectionFactory.java +++ b/dyno-jedis/src/main/java/com/netflix/dyno/jedis/JedisConnectionFactory.java @@ -162,6 +162,7 @@ public ListenableFuture> executeAsync(AsyncOperation Date: Thu, 14 Jan 2021 12:49:12 -0800 Subject: [PATCH 4/7] added multivalue hset for pipeline --- .../com/netflix/dyno/jedis/DynoJedisPipeline.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoJedisPipeline.java b/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoJedisPipeline.java index 05141848..7e60baa8 100644 --- a/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoJedisPipeline.java +++ b/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoJedisPipeline.java @@ -682,7 +682,11 @@ public Response hset(final String key, final String field, final String va @Override public Response hset(String key, Map hash) { - throw new UnsupportedOperationException("not yet implemented"); + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.HSET, () -> jedisPipeline.hset(key, hash)); + } else { + throw new UnsupportedOperationException("not yet implemented"); + } } @Override @@ -1556,7 +1560,11 @@ public Response hset(final byte[] key, final byte[] field, final byte[] va @Override public Response hset(byte[] key, Map hash) { - throw new UnsupportedOperationException("not yet implemented"); + if (CompressionStrategy.NONE == connPool.getConfiguration().getCompressionStrategy()) { + return execOp(key, OpName.HSET, () -> jedisPipeline.hset(key, hash)); + } else { + throw new UnsupportedOperationException("not yet implemented"); + } } @Override From c8328c4dfa2900dcec72bfe724be672f200cc5ea Mon Sep 17 00:00:00 2001 From: Bryan Keller Date: Fri, 22 Jan 2021 20:01:38 -0800 Subject: [PATCH 5/7] fix pipeline handling of pool exhausted exceptions --- .../impl/ConnectionPoolImpl.java | 39 +++++++- .../netflix/dyno/jedis/DynoJedisPipeline.java | 98 +++++++------------ 2 files changed, 70 insertions(+), 67 deletions(-) diff --git a/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/ConnectionPoolImpl.java b/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/ConnectionPoolImpl.java index f614b569..11cd7b4b 100644 --- a/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/ConnectionPoolImpl.java +++ b/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/ConnectionPoolImpl.java @@ -467,9 +467,42 @@ private void updateConnectionContext(ConnectionContext context, Host host) { * @param baseOperation * @return */ - public Connection getConnectionForOperation(BaseOperation baseOperation) { - return selectionStrategy.getConnection(baseOperation, cpConfiguration.getMaxTimeoutWhenExhausted(), - TimeUnit.MILLISECONDS); + public Connection getConnectionWithFailover(BaseOperation baseOperation) { + + RetryPolicy retry = cpConfiguration.getRetryPolicyFactory().getRetryPolicy(); + retry.begin(); + + DynoException lastException = null; + + do { + try { + Connection connection = selectionStrategy.getConnectionUsingRetryPolicy(baseOperation, + cpConfiguration.getMaxTimeoutWhenExhausted(), TimeUnit.MILLISECONDS, retry); + + updateConnectionContext(connection.getContext(), connection.getHost()); + + retry.success(); + cpMonitor.incOperationSuccess(connection.getHost(), 0); + + return connection; + + } catch (NoAvailableHostsException e) { + cpMonitor.incOperationFailure(null, e); + throw e; + } catch (PoolExhaustedException e) { + Logger.warn("Pool exhausted: " + e.getMessage()); + cpMonitor.incOperationFailure(null, e); + cpHealthTracker.trackConnectionError(e.getHostConnectionPool(), e); + } catch (DynoException e) { + retry.failure(e); + lastException = e; + } catch (Throwable t) { + throw new RuntimeException(t); + } + + } while (retry.allowRetry()); + + throw lastException; } @Override diff --git a/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoJedisPipeline.java b/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoJedisPipeline.java index 7e60baa8..9962c530 100644 --- a/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoJedisPipeline.java +++ b/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoJedisPipeline.java @@ -20,15 +20,11 @@ import com.netflix.dyno.connectionpool.Connection; import com.netflix.dyno.connectionpool.exception.DynoException; import com.netflix.dyno.connectionpool.exception.FatalConnectionException; -import com.netflix.dyno.connectionpool.exception.NoAvailableHostsException; import com.netflix.dyno.connectionpool.impl.ConnectionPoolImpl; import com.netflix.dyno.connectionpool.impl.lb.TokenAwareSelection; -import com.netflix.dyno.connectionpool.impl.utils.CollectionUtils; import com.netflix.dyno.connectionpool.impl.utils.ZipUtils; import com.netflix.dyno.jedis.JedisConnectionFactory.JedisConnection; -import com.netflix.dyno.jedis.operation.BaseKeyOperation; -import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,7 +40,6 @@ import javax.annotation.concurrent.NotThreadSafe; import java.io.IOException; -import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -52,7 +47,6 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -90,72 +84,48 @@ public class DynoJedisPipeline implements RedisPipeline, BinaryRedisPipeline, Au } private void pipelined(final byte[] key) { - try { - try { - connection = connPool.getConnectionForOperation(new BaseOperation() { - - @Override - public String getName() { - return DynoPipeline; - } - - @Override - public String getStringKey() {// we do not use it in this context - return null; - } - - @Override - public byte[] getBinaryKey() { - return key; - } - - }); - } catch (NoAvailableHostsException nahe) { - cpMonitor.incOperationFailure(connection != null ? connection.getHost() : null, nahe); - discardPipelineAndReleaseConnection(); - throw nahe; + connection = connPool.getConnectionWithFailover(new BaseOperation() { + + @Override + public String getName() { + return DynoPipeline; } - } catch (NoAvailableHostsException nahe) { - cpMonitor.incOperationFailure(connection != null ? connection.getHost() : null, nahe); - discardPipelineAndReleaseConnection(); - throw nahe; - } + + @Override + public String getStringKey() {// we do not use it in this context + return null; + } + + @Override + public byte[] getBinaryKey() { + return key; + } + + }); Jedis jedis = ((JedisConnection) connection).getClient(); jedisPipeline = jedis.pipelined(); cpMonitor.incOperationSuccess(connection.getHost(), 0); } private void pipelined(final String key) { - try { - try { - connection = connPool.getConnectionForOperation(new BaseOperation() { - - @Override - public String getName() { - return DynoPipeline; - } - - @Override - public String getStringKey() { - return key; - } - - @Override - public byte[] getBinaryKey() { // we do not use it in this context - return null; - } - - }); - } catch (NoAvailableHostsException nahe) { - cpMonitor.incOperationFailure(connection != null ? connection.getHost() : null, nahe); - discardPipelineAndReleaseConnection(); - throw nahe; + connection = connPool.getConnectionWithFailover(new BaseOperation() { + + @Override + public String getName() { + return DynoPipeline; } - } catch (NoAvailableHostsException nahe) { - cpMonitor.incOperationFailure(connection != null ? connection.getHost() : null, nahe); - discardPipelineAndReleaseConnection(); - throw nahe; - } + + @Override + public String getStringKey() { + return key; + } + + @Override + public byte[] getBinaryKey() { // we do not use it in this context + return null; + } + + }); Jedis jedis = ((JedisConnection) connection).getClient(); jedisPipeline = jedis.pipelined(); cpMonitor.incOperationSuccess(connection.getHost(), 0); From 1fd431c99817b470d29b0e117b3694d63250b0b1 Mon Sep 17 00:00:00 2001 From: Bryan Keller Date: Fri, 22 Jan 2021 20:08:40 -0800 Subject: [PATCH 6/7] demo fix --- .../impl/ConnectionPoolImpl.java | 6 ----- .../dyno/demo/redis/DynoJedisDemo.java | 26 ++++++++++--------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/ConnectionPoolImpl.java b/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/ConnectionPoolImpl.java index 11cd7b4b..05fcff20 100644 --- a/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/ConnectionPoolImpl.java +++ b/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/ConnectionPoolImpl.java @@ -468,7 +468,6 @@ private void updateConnectionContext(ConnectionContext context, Host host) { * @return */ public Connection getConnectionWithFailover(BaseOperation baseOperation) { - RetryPolicy retry = cpConfiguration.getRetryPolicyFactory().getRetryPolicy(); retry.begin(); @@ -478,14 +477,9 @@ public Connection getConnectionWithFailover(BaseOperation baseOpe try { Connection connection = selectionStrategy.getConnectionUsingRetryPolicy(baseOperation, cpConfiguration.getMaxTimeoutWhenExhausted(), TimeUnit.MILLISECONDS, retry); - updateConnectionContext(connection.getContext(), connection.getHost()); - retry.success(); - cpMonitor.incOperationSuccess(connection.getHost(), 0); - return connection; - } catch (NoAvailableHostsException e) { cpMonitor.incOperationFailure(null, e); throw e; diff --git a/dyno-demo/src/main/java/com/netflix/dyno/demo/redis/DynoJedisDemo.java b/dyno-demo/src/main/java/com/netflix/dyno/demo/redis/DynoJedisDemo.java index f40dbef8..ce3d06fb 100644 --- a/dyno-demo/src/main/java/com/netflix/dyno/demo/redis/DynoJedisDemo.java +++ b/dyno-demo/src/main/java/com/netflix/dyno/demo/redis/DynoJedisDemo.java @@ -1000,12 +1000,13 @@ public void runLongTest() throws InterruptedException { private class SAXHandler extends DefaultHandler { - private final List> list = new ArrayList>(); + private final List> list = new ArrayList<>(); private final String rootElement; - private final Set interestElements = new HashSet(); + private final Set interestElements = new HashSet<>(); private Map currentPayload = null; private String currentInterestElement = null; + private StringBuilder valueBuffer = new StringBuilder(); private SAXHandler(String root, String... interests) { @@ -1016,12 +1017,11 @@ private SAXHandler(String root, String... interests) { } @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) - throws SAXException { + public void startElement(String uri, String localName, String qName, Attributes attributes) { if (qName.equalsIgnoreCase(rootElement)) { // prep for next instance - currentPayload = new HashMap(); + currentPayload = new HashMap<>(); return; } @@ -1033,7 +1033,13 @@ public void startElement(String uri, String localName, String qName, Attributes } @Override - public void endElement(String uri, String localName, String qName) throws SAXException { + public void endElement(String uri, String localName, String qName) { + if (currentInterestElement != null && currentPayload != null) { + String value = valueBuffer.toString(); + currentPayload.put(currentInterestElement, value); + currentInterestElement = null; + valueBuffer = new StringBuilder(); //reset buffer + } // add host to list if (qName.equalsIgnoreCase(rootElement)) { @@ -1043,13 +1049,9 @@ public void endElement(String uri, String localName, String qName) throws SAXExc } @Override - public void characters(char[] ch, int start, int length) throws SAXException { - - String value = new String(ch, start, length); - + public void characters(char[] ch, int start, int length) { if (currentInterestElement != null && currentPayload != null) { - currentPayload.put(currentInterestElement, value); - currentInterestElement = null; + valueBuffer.append(ch, start, length); } } From 266bcd9b22eecdc5176186a236e11e510385baac Mon Sep 17 00:00:00 2001 From: Bryan Keller Date: Sat, 23 Jan 2021 08:56:24 -0800 Subject: [PATCH 7/7] minor exception handling change --- .../dyno/connectionpool/impl/ConnectionPoolImpl.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/ConnectionPoolImpl.java b/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/ConnectionPoolImpl.java index 05fcff20..6a5231a7 100644 --- a/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/ConnectionPoolImpl.java +++ b/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/ConnectionPoolImpl.java @@ -343,8 +343,6 @@ public OperationResult executeWithFailover(Operation op) throws Dy } else { cpMonitor.incOperationFailure(null, e); } - } catch (Throwable t) { - throw new RuntimeException(t); } finally { if (connection != null) { if (connection.getLastException() != null @@ -422,8 +420,6 @@ public Collection> executeWithRing(TokenRackMapper tokenR cpHealthTracker.trackConnectionError(connection.getParentConnectionPool(), lastException); } - } catch (Throwable t) { - throw new RuntimeException(t); } finally { connection.getContext().reset(); connection.getParentConnectionPool().returnConnection(connection); @@ -442,7 +438,7 @@ public Collection> executeWithRing(TokenRackMapper tokenR connectionToClose.getContext().reset(); connectionToClose.getParentConnectionPool().returnConnection(connectionToClose); } catch (Throwable t) { - + Logger.warn("Error returning connection to pool", t); } } } @@ -490,8 +486,6 @@ public Connection getConnectionWithFailover(BaseOperation baseOpe } catch (DynoException e) { retry.failure(e); lastException = e; - } catch (Throwable t) { - throw new RuntimeException(t); } } while (retry.allowRetry()); @@ -729,8 +723,6 @@ public ListenableFuture> executeAsync(AsyncOperation