联通联通老用户转工行e卡卡是永久的吗 联通联通老用户转工行e卡卡有效期是多久

Redis连接池配置 -
- ITeye技术网站
博客分类:
http://my.oschina.net/damihui/blog/173490
1.使用MAVEN引入使用的包。
view sourceprint?01 &dependency&&
02&&&& &groupId&redis.clients&/groupId&&
03&&&& &artifactId&jedis&/artifactId&&
04&&&& &version&2.1.0&/version&&
05&&&& &scope&provided&/scope&&
06 &/dependency&&
07 &dependency&&
08&&&& &groupId&org.springframework&/groupId&&
09&&&& &artifactId&spring-core&/artifactId&&
10&&&& &version&3.1.0.RELEASE&/version&&
11&&&& &scope&provided&/scope&&
12 &/dependency&&
13 &dependency&&
14&&&& &groupId&org.springframework&/groupId&&
15&&&& &artifactId&spring-context&/artifactId&&
16&&&& &version&3.1.0.RELEASE&/version&&
17&&&& &scope&provided&/scope&&
18 &/dependency&&
19 &dependency&&
20&&&& &groupId&org.springframework&/groupId&&
21&&&& &artifactId&spring-context-support&/artifactId&&
22&&&& &version&3.1.0.RELEASE&/version&&
23&&&& &scope&provided&/scope&&
24 &/dependency&&
25 &dependency&&
26&&&& &groupId&org.springframework&/groupId&&
27&&&& &artifactId&spring-beans&/artifactId&&
28&&&& &version&3.1.0.RELEASE&/version&&
29&&&& &scope&provided&/scope&&
30 &/dependency&&
31 &dependency&&
32&&&& &groupId&org.springframework&/groupId&&
33&&&& &artifactId&org.springframework.context&/artifactId&&
34&&&& &version&3.1.0.RELEASE&/version&&
35&&&& &scope&provided&/scope&&
36 &/dependency&&
37 &dependency&&
38&&&& &groupId&org.springframework&/groupId&&
39&&&& &artifactId&spring-test&/artifactId&&
40&&&& &version&3.1.0.RELEASE&/version&&
41&&&& &scope&test&/scope&&
42 &/dependency&&
43 &dependency&&
44&&&& &groupId&commons-io&/groupId&&
45&&&& &artifactId&commons-io&/artifactId&&
46&&&& &version&1.3.2&/version&&
47 &/dependency&&
48 &dependency&&
49&&&& &groupId&commons-lang&/groupId&&
50&&&& &artifactId&commons-lang&/artifactId&&
51&&&& &version&2.3&/version&&
52&&&& &scope&provided&/scope&&
53 &/dependency&&
54 &dependency&&
55&&&& &groupId&junit&/groupId&&
56&&&& &artifactId&junit&/artifactId&&
57&&&& &version&4.10&/version&&
58&&&& &scope&test&/scope&&
59 &/dependency&&
60 &dependency&&
61&&&& &groupId&org.aspectj&/groupId&&
62&&&& &artifactId&aspectjweaver&/artifactId&&
63&&&& &version&1.6.12&/version&&
64&&&& &scope&provided&/scope&&
65 &/dependency&&
66 &dependency&&
67&&&& &groupId&net.sourceforge.cglib&/groupId&&
68&&&& &artifactId&com.springsource.net.sf.cglib&/artifactId&&
69&&&& &version&2.2.0&/version&&
70&&&& &scope&provided&/scope&&
71 &/dependency&&
72 &dependency&&
73&&&& &groupId&log4j&/groupId&&
74&&&& &artifactId&log4j&/artifactId&&
75&&&& &version&1.2.8&/version&&
76 &/dependency&
2.Jedis的连接池配置需要用到mons.pool.impl.GenericObjectPool.Config.class,此类是 GenericObjectPool的一个内部类,使用spring xml配置时需要转换成以下自定义类。
view sourceprint?001 package com.antilost.redis.&
003 import mons.pool.impl.GenericObjectP&
006& * User: ***&
007& * Date: 13-8-27&
008& * Time: 下午3:49&
010 public class GenericObjectPoolConfigWrapper {&
012&&&& private final GenericObjectPool.C&
014&&&& public GenericObjectPoolConfigWrapper() {&
015&&&&&&&& this.config = new GenericObjectPool.Config();&
016&&&& }&
018&&&& public GenericObjectPool.Config getConfig() {&
019&&&&&&&&&
020&&&& }&
022&&&& public int getMaxIdle() {&
023&&&&&&&& return this.config.maxI&
024&&&& }&
026&&&& public void setMaxIdle(int maxIdle) {&
027&&&&&&&& this.config.maxIdle = maxI&
028&&&& }&
030&&&& public int getMinIdle() {&
031&&&&&&&& return this.config.minI&
032&&&& }&
034&&&& public void setMinIdle(int minIdle) {&
035&&&&&&&& this.config.minIdle = minI&
036&&&& }&
038&&&& public int getMaxActive() {&
039&&&&&&&& return this.config.maxA&
040&&&& }&
042&&&& public void setMaxActive(int maxActive) {&
043&&&&&&&& this.config.maxActive = maxA&
044&&&& }&
046&&&& public long getMaxWait() {&
047&&&&&&&& return this.config.maxW&
048&&&& }&
050&&&& public void setMaxWait(long maxWait) {&
051&&&&&&&& this.config.maxWait = maxW&
052&&&& }&
054&&&& public byte getWhenExhaustedAction() {&
055&&&&&&&& return this.config.whenExhaustedA&
056&&&& }&
058&&&& public void setWhenExhaustedAction(byte whenExhaustedAction) {&
059&&&&&&&& this.config.whenExhaustedAction = whenExhaustedA&
060&&&& }&
062&&&& public boolean isTestOnBorrow() {&
063&&&&&&&& return this.config.testOnB&
064&&&& }&
066&&&& public void setTestOnBorrow(boolean testOnBorrow) {&
067&&&&&&&& this.config.testOnBorrow = testOnB&
068&&&& }&
070&&&& public boolean isTestOnReturn() {&
071&&&&&&&& return this.config.testOnR&
072&&&& }&
074&&&& public void setTestOnReturn(boolean testOnReturn) {&
075&&&&&&&& this.config.testOnReturn = testOnR&
076&&&& }&
078&&&& public boolean isTestWhileIdle() {&
079&&&&&&&& return this.config.testWhileI&
080&&&& }&
082&&&& public void setTestWhileIdle(boolean testWhileIdle) {&
083&&&&&&&& this.config.testWhileIdle = testWhileI&
084&&&& }&
086&&&& public long getTimeBetweenEvictionRunsMillis() {&
087&&&&&&&& return this.config.timeBetweenEvictionRunsM&
088&&&& }&
090&&&& public void setTimeBetweenEvictionRunsMillis( long timeBetweenEvictionRunsMillis) {&
091&&&&&&&& this.config.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsM&
092&&&& }&
094&&&& public int getNumTestsPerEvictionRun() {&
095&&&&&&&& return this.config.numTestsPerEvictionR&
096&&&& }&
098&&&& public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {&
099&&&&&&&& this.config.numTestsPerEvictionRun = numTestsPerEvictionR&
100&&&& }&
102&&&& public long getMinEvictableIdleTimeMillis() {&
103&&&&&&&& return this.config.minEvictableIdleTimeM&
104&&&& }&
106&&&& public void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {&
107&&&&&&&& this.config.minEvictableIdleTimeMillis = minEvictableIdleTimeM&
108&&&& }&
110&&&& public long getSoftMinEvictableIdleTimeMillis() {&
111&&&&&&&& return this.config.softMinEvictableIdleTimeM&
112&&&& }&
114&&&& public void setSoftMinEvictableIdleTimeMillis( long softMinEvictableIdleTimeMillis) {&
115&&&&&&&& this.config.softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeM&
116&&&& }&
118&&&& public boolean isLifo() {&
119&&&&&&&& return this.config.&
120&&&& }&
122&&&& public void setLifo(boolean lifo) {&
123&&&&&&&& this.config.lifo =&
124&&&& }&
3.在Spring配置文件中注入GenericObjectPoolConfigWrapper.java类
view sourceprint?01 &aop:aspectj-autoproxy/&&
02 &context:annotation-config /&&
03 &context:property-placeholder location="classpath:jedis.properties" ignore-unresolvable="true"/&&
04 &bean id="jedisPoolConfig" class="com.antilost.redis.util.GenericObjectPoolConfigWrapper"&&
05&&&&&&&& &!--最大连接数--&
06&&&& &property name="maxActive" value="${${redis.pool.maxActive}}" /&&
07&&&&&&&& &!--最大空闲连接数--&
08&&&& &property name="maxIdle" value="${${redis.pool.maxIdle}}" /&&
09&&&&&&&& &!--初始化连接数--&
10&&&& &property name="minIdle" value="${${redis.pool.minIdle}}"/&&
11&&&&&&&& &!--最大等待时间--&
12&&&& &property name="maxWait" value="${${redis.pool.maxWait}}" /&&
13&&&&&&&& &!--对拿到的connection进行validateObject校验--&
14&&&& &property name="testOnBorrow" value="${redis.pool.testOnBorrow}" /&&
15&&&&&&&& &!--在进行returnObject对返回的connection进行validateObject校验--&
16&&&& &property name="testOnReturn" value="${redis.pool.testOnReturn}" /&&
17&&&&&&&& &!--定时对线程池中空闲的链接进行validateObject校验--&
18&&&&&&&& &property name="testWhileIdle" value="true" /&&
19 &/bean&
4.Redis的连接配置文件jedis.properties中,定义了各个环境的连接参数,具体配置如下
view sourceprint?01 redis.pool.maxActive=redis.pool.maxActive.${ServerType}&
02 redis.pool.maxIdle=redis.pool.maxIdle.${ServerType}&
03 redis.pool.maxWait=redis.pool.maxWait.${ServerType}&
04 redis.pool.minIdle=redis.pool.minIdle.${ServerType}&
05 redis.host=redis.host.${ServerType}&
06 redis.port=redis.port.${ServerType}&
07 redis.password=redis.password.${ServerType}&
08 redis.pool.testOnBorrow=true
09 redis.pool.testOnReturn=true
10 redis.timeout=1000
13 redis.pool.maxActive.REL=200&
14 redis.pool.maxIdle.REL=50&
15 redis.pool.minIdle.REL=10&
16 redis.pool.maxWait.REL=300&
17 redis.host.REL=192.168.*.*&
18 redis.port.REL=6379&
19 redis.password.REL=***
22 redis.pool.maxActive.VRF=200&
23 redis.pool.maxIdle.VRF=50&
24 redis.pool.minIdle.VRF=10&
25 redis.pool.maxWait.VRF=300&
26 redis.host.VRF=192.168.*.*&
27 redis.port.VRF=6379&
28 redis.password.VRF=***
根据系统环境变量JVM中ServerType的值,取不同的配置,实现多环境(测试环境、生产环境)集成。
5.Redis连接池配置
view sourceprint?01 &bean id="jedisPool" class="redis.clients.jedis.JedisPool" destroy-method="destroy"&&
02&&&&& &constructor-arg index="0"&&
03&&&&&&&&&&&& &bean factory-bean="jedisPoolConfig" factory-method="getConfig"/&&
04&&&&& &/constructor-arg&&
05&&&&&&&& &constructor-arg index="1" value="${${redis.host}}"/&&
06&&&&&&&& &constructor-arg index="2" value="${${redis.port}}"/&&
07&&&&&&&& &!--timeout--&
08&&&&&&&& &constructor-arg index="3" value="${redis.timeout}"/&&
09&&&&&&&& &constructor-arg index="4" value="${${redis.password}}"/&&
10 &/bean&
6.Redis 工具类 view sourceprint?001 public abstract class JCacheTools {&
002&&&& public abstract int getDBIndex();&
003&&&& /**&
004&&&&& * 默认日志打印logger_default&
005&&&&& */
006&&&& public static Logger logger_default = Logger.getLogger("logger_jCache_default");&
007&&&& /**&
008&&&&& * 失败日志logger,用于定期del指定的key&
009&&&&& */
010&&&& public static Logger logger_failure = Logger.getLogger("logger_jCache_failure");&
012&&&& @Resource
013&&&& protected JedisPool jedisP&
015&&&& protected Jedis getJedis() throws JedisException {&
016&&&&&&&& Jedis jedis =&
017&&&&&&&& try {&
018&&&&&&&&&&&& jedis = jedisPool.getResource();&
019&&&&&&&& } catch (JedisException e) {&
020&&&&&&&&&&&& LogContext.instance().warn(logger_failure, "failed:jedisPool getResource.", e);&
021&&&&&&&&&&&& if(jedis!=null){&
022&&&&&&&&&&&&&&&& jedisPool.returnBrokenResource(jedis);&
023&&&&&&&&&&&& }&
024&&&&&&&&&&&&&
025&&&&&&&& }&
026&&&&&&&&&
027&&&& }&
029&&&& protected void release(Jedis jedis, boolean isBroken) {&
030&&&&&&&& if (jedis != null) {&
031&&&&&&&&&&&& if (isBroken) {&
032&&&&&&&&&&&&&&&& jedisPool.returnBrokenResource(jedis);&
033&&&&&&&&&&&& } else {&
034&&&&&&&&&&&&&&&& jedisPool.returnResource(jedis);&
035&&&&&&&&&&&& }&
036&&&&&&&& }&
037&&&& }&
039&&&& protected String addStringToJedis(String key, String value, int cacheSeconds, String methodName) {&
040&&&&&&&& Jedis jedis =&
041&&&&&&&& boolean isBroken =&
042&&&&&&&& String lastVal =&
043&&&&&&&& try {&
044&&&&&&&&&&&& jedis = this.getJedis();&
045&&&&&&&&&&&& jedis.select(getDBIndex());&
046&&&&&&&&&&&& lastVal = jedis.getSet(key, value);&
047&&&&&&&&&&&& if(cacheSeconds!=0){&
048&&&&&&&&&&&&&&&& jedis.expire(key,cacheSeconds);&
049&&&&&&&&&&&& }&
050&&&&&&&&&&&& LogContext.instance().debug(logger_default, "succeed:" + methodName, key, value);&
051&&&&&&&& } catch (Exception e) {&
052&&&&&&&&&&&& isBroken =&
053&&&&&&&&&&&& LogContext.instance().warn(logger_failure, "failed:" + methodName, key, value, e);&
054&&&&&&&& } finally {&
055&&&&&&&&&&&& release(jedis, isBroken);&
056&&&&&&&& }&
057&&&&&&&& return lastV&
058&&&& }&
060&&&& protected void addStringToJedis(Map&String,String& batchData, int cacheSeconds, String methodName) {&
061&&&&&&&& Jedis jedis =&
062&&&&&&&& boolean isBroken =&
063&&&&&&&& try {&
064&&&&&&&&&&&& jedis = this.getJedis();&
065&&&&&&&&&&&& jedis.select(getDBIndex());&
066&&&&&&&&&&&& Pipeline pipeline = jedis.pipelined();&
067&&&&&&&&&&&& for(Map.Entry&String,String& element:batchData.entrySet()){&
068&&&&&&&&&&&&&&&& if(cacheSeconds!=0){&
069&&&&&&&&&&&&&&&&&&&& pipeline.setex(element.getKey(),cacheSeconds,element.getValue());&
070&&&&&&&&&&&&&&&& }else{&
071&&&&&&&&&&&&&&&&&&&& pipeline.set(element.getKey(),element.getValue());&
072&&&&&&&&&&&&&&&& }&
073&&&&&&&&&&&& }&
074&&&&&&&&&&&& pipeline.sync();&
075&&&&&&&&&&&& LogContext.instance().debug(logger_default, "succeed:" + methodName,batchData.size());&
076&&&&&&&& } catch (Exception e) {&
077&&&&&&&&&&&& isBroken =&
078&&&&&&&&&&&& e.printStackTrace();&
079&&&&&&&& } finally {&
080&&&&&&&&&&&& release(jedis, isBroken);&
081&&&&&&&& }&
082&&&& }&
084&&&& protected void addListToJedis(String key, List&String& list, int cacheSeconds, String methodName) {&
085&&&&&&&& if (list != null && list.size() & 0) {&
086&&&&&&&&&&&& Jedis jedis =&
087&&&&&&&&&&&& boolean isBroken =&
088&&&&&&&&&&&& try {&
089&&&&&&&&&&&&&&&& jedis = this.getJedis();&
090&&&&&&&&&&&&&&&& jedis.select(getDBIndex());&
091&&&&&&&&&&&&&&&& if (jedis.exists(key)) {&
092&&&&&&&&&&&&&&&&&&&& jedis.del(key);&
093&&&&&&&&&&&&&&&& }&
094&&&&&&&&&&&&&&&& for (String aList : list) {&
095&&&&&&&&&&&&&&&&&&&& jedis.rpush(key, aList);&
096&&&&&&&&&&&&&&&& }&
097&&&&&&&&&&&&&&&& if(cacheSeconds!=0){&
098&&&&&&&&&&&&&&&&&&&& jedis.expire(key, cacheSeconds);&
099&&&&&&&&&&&&&&&& }&
100&&&&&&&&&&&&&&&& LogContext.instance().debug(logger_default, "succeed:" + methodName, key, list.size());&
101&&&&&&&&&&&& } catch (JedisException e) {&
102&&&&&&&&&&&&&&&& isBroken =&
103&&&&&&&&&&&&&&&& LogContext.instance().warn(logger_failure, "failed:" + methodName, key, list.size(), e);&
104&&&&&&&&&&&& } catch (Exception e) {&
105&&&&&&&&&&&&&&&& isBroken =&
106&&&&&&&&&&&&&&&& LogContext.instance().warn(logger_failure, "failed:" + methodName, key, list.size(), e);&
107&&&&&&&&&&&& } finally {&
108&&&&&&&&&&&&&&&& release(jedis, isBroken);&
109&&&&&&&&&&&& }&
110&&&&&&&& }&
111&&&& }&
113&&&& protected void addToSetJedis(String key, String[] value, String methodName) {&
114&&&&&&&& Jedis jedis =&
115&&&&&&&& boolean isBroken =&
116&&&&&&&& try {&
117&&&&&&&&&&&& jedis = this.getJedis();&
118&&&&&&&&&&&& jedis.select(getDBIndex());&
119&&&&&&&&&&&& jedis.sadd(key,value);&
120&&&&&&&&&&&& LogContext.instance().debug(logger_default, "succeed:" + methodName, key, value);&
121&&&&&&&& } catch (Exception e) {&
122&&&&&&&&&&&& isBroken =&
123&&&&&&&&&&&& LogContext.instance().warn(logger_failure, "failed:" + methodName, key, value, e);&
124&&&&&&&& } finally {&
125&&&&&&&&&&&& release(jedis, isBroken);&
126&&&&&&&& }&
127&&&& }&
129&&&& protected void removeSetJedis(String key,String value, String methodName) {&
130&&&&&&&& Jedis jedis =&
131&&&&&&&& boolean isBroken =&
132&&&&&&&& try {&
133&&&&&&&&&&&& jedis = this.getJedis();&
134&&&&&&&&&&&& jedis.select(getDBIndex());&
135&&&&&&&&&&&& jedis.srem(key,value);&
136&&&&&&&&&&&& LogContext.instance().debug(logger_default, "succeed:" + methodName, key, value);&
137&&&&&&&& } catch (Exception e) {&
138&&&&&&&&&&&& isBroken =&
139&&&&&&&&&&&& LogContext.instance().warn(logger_failure, "failed:" + methodName, key, value, e);&
140&&&&&&&& } finally {&
141&&&&&&&&&&&& release(jedis, isBroken);&
142&&&&&&&& }&
143&&&& }&
145&&&& protected void pushDataToListJedis(String key, String data, int cacheSeconds, String methodName) {&
146&&&&&&&& Jedis jedis =&
147&&&&&&&& boolean isBroken =&
148&&&&&&&& try {&
149&&&&&&&&&&&& jedis = this.getJedis();&
150&&&&&&&&&&&& jedis.select(getDBIndex());&
151&&&&&&&&&&&& jedis.rpush(key, data);&
152&&&&&&&&&&&& if(cacheSeconds!=0){&
153&&&&&&&&&&&&&&&& jedis.expire(key,cacheSeconds);&
154&&&&&&&&&&&& }&
155&&&&&&&&&&&& LogContext.instance().debug(logger_default, "succeed:" + methodName, key, data);&
156&&&&&&&& } catch (Exception e) {&
157&&&&&&&&&&&& isBroken =&
158&&&&&&&&&&&& LogContext.instance().warn(logger_failure, "failed:" + methodName, key, data, e);&
159&&&&&&&& } finally {&
160&&&&&&&&&&&& release(jedis, isBroken);&
161&&&&&&&& }&
162&&&& }&
163&&&& protected void pushDataToListJedis(String key,List&String& batchData, int cacheSeconds, String methodName) {&
164&&&&&&&& Jedis jedis =&
165&&&&&&&& boolean isBroken =&
166&&&&&&&& try {&
167&&&&&&&&&&&& jedis = this.getJedis();&
168&&&&&&&&&&&& jedis.select(getDBIndex());&
169&&&&&&&&&&&& jedis.del(key);&
170&&&&&&&&&&&& jedis.lpush(key,batchData.toArray(new String[batchData.size()]));&
171&&&&&&&&&&&& if(cacheSeconds!=0)&
172&&&&&&&&&&&&&&&& jedis.expire(key,cacheSeconds);&
173&&&&&&&&&&&& LogContext.instance().debug(logger_default, "succeed:" + methodName,batchData!=null?batchData.size():0);&
174&&&&&&&& } catch (Exception e) {&
175&&&&&&&&&&&& isBroken =&
176&&&&&&&&&&&& LogContext.instance().warn(logger_failure, "failed:" + methodName, batchData!=null?batchData.size():0, e);&
177&&&&&&&& } finally {&
178&&&&&&&&&&&& release(jedis, isBroken);&
179&&&&&&&& }&
180&&&& }&
182&&&& /**&
183&&&&& * 删除list中的元素&
184&&&&& * @param key&
185&&&&& * @param values&
186&&&&& * @param methodName&
187&&&&& */
188&&&& protected void deleteDataFromListJedis(String key,List&String& values, String methodName) {&
189&&&&&&&& Jedis jedis =&
190&&&&&&&& boolean isBroken =&
191&&&&&&&& try {&
192&&&&&&&&&&&& jedis = this.getJedis();&
193&&&&&&&&&&&& jedis.select(getDBIndex());&
194&&&&&&&&&&&& Pipeline pipeline = jedis.pipelined();&
195&&&&&&&&&&&& if(values!=null && !values.isEmpty()){&
196&&&&&&&&&&&&&&&& for (String val:values){&
197&&&&&&&&&&&&&&&&&&&& pipeline.lrem(key,0,val);&
198&&&&&&&&&&&&&&&& }&
199&&&&&&&&&&&& }&
200&&&&&&&&&&&& pipeline.sync();&
201&&&&&&&&&&&& LogContext.instance().debug(logger_default, "succeed:" + methodName,values!=null?values.size():0);&
202&&&&&&&& } catch (Exception e) {&
203&&&&&&&&&&&& isBroken =&
204&&&&&&&&&&&& LogContext.instance().warn(logger_failure, "failed:" + methodName, values!=null?values.size():0, e);&
205&&&&&&&& } finally {&
206&&&&&&&&&&&& release(jedis, isBroken);&
207&&&&&&&& }&
208&&&& }&
210&&&& protected void addHashMapToJedis(String key, Map&String, String& map, int cacheSeconds, boolean isModified, String methodName) {&
211&&&&&&&& boolean isBroken =&
212&&&&&&&& Jedis jedis =&
213&&&&&&&& if (map != null && map.size() & 0) {&
214&&&&&&&&&&&& try {&
215&&&&&&&&&&&&&&&& jedis = this.getJedis();&
216&&&&&&&&&&&&&&&& jedis.select(getDBIndex());&
217&&&&&&&&&&&&&&&& jedis.hmset(key, map);&
218&&&&&&&&&&&&&&&& if (cacheSeconds &= 0)&
219&&&&&&&&&&&&&&&&&&&& jedis.expire(key, cacheSeconds);&
220&&&&&&&&&&&&&&&& LogContext.instance().debug(logger_default, "succeed:" + methodName, key, map.size());&
221&&&&&&&&&&&& } catch (Exception e) {&
222&&&&&&&&&&&&&&&& isBroken =&
223&&&&&&&&&&&&&&&& LogContext.instance().warn(logger_failure, "failed:" + methodName, key, map.size(), e);&
224&&&&&&&&&&&& } finally {&
225&&&&&&&&&&&&&&&& release(jedis, isBroken);&
226&&&&&&&&&&&& }&
227&&&&&&&& }&
228&&&& }&
230&&&& protected void addHashMapToJedis(String key, String field, String value, int cacheSeconds, String methodName) {&
231&&&&&&&& boolean isBroken =&
232&&&&&&&& Jedis jedis =&
233&&&&&&&& try {&
234&&&&&&&&&&&& jedis = this.getJedis();&
235&&&&&&&&&&&& if (jedis != null) {&
236&&&&&&&&&&&&&&&& jedis.select(getDBIndex());&
237&&&&&&&&&&&&&&&& jedis.hset(key, field, value);&
238&&&&&&&&&&&&&&&& jedis.expire(key, cacheSeconds);&
239&&&&&&&&&&&&&&&& LogContext.instance().debug(logger_default, "succeed:" + methodName, key, field, value);&
240&&&&&&&&&&&& }&
241&&&&&&&& } catch (Exception e) {&
242&&&&&&&&&&&& isBroken =&
243&&&&&&&&&&&& LogContext.instance().warn(logger_failure, "failed:" + methodName, key, field, value, e);&
244&&&&&&&& }finally {&
245&&&&&&&&&&&& release(jedis, isBroken);&
246&&&&&&&& }&
247&&&& }&
249&&&& protected void updateHashMapToJedis(String key, String incrementField, long incrementValue, String dateField, String dateValue, String methodName) {&
250&&&&&&&& boolean isBroken =&
251&&&&&&&& Jedis jedis =&
252&&&&&&&& try {&
253&&&&&&&&&&&& jedis = this.getJedis();&
254&&&&&&&&&&&& jedis.select(getDBIndex());&
255&&&&&&&&&&&& jedis.hincrBy(key, incrementField, incrementValue);&
256&&&&&&&&&&&& jedis.hset(key, dateField, dateValue);&
257&&&&&&&&&&&& LogContext.instance().debug(logger_default, "succeed:" + methodName, key, incrementField, incrementValue);&
258&&&&&&&& } catch (Exception e) {&
259&&&&&&&&&&&& isBroken =&
260&&&&&&&&&&&& LogContext.instance().warn(logger_failure, "failed:" + methodName, key, incrementField, incrementValue, e);&
261&&&&&&&& }finally {&
262&&&&&&&&&&&& release(jedis, isBroken);&
263&&&&&&&& }&
264&&&& }&
266&&&& public String getStringFromJedis(String key, String methodName) {&
267&&&&&&&& String value =&
268&&&&&&&& Jedis jedis =&
269&&&&&&&& boolean isBroken =&
270&&&&&&&& try {&
271&&&&&&&&&&&& jedis = this.getJedis();&
272&&&&&&&&&&&& jedis.select(getDBIndex());&
273&&&&&&&&&&&& if (jedis.exists(key)) {&
274&&&&&&&&&&&&&&&& value = jedis.get(key);&
275&&&&&&&&&&&&&&&& value = StringUtils.isNotBlank(value) && !"nil".equalsIgnoreCase(value)?value:&
276&&&&&&&&&&&&&&&& LogContext.instance().debug(logger_default, "succeed:" + methodName, key, value);&
277&&&&&&&&&&&& }&
278&&&&&&&& } catch (Exception e) {&
279&&&&&&&&&&&& isBroken =&
280&&&&&&&&&&&& LogContext.instance().warn(logger_failure, "failed:" + methodName, key, value, e);&
281&&&&&&&& } finally {&
282&&&&&&&&&&&& release(jedis, isBroken);&
283&&&&&&&& }&
284&&&&&&&&&
285&&&& }&
287&&&& public List&String& getStringFromJedis(String[] keys, String methodName) {&
288&&&&&&&& Jedis jedis =&
289&&&&&&&& boolean isBroken =&
290&&&&&&&& try {&
291&&&&&&&&&&&& jedis = this.getJedis();&
292&&&&&&&&&&&& jedis.select(getDBIndex());&
293&&&&&&&&&&&& return jedis.mget(keys);&
294&&&&&&&& } catch (Exception e) {&
295&&&&&&&&&&&& isBroken =&
296&&&&&&&&&&&& LogContext.instance().warn(logger_failure, "failed:" + methodName, Arrays.toString(keys), e);&
297&&&&&&&& } finally {&
298&&&&&&&&&&&& release(jedis, isBroken);&
299&&&&&&&& }&
300&&&&&&&&&
301&&&& }&
303&&&& protected List&String& getListFromJedis(String key, String methodName) throws JMSCacheException {&
304&&&&&&&& List&String& list =&
305&&&&&&&& boolean isBroken =&
306&&&&&&&& Jedis jedis =&
307&&&&&&&& try {&
308&&&&&&&&&&&& jedis = this.getJedis();&
309&&&&&&&&&&&& jedis.select(getDBIndex());&
310&&&&&&&&&&&& if (jedis.exists(key)) {&
311&&&&&&&&&&&&&&&& list = jedis.lrange(key, 0, -1);&
312&&&&&&&&&&&&&&&& LogContext.instance().debug(logger_default, "succeed:" + methodName, key, list != null ? list.size() : 0);&
313&&&&&&&&&&&& }&
314&&&&&&&& } catch (JedisException e) {&
315&&&&&&&&&&&& isBroken =&
316&&&&&&&&&&&& LogContext.instance().warn(logger_failure, "failed:" + methodName, key, list != null ? list.size() : 0, e);&
317&&&&&&&& } finally {&
318&&&&&&&&&&&& release(jedis, isBroken);&
319&&&&&&&& }&
320&&&&&&&&&
321&&&& }&
323&&&& protected Set&String& getSetFromJedis(String key, String methodName) throws JMSCacheException {&
324&&&&&&&& Set&String& list =&
325&&&&&&&& boolean isBroken =&
326&&&&&&&& Jedis jedis =&
327&&&&&&&& try {&
328&&&&&&&&&&&& jedis = this.getJedis();&
329&&&&&&&&&&&& jedis.select(getDBIndex());&
330&&&&&&&&&&&& if (jedis.exists(key)) {&
331&&&&&&&&&&&&&&&& list = jedis.smembers(key);&
332&&&&&&&&&&&&&&&& LogContext.instance().debug(logger_default, "succeed:" + methodName, key, list != null ? list.size() : 0);&
333&&&&&&&&&&&& }&
334&&&&&&&& } catch (Exception e) {&
335&&&&&&&&&&&& isBroken =&
336&&&&&&&&&&&& LogContext.instance().warn(logger_failure, "failed:" + methodName, key, list != null ? list.size() : 0, e);&
337&&&&&&&& } finally {&
338&&&&&&&&&&&& release(jedis, isBroken);&
339&&&&&&&& }&
340&&&&&&&&&
341&&&& }&
343&&&& protected Map&String, String& getHashMapFromJedis(String key, String methodName) {&
344&&&&&&&& Map&String, String& hashMap =&
345&&&&&&&& boolean isBroken =&
346&&&&&&&& Jedis jedis =&
347&&&&&&&& try {&
348&&&&&&&&&&&& jedis = this.getJedis();&
349&&&&&&&&&&&& jedis.select(getDBIndex());&
350&&&&&&&&&&&& hashMap = jedis.hgetAll(key);&
351&&&&&&&&&&&& LogContext.instance().debug(logger_default, "succeed:" + methodName, key, hashMap != null ? hashMap.size() : 0);&
352&&&&&&&& } catch (Exception e) {&
353&&&&&&&&&&&& isBroken =&
354&&&&&&&&&&&& LogContext.instance().warn(logger_failure, "failed:" + methodName, key, hashMap != null ? hashMap.size() : 0, e);&
355&&&&&&&& } finally {&
356&&&&&&&&&&&& release(jedis, isBroken);&
357&&&&&&&& }&
358&&&&&&&& return hashM&
359&&&& }&
361&&&& protected String getHashMapValueFromJedis(String key, String field, String methodName) {&
362&&&&&&&& String value =&
363&&&&&&&& boolean isBroken =&
364&&&&&&&& Jedis jedis =&
365&&&&&&&& try {&
366&&&&&&&&&&&& jedis = this.getJedis();&
367&&&&&&&&&&&& if (jedis != null) {&
368&&&&&&&&&&&&&&&& jedis.select(getDBIndex());&
369&&&&&&&&&&&&&&&& if (jedis.exists(key)) {&
370&&&&&&&&&&&&&&&&&&&& value = jedis.hget(key, field);&
371&&&&&&&&&&&&&&&&&&&& LogContext.instance().debug(logger_default, "succeed:" + methodName, key, field, value);&
372&&&&&&&&&&&&&&&& }&
373&&&&&&&&&&&& }&
374&&&&&&&& } catch (Exception e) {&
375&&&&&&&&&&&& isBroken =&
376&&&&&&&&&&&& LogContext.instance().warn(logger_failure, "failed:" + methodName, key, field, value, e);&
377&&&&&&&& } finally {&
378&&&&&&&&&&&& release(jedis, isBroken);&
379&&&&&&&& }&
380&&&&&&&&&
381&&&& }&
383&&&& public Long getIdentifyId(String identifyName ,String methodName) {&
384&&&&&&&& boolean isBroken =&
385&&&&&&&& Jedis jedis =&
386&&&&&&&& Long identify=&
387&&&&&&&& try {&
388&&&&&&&&&&&& jedis = this.getJedis();&
389&&&&&&&&&&&& if (jedis != null) {&
390&&&&&&&&&&&&&&&& jedis.select(getDBIndex());&
391&&&&&&&&&&&&&&&& identify = jedis.incr(identifyName);&
392&&&&&&&&&&&&&&&& if(identify==0){&
393&&&&&&&&&&&&&&&&&&&& return jedis.incr(identifyName);&
394&&&&&&&&&&&&&&&& }else {&
395&&&&&&&&&&&&&&&&&&&&&
396&&&&&&&&&&&&&&&& }&
397&&&&&&&&&&&& }&
398&&&&&&&& } catch (Exception e) {&
399&&&&&&&&&&&& isBroken =&
400&&&&&&&&&&&& LogContext.instance().warn(logger_failure, "failed:" + methodName, identifyName, "", identify, e);&
401&&&&&&&& } finally {&
402&&&&&&&&&&&& release(jedis, isBroken);&
403&&&&&&&& }&
404&&&&&&&&&
405&&&& }&
408&&&& /**&
409&&&&& * 删除某db的某个key值&
410&&&&& * @param key&
411&&&&& * @return&
412&&&&& */
413&&&& public Long delKeyFromJedis(String key) {&
414&&&&&&&& boolean isBroken =&
415&&&&&&&& Jedis jedis =&
416&&&&&&&& long result = 0;&
417&&&&&&&& try {&
418&&&&&&&&&&&& jedis = this.getJedis();&
419&&&&&&&&&&&& jedis.select(getDBIndex());&
420&&&&&&&&&&&& LogContext.instance().debug(logger_default, "succeed:delKeyFromJedis");&
421&&&&&&&&&&&& return jedis.del(key);&
422&&&&&&&& } catch (Exception e) {&
423&&&&&&&&&&&& isBroken =&
424&&&&&&&&&&&& LogContext.instance().warn(logger_failure, "failed:delKeyFromJedis", e);&
425&&&&&&&& } finally {&
426&&&&&&&&&&&& release(jedis, isBroken);&
427&&&&&&&& }&
428&&&&&&&&&
429&&&& }&
431&&&& /**&
432&&&&& * 根据dbIndex flushDB每个shard&
433&&&&& *&
434&&&&& * @param dbIndex&
435&&&&& */
436&&&& public void flushDBFromJedis(int dbIndex) {&
437&&&&&&&& Jedis jedis =&
438&&&&&&&& boolean isBroken =&
439&&&&&&&& try {&
440&&&&&&&&&&&& jedis = this.getJedis();&
441&&&&&&&&&&&& jedis.select(dbIndex);&
442&&&&&&&&&&&& jedis.flushDB();&
443&&&&&&&&&&&& LogContext.instance().debug(logger_default, "succeed:flushDBFromJedis");&
444&&&&&&&& } catch (Exception e) {&
445&&&&&&&&&&&& isBroken =&
446&&&&&&&&&&&& LogContext.instance().warn(logger_failure, "failed:flushDBFromJedis", e);&
447&&&&&&&& } finally {&
448&&&&&&&&&&&& release(jedis, isBroken);&
449&&&&&&&& }&
450&&&& }&
452&&&& public boolean existKey(String key, String methodName) {&
453&&&&&&&& Jedis jedis =&
454&&&&&&&& boolean isBroken =&
455&&&&&&&& try {&
456&&&&&&&&&&&& jedis = this.getJedis();&
457&&&&&&&&&&&& jedis.select(getDBIndex());&
458&&&&&&&&&&&& LogContext.instance().debug(logger_default, "succeed:"+methodName);&
459&&&&&&&&&&&& return jedis.exists(key);&
460&&&&&&&& } catch (Exception e) {&
461&&&&&&&&&&&& isBroken =&
462&&&&&&&&&&&& LogContext.instance().warn(logger_failure, "failed:"+methodName, e);&
463&&&&&&&& } finally {&
464&&&&&&&&&&&& release(jedis, isBroken);&
465&&&&&&&& }&
466&&&&&&&&&
467&&&& }&
浏览 21518
浏览: 281853 次
来自: 北京
请问那种图,uml图是怎么画出来的呢?是您自己手工画的,还是有 ...
client ?有一个参数是可以忽略一些URL 不进行验证登录 ...
好啊。。。。。}

我要回帖

更多关于 工行e时代卡有效期 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信