com.lambdaworks.redis
Class RedisConnection<K,V>

java.lang.Object
  extended by com.lambdaworks.redis.RedisConnection<K,V>

public class RedisConnection<K,V>
extends Object

A synchronous thread-safe connection to a redis server. Multiple threads may share one RedisConnection provided they avoid blocking and transactional operations such as blpop(long, K...) and multi()/exec(). A ConnectionWatchdog monitors each connection and reconnects automatically until close() is called. All pending commands will be (re)sent after successful reconnection.

Author:
Will Glozer

Field Summary
protected  RedisAsyncConnection<K,V> c
           
protected  long timeout
           
protected  TimeUnit unit
           
 
Constructor Summary
RedisConnection(RedisAsyncConnection<K,V> c)
          Initialize a new connection.
 
Method Summary
 Long append(K key, V value)
           
 String auth(String password)
           
 String bgrewriteaof()
           
 String bgsave()
           
 Long bitcount(K key)
           
 Long bitcount(K key, long start, long end)
           
 Long bitopAnd(K destination, K... keys)
           
 Long bitopNot(K destination, K source)
           
 Long bitopOr(K destination, K... keys)
           
 Long bitopXor(K destination, K... keys)
           
 KeyValue<K,V> blpop(long timeout, K... keys)
           
 KeyValue<K,V> brpop(long timeout, K... keys)
           
 V brpoplpush(long timeout, K source, K destination)
           
 K clientGetname()
           
 String clientKill(String addr)
           
 String clientList()
           
 String clientSetname(K name)
           
 void close()
          Close the connection.
 List<String> configGet(String parameter)
           
 String configResetstat()
           
 String configSet(String parameter, String value)
           
 Long dbsize()
           
 String debugObject(K key)
           
 Long decr(K key)
           
 Long decrby(K key, long amount)
           
 Long del(K... keys)
           
 String digest(V script)
          Generate SHA-1 digest for the supplied script.
 String discard()
           
 byte[] dump(K key)
           
 V echo(V msg)
           
<T> T
eval(V script, ScriptOutputType type, K... keys)
          Eval the supplied script, which must result in the requested type.
<T> T
eval(V script, ScriptOutputType type, K[] keys, V... values)
           
<T> T
evalsha(String digest, ScriptOutputType type, K... keys)
          Eval a pre-loaded script identified by its SHA-1 digest, which must result in the requested type.
<T> T
evalsha(String digest, ScriptOutputType type, K[] keys, V... values)
           
 List<Object> exec()
           
 Boolean exists(K key)
           
 Boolean expire(K key, long seconds)
           
 Boolean expireat(K key, Date timestamp)
           
 Boolean expireat(K key, long timestamp)
           
 String flushall()
           
 String flushdb()
           
 V get(K key)
           
 Long getbit(K key, long offset)
           
 V getrange(K key, long start, long end)
           
 V getset(K key, V value)
           
 Long hdel(K key, K... fields)
           
 Boolean hexists(K key, K field)
           
 V hget(K key, K field)
           
 Map<K,V> hgetall(K key)
           
 Long hincrby(K key, K field, long amount)
           
 Double hincrbyfloat(K key, K field, double amount)
           
 List<K> hkeys(K key)
           
 Long hlen(K key)
           
 List<V> hmget(K key, K... fields)
           
 String hmset(K key, Map<K,V> map)
           
 Boolean hset(K key, K field, V value)
           
 Boolean hsetnx(K key, K field, V value)
           
 List<V> hvals(K key)
           
 Long incr(K key)
           
 Long incrby(K key, long amount)
           
 Double incrbyfloat(K key, double amount)
           
 String info()
           
 String info(String section)
           
 List<K> keys(K pattern)
           
 Date lastsave()
           
 V lindex(K key, long index)
           
 Long linsert(K key, boolean before, V pivot, V value)
           
 Long llen(K key)
           
 V lpop(K key)
           
 Long lpush(K key, V... values)
           
 Long lpushx(K key, V value)
           
 List<V> lrange(K key, long start, long stop)
           
 Long lrem(K key, long count, V value)
           
 String lset(K key, long index, V value)
           
 String ltrim(K key, long start, long stop)
           
 List<V> mget(K... keys)
           
 String migrate(String host, int port, K key, int db, long timeout)
           
 Boolean move(K key, int db)
           
 String mset(Map<K,V> map)
           
 Boolean msetnx(Map<K,V> map)
           
 String multi()
           
 String objectEncoding(K key)
           
 Long objectIdletime(K key)
           
 Long objectRefcount(K key)
           
 Boolean persist(K key)
           
 Boolean pexpire(K key, long milliseconds)
           
 Boolean pexpireat(K key, Date timestamp)
           
 Boolean pexpireat(K key, long timestamp)
           
 String ping()
           
 Long pttl(K key)
           
 Long publish(K channel, V message)
           
 String quit()
           
 V randomkey()
           
 String rename(K key, K newKey)
           
 Boolean renamenx(K key, K newKey)
           
 String restore(K key, long ttl, byte[] value)
           
 V rpop(K key)
           
 V rpoplpush(K source, K destination)
           
 Long rpush(K key, V... values)
           
 Long rpushx(K key, V value)
           
 Long sadd(K key, V... members)
           
 String save()
           
 Long scard(K key)
           
 List<Boolean> scriptExists(String... digests)
           
 String scriptFlush()
           
 String scriptKill()
           
 String scriptLoad(V script)
           
 Set<V> sdiff(K... keys)
           
 Long sdiffstore(K destination, K... keys)
           
 String select(int db)
           
 String set(K key, V value)
           
 Long setbit(K key, long offset, int value)
           
 String setex(K key, long seconds, V value)
           
 Boolean setnx(K key, V value)
           
 Long setrange(K key, long offset, V value)
           
 void setTimeout(long timeout, TimeUnit unit)
          Set the command timeout for this connection.
 void shutdown()
          Deprecated. 
 void shutdown(boolean save)
           
 Set<V> sinter(K... keys)
           
 Long sinterstore(K destination, K... keys)
           
 Boolean sismember(K key, V member)
           
 String slaveof(String host, int port)
           
 String slaveofNoOne()
           
 List<Object> slowlogGet()
           
 List<Object> slowlogGet(int count)
           
 Long slowlogLen()
           
 String slowlogReset()
           
 Set<V> smembers(K key)
           
 Boolean smove(K source, K destination, V member)
           
 List<V> sort(K key)
           
 List<V> sort(K key, SortArgs sortArgs)
           
 Long sortStore(K key, SortArgs sortArgs, K destination)
           
 V spop(K key)
           
 V srandmember(K key)
           
 Set<V> srandmember(K key, long count)
           
 Long srem(K key, V... members)
           
 Long strlen(K key)
           
 Set<V> sunion(K... keys)
           
 Long sunionstore(K destination, K... keys)
           
 String sync()
           
 Long ttl(K key)
           
 String type(K key)
           
 String unwatch()
           
 String watch(K... keys)
           
 Long zadd(K key, double score, V member)
           
 Long zadd(K key, Object... scoresAndValues)
           
 Long zcard(K key)
           
 Long zcount(K key, double min, double max)
           
 Long zcount(K key, String min, String max)
           
 Double zincrby(K key, double amount, K member)
           
 Long zinterstore(K destination, K... keys)
           
 Long zinterstore(K destination, ZStoreArgs storeArgs, K... keys)
           
 List<V> zrange(K key, long start, long stop)
           
 List<V> zrangebyscore(K key, double min, double max)
           
 List<V> zrangebyscore(K key, double min, double max, long offset, long count)
           
 List<V> zrangebyscore(K key, String min, String max)
           
 List<V> zrangebyscore(K key, String min, String max, long offset, long count)
           
 List<ScoredValue<V>> zrangebyscoreWithScores(K key, double min, double max)
           
 List<ScoredValue<V>> zrangebyscoreWithScores(K key, double min, double max, long offset, long count)
           
 List<ScoredValue<V>> zrangebyscoreWithScores(K key, String min, String max)
           
 List<ScoredValue<V>> zrangebyscoreWithScores(K key, String min, String max, long offset, long count)
           
 List<ScoredValue<V>> zrangeWithScores(K key, long start, long stop)
           
 Long zrank(K key, V member)
           
 Long zrem(K key, V... members)
           
 Long zremrangebyrank(K key, long start, long stop)
           
 Long zremrangebyscore(K key, double min, double max)
           
 Long zremrangebyscore(K key, String min, String max)
           
 List<V> zrevrange(K key, long start, long stop)
           
 List<V> zrevrangebyscore(K key, double max, double min)
           
 List<V> zrevrangebyscore(K key, double max, double min, long offset, long count)
           
 List<V> zrevrangebyscore(K key, String max, String min)
           
 List<V> zrevrangebyscore(K key, String max, String min, long offset, long count)
           
 List<ScoredValue<V>> zrevrangebyscoreWithScores(K key, double max, double min)
           
 List<ScoredValue<V>> zrevrangebyscoreWithScores(K key, double max, double min, long offset, long count)
           
 List<ScoredValue<V>> zrevrangebyscoreWithScores(K key, String max, String min)
           
 List<ScoredValue<V>> zrevrangebyscoreWithScores(K key, String max, String min, long offset, long count)
           
 List<ScoredValue<V>> zrevrangeWithScores(K key, long start, long stop)
           
 Long zrevrank(K key, V member)
           
 Double zscore(K key, V member)
           
 Long zunionstore(K destination, K... keys)
           
 Long zunionstore(K destination, ZStoreArgs storeArgs, K... keys)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

c

protected RedisAsyncConnection<K,V> c

timeout

protected long timeout

unit

protected TimeUnit unit
Constructor Detail

RedisConnection

public RedisConnection(RedisAsyncConnection<K,V> c)
Initialize a new connection.

Parameters:
c - Underlying async connection.
Method Detail

setTimeout

public void setTimeout(long timeout,
                       TimeUnit unit)
Set the command timeout for this connection.

Parameters:
timeout - Command timeout.
unit - Unit of time for the timeout.

append

public Long append(K key,
                   V value)

auth

public String auth(String password)

bgrewriteaof

public String bgrewriteaof()

bgsave

public String bgsave()

bitcount

public Long bitcount(K key)

bitcount

public Long bitcount(K key,
                     long start,
                     long end)

bitopAnd

public Long bitopAnd(K destination,
                     K... keys)

bitopNot

public Long bitopNot(K destination,
                     K source)

bitopOr

public Long bitopOr(K destination,
                    K... keys)

bitopXor

public Long bitopXor(K destination,
                     K... keys)

blpop

public KeyValue<K,V> blpop(long timeout,
                           K... keys)

brpop

public KeyValue<K,V> brpop(long timeout,
                           K... keys)

brpoplpush

public V brpoplpush(long timeout,
                    K source,
                    K destination)

clientGetname

public K clientGetname()

clientSetname

public String clientSetname(K name)

clientKill

public String clientKill(String addr)

clientList

public String clientList()

configGet

public List<String> configGet(String parameter)

configResetstat

public String configResetstat()

configSet

public String configSet(String parameter,
                        String value)

dbsize

public Long dbsize()

debugObject

public String debugObject(K key)

decr

public Long decr(K key)

decrby

public Long decrby(K key,
                   long amount)

del

public Long del(K... keys)

discard

public String discard()

dump

public byte[] dump(K key)

echo

public V echo(V msg)

eval

public <T> T eval(V script,
                  ScriptOutputType type,
                  K... keys)
Eval the supplied script, which must result in the requested type.

Type Parameters:
T - Expected return type.
Parameters:
script - Lua script to evaluate.
type - Script output type.
keys - Redis keys to pass to script.
Returns:
The result of evaluating the script.

eval

public <T> T eval(V script,
                  ScriptOutputType type,
                  K[] keys,
                  V... values)

evalsha

public <T> T evalsha(String digest,
                     ScriptOutputType type,
                     K... keys)
Eval a pre-loaded script identified by its SHA-1 digest, which must result in the requested type.

Type Parameters:
T - Expected return type.
Parameters:
digest - Lowercase hex string of script's SHA-1 digest.
type - Script output type.
keys - Redis keys to pass to script.
Returns:
The result of evaluating the script.

evalsha

public <T> T evalsha(String digest,
                     ScriptOutputType type,
                     K[] keys,
                     V... values)

exists

public Boolean exists(K key)

expire

public Boolean expire(K key,
                      long seconds)

expireat

public Boolean expireat(K key,
                        Date timestamp)

expireat

public Boolean expireat(K key,
                        long timestamp)

exec

public List<Object> exec()

flushall

public String flushall()
                throws Exception
Throws:
Exception

flushdb

public String flushdb()
               throws Exception
Throws:
Exception

get

public V get(K key)

getbit

public Long getbit(K key,
                   long offset)

getrange

public V getrange(K key,
                  long start,
                  long end)

getset

public V getset(K key,
                V value)

hdel

public Long hdel(K key,
                 K... fields)

hexists

public Boolean hexists(K key,
                       K field)

hget

public V hget(K key,
              K field)

hincrby

public Long hincrby(K key,
                    K field,
                    long amount)

hincrbyfloat

public Double hincrbyfloat(K key,
                           K field,
                           double amount)

hgetall

public Map<K,V> hgetall(K key)

hkeys

public List<K> hkeys(K key)

hlen

public Long hlen(K key)

hmget

public List<V> hmget(K key,
                     K... fields)

hmset

public String hmset(K key,
                    Map<K,V> map)

hset

public Boolean hset(K key,
                    K field,
                    V value)

hsetnx

public Boolean hsetnx(K key,
                      K field,
                      V value)

hvals

public List<V> hvals(K key)

incr

public Long incr(K key)

incrby

public Long incrby(K key,
                   long amount)

incrbyfloat

public Double incrbyfloat(K key,
                          double amount)

info

public String info()

info

public String info(String section)

keys

public List<K> keys(K pattern)

lastsave

public Date lastsave()

lindex

public V lindex(K key,
                long index)

linsert

public Long linsert(K key,
                    boolean before,
                    V pivot,
                    V value)

llen

public Long llen(K key)

lpop

public V lpop(K key)

lpush

public Long lpush(K key,
                  V... values)

lpushx

public Long lpushx(K key,
                   V value)

lrange

public List<V> lrange(K key,
                      long start,
                      long stop)

lrem

public Long lrem(K key,
                 long count,
                 V value)

lset

public String lset(K key,
                   long index,
                   V value)

ltrim

public String ltrim(K key,
                    long start,
                    long stop)

migrate

public String migrate(String host,
                      int port,
                      K key,
                      int db,
                      long timeout)

mget

public List<V> mget(K... keys)

move

public Boolean move(K key,
                    int db)

multi

public String multi()

mset

public String mset(Map<K,V> map)

msetnx

public Boolean msetnx(Map<K,V> map)

objectEncoding

public String objectEncoding(K key)

objectIdletime

public Long objectIdletime(K key)

objectRefcount

public Long objectRefcount(K key)

persist

public Boolean persist(K key)

pexpire

public Boolean pexpire(K key,
                       long milliseconds)

pexpireat

public Boolean pexpireat(K key,
                         Date timestamp)

pexpireat

public Boolean pexpireat(K key,
                         long timestamp)

ping

public String ping()

pttl

public Long pttl(K key)

publish

public Long publish(K channel,
                    V message)

quit

public String quit()

randomkey

public V randomkey()

rename

public String rename(K key,
                     K newKey)

renamenx

public Boolean renamenx(K key,
                        K newKey)

restore

public String restore(K key,
                      long ttl,
                      byte[] value)

rpop

public V rpop(K key)

rpoplpush

public V rpoplpush(K source,
                   K destination)

rpush

public Long rpush(K key,
                  V... values)

rpushx

public Long rpushx(K key,
                   V value)

sadd

public Long sadd(K key,
                 V... members)

save

public String save()

scard

public Long scard(K key)

scriptExists

public List<Boolean> scriptExists(String... digests)

scriptFlush

public String scriptFlush()

scriptKill

public String scriptKill()

scriptLoad

public String scriptLoad(V script)

sdiff

public Set<V> sdiff(K... keys)

sdiffstore

public Long sdiffstore(K destination,
                       K... keys)

select

public String select(int db)

set

public String set(K key,
                  V value)

setbit

public Long setbit(K key,
                   long offset,
                   int value)

setex

public String setex(K key,
                    long seconds,
                    V value)

setnx

public Boolean setnx(K key,
                     V value)

setrange

public Long setrange(K key,
                     long offset,
                     V value)

shutdown

@Deprecated
public void shutdown()
Deprecated. 


shutdown

public void shutdown(boolean save)

sinter

public Set<V> sinter(K... keys)

sinterstore

public Long sinterstore(K destination,
                        K... keys)

sismember

public Boolean sismember(K key,
                         V member)

smove

public Boolean smove(K source,
                     K destination,
                     V member)

slaveof

public String slaveof(String host,
                      int port)

slaveofNoOne

public String slaveofNoOne()

slowlogGet

public List<Object> slowlogGet()

slowlogGet

public List<Object> slowlogGet(int count)

slowlogLen

public Long slowlogLen()

slowlogReset

public String slowlogReset()

smembers

public Set<V> smembers(K key)

sort

public List<V> sort(K key)

sort

public List<V> sort(K key,
                    SortArgs sortArgs)

sortStore

public Long sortStore(K key,
                      SortArgs sortArgs,
                      K destination)

spop

public V spop(K key)

srandmember

public V srandmember(K key)

srandmember

public Set<V> srandmember(K key,
                          long count)

srem

public Long srem(K key,
                 V... members)

sunion

public Set<V> sunion(K... keys)

sunionstore

public Long sunionstore(K destination,
                        K... keys)

sync

public String sync()

strlen

public Long strlen(K key)

ttl

public Long ttl(K key)

type

public String type(K key)

watch

public String watch(K... keys)

unwatch

public String unwatch()

zadd

public Long zadd(K key,
                 double score,
                 V member)

zadd

public Long zadd(K key,
                 Object... scoresAndValues)

zcard

public Long zcard(K key)

zcount

public Long zcount(K key,
                   double min,
                   double max)

zcount

public Long zcount(K key,
                   String min,
                   String max)

zincrby

public Double zincrby(K key,
                      double amount,
                      K member)

zinterstore

public Long zinterstore(K destination,
                        K... keys)

zinterstore

public Long zinterstore(K destination,
                        ZStoreArgs storeArgs,
                        K... keys)

zrange

public List<V> zrange(K key,
                      long start,
                      long stop)

zrangeWithScores

public List<ScoredValue<V>> zrangeWithScores(K key,
                                             long start,
                                             long stop)

zrangebyscore

public List<V> zrangebyscore(K key,
                             double min,
                             double max)

zrangebyscore

public List<V> zrangebyscore(K key,
                             String min,
                             String max)

zrangebyscore

public List<V> zrangebyscore(K key,
                             double min,
                             double max,
                             long offset,
                             long count)

zrangebyscore

public List<V> zrangebyscore(K key,
                             String min,
                             String max,
                             long offset,
                             long count)

zrangebyscoreWithScores

public List<ScoredValue<V>> zrangebyscoreWithScores(K key,
                                                    double min,
                                                    double max)

zrangebyscoreWithScores

public List<ScoredValue<V>> zrangebyscoreWithScores(K key,
                                                    String min,
                                                    String max)

zrangebyscoreWithScores

public List<ScoredValue<V>> zrangebyscoreWithScores(K key,
                                                    double min,
                                                    double max,
                                                    long offset,
                                                    long count)

zrangebyscoreWithScores

public List<ScoredValue<V>> zrangebyscoreWithScores(K key,
                                                    String min,
                                                    String max,
                                                    long offset,
                                                    long count)

zrank

public Long zrank(K key,
                  V member)

zrem

public Long zrem(K key,
                 V... members)

zremrangebyrank

public Long zremrangebyrank(K key,
                            long start,
                            long stop)

zremrangebyscore

public Long zremrangebyscore(K key,
                             double min,
                             double max)

zremrangebyscore

public Long zremrangebyscore(K key,
                             String min,
                             String max)

zrevrange

public List<V> zrevrange(K key,
                         long start,
                         long stop)

zrevrangeWithScores

public List<ScoredValue<V>> zrevrangeWithScores(K key,
                                                long start,
                                                long stop)

zrevrangebyscore

public List<V> zrevrangebyscore(K key,
                                double max,
                                double min)

zrevrangebyscore

public List<V> zrevrangebyscore(K key,
                                String max,
                                String min)

zrevrangebyscore

public List<V> zrevrangebyscore(K key,
                                double max,
                                double min,
                                long offset,
                                long count)

zrevrangebyscore

public List<V> zrevrangebyscore(K key,
                                String max,
                                String min,
                                long offset,
                                long count)

zrevrangebyscoreWithScores

public List<ScoredValue<V>> zrevrangebyscoreWithScores(K key,
                                                       double max,
                                                       double min)

zrevrangebyscoreWithScores

public List<ScoredValue<V>> zrevrangebyscoreWithScores(K key,
                                                       String max,
                                                       String min)

zrevrangebyscoreWithScores

public List<ScoredValue<V>> zrevrangebyscoreWithScores(K key,
                                                       double max,
                                                       double min,
                                                       long offset,
                                                       long count)

zrevrangebyscoreWithScores

public List<ScoredValue<V>> zrevrangebyscoreWithScores(K key,
                                                       String max,
                                                       String min,
                                                       long offset,
                                                       long count)

zrevrank

public Long zrevrank(K key,
                     V member)

zscore

public Double zscore(K key,
                     V member)

zunionstore

public Long zunionstore(K destination,
                        K... keys)

zunionstore

public Long zunionstore(K destination,
                        ZStoreArgs storeArgs,
                        K... keys)

close

public void close()
Close the connection.


digest

public String digest(V script)
Generate SHA-1 digest for the supplied script.

Parameters:
script - Lua script.
Returns:
Script digest as a lowercase hex string.


Copyright © 2013. All Rights Reserved.