All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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.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.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 java.io.IOException;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;

import static com.netflix.dyno.connectionpool.ConnectionPoolConfiguration.CompressionStrategy;


public class DynoJedisClient implements JedisCommands, BinaryJedisCommands, MultiKeyCommands {

    private static final Logger Logger = org.slf4j.LoggerFactory.getLogger(DynoJedisClient.class);

    private final String appName;
    private final ConnectionPool connPool;
    private final AtomicReference pipelineMonitor = new AtomicReference();
    private final EnumSet compressionOperations = EnumSet.of(OpName.APPEND);

    public DynoJedisClient(String name, ConnectionPool pool, DynoOPMonitor operationMonitor) {
        this.appName = name;
        this.connPool = pool;
    }

    public ConnectionPoolImpl getConnPool() {
        return (ConnectionPoolImpl) connPool;
    }
   

    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 = null;
        	this.op = o;
        }
        
        @Override
        public String getName() {
            return op.name();
        }

        @Override
        public String getKey() {
            return this.key;
        }
        
        public byte[] getBinaryKey() {
        	return this.binaryKey;
        }
        
    }
 


    /**
     * 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 [" + getKey() + "]; 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 (TopologyView) 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(); } @Override public Long pexpire(String key, long milliseconds) { throw new UnsupportedOperationException("not yet implemented"); } public OperationResult d_expire(final String key, final Integer 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 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 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) { ScanParams sp = new ScanParams(); 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 pexpire(final String key, final int milliseconds) { return d_pexpire(key, milliseconds).getResult(); } public OperationResult d_pexpire(final String key, final Integer milliseconds) { return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.PEXPIRE) { @Override public Long execute(Jedis client, ConnectionContext state) { return client.pexpire(key, milliseconds); } }); } 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 String psetex(final String key, final int milliseconds, final String value) { return d_psetex(key, milliseconds, value).getResult(); } public OperationResult d_psetex(final String key, final Integer milliseconds, final String value) { return connPool.executeWithFailover(new BaseKeyOperation(key, OpName.PSETEX) { @Override public String execute(Jedis client, ConnectionContext state) { return client.psetex(key, milliseconds, value); } }); } 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(); } @Override public String set(String key, String value, String nxxx, String expx, long time) { throw new UnsupportedOperationException("not yet implemented"); } 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 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(String key, long offset, 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 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 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); } }); } @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); } }); } @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); } }); } @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); } }); } @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); } }); } @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); } }); } @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); } }); } @Override public Long zremrangeByRank(final String key, final long start, final long end) { return d_zremrangeByRank(key, start, end).getResult(); } 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 d_zremrangeByScore(key, start, end).getResult(); } 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 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); } }); } @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); } }); } @Override public ScanResult zscan(final String key, final int cursor) { return d_zscan(key, cursor).getResult(); } public OperationResult> d_zscan(final String key, final int cursor){ return connPool.executeWithFailover(new BaseKeyOperation>(key, OpName.ZSCAN) { @Override public ScanResult execute(Jedis client, ConnectionContext state) { return client.zscan(key, cursor); } }); } @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); } }); } @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); } }); } @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); } }); } @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); } }); } @Override public Set zrangeByScore(String key, String min, String max, int offset, int count) { return d_zrangeByScore(key, min, max, offset, count).getResult(); } 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, 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); } }); } @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); } }); } @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); } }); } @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); } }); } @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); } }); } @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); } }); } @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); } }); } @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); } }); } @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); } }); } @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); } }); } @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); } }); } @Override public Long zremrangeByScore(String key, String start, String end) { return d_zremrangeByScore(key, start, end).getResult(); } @Override public Long zlexcount(String key, String min, String max) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrangeByLex(String key, String min, String max) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrangeByLex(String key, String min, String max, int offset, int count) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long zremrangeByLex(String key, String min, String max) { throw new UnsupportedOperationException("not yet implemented"); } 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); } }); } @Override public List blpop(String arg) { return d_blpop(arg).getResult(); } @Override public List blpop(int timeout, String key) { throw new UnsupportedOperationException("not yet implemented"); } public OperationResult> d_blpop(final String arg) { return connPool.executeWithFailover(new BaseKeyOperation>(arg, OpName.BLPOP) { @Override public List execute(Jedis client, ConnectionContext state) { return client.blpop(arg); } }); } @Override public List brpop(String arg) { return d_brpop(arg).getResult(); } @Override public List brpop(int timeout, String key) { throw new UnsupportedOperationException("not yet implemented"); } public OperationResult> d_brpop(final String arg) { return connPool.executeWithFailover(new BaseKeyOperation>(arg, OpName.BRPOP) { @Override public List execute(Jedis client, ConnectionContext state) { return client.brpop(arg); } }); } @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); } }); } @Override public Long bitcount(String key) { return d_bitcount(key).getResult(); } 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 Long bitcount(String key, long start, long end) { return d_bitcount(key, start, end).getResult(); } @Override public Long pfadd(String key, String... elements) { throw new UnsupportedOperationException("not yet implemented"); } @Override public long pfcount(String key) { throw new UnsupportedOperationException("not yet implemented"); } 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); } }); } /** MULTI-KEY COMMANDS */ @Override public Long del(String... keys) { throw new UnsupportedOperationException("not yet implemented"); } @Override public List blpop(int timeout, String... keys) { throw new UnsupportedOperationException("not yet implemented"); } @Override public List brpop(int timeout, String... keys) { throw new UnsupportedOperationException("not yet implemented"); } @Override public List blpop(String... args) { throw new UnsupportedOperationException("not yet implemented"); } @Override public List brpop(String... args) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set keys(String pattern) { Set allResults = new HashSet(); Collection>> results = d_keys(pattern); for (OperationResult> result : results) { allResults.addAll(result.getResult()); } return allResults; } /** * Use this with care, especially in the context of production databases. * * @param pattern Specifies the mach set for keys * @return a collection of operation results * @see keys */ public Collection>> d_keys(final String pattern) { Logger.warn("Executing d_keys for pattern: " + pattern); Collection>> results = connPool.executeWithRing(new BaseKeyOperation>(pattern, OpName.KEYS) { @Override public Set execute(Jedis client, ConnectionContext state) throws DynoException { return client.keys(pattern); } }); return results; } @Override public List mget(String... keys) { throw new UnsupportedOperationException("not yet implemented"); } @Override public String mset(String... keysvalues) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long msetnx(String... keysvalues) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set sinter(String... keys) { throw new UnsupportedOperationException("not yet implemented"); } public Long sinterstore(final String dstkey, final String... keys) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long sort(String key, SortingParams sortingParameters, String dstkey) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long sort(String key, String dstkey) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set sunion(String... keys) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long sunionstore(String dstkey, String... keys) { throw new UnsupportedOperationException("not yet implemented"); } @Override public String watch(String... keys) { throw new UnsupportedOperationException("not yet implemented"); } @Override public String unwatch() { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long zinterstore(String dstkey, String... sets) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long zinterstore(String dstkey, ZParams params, String... sets) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrevrangeByLex(String key, String max, String min) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrevrangeByLex(String key, String max, String min, int offset, int count) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long zunionstore(String dstkey, String... sets) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long zunionstore(String dstkey, ZParams params, String... sets) { throw new UnsupportedOperationException("not yet implemented"); } @Override public String brpoplpush(String source, String destination, int timeout) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long publish(String channel, String message) { throw new UnsupportedOperationException("not yet implemented"); } @Override public void subscribe(JedisPubSub jedisPubSub, String... channels) { throw new UnsupportedOperationException("not yet implemented"); } @Override public void psubscribe(JedisPubSub jedisPubSub, String... patterns) { throw new UnsupportedOperationException("not yet implemented"); } @Override public String randomKey() { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long bitop(BitOP op, String destKey, String... srcKeys) { 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 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 byte[] get(final byte[] key) { return d_get(key).getResult(); } 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); } }); } @Override public String setex(final byte[] key, final int seconds, final byte[] value) { return d_setex(key, seconds, value).getResult(); } 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 String set(byte[] key, byte[] value, byte[] nxxx, byte[] expx, long time) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Boolean exists(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long persist(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override public String type(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long expire(byte[] key, int seconds) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long pexpire(byte[] key, final long milliseconds) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long expireAt(byte[] key, long unixTime) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long pexpireAt(byte[] key, long millisecondsTimestamp) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long ttl(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Boolean setbit(byte[] key, long offset, boolean value) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Boolean setbit(byte[] key, long offset, byte[] value) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Boolean getbit(byte[] key, long offset) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long setrange(byte[] key, long offset, byte[] value) { throw new UnsupportedOperationException("not yet implemented"); } @Override public byte[] getrange(byte[] key, long startOffset, long endOffset) { throw new UnsupportedOperationException("not yet implemented"); } @Override public byte[] getSet(byte[] key, byte[] value) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long setnx(byte[] key, byte[] value) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long decrBy(byte[] key, long integer) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long decr(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long incrBy(byte[] key, long integer) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Double incrByFloat(byte[] key, double value) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long incr(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long append(byte[] key, byte[] value) { throw new UnsupportedOperationException("not yet implemented"); } @Override public byte[] substr(byte[] key, int start, int end) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long hset(byte[] key, byte[] field, byte[] value) { throw new UnsupportedOperationException("not yet implemented"); } @Override public byte[] hget(byte[] key, byte[] field) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long hsetnx(byte[] key, byte[] field, byte[] value) { throw new UnsupportedOperationException("not yet implemented"); } @Override public String hmset(byte[] key, Map hash) { throw new UnsupportedOperationException("not yet implemented"); } @Override public List hmget(byte[] key, byte[]... fields) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long hincrBy(byte[] key, byte[] field, long value) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Double hincrByFloat(byte[] key, byte[] field, double value) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Boolean hexists(byte[] key, byte[] field) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long hdel(byte[] key, byte[]... field) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long hlen(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set hkeys(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Collection hvals(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Map hgetAll(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long rpush(byte[] key, byte[]... args) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long lpush(byte[] key, byte[]... args) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long llen(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override public List lrange(byte[] key, long start, long end) { throw new UnsupportedOperationException("not yet implemented"); } @Override public String ltrim(byte[] key, long start, long end) { throw new UnsupportedOperationException("not yet implemented"); } @Override public byte[] lindex(byte[] key, long index) { throw new UnsupportedOperationException("not yet implemented"); } @Override public String lset(byte[] key, long index, byte[] value) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long lrem(byte[] key, long count, byte[] value) { throw new UnsupportedOperationException("not yet implemented"); } @Override public byte[] lpop(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override public byte[] rpop(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long sadd(byte[] key, byte[]... member) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set smembers(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long srem(byte[] key, byte[]... member) { throw new UnsupportedOperationException("not yet implemented"); } @Override public byte[] spop(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set spop(byte[] key, long count) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long scard(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Boolean sismember(byte[] key, byte[] member) { throw new UnsupportedOperationException("not yet implemented"); } @Override public byte[] srandmember(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override public List srandmember(final byte[] key, final int count){ throw new UnsupportedOperationException("not yet implemented"); } @Override public Long strlen(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long zadd(byte[] key, double score, byte[] member) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long zadd(byte[] key, Map scoreMembers) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrange(byte[] key, long start, long end) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long zrem(byte[] key, byte[]... member) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Double zincrby(byte[] key, double score, byte[] member) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long zrank(byte[] key, byte[] member) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long zrevrank(byte[] key, byte[] member) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrevrange(byte[] key, long start, long end) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrangeWithScores(byte[] key, long start, long end) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrevrangeWithScores(byte[] key, long start, long end) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long zcard(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Double zscore(byte[] key, byte[] member) { throw new UnsupportedOperationException("not yet implemented"); } @Override public List sort(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override public List sort(byte[] key, SortingParams sortingParameters) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long zcount(byte[] key, double min, double max) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long zcount(byte[] key, byte[] min, byte[] max) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrangeByScore(byte[] key, double min, double max) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrangeByScore(byte[] key, byte[] min, byte[] max) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrevrangeByScore(byte[] key, double max, double min) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrangeByScore(byte[] key, double min, double max, int offset, int count) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrevrangeByScore(byte[] key, byte[] max, byte[] min) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrangeByScore(byte[] key, byte[] min, byte[] max, int offset, int count) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrevrangeByScore(byte[] key, double max, double min, int offset, int count) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrangeByScoreWithScores(byte[] key, double min, double max) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrevrangeByScoreWithScores(byte[] key, double max, double min) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrangeByScoreWithScores(byte[] key, double min, double max, int offset, int count) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrevrangeByScore(byte[] key, byte[] max, byte[] min, int offset, int count) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max, int offset, int count) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrevrangeByScoreWithScores(byte[] key, double max, double min, int offset, int count) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min, int offset, int count) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long zremrangeByRank(byte[] key, long start, long end) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long zremrangeByScore(byte[] key, double start, double end) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long zremrangeByScore(byte[] key, byte[] start, byte[] end) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long zlexcount(final byte[] key, final byte[] min, final byte[] max) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrangeByLex(final byte[] key, final byte[] min, final byte[] max) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrangeByLex(final byte[] key, final byte[] min, final byte[] max, int offset, int count) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrevrangeByLex(final byte[] key, final byte[] max, final byte[] min) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Set zrevrangeByLex(final byte[] key, final byte[] max, final byte[] min, int offset, int count) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long zremrangeByLex(final byte[] key, final byte[] min, final byte[] max) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long linsert(byte[] key, BinaryClient.LIST_POSITION where, byte[] pivot, byte[] value) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long lpushx(byte[] key, byte[]... arg) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long rpushx(byte[] key, byte[]... arg) { throw new UnsupportedOperationException("not yet implemented"); } @Override public List blpop(byte[] arg) { throw new UnsupportedOperationException("not yet implemented"); } @Override public List brpop(byte[] arg) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long del(byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override public byte[] echo(byte[] arg) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long move(byte[] key, int dbIndex) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long bitcount(final byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long bitcount(final byte[] key, long start, long end) { throw new UnsupportedOperationException("not yet implemented"); } @Override public Long pfadd(final byte[] key, final byte[]... elements) { throw new UnsupportedOperationException("not yet implemented"); } @Override public long pfcount(final byte[] key) { throw new UnsupportedOperationException("not yet implemented"); } /** * NOT SUPPORTED ! Use {@link #dyno_scan(CursorBasedResult, String...)} * instead. * * @param cursor * @return nothing -- throws UnsupportedOperationException when invoked * @see #dyno_scan(CursorBasedResult, String...) */ @Override public ScanResult scan(int cursor) { throw new UnsupportedOperationException("Not supported - use dyno_scan(String, CursorBasedResult"); } /** * NOT SUPPORTED ! Use {@link #dyno_scan(CursorBasedResult, String...)} * instead. * * @param cursor * @return nothing -- throws UnsupportedOperationException when invoked * @see #dyno_scan(CursorBasedResult, 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(null, pattern); } public CursorBasedResult dyno_scan(CursorBasedResult cursor, String... pattern) { final Map> results = new LinkedHashMap<>(); List>> opResults = scatterGatherScan(cursor, pattern); for (OperationResult> opResult: opResults) { results.put(opResult.getNode().getHostName(), opResult.getResult()); } return new CursorBasedResultImpl<>(results); } @Override public String pfmerge(String destkey, String... sourcekeys) { throw new UnsupportedOperationException("not yet implemented"); } @Override public long pfcount(String... keys) { throw new UnsupportedOperationException("not yet implemented"); } public void stopClient() { if (pipelineMonitor.get() != null) { pipelineMonitor.get().stop(); } this.connPool.shutdown(); } public DynoJedisPipeline pipelined() { return new DynoJedisPipeline(getConnPool(), checkAndInitPipelineMonitor(), getConnPool().getMonitor()); } private DynoJedisPipelineMonitor checkAndInitPipelineMonitor() { if (pipelineMonitor.get() != null) { return pipelineMonitor.get(); } int flushTimerFrequency = this.connPool.getConfiguration().getTimingCountersResetFrequencySeconds(); DynoJedisPipelineMonitor plMonitor = new DynoJedisPipelineMonitor(appName, flushTimerFrequency); boolean success = pipelineMonitor.compareAndSet(null, plMonitor); if (success) { pipelineMonitor.get().init(); } return pipelineMonitor.get(); } public static class Builder { private String appName; private String clusterName; private int port = -1; private ConnectionPoolConfigurationImpl cpConfig; private HostSupplier hostSupplier; private DiscoveryClient discoveryClient; public Builder() { } public Builder withApplicationName(String applicationName) { appName = applicationName; return this; } public Builder withDynomiteClusterName(String cluster) { clusterName = cluster; return this; } public Builder withCPConfig(ConnectionPoolConfigurationImpl config) { cpConfig = config; return this; } public Builder withHostSupplier(HostSupplier hSupplier) { hostSupplier = hSupplier; return this; } public Builder withPort(int suppliedPort) { port = suppliedPort; return this; } public Builder withDiscoveryClient(DiscoveryClient client) { discoveryClient = client; return this; } public DynoJedisClient build() { assert (appName != null); assert (clusterName != null); if (cpConfig == null) { cpConfig = new ArchaiusConnectionPoolConfiguration(appName); } if (port != -1) { cpConfig.setPort(port); } if (hostSupplier == null) { if (discoveryClient == null) { throw new DynoConnectException("HostSupplier not provided. Cannot init EurekaHostsSupplier which needs a non null DiscoveryClient"); } else { hostSupplier = new EurekaHostsSupplier(clusterName, discoveryClient); } } cpConfig.withHostSupplier(hostSupplier); if (cpConfig.getTokenSupplier() == null) { Logger.info("TOKEN AWARE selected and no token supplier found, using default HttpEndpointBasedTokenMapSupplier()"); cpConfig.withTokenSupplier(new HttpEndpointBasedTokenMapSupplier(port)); } DynoCPMonitor cpMonitor = new DynoCPMonitor(appName); DynoOPMonitor opMonitor = new DynoOPMonitor(appName); // Configure cp config publisher if it is specified ConnectionPoolConfigurationPublisher cpConfigPublisher = new ConnectionPoolConfigPublisherFactory().createPublisher(appName, clusterName, cpConfig); JedisConnectionFactory connFactory = new JedisConnectionFactory(opMonitor); final ConnectionPoolImpl pool = new ConnectionPoolImpl(connFactory, cpConfig, cpMonitor, cpConfigPublisher); try { pool.start().get(); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { pool.shutdown(); } })); } catch (NoAvailableHostsException e) { if (cpConfig.getFailOnStartupIfNoHosts()) { throw new RuntimeException(e); } Logger.warn("UNABLE TO START CONNECTION POOL -- IDLING"); pool.idle(); } catch (Exception e) { throw new RuntimeException(e); } final DynoJedisClient client = new DynoJedisClient(appName, pool, opMonitor); return client; } } /** * Used for unit testing ONLY */ /*package*/ static class TestBuilder { private ConnectionPool cp; private String appName; public TestBuilder withAppname(String appName) { this.appName = appName; return this; } public TestBuilder withConnectionPool(ConnectionPool cp) { this.cp = cp; return this; } public DynoJedisClient build() { return new DynoJedisClient(appName, cp, null); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy