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


Java JedisPool類代碼示例

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


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

示例1: isAvailable

import redis.clients.jedis.JedisPool; //導入依賴的package包/類
public boolean isAvailable() {
    for (JedisPool jedisPool : jedisPools.values()) {
        Jedis jedis = jedisPool.getResource();
        boolean isBroken = false;
        try {
            if (jedis.isConnected()) {
                return true; // 至少需單台機器可用
            }
        } catch (JedisConnectionException e) {
            isBroken = true;
        } finally {
            if (isBroken) {
                jedisPool.returnBrokenResource(jedis);
            } else {
                jedisPool.returnResource(jedis);
            }
        }
    }
    return false;
}
 
開發者ID:zhuxiaolei,項目名稱:dubbo2,代碼行數:21,代碼來源:RedisRegistry.java

示例2: checkJedisIsReusedWhenReturned

import redis.clients.jedis.JedisPool; //導入依賴的package包/類
@Test
public void checkJedisIsReusedWhenReturned() {

  JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort());
  Jedis jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.set("foo", "0");
  pool.returnResource(jedis);

  jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.incr("foo");
  pool.returnResource(jedis);
  pool.destroy();
  assertTrue(pool.isClosed());
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:17,代碼來源:JedisPoolTest.java

示例3: toJedisPool0

import redis.clients.jedis.JedisPool; //導入依賴的package包/類
private JedisPool toJedisPool0() {
    return new JedisPool(new GenericObjectPoolConfig(), this.getHost(), this.getPort(), this.getTimeout(), this.getPassword(), this.getDatabase()) {
        @Override
        public Jedis getResource() {
            try {
                return super.getResource();
            } catch (JedisConnectionException var2) {
                RedisConfig.LOGGER.error(RedisConfig.this.toString(), var2);
                throw new JedisConnectionException(RedisConfig.this.toString(), var2);
            }
        }

        @Override
        public void close() {
        }
    };
}
 
開發者ID:wxz1211,項目名稱:dooo,代碼行數:18,代碼來源:RedisConfig.java

示例4: Client

import redis.clients.jedis.JedisPool; //導入依賴的package包/類
/**
 * Create a new client to a RediSearch index
 * @param indexName the name of the index we are connecting to or creating
 * @param host the redis host
 * @param port the redis pot
 */
public Client(String indexName, String host, int port, int timeout, int poolSize) {
    JedisPoolConfig conf = new JedisPoolConfig();
    conf.setMaxTotal(poolSize);
    conf.setTestOnBorrow(false);
    conf.setTestOnReturn(false);
    conf.setTestOnCreate(false);
    conf.setTestWhileIdle(false);
    conf.setMinEvictableIdleTimeMillis(60000);
    conf.setTimeBetweenEvictionRunsMillis(30000);
    conf.setNumTestsPerEvictionRun(-1);
    conf.setFairness(true);

    pool = new JedisPool(conf, host, port, timeout);

    this.indexName = indexName;
    this.commands = new Commands.SingleNodeCommands();
}
 
開發者ID:RedisLabs,項目名稱:JRediSearch,代碼行數:24,代碼來源:Client.java

示例5: available

import redis.clients.jedis.JedisPool; //導入依賴的package包/類
@Override
public boolean available() {
    for (JedisPool jedisPool : jedisPools.values()) {
        Jedis jedis = jedisPool.getResource();
        try {
            if (jedis.isConnected()) {
                return true; // 至少需單台機器可用
            }
        } catch (JedisConnectionException e) {
        	logger.error("Jedis Connection Exception", e);
        } finally {
        	if(jedis != null){
            	jedis.close();
            }
        }
    }
    return false;
}
 
開發者ID:yu120,項目名稱:coon,代碼行數:19,代碼來源:RedisMreg.java

示例6: searchForUsersByExpression

import redis.clients.jedis.JedisPool; //導入依賴的package包/類
@Override
public Optional<List<String>> searchForUsersByExpression(String expression) {
	System.out.println("expression: " + expression);
	JedisPool jedisPool = JedisFactory.getPool();
	try (Jedis jedis = jedisPool.getResource()) {
		if (jedis.exists("0")) {
			jedis.del("0");
		}
		long lenght = jedis.zcard("all_users");
		Set<String> sresult = jedis.zrange("all_users", 0, lenght);

		for (Iterator<String> iterator = sresult.iterator(); iterator.hasNext();) {
			String iter = iterator.next();
			System.out.println("Iterator: " + iter);
			if (iter.length() >= expression.length() && iter.substring(0, expression.length()).equals(expression)) {
				jedis.lpush("0", iter);
				System.out.println("Suche hinzugefuegt: " + iter);
			}
		}
		return Optional.of(jedis.lrange("0", 0, 1));
	} catch (Exception e) {
		System.out.println("Mock SearchUserByExpression: " + expression);
		e.printStackTrace();
		return Optional.of(new ArrayList<String>());
	}
	// return Optional.ofNullable("searchForUsersByExpression:
	// Redis-Answer-Expression");
}
 
開發者ID:SystemOfAProg,項目名稱:VS2Labor,代碼行數:29,代碼來源:MockRedisService.java

示例7: publish

import redis.clients.jedis.JedisPool; //導入依賴的package包/類
public void publish(byte[] channel, byte[] message) {
    Collection<JedisPool> poolCollection = jedisCluster.getClusterNodes().values();
    Iterator<JedisPool> iterator = poolCollection.iterator();
    if (iterator.hasNext()) {
        JedisPool jedisPool = (JedisPool)iterator.next();
        Jedis jedis = null;

        try {
            jedis = jedisPool.getResource();
            jedis.publish(channel, message);
        } catch (Exception var11) {
            throw new RuntimeException(var11);
        } finally {
            jedisPool.returnResourceObject(jedis);
        }
    }

}
 
開發者ID:bitstd,項目名稱:bitstd,代碼行數:19,代碼來源:RedisCacheWithCluster.java

示例8: connect

import redis.clients.jedis.JedisPool; //導入依賴的package包/類
public void connect()
{
    this.instance.log(Level.INFO, "Connecting to database...");

    JedisPoolConfig jedisConfiguration = new JedisPoolConfig();
    jedisConfiguration.setMaxTotal(-1);
    jedisConfiguration.setJmxEnabled(false);

    Logger logger = Logger.getLogger(JedisPool.class.getName());
    logger.setLevel(Level.OFF);

    this.jedisPool = new JedisPool(jedisConfiguration, this.instance.getConfiguration().redisIp, this.instance.getConfiguration().redisPort, 0, this.instance.getConfiguration().redisPassword);
    try
    {
        this.jedisPool.getResource().close();
    } catch (Exception e)
    {
        this.instance.log(Level.SEVERE, "Can't connect to the database!");
        System.exit(8);
    }

    this.instance.log(Level.INFO, "Connected to database.");
}
 
開發者ID:SamaGames,項目名稱:Hydroangeas,代碼行數:24,代碼來源:DatabaseConnector.java

示例9: call

import redis.clients.jedis.JedisPool; //導入依賴的package包/類
@SuppressWarnings("deprecation")
@Override
public <T> T call(JedisPool jedisPool) {
	Jedis jedis = null;
	try {
		jedis = jedisPool.getResource();
		return exec(jedis);
	} catch (Exception e) {
		logger.error("jedisPool getResouce or exec has exception");
		throw e;
	} finally {
		if (jedis != null) {
			jedisPool.returnResource(jedis);
		}
	}
}
 
開發者ID:zh-cn-trio,項目名稱:trioAop,代碼行數:17,代碼來源:AbstractCommandCall.java

示例10: main

import redis.clients.jedis.JedisPool; //導入依賴的package包/類
public static void main(String[] args) {
        //定義redis的連接池
        JedisPool jedisPool = new JedisPool(new GenericObjectPoolConfig(),
                "127.0.0.1", 6379, 30000);
//        JedisPool jedisPool = new JedisPool(new GenericObjectPoolConfig(),
//                "127.0.0.1", 6379, 30000, "123456"); //有密碼

        //create, config and start
        Spider spider = Spider.create()                                                 //創建爬蟲實例
                .setThreadCount(10)                                     //設置任務線程池數量
                .addStartRequests("http://blog.csdn.net/")           //添加起始url
                .setPageProcessor(new HelloWorldPageProcessor())        //設置頁麵解析器
                .setScheduler(new RedisScheduler(jedisPool))            //設置請求任務調度器
                .setPipeline(new HelloWorldPipeline());                  //結果集處理器

        //監控
        SpiderMonitor.register(spider);

        //啟動
        spider.start();
    }
 
開發者ID:brucezee,項目名稱:jspider,代碼行數:22,代碼來源:RedisSchedulerSample.java

示例11: setUp

import redis.clients.jedis.JedisPool; //導入依賴的package包/類
@Before
public void setUp() throws IOException {
    initMocks(this);
    final Random random = new SecureRandom();
    redisServer = new RedisServer();
    redisServer.start();

    pool = new JedisPool();
    repository = new RedisKeyRepository(pool);
    manager = new RedisKeyManager(random, pool, repository);
    manager.setMaxActiveKeys(3);

    clearData();
    manager.initialiseNewRepository();

    resource = new ProtectedResource(repository, random);
}
 
開發者ID:l0s,項目名稱:fernet-java8,代碼行數:18,代碼來源:KeyRotationExampleIT.java

示例12: transformResponseToUserList

import redis.clients.jedis.JedisPool; //導入依賴的package包/類
private List<User> transformResponseToUserList(List<String> userList) {

		JedisPool jedisPool = JedisFactory.getPool();
		try (Jedis jedis = jedisPool.getResource()) {
			System.out.println("Die Uebergebene userList" + userList.toString());
			List<User> users = new ArrayList<>();
			for (int i = 0; i < userList.size(); i++) {
				String keyUser = userList.get(i);
				System.out.println("keyUser: " + keyUser);

				// String pw = jedis.hget(keyUser, "pw");
				User user = new User(jedis.hget(keyUser, "name"), null);

				users.add(user);
			}
			System.out.println("users:" + users);
			return users;
		} catch (Exception e) {
			System.out.println("transformResponseToUserList");
			e.printStackTrace();
			return null;
		}
	}
 
開發者ID:SystemOfAProg,項目名稱:VS2Labor,代碼行數:24,代碼來源:ServiceBundle.java

示例13: intercept

import redis.clients.jedis.JedisPool; //導入依賴的package包/類
/**
 * 攔截所有調用,選擇正確的實例執行命令
 * @param o 調用實例
 * @param method 調用方法
 * @param args 方法參數
 * @param methodProxy 方法代理
 * @return 命令返回值
 * @throws Throwable 方法執行異常或連接異常
 */
@Override
public Object intercept(Object o, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
    GedisInstanceType type;
    if (READ_METHOD_LIST.contains(method.getName())) {
        type = GedisInstanceType.READ;
    } else {
        type = GedisInstanceType.WRITE;
    }
    JedisPool pool = getJedisPoolByType(type);
    Jedis jedis = pool.getResource();
    try {
        return method.invoke(jedis, args);
    } catch (Exception e) {
        jedis.close();
        throw e;
    } finally {
        jedis.close();
    }
}
 
開發者ID:ganpengyu,項目名稱:gedis,代碼行數:29,代碼來源:JedisMethodInterceptor.java

示例14: selectDatabaseOnActivation

import redis.clients.jedis.JedisPool; //導入依賴的package包/類
@Test
public void selectDatabaseOnActivation() {
  JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000,
      "foobared");

  Jedis jedis0 = pool.getResource();
  assertEquals(0L, jedis0.getDB().longValue());

  jedis0.select(1);
  assertEquals(1L, jedis0.getDB().longValue());

  pool.returnResource(jedis0);

  Jedis jedis1 = pool.getResource();
  assertTrue("Jedis instance was not reused", jedis1 == jedis0);
  assertEquals(0L, jedis1.getDB().longValue());

  pool.returnResource(jedis1);
  pool.destroy();
  assertTrue(pool.isClosed());
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:22,代碼來源:JedisPoolTest.java

示例15: connect

import redis.clients.jedis.JedisPool; //導入依賴的package包/類
@Override
public void connect(NURL nurl) {
	super.connect(nurl);
	this.retryPeriod = nurl.getParameter("retryPeriod", retryPeriod);

	JedisPoolConfig config = new JedisPoolConfig();
	Map<String, String> parameters = nurl.getParameters();
	if (parameters != null) {
		if (!parameters.isEmpty()) {
			try {
				Beans.copyProperties(config, nurl.getParameters());
			} catch (Exception e) {
				logger.error("The copy properties exception.", e);
			}
		}
	}

	jedisPool = new JedisPool(config, nurl.getHost(), nurl.getPort());
}
 
開發者ID:yu120,項目名稱:coon,代碼行數:20,代碼來源:RedisMconf.java


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