当前位置: 首页>>代码示例>>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;未经允许,请勿转载。