當前位置: 首頁>>代碼示例>>Java>>正文


Java Protocol類代碼示例

本文整理匯總了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());
    }
}
 
開發者ID:YanXs,項目名稱:nighthawk,代碼行數:17,代碼來源:JaRedisPool.java

示例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()][]);
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:27,代碼來源:GeoRadiusParam.java

示例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;
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:17,代碼來源:ProtocolBenchmark.java

示例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));
  }

}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:24,代碼來源:ShardedJedisTest.java

示例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());
  }
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:23,代碼來源:ShardedJedisTest.java

示例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());
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:21,代碼來源:ProtocolTest.java

示例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, ""));
    }
 
開發者ID:thundernet8,項目名稱:Elune,代碼行數:18,代碼來源:RedisManager.java

示例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;

}
 
開發者ID:grails,項目名稱:gorm-redis,代碼行數:24,代碼來源:RedisEntityPersister.java

示例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);
}
 
開發者ID:spinnaker,項目名稱:fiat,代碼行數:26,代碼來源:RedisConfig.java

示例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()][]);
}
 
開發者ID:sohutv,項目名稱:cachecloud,代碼行數:27,代碼來源:GeoRadiusParam.java

示例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;
}
 
開發者ID:sohutv,項目名稱:cachecloud,代碼行數:27,代碼來源:RedisDeployCenterImpl.java

示例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();
}
 
開發者ID:nince-wyj,項目名稱:jahhan,代碼行數:25,代碼來源:JedisSentinelPoolExt.java

示例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);
	}
}
 
開發者ID:nince-wyj,項目名稱:jahhan,代碼行數:25,代碼來源:JedisSentinelPoolExt.java

示例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);
	}
}
 
開發者ID:5waynewang,項目名稱:commons-jkit,代碼行數:21,代碼來源:JedisFacade.java

示例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);
	}
}
 
開發者ID:5waynewang,項目名稱:commons-jkit,代碼行數:17,代碼來源:JedisClusterFacade.java


注:本文中的redis.clients.jedis.Protocol類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。