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


Java ShardedJedisPool類代碼示例

本文整理匯總了Java中redis.clients.jedis.ShardedJedisPool的典型用法代碼示例。如果您正苦於以下問題:Java ShardedJedisPool類的具體用法?Java ShardedJedisPool怎麽用?Java ShardedJedisPool使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ShardedJedisPool類屬於redis.clients.jedis包,在下文中一共展示了ShardedJedisPool類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkResourceIsCloseable

import redis.clients.jedis.ShardedJedisPool; //導入依賴的package包/類
@Test
public void checkResourceIsCloseable() throws URISyntaxException {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);

  List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
  shards.add(new JedisShardInfo(new URI("redis://:[email protected]:6380")));
  shards.add(new JedisShardInfo(new URI("redis://:[email protected]:6379")));

  ShardedJedisPool pool = new ShardedJedisPool(config, shards);

  ShardedJedis jedis = pool.getResource();
  try {
    jedis.set("hello", "jedis");
  } finally {
    jedis.close();
  }

  ShardedJedis jedis2 = pool.getResource();
  try {
    assertEquals(jedis, jedis2);
  } finally {
    jedis2.close();
  }
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:27,代碼來源:ShardedJedisPoolTest.java

示例2: getJedisPool

import redis.clients.jedis.ShardedJedisPool; //導入依賴的package包/類
@Bean(name="monitorJedisPool")
public ShardedJedisPool getJedisPool() {
    try {
        List<JedisShardInfo> shardList = new ArrayList<>();
        String hostStr = env.getProperty("spring.redis.shard.monitor.hostList");
        int timeOut = Integer.parseInt(env.getProperty("spring.redis.shard.monitor.timeOut"));
        if(!StringUtils.isEmpty(hostStr)){
            String[] hosts = hostStr.split(",");
            for(int i = 0; i < hosts.length; i++){
                String[] temp = hosts[i].split(":");
                JedisShardInfo info = new JedisShardInfo(temp[0], Integer.valueOf(temp[1]), timeOut);
                shardList.add(info);
            }
        }
        
        if(shardList.size() == 0){
            //無法加載redis
            throw new IOException();
        }
        return new ShardedJedisPool(getJedisPoolConfig(), shardList);
    } catch (Exception e) {
        throw new RuntimeException("無法加載資源文件!");
    }
}
 
開發者ID:Zigin,項目名稱:MonitorPlatform,代碼行數:25,代碼來源:SharedRedisConfig.java

示例3: afterPropertiesSet

import redis.clients.jedis.ShardedJedisPool; //導入依賴的package包/類
@Override
public void afterPropertiesSet() throws Exception {
	final JedisPoolConfig config = JedisPoolConfigFactory.createJedisPoolConfig();

	final Set<JedisShardInfo> shardInfos = new HashSet<JedisShardInfo>();
	final HostInfo[] hostInfos = HostInfoFactory.split(hosts);
	for (final HostInfo hostInfo : hostInfos) {
		shardInfos.add(hostInfo.createJedisShardInfo());
	}
	if (redisService == null) {
		final ShardedJedisPool jedisPool = new ShardedJedisPool(config, new ArrayList<JedisShardInfo>(shardInfos));
		redisService = new RedisServiceImpl(jedisPool);
	}

	final RedisServiceProxy redisServiceProxy = new RedisServiceProxy();
	this.redisService = redisServiceProxy.bind(redisService);
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:18,代碼來源:RedisServiceFactory.java

示例4: initialShardedPool

import redis.clients.jedis.ShardedJedisPool; //導入依賴的package包/類
/** 
 * 初始化切片池 
 */ 
private void initialShardedPool() 
{ 
    // 池基本配置 
    JedisPoolConfig config = new JedisPoolConfig(); 
    config.setMaxActive(20); 
    config.setMaxIdle(5); 
    config.setMaxWait(1000l); 
    config.setTestOnBorrow(false); 
    // slave鏈接 
    List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>(); 
    shards.add(new JedisShardInfo("127.0.0.1", 6379, "master")); 

    // 構造池 
    shardedJedisPool = new ShardedJedisPool(config, shards); 
}
 
開發者ID:yangliguang,項目名稱:preliminary.demo,代碼行數:19,代碼來源:RedisClient.java

示例5: createJedisManager

import redis.clients.jedis.ShardedJedisPool; //導入依賴的package包/類
/**
 * 
 * @return
 */
public static JedisManager createJedisManager() {

    Config conf = Config.newInstance();

    // 池基本配置
    JedisPoolConfig config = new JedisPoolConfig();
    config.setMaxIdle(conf.getInt("redis.maxIdle"));
    config.setMinIdle(conf.getInt("redis.minIdle"));
    config.setMaxWaitMillis(conf.getLong("redis.maxWaitMillis"));
    config.setTestOnBorrow(conf.getBoolean("redis.testOnBorrow"));
    List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
    // slave鏈接
    shards.add(new JedisShardInfo(conf.getString("redis.slave.host"), conf
            .getInt("redis.slave.port"), conf.getInt("redis.timeout")));
    // master鏈接
    shards.add(new JedisShardInfo(conf.getString("redis.master.host"), conf
            .getInt("redis.master.port"), conf.getInt("redis.timeout")));

    // 構造池
    ShardedJedisPool shardedJedisPool = new ShardedJedisPool(config, shards);

    return new JedisManager(shardedJedisPool);
}
 
開發者ID:hailin0,項目名稱:pagecache-parent,代碼行數:28,代碼來源:JedisManagerFactory.java

示例6: createJedisManager

import redis.clients.jedis.ShardedJedisPool; //導入依賴的package包/類
/**
 * 根據配置創建
 * 
 * @return
 */
private static JedisManager createJedisManager() {

    // 池基本配置
    JedisPoolConfig config = new JedisPoolConfig();
    config.setMaxIdle(Conf.getInt("redis.maxIdle"));
    config.setMinIdle(Conf.getInt("redis.minIdle"));
    config.setMaxWaitMillis(Conf.getLong("redis.maxWaitMillis"));
    config.setTestOnBorrow(Conf.getBoolean("redis.testOnBorrow"));
    List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
    // 鏈接
    shards.add(new JedisShardInfo(Conf.getString("redis.host"), Conf.getInt("redis.port"), Conf
            .getInt("redis.timeout")));

    // 構造池
    ShardedJedisPool shardedJedisPool = new ShardedJedisPool(config, shards);

    return new JedisManager(shardedJedisPool);
}
 
開發者ID:hailin0,項目名稱:redis-distributedLock,代碼行數:24,代碼來源:JedisManagerFactory.java

示例7: appendJedis

import redis.clients.jedis.ShardedJedisPool; //導入依賴的package包/類
public ShardedJedisPool appendJedis(final RedisConfig conf) {
    Assert.notNull(conf);
    Assert.hasLength(conf.getRedisType());

    if(conf.getCluster() == null || !conf.getCluster()) {
        if (!jedisPool.containsKey(conf.getRedisType())) {
            redisConfigs.put(conf.getRedisType(), conf);
            final ShardedJedisPool pool;
            jedisPool.put(conf.getRedisType(), pool = createJedisPool(conf));
            bindGlobal(conf);
            return pool;
        }
        
        return jedisPool.get(conf.getRedisType());
    }

    throw new RedisClientException("Can't append ShardedJedis, this is a redis cluster config");
}
 
開發者ID:nano-projects,項目名稱:nano-framework,代碼行數:19,代碼來源:RedisClientPool.java

示例8: getJedis

import redis.clients.jedis.ShardedJedisPool; //導入依賴的package包/類
public ShardedJedis getJedis(final String poolName) {
    Assert.hasText(poolName);
    ShardedJedis shardedJedis = null;
    try {
        final ShardedJedisPool pool = jedisPool.get(poolName);
        if (pool != null) {
            shardedJedis = pool.getResource();
        }

        Assert.notNull(shardedJedis, "Not found ShardedJedis.");
        return shardedJedis;
    } catch (final Throwable e) {
        close(shardedJedis);
        throw new RedisClientException(e.getMessage(), e);
    }
}
 
開發者ID:nano-projects,項目名稱:nano-framework,代碼行數:17,代碼來源:RedisClientPool.java

示例9: create

import redis.clients.jedis.ShardedJedisPool; //導入依賴的package包/類
public void create() {
    try {
        LOG.debug("Starting RedisShardedProvider ... configuration:" + redisConfiguration);

        JedisPoolConfig poolConfig = new JedisPoolConfig();
        poolConfig.setMaxTotal(1000);
        poolConfig.setMinIdle(2);

        pool = new ShardedJedisPool(poolConfig, shards(redisConfiguration.getServers()));

        testConnection();
        LOG.debug("RedisShardedProvider started.");
    } catch (Exception e) {
        LOG.error("Failed to start RedisShardedProvider.");
        throw new IllegalStateException("Error starting RedisShardedProvider", e);
    }
}
 
開發者ID:GluuFederation,項目名稱:oxCore,代碼行數:18,代碼來源:RedisShardedProvider.java

示例10: testShardSimplePool

import redis.clients.jedis.ShardedJedisPool; //導入依賴的package包/類
/**
 * 分布式連接池同步調用
 * 1.288 seconds
 * 1.291 seconds
 */
@Test
public void testShardSimplePool() {
	List<JedisShardInfo> shards = Arrays.asList(new JedisShardInfo(
			"localhost", 6379), new JedisShardInfo("localhost", 6379));

	ShardedJedisPool pool = new ShardedJedisPool(new JedisPoolConfig(), shards);
	ShardedJedis one = pool.getResource();

	long start = System.currentTimeMillis();
	for (int i = 0; i < COUNTER; i++) {
		String result = one.set("spn" + i, "n" + i);
	}
	long end = System.currentTimeMillis();
	pool.returnResource(one);
	logger.info("[email protected] SET: " + ((end - start) / 1000.0) + " seconds");

	pool.destroy();
}
 
開發者ID:leopardoooo,項目名稱:easyooo-framework,代碼行數:24,代碼來源:JedisApiTest.java

示例11: testShardPipelinedPool

import redis.clients.jedis.ShardedJedisPool; //導入依賴的package包/類
/**
 * 分布式連接池異步調用
 * 0.452 seconds
 * 0.43 seconds
 */
@Test
@Ignore
public void testShardPipelinedPool() {
    List<JedisShardInfo> shards = Arrays.asList(
            new JedisShardInfo("localhost",6379),
            new JedisShardInfo("localhost",6379));

    ShardedJedisPool pool = new ShardedJedisPool(new JedisPoolConfig(), shards);
    ShardedJedis one = pool.getResource();
    ShardedJedisPipeline pipeline = one.pipelined();
    
    long start = System.currentTimeMillis();
    for (int i = 0; i < COUNTER; i++) {
        pipeline.set("sppn" + i, "n" + i);
    }
    List<Object> results = pipeline.syncAndReturnAll();
    long end = System.currentTimeMillis();
    pool.returnResource(one);
    logger.info("[email protected] SET: " + ((end - start)/1000.0) + " seconds");
    pool.destroy();
}
 
開發者ID:leopardoooo,項目名稱:easyooo-framework,代碼行數:27,代碼來源:JedisApiTest.java

示例12: init

import redis.clients.jedis.ShardedJedisPool; //導入依賴的package包/類
private void init() {
	redis1.slaveofnoone();
	redis2.slaveofnoone();
	redis3.slaveofnoone();
	List<Redis> shards = new ArrayList<Redis>(3);
	shards.add(redis1);
	shards.add(redis2);
	shards.add(redis3);
	shardedRedis = RedisFactory.newShardedRedis(shards);
	
	List<JedisShardInfo> shardinfos = new ArrayList<JedisShardInfo>();
	shardinfos.add(new JedisShardInfo(HOST, PORT1));
	shardinfos.add(new JedisShardInfo(HOST, PORT2));
	shardinfos.add(new JedisShardInfo(HOST, PORT3));
	shardedPool = new ShardedJedisPool(new JedisPoolConfig(), shardinfos);
}
 
開發者ID:mindwind,項目名稱:craft-atom,代碼行數:17,代碼來源:TestShardedRedis.java

示例13: main

import redis.clients.jedis.ShardedJedisPool; //導入依賴的package包/類
/**
 * @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);
	}
}
 
開發者ID:howsun,項目名稱:howsun-javaee-framework,代碼行數:21,代碼來源:JedisShartClient.java

示例14: newShardedJedisPool

import redis.clients.jedis.ShardedJedisPool; //導入依賴的package包/類
/**
 * Create a new {@link ShardedJedisPool}.
 * 
 * @param poolConfig
 *            format {@code host1:port1,host2:port2,...}, default Redis port is used if not
 *            specified
 * @param password
 * @param timeoutMs
 * @return
 */
public static ShardedJedisPool newShardedJedisPool(JedisPoolConfig poolConfig,
        String hostsAndPorts, String password, int timeoutMs) {
    List<JedisShardInfo> shards = new ArrayList<>();
    String[] hapList = hostsAndPorts.split("[,;\\s]+");
    for (String hostAndPort : hapList) {
        String[] tokens = hostAndPort.split(":");
        String host = tokens.length > 0 ? tokens[0] : Protocol.DEFAULT_HOST;
        int port = tokens.length > 1 ? Integer.parseInt(tokens[1]) : Protocol.DEFAULT_PORT;
        JedisShardInfo shardInfo = new JedisShardInfo(host, port, timeoutMs);
        shardInfo.setPassword(password);
        shards.add(shardInfo);
    }
    ShardedJedisPool jedisPool = new ShardedJedisPool(poolConfig, shards);
    return jedisPool;
}
 
開發者ID:DDTH,項目名稱:ddth-commons,代碼行數:26,代碼來源:JedisUtils.java

示例15: setSharedJedisPool

import redis.clients.jedis.ShardedJedisPool; //導入依賴的package包/類
public static void setSharedJedisPool() {
        JedisPoolConfig config = new JedisPoolConfig();//Jedis池配置
        // 共享jedis池,用於集群
        List<JedisShardInfo> jedisShardInfos = new ArrayList<>();
        JedisShardInfo node01 = new JedisShardInfo("120.24.238.195", 6379);
//        JedisShardInfo node02 = new JedisShardInfo("120.25.162.32", 6379);
//        JedisShardInfo node03 = new JedisShardInfo("112.74.114.226", 6379);
        node01.setPassword("110110");
        jedisShardInfos.add(node01);
//        jedisShardInfos.add(node02);
//        jedisShardInfos.add(node03);
        pool = new ShardedJedisPool(config, jedisShardInfos);
        isSetup = true;
    }
 
開發者ID:wanghan0501,項目名稱:WiFiProbeAnalysis,代碼行數:15,代碼來源:JedisPoolManager.java


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