package redis.clients.jedis;
import redis.clients.jedis.BinaryClient.LIST_POSITION;
import redis.clients.jedis.exceptions.InvalidURIException;
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.exceptions.JedisException;
import redis.clients.jedis.params.geo.GeoRadiusParam;
import redis.clients.jedis.params.sortedset.ZAddParams;
import redis.clients.jedis.params.sortedset.ZIncrByParams;
import redis.clients.util.JedisByteHashMap;
import redis.clients.util.JedisURIHelper;
import redis.clients.util.SafeEncoder;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSocketFactory;
import java.io.Closeable;
import java.io.Serializable;
import java.net.URI;
import java.util.*;
import static redis.clients.jedis.Protocol.toByteArray;
public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKeyBinaryCommands,
AdvancedBinaryJedisCommands, BinaryScriptingCommands, Closeable {
protected Client client = null;
protected Transaction transaction = null;
protected Pipeline pipeline = null;
public BinaryJedis() {
client = new Client();
}
public BinaryJedis(final String host) {
URI uri = URI.create(host);
if (uri.getScheme() != null && uri.getScheme().equals("redis")) {
initializeClientFromURI(uri);
} else {
client = new Client(host);
}
}
public BinaryJedis(final String host, final int port) {
client = new Client(host, port);
}
public BinaryJedis(final String host, final int port, final boolean ssl) {
client = new Client(host, port, ssl);
}
public BinaryJedis(final String host, final int port, final boolean ssl,
final SSLSocketFactory sslSocketFactory, final SSLParameters sslParameters,
final HostnameVerifier hostnameVerifier) {
client = new Client(host, port, ssl, sslSocketFactory, sslParameters, hostnameVerifier);
}
public BinaryJedis(final String host, final int port, final int timeout) {
client = new Client(host, port);
client.setConnectionTimeout(timeout);
client.setSoTimeout(timeout);
}
public BinaryJedis(final String host, final int port, final int timeout, final boolean ssl) {
client = new Client(host, port, ssl);
client.setConnectionTimeout(timeout);
client.setSoTimeout(timeout);
}
public BinaryJedis(final String host, final int port, final int timeout, final boolean ssl,
final SSLSocketFactory sslSocketFactory, final SSLParameters sslParameters,
final HostnameVerifier hostnameVerifier) {
client = new Client(host, port, ssl, sslSocketFactory, sslParameters, hostnameVerifier);
client.setConnectionTimeout(timeout);
client.setSoTimeout(timeout);
}
public BinaryJedis(final String host, final int port, final int connectionTimeout,
final int soTimeout) {
client = new Client(host, port);
client.setConnectionTimeout(connectionTimeout);
client.setSoTimeout(soTimeout);
}
public BinaryJedis(final String host, final int port, final int connectionTimeout,
final int soTimeout, final boolean ssl) {
client = new Client(host, port, ssl);
client.setConnectionTimeout(connectionTimeout);
client.setSoTimeout(soTimeout);
}
public BinaryJedis(final String host, final int port, final int connectionTimeout,
final int soTimeout, final boolean ssl, final SSLSocketFactory sslSocketFactory,
final SSLParameters sslParameters, final HostnameVerifier hostnameVerifier) {
client = new Client(host, port, ssl, sslSocketFactory, sslParameters, hostnameVerifier);
client.setConnectionTimeout(connectionTimeout);
client.setSoTimeout(soTimeout);
}
public BinaryJedis(final JedisShardInfo shardInfo) {
client = new Client(shardInfo.getHost(), shardInfo.getPort(), shardInfo.getSsl(),
shardInfo.getSslSocketFactory(), shardInfo.getSslParameters(),
shardInfo.getHostnameVerifier());
client.setConnectionTimeout(shardInfo.getConnectionTimeout());
client.setSoTimeout(shardInfo.getSoTimeout());
client.setPassword(shardInfo.getPassword());
client.setDb(shardInfo.getDb());
}
public BinaryJedis(URI uri) {
initializeClientFromURI(uri);
}
public BinaryJedis(URI uri, final SSLSocketFactory sslSocketFactory,
final SSLParameters sslParameters, final HostnameVerifier hostnameVerifier) {
initializeClientFromURI(uri, sslSocketFactory, sslParameters, hostnameVerifier);
}
public BinaryJedis(final URI uri, final int timeout) {
initializeClientFromURI(uri);
client.setConnectionTimeout(timeout);
client.setSoTimeout(timeout);
}
public BinaryJedis(final URI uri, final int timeout, final SSLSocketFactory sslSocketFactory,
final SSLParameters sslParameters, final HostnameVerifier hostnameVerifier) {
initializeClientFromURI(uri, sslSocketFactory, sslParameters, hostnameVerifier);
client.setConnectionTimeout(timeout);
client.setSoTimeout(timeout);
}
public BinaryJedis(final URI uri, final int connectionTimeout, final int soTimeout) {
initializeClientFromURI(uri);
client.setConnectionTimeout(connectionTimeout);
client.setSoTimeout(soTimeout);
}
public BinaryJedis(final URI uri, final int connectionTimeout, final int soTimeout,
final SSLSocketFactory sslSocketFactory,final SSLParameters sslParameters,
final HostnameVerifier hostnameVerifier) {
initializeClientFromURI(uri, sslSocketFactory, sslParameters, hostnameVerifier);
client.setConnectionTimeout(connectionTimeout);
client.setSoTimeout(soTimeout);
}
private void initializeClientFromURI(URI uri) {
if (!JedisURIHelper.isValid(uri)) {
throw new InvalidURIException(String.format(
"Cannot open Redis connection due invalid URI. %s", uri.toString()));
}
client = new Client(uri.getHost(), uri.getPort(), uri.getScheme().equals("rediss"));
String password = JedisURIHelper.getPassword(uri);
if (password != null) {
client.auth(password);
client.getStatusCodeReply();
}
int dbIndex = JedisURIHelper.getDBIndex(uri);
if (dbIndex > 0) {
client.select(dbIndex);
client.getStatusCodeReply();
client.setDb(dbIndex);
}
}
private void initializeClientFromURI(URI uri, final SSLSocketFactory sslSocketFactory,
final SSLParameters sslParameters, final HostnameVerifier hostnameVerifier) {
if (!JedisURIHelper.isValid(uri)) {
throw new InvalidURIException(String.format(
"Cannot open Redis connection due invalid URI. %s", uri.toString()));
}
client = new Client(uri.getHost(), uri.getPort(), uri.getScheme().equals("rediss"),
sslSocketFactory, sslParameters, hostnameVerifier);
String password = JedisURIHelper.getPassword(uri);
if (password != null) {
client.auth(password);
client.getStatusCodeReply();
}
int dbIndex = JedisURIHelper.getDBIndex(uri);
if (dbIndex > 0) {
client.select(dbIndex);
client.getStatusCodeReply();
client.setDb(dbIndex);
}
}
@Override
public String ping() {
checkIsInMultiOrPipeline();
client.ping();
return client.getStatusCodeReply();
}
/**
* Set the string value as value of the key. The string can't be longer than 1073741824 bytes (1
* GB).
* <p>
* Time complexity: O(1)
* @param key
* @param value
* @return Status code reply
*/
public String set(final byte[] key, final byte[] value) {
checkIsInMultiOrPipeline();
client.set(key, value);
return client.getStatusCodeReply();
}
/**
* Set the string value as value of the key. The string can't be longer than 1073741824 bytes (1
* GB).
* @param key
* @param value
* @param nxxx NX|XX, NX -- Only set the key if it does not already exist. XX -- Only set the key
* if it already exist.
* @param expx EX|PX, expire time units: EX = seconds; PX = milliseconds
* @param time expire time in the unit
没有合适的资源?快使用搜索试试~ 我知道了~
jedis-2.9.0 源码项目工程
共747个文件
class:580个
java:161个
jar:2个
需积分: 18 20 下载量 82 浏览量
2017-09-25
14:41:08
上传
评论
收藏 718KB 7Z 举报
温馨提示
jedis-2.9.0 源码项目工程 导入 eclipse 可直接运行 * 基本测试: src\redis\clients\jedis\tests\JedisTest.java * 连接池测试: src\redis\clients\jedis\tests\JedisPoolTest.java * 常用命令测试: src\redis\clients\jedis\tests\commands
资源推荐
资源详情
资源评论
收起资源包目录
jedis-2.9.0 源码项目工程 (747个子文件)
Jedis.class 60KB
PipelineBase.class 57KB
JedisCluster.class 56KB
BinaryJedisCluster.class 51KB
BinaryJedis.class 51KB
BinaryClient.class 43KB
Client.class 37KB
ShardedJedis.class 30KB
BinaryShardedJedis.class 26KB
SortedSetCommandsTest.class 24KB
MultiKeyPipelineBase.class 19KB
PipeliningTest.class 19KB
JedisClusterTest.class 19KB
AllKindOfValuesCommandsTest.class 14KB
ListCommandsTest.class 12KB
SetCommandsTest.class 12KB
HashesCommandsTest.class 12KB
JedisSentinelPool.class 11KB
JedisPool.class 11KB
RedisPipeline.class 11KB
ShardedJedisTest.class 11KB
JedisClusterInfoCache.class 11KB
JedisCommands.class 10KB
TransactionCommandsTest.class 10KB
JedisPoolTest.class 10KB
Connection.class 10KB
Protocol$Command.class 10KB
BinaryRedisPipeline.class 9KB
JedisShardInfo.class 9KB
GeoCommandsTest.class 9KB
ShardedJedisPoolTest.class 8KB
Protocol.class 8KB
PublishSubscribeCommandsTest.class 8KB
ScriptingCommandsTest.class 8KB
JedisSentinelPoolTest.class 8KB
BinaryValuesCommandsTest.class 8KB
SortingCommandsTest.class 7KB
ClusterScriptingCommandsTest.class 7KB
BinaryJedisCommands.class 7KB
ClusterBinaryJedisCommandsTest.class 7KB
BinaryJedisClusterCommands.class 7KB
JedisTest.class 7KB
ShardedJedisPipelineTest.class 7KB
SSLJedisTest.class 6KB
JedisSentinelTest.class 6KB
StringValuesCommandsTest.class 6KB
JedisFactory.class 6KB
VariadicCommandsTest.class 6KB
RedisOutputStream.class 6KB
JedisPubSub.class 5KB
Sharded.class 5KB
ProtocolTest.class 5KB
BitCommandsTest.class 5KB
ClusterCommandsTest.class 5KB
JedisClusterCommand.class 5KB
Commands.class 5KB
Pool.class 5KB
Pipeline.class 4KB
ControlCommandsTest.class 4KB
JedisByteHashMap.class 4KB
BinaryJedisPubSub.class 4KB
JedisClusterCRC16.class 4KB
JedisSentinelPool$MasterListener.class 4KB
BuilderFactory.class 4KB
HostAndPort.class 4KB
BinaryJedis$SetFromList.class 4KB
JedisClusterConnectionHandler.class 4KB
SetFromListTest.class 4KB
RedisInputStream.class 3KB
Protocol$Keyword.class 3KB
ShardedJedisPool.class 3KB
HyperLogLogCommandsTest.class 3KB
ShardedJedisPool$ShardedJedisFactory.class 3KB
JedisSlotBasedConnectionHandler.class 3KB
ProtocolBenchmark.class 3KB
ScanParams.class 3KB
PoolBenchmark.class 3KB
HashingBenchmark.class 3KB
HostAndPortUtil.class 3KB
MultiKeyCommandsPipeline.class 3KB
ShardedJedisPipeline.class 3KB
Pipeline$MultiResponseBuilder.class 3KB
BuilderFactory$19.class 3KB
Transaction.class 3KB
JedisClusterTestUtil.class 3KB
JedisCommandTestBase.class 3KB
Slowlog.class 3KB
SortingParams.class 3KB
ConnectionTest.class 3KB
MultiKeyCommands.class 3KB
Tuple.class 3KB
MurmurHash.class 3KB
PipelinedGetSetBenchmark.class 2KB
Params.class 2KB
BuilderFactory$18.class 2KB
Response.class 2KB
JedisPoolTest$1CrashingJedisPooledObjectFactory.class 2KB
JedisSentinelPool$MasterListener$1.class 2KB
MultiKeyBinaryRedisPipeline.class 2KB
JedisClusterCRC16Test.class 2KB
共 747 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
sugarTan
- 粉丝: 158
- 资源: 560
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功