Java Code Examples for redis.clients.jedis.JedisShardInfo#setPassword()

The following examples show how to use redis.clients.jedis.JedisShardInfo#setPassword() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedisClient.java    From Redis_Learning with Apache License 2.0 6 votes vote down vote up
/**
 * ��ʼ����Ƭ��
 */
private void initialShardedPool() {
	// �ػ�������
	JedisPoolConfig config = new JedisPoolConfig();
	config.setMaxActive(20);
	config.setMaxIdle(5);
	config.setMaxWait(1000l);
	config.setTestOnBorrow(false);

	List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
	JedisShardInfo infoA = new JedisShardInfo(ADDR, PORT);
	infoA.setPassword("redis");
	shards.add(infoA);
	// ���Dz��� ��ʱ���������ķ������������ӷ���������
	// JedisShardInfo infoB = new JedisShardInfo(SUB_ADDR, PORT2);
	// infoB.setPassword("redis");
	// shards.add(infoB);
	// shards = Arrays.asList(infoA,infoB);
	shardedJedisPool = new ShardedJedisPool(config, shards,
			Hashing.MURMUR_HASH, ShardedJedis.DEFAULT_KEY_TAG_PATTERN);
}
 
Example 2
Source File: RedisExample.java    From java-platform with Apache License 2.0 6 votes vote down vote up
public void testShardNormal() {// 13.619秒
	JedisShardInfo jedis = new JedisShardInfo("120.25.241.144", 6379);
	jedis.setPassword("b840fc02d52404542994");

	List<JedisShardInfo> shards = Arrays.asList(jedis);
	ShardedJedis sharding = new ShardedJedis(shards);

	long start = System.currentTimeMillis();
	for (int i = 0; i < 1000; i++) {
		sharding.set("n" + i, "n" + i);
		System.out.println(i);
	}
	long end = System.currentTimeMillis();
	System.out.println("共花费:" + (end - start) / 1000.0 + "秒");

	sharding.disconnect();
	try {
		Closeables.close(sharding, true);
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example 3
Source File: RedisExample.java    From java-platform with Apache License 2.0 6 votes vote down vote up
public void testShardPipelined() {// 0.127秒
	JedisShardInfo jedis = new JedisShardInfo("120.25.241.144", 6379);
	jedis.setPassword("b840fc02d52404542994");

	List<JedisShardInfo> shards = Arrays.asList(jedis);
	ShardedJedis sharding = new ShardedJedis(shards);
	ShardedJedisPipeline pipeline = sharding.pipelined();

	long start = System.currentTimeMillis();
	for (int i = 0; i < 1000; i++) {
		pipeline.set("n" + i, "n" + i);
		System.out.println(i);
	}
	pipeline.syncAndReturnAll();
	long end = System.currentTimeMillis();
	System.out.println("共花费:" + (end - start) / 1000.0 + "秒");

	sharding.disconnect();
	try {
		Closeables.close(sharding, true);
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example 4
Source File: JedisShartClient.java    From howsun-javaee-framework with Apache License 2.0 6 votes vote down vote up
/**
 * @param args
 */
public static void main(String[] args) {
	List<JedisShardInfo> list = new LinkedList<JedisShardInfo>();
	JedisShardInfo jedisShardInfo1 = new JedisShardInfo(ip1, port);
	jedisShardInfo1.setPassword(JedisConstant.password);
	list.add(jedisShardInfo1);
	JedisShardInfo jedisShardInfo2 = new JedisShardInfo(ip2, port);
	jedisShardInfo2.setPassword(JedisConstant.password);
	list.add(jedisShardInfo2);
	ShardedJedisPool pool = new ShardedJedisPool(config, list);
	for (int i = 0; i < 2000; i++) {
		ShardedJedis jedis = pool.getResource();
		String key = "howsun_" + i;
		//jedis.set(key, UUID.randomUUID().toString());
		System.out.println(key + "\t" + jedis.get(key) + "\t" + jedis.toString());
		pool.returnResource(jedis);
	}
}
 
Example 5
Source File: JedisTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test
public void connectWithShardInfo() {
  JedisShardInfo shardInfo = new JedisShardInfo("localhost", Protocol.DEFAULT_PORT);
  shardInfo.setPassword("foobared");
  Jedis jedis = new Jedis(shardInfo);
  jedis.get("foo");
}
 
Example 6
Source File: RedisExample.java    From java-platform with Apache License 2.0 5 votes vote down vote up
public void testShardSimplePool() {// 12.642秒
	JedisShardInfo jedis = new JedisShardInfo("120.25.241.144", 6379);
	jedis.setPassword("b840fc02d52404542994");

	List<JedisShardInfo> shards = Arrays.asList(jedis);
	ShardedJedisPool pool = new ShardedJedisPool(new JedisPoolConfig(), shards);

	ShardedJedis sharding = pool.getResource();

	long start = System.currentTimeMillis();
	for (int i = 0; i < 1000; i++) {
		sharding.set("n" + i, "n" + i);
		System.out.println(i);
	}
	long end = System.currentTimeMillis();
	System.out.println("共花费:" + (end - start) / 1000.0 + "秒");

	sharding.disconnect();
	pool.destroy();
	try {
		Closeables.close(sharding, true);
		Closeables.close(pool, true);
	} catch (IOException e) {
		e.printStackTrace();
	}

}
 
Example 7
Source File: RedisExample.java    From java-platform with Apache License 2.0 5 votes vote down vote up
public void testShardPipelinnedPool() {// 0.124秒
	JedisShardInfo jedis = new JedisShardInfo("120.25.241.144", 6379);
	jedis.setPassword("b840fc02d52404542994");

	List<JedisShardInfo> shards = Arrays.asList(jedis);
	ShardedJedisPool pool = new ShardedJedisPool(new JedisPoolConfig(), shards);

	ShardedJedis sharding = pool.getResource();
	ShardedJedisPipeline pipeline = sharding.pipelined();

	long start = System.currentTimeMillis();
	for (int i = 0; i < 1000; i++) {
		pipeline.set("n" + i, "n" + i);
		System.out.println(i);
	}
	pipeline.syncAndReturnAll();
	long end = System.currentTimeMillis();
	System.out.println("共花费:" + (end - start) / 1000.0 + "秒");

	sharding.disconnect();
	pool.destroy();

	try {
		Closeables.close(sharding, true);
		Closeables.close(pool, true);
	} catch (IOException e) {
		e.printStackTrace();
	}

}
 
Example 8
Source File: ShardedRedisCache.java    From framework with Apache License 2.0 5 votes vote down vote up
/**
 * ShardedRedisCache
 */
public ShardedRedisCache() {
    String cacheModel = PropertyHolder.getProperty("cache.model");
    if (CACHE_MODEL.equals(cacheModel)) {
        Address[] addresses = getAddresses();
        String passwd = CommonUtil.isNotEmpty(addresses) ? addresses[0].getPassword() : null;
        List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(addresses.length);
        for (Address addr : addresses) {
            JedisShardInfo jedisShardInfo = new JedisShardInfo(addr.getHost(), addr.getPort());
            jedisShardInfo.setPassword(passwd);
            shards.add(jedisShardInfo);
        }
        shardedPool = new ShardedJedisPool(getConfig(), shards);
    }
}
 
Example 9
Source File: SpringDataRedis.java    From howsun-javaee-framework with Apache License 2.0 5 votes vote down vote up
/**
 * @param args
 */
public static void main(String[] args) {
	JedisShardInfo jedisShardInfo1 = new JedisShardInfo(ip1);
	jedisShardInfo1.setPassword(JedisConstant.password);
	JedisShardInfo jedisShardInfo2 = new JedisShardInfo(ip2);
	jedisShardInfo2.setPassword(JedisConstant.password);

	List<JedisShardInfo> jedisShardInfos = new ArrayList<JedisShardInfo>();
	jedisShardInfos.add(jedisShardInfo1);
	jedisShardInfos.add(jedisShardInfo2);

	JedisPoolConfig poolConfig = new JedisPoolConfig();
	poolConfig.setMaxActive(JedisConstant.maxActive);
	poolConfig.setMaxIdle(JedisConstant.maxIdle);
	poolConfig.setMaxWait(JedisConstant.maxWait);
	poolConfig.setTestOnBorrow(JedisConstant.testOnBorrow);
	poolConfig.setTestOnReturn(JedisConstant.testOnReturn);


	ShardedJedisPool shardedJedisPool = new ShardedJedisPool(poolConfig, jedisShardInfos);

	JedisConnectionFactory factory = new JedisConnectionFactory(jedisShardInfo1);
	StringRedisTemplate template = new StringRedisTemplate(factory);
	for (int i = 0; i < 2000; i++) {
		String key = "howsun_" + i;
		BoundValueOperations<String, String> v = template.boundValueOps(key);
		//jedis.set(key, UUID.randomUUID().toString());
		System.out.println(key + "\t" + v.get() + "\t" + factory.getHostName());
	}

}
 
Example 10
Source File: ShardedJedisTest.java    From cachecloud with Apache License 2.0 4 votes vote down vote up
/**
 * Test for "Issue - BinaryShardedJedis.disconnect() may occur memory leak". You can find more
 * detailed information at https://github.com/xetorthio/jedis/issues/808
 * @throws InterruptedException
 */
@Test
public void testAvoidLeaksUponDisconnect() throws InterruptedException {
  List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(2);
  // 6379
  JedisShardInfo shard1 = new JedisShardInfo(redis1.getHost(), redis1.getPort());
  shard1.setPassword("foobared");
  shards.add(shard1);
  // 6380
  JedisShardInfo shard2 = new JedisShardInfo(redis2.getHost(), redis2.getPort());
  shard2.setPassword("foobared");
  shards.add(shard2);

  @SuppressWarnings("resource")
  ShardedJedis shardedJedis = new ShardedJedis(shards);
  // establish the connection for two redis servers
  shardedJedis.set("a", "bar");
  JedisShardInfo ak = shardedJedis.getShardInfo("a");
  assertEquals(shard2, ak);
  shardedJedis.set("b", "bar1");
  JedisShardInfo bk = shardedJedis.getShardInfo("b");
  assertEquals(shard1, bk);

  // We set a name to the instance so it's easy to find it
  Iterator<Jedis> it = shardedJedis.getAllShards().iterator();
  Jedis deadClient = it.next();
  deadClient.clientSetname("DEAD");

  ClientKillerUtil.killClient(deadClient, "DEAD");

  assertEquals(true, deadClient.isConnected());
  assertEquals(false, deadClient.getClient().getSocket().isClosed());
  assertEquals(false, deadClient.getClient().isBroken()); // normal - not found

  shardedJedis.disconnect();

  assertEquals(false, deadClient.isConnected());
  assertEquals(true, deadClient.getClient().getSocket().isClosed());
  assertEquals(true, deadClient.getClient().isBroken());

  Jedis jedis2 = it.next();
  assertEquals(false, jedis2.isConnected());
  assertEquals(true, jedis2.getClient().getSocket().isClosed());
  assertEquals(false, jedis2.getClient().isBroken());

}