Redis链接方式
来源:互联网 发布:高速公路客流量数据 编辑:程序博客网 时间:2024/05/20 17:38
package com.otsuser.usualpassenger.codisConnect;
import io.codis.jodis.JedisResourcePool;
import io.codis.jodis.RoundRobinJedisPool;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.JedisPoolConfig;
/**
* xiaoxu
*/
public class PoolFactory {
private Logger log = LoggerFactory.getLogger(PoolFactory.class);
// 创建当前的连接池类
JedisResourcePool jedisResourcePool;
/**
* 获取链接池
*
* @return
*/
public void initJedisPool() {
Properties prop = new Properties();
InputStream is = PoolFactory.class
.getResourceAsStream("/codis-connect.properties");
try {
// 读取配置文件
prop.load(is);
String zkAddr = prop.getProperty("zkAddr");
String zkProxyDir = prop.getProperty("zkProxyDir");
int maxTotal = Integer.parseInt(prop.getProperty("maxTotal"));
int maxIdle = Integer.parseInt(prop.getProperty("maxIdle"));
int minIdle = Integer.parseInt(prop.getProperty("minIdle"));
long maxWaitMillis = Integer.parseInt(prop
.getProperty("maxWaitMillis"));
int soTimeoutMs = Integer.parseInt(prop.getProperty("soTimeoutMs"));
int timeoutMs = Integer.parseInt(prop.getProperty("timeoutMs"));
int zkSessionTimeoutMs = Integer.parseInt(prop
.getProperty("zkSessionTimeoutMs"));
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxIdle(maxIdle);
poolConfig.setMinIdle(minIdle);
poolConfig.setMaxTotal(maxTotal);
poolConfig.setMaxWaitMillis(maxWaitMillis);
// 获取连接池
jedisResourcePool = RoundRobinJedisPool.create()
.soTimeoutMs(soTimeoutMs).timeoutMs(timeoutMs)
.curatorClient(zkAddr, zkSessionTimeoutMs)
.zkProxyDir(zkProxyDir).poolConfig(poolConfig).build();
} catch (IOException e) {
log.error("initJedisPool error:", e.getStackTrace().toString());
}
}
/**
* 返回当前的实例
*
* @return
*/
public JedisResourcePool getjedisResourcePool() {
return jedisResourcePool;
}
import io.codis.jodis.JedisResourcePool;
import io.codis.jodis.RoundRobinJedisPool;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.JedisPoolConfig;
/**
* xiaoxu
*/
public class PoolFactory {
private Logger log = LoggerFactory.getLogger(PoolFactory.class);
// 创建当前的连接池类
JedisResourcePool jedisResourcePool;
/**
* 获取链接池
*
* @return
*/
public void initJedisPool() {
Properties prop = new Properties();
InputStream is = PoolFactory.class
.getResourceAsStream("/codis-connect.properties");
try {
// 读取配置文件
prop.load(is);
String zkAddr = prop.getProperty("zkAddr");
String zkProxyDir = prop.getProperty("zkProxyDir");
int maxTotal = Integer.parseInt(prop.getProperty("maxTotal"));
int maxIdle = Integer.parseInt(prop.getProperty("maxIdle"));
int minIdle = Integer.parseInt(prop.getProperty("minIdle"));
long maxWaitMillis = Integer.parseInt(prop
.getProperty("maxWaitMillis"));
int soTimeoutMs = Integer.parseInt(prop.getProperty("soTimeoutMs"));
int timeoutMs = Integer.parseInt(prop.getProperty("timeoutMs"));
int zkSessionTimeoutMs = Integer.parseInt(prop
.getProperty("zkSessionTimeoutMs"));
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxIdle(maxIdle);
poolConfig.setMinIdle(minIdle);
poolConfig.setMaxTotal(maxTotal);
poolConfig.setMaxWaitMillis(maxWaitMillis);
// 获取连接池
jedisResourcePool = RoundRobinJedisPool.create()
.soTimeoutMs(soTimeoutMs).timeoutMs(timeoutMs)
.curatorClient(zkAddr, zkSessionTimeoutMs)
.zkProxyDir(zkProxyDir).poolConfig(poolConfig).build();
} catch (IOException e) {
log.error("initJedisPool error:", e.getStackTrace().toString());
}
}
/**
* 返回当前的实例
*
* @return
*/
public JedisResourcePool getjedisResourcePool() {
return jedisResourcePool;
}
}
codis-connect.properties
# codis connect
zkAddr=10.2.202.26:2181,10.2.202.27:2181,10.2.202.28:2181,10.2.202.29:2181,10.2.202.30:2181
zkProxyDir=/jodis/usualpassenger
maxTotal=10000
maxIdle=1000
minIdle=100
maxWaitMillis=100
soTimeoutMs=10000
timeoutMs=10000
zkSessionTimeoutMs=50000
阅读全文
0 0
- Redis链接方式
- redis 链接
- redis 链接
- 链接/Redis
- 链接方式
- scala链接redis
- java链接redis
- redis 配置远程链接
- node.js 链接 redis
- java链接redis
- redis集群链接-java
- redis 无法远程链接
- php链接redis
- tomcat与redis链接redis存储session
- 链接方式(二)
- 链接方式(一)
- Oracle 的链接方式
- DLL的链接方式
- opencv svm学习
- oracle instr
- 关于Access restriction: The type basic is not accessible due to restriction on required library异常
- job命令
- 1. javascript继承的方式
- Redis链接方式
- TypeError: Fetch argument None has invalid type <class 'NoneType'>解决方案
- Lua学习笔记(1)-基础知识、表达式语法
- 67. Add Binary
- C语言中变量的作用域和生命周期
- meta标签的属性介绍
- 集成——Mac电脑上app自动化测试(Appium + xcode 8.2 + python)环境搭建
- swagger API 摆脱手写API的烦恼(ssm + swagger)
- mybatis疑难杂症之配置文件无限加载 Property 'configLocation' not specified, using default MyBatis Configuration