本文整理汇总了Java中redis.clients.jedis.Protocol类的典型用法代码示例。如果您正苦于以下问题:Java Protocol类的具体用法?Java Protocol怎么用?Java Protocol使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Protocol类属于redis.clients.jedis包,在下文中一共展示了Protocol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: JaRedisPool
import redis.clients.jedis.Protocol; //导入依赖的package包/类
public JaRedisPool(final String host) {
URI uri = URI.create(host);
if (JedisURIHelper.isValid(uri)) {
String h = uri.getHost();
int port = uri.getPort();
String password = JedisURIHelper.getPassword(uri);
int database = JedisURIHelper.getDBIndex(uri);
this.internalPool = new GenericObjectPool<>(new JaRedisFactory(h, port,
Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, password, database, null),
new GenericObjectPoolConfig());
} else {
this.internalPool = new GenericObjectPool<>(new JaRedisFactory(host,
Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, null,
Protocol.DEFAULT_DATABASE, null), new GenericObjectPoolConfig());
}
}
示例2: getByteParams
import redis.clients.jedis.Protocol; //导入依赖的package包/类
public byte[][] getByteParams(byte[]... args) {
ArrayList<byte[]> byteParams = new ArrayList<byte[]>();
for (byte[] arg : args) {
byteParams.add(arg);
}
if (contains(WITHCOORD)) {
byteParams.add(SafeEncoder.encode(WITHCOORD));
}
if (contains(WITHDIST)) {
byteParams.add(SafeEncoder.encode(WITHDIST));
}
if (contains(COUNT)) {
byteParams.add(SafeEncoder.encode(COUNT));
byteParams.add(Protocol.toByteArray((Integer) getParam(COUNT)));
}
if (contains(ASC)) {
byteParams.add(SafeEncoder.encode(ASC));
} else if (contains(DESC)) {
byteParams.add(SafeEncoder.encode(DESC));
}
return byteParams.toArray(new byte[byteParams.size()][]);
}
示例3: measureInputMulti
import redis.clients.jedis.Protocol; //导入依赖的package包/类
private static long measureInputMulti() throws Exception {
long duration = 0;
InputStream is = new ByteArrayInputStream(
"*4\r\n$3\r\nfoo\r\n$13\r\nbarbarbarfooz\r\n$5\r\nHello\r\n$5\r\nWorld\r\n".getBytes());
RedisInputStream in = new RedisInputStream(is);
for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
long start = System.nanoTime();
Protocol.read(in);
duration += (System.nanoTime() - start);
in.reset();
}
return duration;
}
示例4: testMasterSlaveShardingConsistency
import redis.clients.jedis.Protocol; //导入依赖的package包/类
@Test
public void testMasterSlaveShardingConsistency() {
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(3);
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT));
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1));
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2));
Sharded<Jedis, JedisShardInfo> sharded = new Sharded<Jedis, JedisShardInfo>(shards,
Hashing.MURMUR_HASH);
List<JedisShardInfo> otherShards = new ArrayList<JedisShardInfo>(3);
otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT));
otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT + 1));
otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT + 2));
Sharded<Jedis, JedisShardInfo> sharded2 = new Sharded<Jedis, JedisShardInfo>(otherShards,
Hashing.MURMUR_HASH);
for (int i = 0; i < 1000; i++) {
JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer.toString(i));
JedisShardInfo jedisShardInfo2 = sharded2.getShardInfo(Integer.toString(i));
assertEquals(shards.indexOf(jedisShardInfo), otherShards.indexOf(jedisShardInfo2));
}
}
示例5: testMasterSlaveShardingConsistencyWithShardNaming
import redis.clients.jedis.Protocol; //导入依赖的package包/类
@Test
public void testMasterSlaveShardingConsistencyWithShardNaming() {
List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(3);
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT, "HOST1:1234"));
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 1, "HOST2:1234"));
shards.add(new JedisShardInfo("localhost", Protocol.DEFAULT_PORT + 2, "HOST3:1234"));
Sharded<Jedis, JedisShardInfo> sharded = new Sharded<Jedis, JedisShardInfo>(shards,
Hashing.MURMUR_HASH);
List<JedisShardInfo> otherShards = new ArrayList<JedisShardInfo>(3);
otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT, "HOST2:1234"));
otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT + 1, "HOST3:1234"));
otherShards.add(new JedisShardInfo("otherhost", Protocol.DEFAULT_PORT + 2, "HOST1:1234"));
Sharded<Jedis, JedisShardInfo> sharded2 = new Sharded<Jedis, JedisShardInfo>(otherShards,
Hashing.MURMUR_HASH);
for (int i = 0; i < 1000; i++) {
JedisShardInfo jedisShardInfo = sharded.getShardInfo(Integer.toString(i));
JedisShardInfo jedisShardInfo2 = sharded2.getShardInfo(Integer.toString(i));
assertEquals(jedisShardInfo.getName(), jedisShardInfo2.getName());
}
}
示例6: buildACommand
import redis.clients.jedis.Protocol; //导入依赖的package包/类
@Test
public void buildACommand() throws IOException {
PipedInputStream pis = new PipedInputStream();
BufferedInputStream bis = new BufferedInputStream(pis);
PipedOutputStream pos = new PipedOutputStream(pis);
RedisOutputStream ros = new RedisOutputStream(pos);
Protocol.sendCommand(ros, Protocol.Command.GET, "SOMEKEY".getBytes(Protocol.CHARSET));
ros.flush();
pos.close();
String expectedCommand = "*2\r\n$3\r\nGET\r\n$7\r\nSOMEKEY\r\n";
int b;
StringBuilder sb = new StringBuilder();
while ((b = bis.read()) != -1) {
sb.append((char) b);
}
assertEquals(expectedCommand, sb.toString());
}
示例7: createJedisPool
import redis.clients.jedis.Protocol; //导入依赖的package包/类
private void createJedisPool() {
JedisPoolConfig config = new JedisPoolConfig();
// 设置最大连接数
config.setMaxTotal(500);
// 设置最大阻塞时间(毫秒)
config.setMaxWaitMillis(1000);
// 设置空闲连接数
config.setMaxIdle(20);
config.setMinIdle(10);
// 创建连接池
pool = new JedisPool(config, appConfig.get(CONFIG_KEY_REDIS_HOST, DEFAULT_REDIS_HOST), appConfig.getInt(CONFIG_KEY_REDIS_PORT, DEFAULT_REDIS_PORT), Protocol.DEFAULT_TIMEOUT, appConfig.get(CONFIG_KEY_REDIS_PASS, ""));
}
示例8: createEntityAccess
import redis.clients.jedis.Protocol; //导入依赖的package包/类
@Override
protected EntityAccess createEntityAccess(PersistentEntity persistentEntity, Object obj, Map nativeEntry) {
final NativeEntryModifyingEntityAccess ea = new NativeEntryModifyingEntityAccess(persistentEntity, obj) {
public void setProperty(String name, Object value) {
Class type = getPropertyType(name);
if(type.isArray() && byte.class.isAssignableFrom(type.getComponentType()) && value instanceof CharSequence) {
try {
super.setProperty(name, value.toString().getBytes(Protocol.CHARSET));
} catch (UnsupportedEncodingException e) {
// ignore
}
}
else {
super.setProperty(name, value);
}
}
};
ea.setConversionService(getMappingContext().getConversionService());
ea.setNativeEntry(nativeEntry);
return ea;
}
示例9: createPool
import redis.clients.jedis.Protocol; //导入依赖的package包/类
private static JedisPool createPool(GenericObjectPoolConfig redisPoolConfig,
String connection,
int timeout) {
URI redisConnection = URI.create(connection);
String host = redisConnection.getHost();
int port = redisConnection.getPort() == -1 ? Protocol.DEFAULT_PORT : redisConnection.getPort();
String path = redisConnection.getPath();
if (StringUtils.isEmpty(path)) {
path = "/" + String.valueOf(Protocol.DEFAULT_DATABASE);
}
int database = Integer.parseInt(path.split("/", 2)[1]);
String password = null;
if (redisConnection.getUserInfo() != null) {
password = redisConnection.getUserInfo().split(":", 2)[1];
}
if (redisPoolConfig == null) {
redisPoolConfig = new GenericObjectPoolConfig();
}
return new JedisPool(redisPoolConfig, host, port, timeout, password, database, null);
}
示例10: getByteParams
import redis.clients.jedis.Protocol; //导入依赖的package包/类
public byte[][] getByteParams(byte[]... args) {
ArrayList<byte[]> byteParams = new ArrayList<byte[]>();
for (byte[] arg : args) {
byteParams.add(arg);
}
if (contains(WITHCOORD)) {
byteParams.add(SafeEncoder.encode(WITHCOORD));
}
if (contains(WITHDIST)) {
byteParams.add(SafeEncoder.encode(WITHDIST));
}
if (contains(COUNT)) {
byteParams.add(SafeEncoder.encode(COUNT));
byteParams.add(Protocol.toByteArray((Integer) getParam(COUNT)));
}
if (contains(ASC)) {
byteParams.add(SafeEncoder.encode(ASC));
} else if (contains(DESC)) {
byteParams.add(SafeEncoder.encode(DESC));
}
return byteParams.toArray(new byte[byteParams.size()][]);
}
示例11: slaveOf
import redis.clients.jedis.Protocol; //导入依赖的package包/类
private boolean slaveOf(final long appId, final String masterHost, final int masterPort, final String slaveHost,
final int slavePort) {
final Jedis slave = redisCenter.getJedis(appId, slaveHost, slavePort, Protocol.DEFAULT_TIMEOUT * 3, Protocol.DEFAULT_TIMEOUT * 3);
try {
boolean isSlave = new IdempotentConfirmer() {
@Override
public boolean execute() {
String result = slave.slaveof(masterHost, masterPort);
return result != null && result.equalsIgnoreCase("OK");
}
}.run();
if (!isSlave) {
logger.error(String.format("modifyAppConfig:ip=%s,port=%s failed", slaveHost, slavePort));
return false;
}
redisCenter.configRewrite(appId, slaveHost, slavePort);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return false;
} finally {
if (slave != null)
slave.close();
}
return true;
}
示例12: JedisSentinelPoolExt
import redis.clients.jedis.Protocol; //导入依赖的package包/类
public JedisSentinelPoolExt(String masterName, String sentinels, final GenericObjectPoolConfig poolConfig,
final String password, int connectionTimeout, int failMax, boolean masterWriteOnly, String clientName) {
String[] strings = sentinels.split(",");
Collections.addAll(_sentinels, strings);
this.poolConfig = poolConfig;
this.connectionTimeout = connectionTimeout;
if (!StringUtils.isBlank(password)) {
this.password = password;
}
this.database = Protocol.DEFAULT_DATABASE;
this.failMax = failMax;
this.masterName = masterName;
this.masterWriteOnly = masterWriteOnly;
if (!StringUtils.isBlank(clientName)) {
this.clientName = clientName;
}
HostAndPort master = initSentinels(_sentinels, masterName);
initPool(master);
initReadPool();
}
示例13: insertReadPool
import redis.clients.jedis.Protocol; //导入依赖的package包/类
/**
* 读池增加新节点
*
* @param hostAndPort
*/
protected synchronized void insertReadPool(HostAndPort hostAndPort) {
boolean exists = false;
for (JedisPoolExt oldJedisPool : jedisReadPools) {
if (oldJedisPool.getHostAndPort().equals(hostAndPort)) {
exists = true;
break;
}
}
if (!exists) {
JedisPoolExt newJedisPool = new JedisPoolExt(poolConfig, hostAndPort.getHost(), hostAndPort.getPort(),
connectionTimeout, password, Protocol.DEFAULT_DATABASE, clientName);
jedisReadPools.add(newJedisPool);
// 新来的节点,可能是之前挂掉后恢复的节点,所以要检查其是否存在于失败列表中,要去除
failMap.remove(hostAndPort);
log.info("Add JedisReadPool at " + hostAndPort);
}
}
示例14: getNoIncr
import redis.clients.jedis.Protocol; //导入依赖的package包/类
@Override
public Long getNoIncr(String key) {
final Jedis resource = this.getResource();
try {
final byte[] rawKey = this.serializeKey(key);
final byte[] rawValue = resource.get(rawKey);
if (ArrayUtils.isEmpty(rawValue)) {
return null;
}
return Long.valueOf(new String(rawValue, Protocol.CHARSET));
}
catch (Exception e) {
throw new CacheException("redis:get", e);
}
finally {
this.returnResource(resource);
}
}
示例15: getNoIncr
import redis.clients.jedis.Protocol; //导入依赖的package包/类
@Override
public Long getNoIncr(String key) {
try {
final byte[] rawKey = this.serializeKey(key);
final byte[] rawValue = this.jedisCluster.get(rawKey);
if (ArrayUtils.isEmpty(rawValue)) {
return null;
}
return Long.valueOf(new String(rawValue, Protocol.CHARSET));
}
catch (Exception e) {
throw new CacheException("redis:get", e);
}
}