Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.netflix.dyno.jedis.DynoJedisClient Maven / Gradle / Ivy
/*******************************************************************************
* Copyright 2011 Netflix
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package com.netflix.dyno.jedis;
import com.netflix.discovery.DiscoveryClient;
import com.netflix.discovery.EurekaClient;
import com.netflix.dyno.connectionpool.*;
import com.netflix.dyno.connectionpool.exception.DynoConnectException;
import com.netflix.dyno.connectionpool.exception.DynoException;
import com.netflix.dyno.connectionpool.exception.NoAvailableHostsException;
import com.netflix.dyno.connectionpool.impl.ConnectionPoolConfigurationImpl;
import com.netflix.dyno.connectionpool.impl.ConnectionPoolImpl;
import com.netflix.dyno.connectionpool.impl.lb.HostToken;
import com.netflix.dyno.connectionpool.impl.lb.HttpEndpointBasedTokenMapSupplier;
import com.netflix.dyno.connectionpool.impl.utils.CollectionUtils;
import com.netflix.dyno.connectionpool.impl.utils.ZipUtils;
import com.netflix.dyno.contrib.*;
import org.slf4j.Logger;
import redis.clients.jedis.BinaryClient.LIST_POSITION;
import redis.clients.jedis.*;
import redis.clients.jedis.params.geo.GeoRadiusParam;
import redis.clients.jedis.params.sortedset.ZAddParams;
import redis.clients.jedis.params.sortedset.ZIncrByParams;
import javax.net.ssl.SSLSocketFactory;
import java.io.IOException;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.lang3.ArrayUtils;
import static com.netflix.dyno.connectionpool.ConnectionPoolConfiguration.CompressionStrategy;
public class DynoJedisClient implements JedisCommands, BinaryJedisCommands, MultiKeyCommands,
ScriptingCommands {
private static final Logger Logger = org.slf4j.LoggerFactory.getLogger(DynoJedisClient.class);
private final String appName;
private final String clusterName;
private final ConnectionPool connPool;
private final AtomicReference pipelineMonitor = new AtomicReference();
private final EnumSet compressionOperations = EnumSet.of(OpName.APPEND);
protected final DynoOPMonitor opMonitor;
protected final ConnectionPoolMonitor cpMonitor;
public DynoJedisClient(String name, String clusterName, ConnectionPool pool, DynoOPMonitor operationMonitor,
ConnectionPoolMonitor cpMonitor) {
this.appName = name;
this.clusterName = clusterName;
this.connPool = pool;
this.opMonitor = operationMonitor;
this.cpMonitor = cpMonitor;
}
public ConnectionPoolImpl getConnPool() {
return (ConnectionPoolImpl) connPool;
}
public String getApplicationName() {
return appName;
}
public String getClusterName() {
return clusterName;
}
private abstract class BaseKeyOperation implements Operation {
private final String key;
private final byte[] binaryKey;
private final OpName op;
private BaseKeyOperation(final String k, final OpName o) {
this.key = k;
this.binaryKey = null;
this.op = o;
}
private BaseKeyOperation(final byte[] k, final OpName o) {
this.key = null;
this.binaryKey = k;
this.op = o;
}
@Override
public String getName() {
return op.name();
}
@Override
public String getStringKey() {
return this.key;
}
public byte[] getBinaryKey() {
return this.binaryKey;
}
}
/**
* A poor man's solution for multikey operation. This is similar to
* basekeyoperation just that it takes a list of keys as arguments. For
* token aware, we just use the first key in the list. Ideally we should be
* doing a scatter gather
*/
private abstract class MultiKeyOperation implements Operation {
private final List keys;
private final List binaryKeys;
private final OpName op;
private MultiKeyOperation(final List keys, final OpName o) {
this.keys = keys;
this.binaryKeys = null;
this.op = o;
}
@Override
public String getName() {
return op.name();
}
@Override
public String getStringKey() {
return this.keys.get(0);
}
public byte[] getBinaryKey() {
return this.binaryKeys.get(0);
}
}
/**
* The following commands are supported
*
*
* String Operations
* {@link #get(String) GET}
* {@link #getSet(String, String) GETSET}
* {@link #set(String, String) SET}
* {@link #setex(String, int, String) SETEX}
*
*
* Hash Operations
* {@link #hget(String, String) HGET}
* {@link #hgetAll(String) HGETALL}
* {@link #hmget(String, String...) HMGET}
* {@link #hmset(String, Map) HMSET}
* {@link #hscan(String, String) HSCAN}
* {@link #hset(String, String, String) HSET}
* {@link #hsetnx(String, String, String) HSETNX}
* {@link #hvals(String) HVALS}
*
*
*
* {@link #get(byte[]) GET}
* {@link #set(byte[], byte[]) SET}
* {@link #setex(byte[], int, byte[]) SETEX}
*
*
* @param
* the parameterized type
*/
private abstract class CompressionValueOperation extends BaseKeyOperation
implements CompressionOperation {
private CompressionValueOperation(String k, OpName o) {
super(k, o);
}
/**
* Compresses the value based on the threshold defined by
* {@link ConnectionPoolConfiguration#getValueCompressionThreshold()}
*
* @param value
* @return
*/
@Override
public String compressValue(String value, ConnectionContext ctx) {
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);
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 {
if (ZipUtils.isCompressed(value)) {
ctx.setMetadata("decompression", true);
return ZipUtils.decompressFromBase64String(value);
}
} catch (IOException e) {
Logger.warn("Unable to decompress value [" + value + "]");
}
return value;
}
}
/**
* The following commands are supported
*
*
* String Operations
* {@link #mget(String...) MGET}
*
*
* @param
* the parameterized type
*/
private abstract class CompressionValueMultiKeyOperation extends MultiKeyOperation
implements CompressionOperation {
private CompressionValueMultiKeyOperation(List keys, OpName o) {
super(keys, o);
}
/**
* Compresses the value based on the threshold defined by
* {@link ConnectionPoolConfiguration#getValueCompressionThreshold()}
*
* @param value
* @return
*/
@Override
public String compressValue(String value, ConnectionContext ctx) {
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);
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 {
if (ZipUtils.isCompressed(value)) {
ctx.setMetadata("decompression", true);
return ZipUtils.decompressFromBase64String(value);
}
} catch (IOException e) {
Logger.warn("Unable to decompress value [" + value + "]");
}
return value;
}
}
public TopologyView getTopologyView() {
return this.getConnPool();
}
@Override
public Long append(final String key, final String value) {
return d_append(key, value).getResult();
}
public OperationResult d_append(final String key, final String value) {
return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.APPEND) {
@Override
public Long execute(Jedis client, ConnectionContext state) {
return client.append(key, value);
}
});
}
@Override
public Long decr(final String key) {
return d_decr(key).getResult();
}
public OperationResult d_decr(final String key) {
return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.DECR) {
@Override
public Long execute(Jedis client, ConnectionContext state) {
return client.decr(key);
}
});
}
@Override
public Long decrBy(final String key, final long delta) {
return d_decrBy(key, delta).getResult();
}
public OperationResult d_decrBy(final String key, final Long delta) {
return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.DECRBY) {
@Override
public Long execute(Jedis client, ConnectionContext state) {
return client.decrBy(key, delta);
}
});
}
@Override
public Long del(final String key) {
return d_del(key).getResult();
}
public OperationResult d_del(final String key) {
return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.DEL) {
@Override
public Long execute(Jedis client, ConnectionContext state) {
return client.del(key);
}
});
}
public byte[] dump(final String key) {
return d_dump(key).getResult();
}
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);
}
});
}
@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);
}
});
}
@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);
}
});
}
@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);
}
});
}
@Override
public Object eval(String script, List keys, List args) {
String[] params = (String[])ArrayUtils.addAll(keys.toArray(), args.toArray());
return eval(script, keys.size(), params);
}
@Override
public Object eval(String script) {
return eval(script, 0);
}
@Override
public Object evalsha(String sha1, int keyCount, String... params) {
throw new UnsupportedOperationException("This function is Not Implemented. Please use eval instead.");
}
@Override
public Object evalsha(String sha1, List keys, List args) {
throw new UnsupportedOperationException("This function is Not Implemented. Please use eval instead.");
}
@Override
public Object evalsha(String script) {
throw new UnsupportedOperationException("This function is Not Implemented. Please use eval instead.");
}
@Override
public Boolean scriptExists(String sha1) {
throw new UnsupportedOperationException("This function is Not Implemented");
}
@Override
public List scriptExists(String... sha1) {
throw new UnsupportedOperationException("This function is Not Implemented");
}
@Override
public String scriptLoad(String script) {
throw new UnsupportedOperationException("This function is Not Implemented");
}
@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);
}
});
} 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);
}
});
}
}
@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);
}
});
}
@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);
}
});
}
@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);
}
});
} 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);
}
});
}
}
@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);
}
});
}
@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);
}
});
}
@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);
}
});
} 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);
}
});
}
}
@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);
}
});
} 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);
}
});
}
});
}
}
@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);
}
});
}
/* 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);
}
});
}
@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);
}
});
} 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));
}
});
}
}
@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);
}
});
}
@Override
public ScanResult> hscan(final String key, final int cursor) {
throw new UnsupportedOperationException("This function is deprecated, use hscan(String, String)");
}
@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);
}
});
} 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;
}
})));
}
});
}
}
private String getCursorValue(final ConnectionContext state, final CursorBasedResult cursor) {
if (state != null && state.getMetadata("host") != null && cursor != null) {
return cursor.getCursorForHost(state.getMetadata("host").toString());
}
return "0";
}
private List>> scatterGatherScan(final CursorBasedResult cursor,
final int count, final String... pattern) {
return new ArrayList<>(connPool.executeWithRing(new BaseKeyOperation>("SCAN", OpName.SCAN) {
@Override
public ScanResult execute(final Jedis client, final ConnectionContext state) throws DynoException {
if (pattern != null && pattern.length > 0) {
ScanParams sp = new ScanParams().count(count);
for (String s : pattern) {
sp.match(s);
}
return client.scan(getCursorValue(state, cursor), sp);
} else {
return client.scan(getCursorValue(state, cursor));
}
}
}));
}
@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);
}
});
}
@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);
}
});
} 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);
}
}));
}
});
}
}
@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);
}
});
} 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);
}
}));
}
});
}
}
@Override
public Long hset(final String key, final String field, final String value) {
return d_hset(key, field, value).getResult();
}
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);
}
});
} 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));
}
});
}
}
@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);
}
});
} 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);
}
}));
}
});
}
}
@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);
}
});
}
@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);
}
});
}
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);
}
});
}
@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);
}
});
}
@Override
public Long linsert(final String key, final LIST_POSITION where, final String pivot, final String value) {
return d_linsert(key, where, pivot, value).getResult();
}
public OperationResult d_linsert(final String key, final LIST_POSITION 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);
}
});
}
@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);
}
});
}
@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);
}
});
}
@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);
}
});
}
@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);
}
});
}
@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);
}
});
}
@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);
}
});
}
@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);
}
});
}
@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);
}
});
}
@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);
}
});
}
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);
}
});
}
public Long pttl(final String key) {
return d_pttl(key).getResult();
}
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);
}
});
}
@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);
}
});
}
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);
}
});
}
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);
}
});
}
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);
}
});
}
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);
}
});
}
@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);
}
});
}
@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);
}
});
}
@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);
}
});
}
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);
}
});
}
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);
}
});
}
@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);
}
});
} 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));
}
});
}
}
@Override
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) {
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, nxxx, expx, time);
}
});
} 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), nxxx, expx, time);
}
});
}
}
@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);
}
});
}
@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);
}
});
}
@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);
}
});
} 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));
}
});
}
}
@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);
}
});
} 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));
}
});
}
}
@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);
}
});
}
@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);
}
});
}
@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);
}
});
}
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);
}
});
}
@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);
}
});
}
@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);
}
});
}
@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);
}
});
}
@Override
public Set spop(String key, long count) {
throw new UnsupportedOperationException("not yet implemented");
}
@Override
public String srandmember(final String key) {
return d_srandmember(key).getResult();
}
@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);
}
});
}
@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);
}
});
}
@Override
public ScanResult sscan(final String key, final int cursor) {
return d_sscan(key, cursor).getResult();
}
public OperationResult> d_sscan(final String key, final int cursor) {
return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.SSCAN) {
@Override
public ScanResult execute(Jedis client, ConnectionContext state) {
return client.sscan(key, cursor);
}
});
}
@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);
}
});
}
@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);
}
});
}
@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);
}
});
}
@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);
}
});
}
@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);
}
});
}
@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);
}
});
}
@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);
}
});
}
@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);
}
});
}
@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);
}
});
}
@Override
public Long zcard(final String key) {
return d_zcard(key).getResult();
}
public OperationResult