Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// Copyright (C) 2011 - Will Glozer. All rights reserved.
package com.lambdaworks.redis;
import com.lambdaworks.redis.protocol.Command;
import com.lambdaworks.redis.protocol.ConnectionWatchdog;
import java.util.*;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import static com.lambdaworks.redis.protocol.CommandType.MULTI;
import static java.lang.Math.max;
import static java.util.concurrent.TimeUnit.SECONDS;
/**
* A synchronous thread-safe connection to a redis server. Multiple threads may
* share one {@link RedisConnection} provided they avoid blocking and transactional
* operations such as {@link #blpop} and {@link #multi()}/{@link #exec}.
*
* A {@link ConnectionWatchdog} monitors each connection and reconnects
* automatically until {@link #close} is called. All pending commands will be
* (re)sent after successful reconnection.
*
* @author Will Glozer
*/
public class RedisConnection {
protected RedisAsyncConnection c;
protected long timeout;
protected TimeUnit unit;
/**
* Initialize a new connection.
*
* @param c Underlying async connection.
*/
public RedisConnection(RedisAsyncConnection c) {
this.c = c;
this.timeout = c.timeout;
this.unit = c.unit;
}
/**
* Set the command timeout for this connection.
*
* @param timeout Command timeout.
* @param unit Unit of time for the timeout.
*/
public void setTimeout(long timeout, TimeUnit unit) {
this.timeout = timeout;
this.unit = unit;
c.setTimeout(timeout, unit);
}
public Long append(K key, V value) {
return await(c.append(key, value));
}
public String auth(String password) {
return c.auth(password);
}
public String bgrewriteaof() {
return await(c.bgrewriteaof());
}
public String bgsave() {
return await(c.bgsave());
}
public Long bitcount(K key) {
return await(c.bitcount(key));
}
public Long bitcount(K key, long start, long end) {
return await(c.bitcount(key, start, end));
}
public Long bitopAnd(K destination, K... keys) {
return await(c.bitopAnd(destination, keys));
}
public Long bitopNot(K destination, K source) {
return await(c.bitopNot(destination, source));
}
public Long bitopOr(K destination, K... keys) {
return await(c.bitopOr(destination, keys));
}
public Long bitopXor(K destination, K... keys) {
return await(c.bitopXor(destination, keys));
}
public KeyValue blpop(long timeout, K... keys) {
long timeout2 = (timeout == 0 ? Long.MAX_VALUE : max(timeout, unit.toSeconds(this.timeout)));
return await(c.blpop(timeout, keys), timeout2, SECONDS);
}
public KeyValue brpop(long timeout, K... keys) {
long timeout2 = (timeout == 0 ? Long.MAX_VALUE : max(timeout, unit.toSeconds(this.timeout)));
return await(c.brpop(timeout, keys), timeout2, SECONDS);
}
public V brpoplpush(long timeout, K source, K destination) {
long timeout2 = (timeout == 0 ? Long.MAX_VALUE : max(timeout, unit.toSeconds(this.timeout)));
return await(c.brpoplpush(timeout, source, destination), timeout2, SECONDS);
}
public K clientGetname() {
return await(c.clientGetname());
}
public String clientSetname(K name) {
return await(c.clientSetname(name));
}
public String clientKill(String addr) {
return await(c.clientKill(addr));
}
public String clientList() {
return await(c.clientList());
}
public List configGet(String parameter) {
return await(c.configGet(parameter));
}
public String configResetstat() {
return await(c.configResetstat());
}
public String configSet(String parameter, String value) {
return await(c.configSet(parameter, value));
}
public Long dbsize() {
return await(c.dbsize());
}
public String debugObject(K key) {
return await(c.debugObject(key));
}
public Long decr(K key) {
return await(c.decr(key));
}
public Long decrby(K key, long amount) {
return await(c.decrby(key, amount));
}
public Long del(K... keys) {
return await(c.del(keys));
}
public String discard() {
return await(c.discard());
}
public byte[] dump(K key) {
return await(c.dump(key));
}
public V echo(V msg) {
return await(c.echo(msg));
}
/**
* Eval the supplied script, which must result in the requested
* {@link ScriptOutputType type}.
*
* @param script Lua script to evaluate.
* @param type Script output type.
* @param keys Redis keys to pass to script.
*
* @param Expected return type.
*
* @return The result of evaluating the script.
*/
@SuppressWarnings("unchecked")
public T eval(V script, ScriptOutputType type, K... keys) {
return (T) await(c.eval(script, type, keys, (V[]) new Object[0]));
}
@SuppressWarnings("unchecked")
public T eval(V script, ScriptOutputType type, K[] keys, V... values) {
return (T) await(c.eval(script, type, keys, values));
}
/**
* Eval a pre-loaded script identified by its SHA-1 digest, which must result
* in the requested {@link ScriptOutputType type}.
*
* @param digest Lowercase hex string of script's SHA-1 digest.
* @param type Script output type.
* @param keys Redis keys to pass to script.
*
* @param Expected return type.
*
* @return The result of evaluating the script.
*/
@SuppressWarnings("unchecked")
public T evalsha(String digest, ScriptOutputType type, K... keys) {
return (T) await(c.evalsha(digest, type, keys, (V[]) new Object[0]));
}
@SuppressWarnings("unchecked")
public T evalsha(String digest, ScriptOutputType type, K[] keys, V... values) {
return (T) await(c.evalsha(digest, type, keys, values));
}
public Boolean exists(K key) {
return await(c.exists(key));
}
public Boolean expire(K key, long seconds) {
return await(c.expire(key, seconds));
}
public Boolean expireat(K key, Date timestamp) {
return await(c.expireat(key, timestamp));
}
public Boolean expireat(K key, long timestamp) {
return await(c.expireat(key, timestamp));
}
public List