public static JedisPool init() { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxWait(1000000); config.setMaxActive(1000); config.setMaxIdle(100); pool = new JedisPool(config, ConfigUtil.getProperty("redis","redis.ip"),6379,9999999); jedis = pool.getResource(); index = Integer.parseInt(ConfigUtil.getProperty("redis","redis.index")); jedis.select(index); return pool; } // List:队列右边插入
public void insert(String host, int port, String key, Map<String, String> hash) { if (jredisPoolMap == null) { jredisPoolMap = new ConcurrentHashMap<String, JedisPool>(); } JedisPool pool = jredisPoolMap.get(host + ":" + port); if (pool == null) { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxActive(100); config.setMaxIdle(20); config.setMaxWait(1000l); pool = new JedisPool(host, port); jredisPoolMap.put(host + ":" + port, pool); } Jedis jedis = null; try { jedis = pool.getResource(); jedis.hmset(key, hash); } finally { pool.returnResource(jedis); } }
public void insert(String host, int port, String key, String mapKey,String mapValue) { if (jredisPoolMap == null) { jredisPoolMap = new ConcurrentHashMap<String, JedisPool>(); } JedisPool pool = jredisPoolMap.get(host + ":" + port); if (pool == null) { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxActive(100); config.setMaxIdle(20); config.setMaxWait(1000l); pool = new JedisPool(host, port); jredisPoolMap.put(host + ":" + port, pool); } Jedis jedis = null; try { jedis = pool.getResource(); jedis.hset(key, mapKey, mapValue); } finally { pool.returnResource(jedis); } }
public String read(String host, int port, String key,String mapKey) throws Exception { // host = "10.1.1.26"; if (jredisPoolMap == null) { jredisPoolMap = new ConcurrentHashMap<String, JedisPool>(); } JedisPool pool = jredisPoolMap.get(host + ":" + port); if (pool == null) { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxActive(100); config.setMaxIdle(20); config.setMaxWait(1000l); pool = new JedisPool(host, port); jredisPoolMap.put(host + ":" + port, pool); } Jedis jedis = null; try { jedis = pool.getResource(); return jedis.hget(key,mapKey); // for test /* * AtomicLong tmp = count.get(host); if (tmp == null) { tmp = new * AtomicLong(0); } tmp.addAndGet(1); count.put(host, tmp); */ //return user; // System.out.println("********************"+count.toString()); } finally { pool.returnResource(jedis); } }
public Map<String, String> read(String host, int port, String key) throws Exception { // host = "10.1.1.26"; if (jredisPoolMap == null) { jredisPoolMap = new ConcurrentHashMap<String, JedisPool>(); } JedisPool pool = jredisPoolMap.get(host + ":" + port); if (pool == null) { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxActive(100); config.setMaxIdle(20); config.setMaxWait(1000l); pool = new JedisPool(host, port); jredisPoolMap.put(host + ":" + port, pool); } Jedis jedis = null; try { jedis = pool.getResource(); Map<String, String> user = jedis.hgetAll(key); // for test /* * AtomicLong tmp = count.get(host); if (tmp == null) { tmp = new * AtomicLong(0); } tmp.addAndGet(1); count.put(host, tmp); */ return user; // System.out.println("********************"+count.toString()); } finally { pool.returnResource(jedis); } }
private static JedisPool createRedisPool( String host, int port, int poolSize, int maxWaitMillis, int socketTimeoutMillis) { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxWait(maxWaitMillis); config.setMaxActive(poolSize); config.setMaxIdle(poolSize); // Deal with idle connection eviction. config.setTestOnBorrow(false); config.setTestOnReturn(false); config.setTestWhileIdle(true); config.setMinEvictableIdleTimeMillis(5 * 60 * 1000); config.setTimeBetweenEvictionRunsMillis(3 * 60 * 1000); config.setNumTestsPerEvictionRun(poolSize); JedisPool pool = new JedisPool(config, host, port, socketTimeoutMillis); // Force connection pool initialization. Jedis jedis = null; try { jedis = pool.getResource(); } catch (JedisConnectionException e) { LOG.error( String.format("Failed to get a redis connection when creating redis pool, " + "host: %s, port: %d", host, port), e); } finally { pool.returnResource(jedis); } return pool; } }
public JedisPool createClient(RedisClientConfig redisClientConfig, EndPoint endPoint) { JedisPoolConfig config = new JedisPoolConfig(); config.setMaxWait(redisClientConfig.getMaxWaitMillis()); config.setMaxActive(redisClientConfig.getNumConnections()); config.setMaxIdle(redisClientConfig.getNumConnections()); // Deal with idle connection eviction. config.setTestOnBorrow(false); config.setTestOnReturn(false); config.setTestWhileIdle(true); config.setMinEvictableIdleTimeMillis(5 * 60 * 1000); config.setTimeBetweenEvictionRunsMillis(3 * 60 * 1000); config.setNumTestsPerEvictionRun(redisClientConfig.getNumConnections()); JedisPool jedisPool = new JedisPool( config, endPoint.host, endPoint.port, redisClientConfig.getSocketTimeoutMillis()); return jedisPool; }
config.setMaxIdle(getMaxIdle()); config.setMinIdle(getMinIdle()); config.setMaxWait(getMaxWait()); config.setWhenExhaustedAction((byte)getWhenExhaustedAction()); config.setTestOnBorrow(getTestOnBorrow());
config.setMaxIdle(getMaxIdle()); config.setMinIdle(getMinIdle()); config.setMaxWait(getMaxWait()); config.setWhenExhaustedAction((byte)getWhenExhaustedAction()); config.setTestOnBorrow(getTestOnBorrow());