- 浏览: 67853 次
文章分类
最新评论
-
小色帝:
我是天才是打发
Jquery实现的Tabs页 -
小色帝:
小色帝 写道1111而温热
Jquery实现的Tabs页 -
小色帝:
1111而温热
Jquery实现的Tabs页
package com.paic.icorepnbs.web.util;
import com.paic.icorepnbs.common.util.LogUtils;
import com.paic.icorepnbs.common.util.SerializableUtil;
import com.paic.icorepnbs.common.util.StringUtils;
import java.util.Map;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.exceptions.JedisException;
public class RedisCacheServiceUtil
{
protected JedisPool jedisPool;
public static final String KEY_NAME_SEP = ":";
protected Jedis getJedis()
throws JedisException
{
Jedis jedis = null;
try {
jedis = this.jedisPool.getResource();
} catch (JedisException e) {
LogUtils.error("获取jedis连接异常", e, null, new Object[0]);
if (jedis != null)
this.jedisPool.returnBrokenResource(jedis);
throw e;
}
return jedis;
}
public void setObject(String key, Object object, int cacheSeconds)
{
Jedis jedis = null;
boolean isBroken = false;
try {
jedis = getJedis();
String storedKey = getRedisStoreKey(object.getClass(), key);
jedis.set(storedKey.getBytes("UTF-8"), SerializableUtil.serializable(object));
if (cacheSeconds >= 0)
jedis.expire(storedKey, cacheSeconds);
}
catch (Exception e) {
isBroken = true;
} finally {
release(jedis, isBroken);
}
}
protected String getRedisStoreKey(Class<?> clazz, String key)
{
StringBuffer keyBuffer = new StringBuffer(clazz.getName()).append(":").append(key);
return keyBuffer.toString();
}
public String getStringValue(String key)
{
String value = null;
Jedis jedis = null;
try {
jedis = getJedis();
if (jedis.exists(key).booleanValue()) {
value = jedis.get(key);
value = ((StringUtils.isNotBlank(value)) && (!("nil".equalsIgnoreCase(value)))) ? value : null;
}
}
catch (Exception e) {
LogUtils.error("InternetRquestAstrictFilter--->get异常", e, null, new Object[0]);
}
finally {
}
return value;
}
public Object getObject(String key, Class<?> clazz)
{
Jedis jedis = null;
boolean isBroken = false;
Object obj = null;
try {
jedis = getJedis();
String storedKey = getRedisStoreKey(clazz, key);
byte[] bytes = jedis.get(storedKey.getBytes("UTF-8"));
obj = SerializableUtil.deSerializable(bytes);
} catch (Exception e) {
isBroken = true;
} finally {
release(jedis, isBroken);
}
return obj;
}
public void setHashField(String redisKey, String itemKey, String value)
{
boolean isBroken = false;
Jedis jedis = null;
try {
jedis = getJedis();
jedis.hset(redisKey, itemKey, value);
} catch (JedisException e) {
isBroken = true;
LogUtils.error("redis执行失败", e, null, new Object[0]);
} finally {
release(jedis, isBroken);
}
}
public void setHashMap(String key, Map<String, String> map, int cacheSeconds)
{
boolean isBroken = false;
Jedis jedis = null;
if ((map != null) && (map.size() > 0))
try {
jedis = getJedis();
jedis.hmset(key, map);
if (cacheSeconds >= 0)
jedis.expire(key, cacheSeconds);
}
catch (JedisException e) {
isBroken = true;
LogUtils.error("redis执行失败,setHashMap(" + key + "," + map.toString() + "," + cacheSeconds + ")", e, null, new Object[0]);
}
finally
{
release(jedis, isBroken);
}
}
public Map<String, String> getHashMapByKey(String key)
{
boolean isBroken = false;
Jedis jedis = null;
Map valueMap = null;
try {
jedis = getJedis();
valueMap = jedis.hgetAll(key);
} catch (JedisException e) {
isBroken = true;
LogUtils.error("redis执行失败,getHashMapByKey(" + key + ")", e, null, new Object[0]);
} finally {
release(jedis, isBroken);
}
return valueMap;
}
public String getItemFromMap(String redisKey, String itemKey)
{
boolean isBroken = false;
Jedis jedis = null;
String result = "";
try {
jedis = getJedis();
result = jedis.hget(redisKey, itemKey);
} catch (JedisException e) {
isBroken = true;
LogUtils.error("redis执行失败,getItemFromMap", e, null, new Object[0]);
} finally {
release(jedis, isBroken);
}
return result;
}
public long removeItemFromHashMap(String redisKey, String itemKey)
{
boolean isBroken = false;
Jedis jedis = null;
try {
jedis = getJedis();
long l = jedis.hdel(redisKey, new String[] { itemKey }).longValue();
return l;
}
catch (JedisException e)
{
isBroken = true;
LogUtils.error("redis执行失败,removeItemFormHashMap(" + redisKey + "," + itemKey + ")", e, null, new Object[0]);
}
finally {
release(jedis, isBroken);
}
return 0L;
}
public void setString(String key, String value, int cacheSeconds)
{
Jedis jedis = null;
boolean isBroken = false;
try {
jedis = getJedis();
jedis.set(key, value);
if (cacheSeconds >= 0)
jedis.expire(key, cacheSeconds);
}
catch (JedisException e) {
isBroken = true;
LogUtils.error("redis执行失败;" + key + ":" + value, e, null, new Object[0]);
} finally {
release(jedis, isBroken);
}
}
public long deleteJedisByKey(String key)
{
boolean isBroken = false;
Jedis jedis = null;
try {
jedis = getJedis();
long l = jedis.del(key).longValue();
return l;
}
catch (Exception e)
{
isBroken = true;
LogUtils.error("redis执行,移除key:" + key + ",失败。", e, null, new Object[0]);
} finally {
release(jedis, isBroken);
}
return 0L;
}
public boolean existKey(String key)
{
Jedis jedis = null;
boolean isBroken = false;
try {
jedis = getJedis();
boolean bool1 = jedis.exists(key).booleanValue();
return bool1;
}
catch (Exception e)
{
isBroken = true;
LogUtils.error("existKey异常!", e, null, new Object[0]);
} finally {
release(jedis, isBroken);
}
return false;
}
public Long expire(String key, int seconds)
{
Long result = null;
boolean isBroken = false;
Jedis jedis = null;
try {
jedis = getJedis();
result = jedis.expire(key, seconds);
} catch (Exception e) {
isBroken = true;
LogUtils.error("expire异常:", e, null, new Object[0]);
} finally {
release(jedis, isBroken);
}
return result;
}
public void release(Jedis jedis, boolean isBroken) {
if (jedis != null)
if (isBroken)
this.jedisPool.returnBrokenResource(jedis);
else
this.jedisPool.returnResource(jedis);
}
public void setJedisPool(JedisPool jedisPool)
{
this.jedisPool = jedisPool;
}
}
import com.paic.icorepnbs.common.util.LogUtils;
import com.paic.icorepnbs.common.util.SerializableUtil;
import com.paic.icorepnbs.common.util.StringUtils;
import java.util.Map;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.exceptions.JedisException;
public class RedisCacheServiceUtil
{
protected JedisPool jedisPool;
public static final String KEY_NAME_SEP = ":";
protected Jedis getJedis()
throws JedisException
{
Jedis jedis = null;
try {
jedis = this.jedisPool.getResource();
} catch (JedisException e) {
LogUtils.error("获取jedis连接异常", e, null, new Object[0]);
if (jedis != null)
this.jedisPool.returnBrokenResource(jedis);
throw e;
}
return jedis;
}
public void setObject(String key, Object object, int cacheSeconds)
{
Jedis jedis = null;
boolean isBroken = false;
try {
jedis = getJedis();
String storedKey = getRedisStoreKey(object.getClass(), key);
jedis.set(storedKey.getBytes("UTF-8"), SerializableUtil.serializable(object));
if (cacheSeconds >= 0)
jedis.expire(storedKey, cacheSeconds);
}
catch (Exception e) {
isBroken = true;
} finally {
release(jedis, isBroken);
}
}
protected String getRedisStoreKey(Class<?> clazz, String key)
{
StringBuffer keyBuffer = new StringBuffer(clazz.getName()).append(":").append(key);
return keyBuffer.toString();
}
public String getStringValue(String key)
{
String value = null;
Jedis jedis = null;
try {
jedis = getJedis();
if (jedis.exists(key).booleanValue()) {
value = jedis.get(key);
value = ((StringUtils.isNotBlank(value)) && (!("nil".equalsIgnoreCase(value)))) ? value : null;
}
}
catch (Exception e) {
LogUtils.error("InternetRquestAstrictFilter--->get异常", e, null, new Object[0]);
}
finally {
}
return value;
}
public Object getObject(String key, Class<?> clazz)
{
Jedis jedis = null;
boolean isBroken = false;
Object obj = null;
try {
jedis = getJedis();
String storedKey = getRedisStoreKey(clazz, key);
byte[] bytes = jedis.get(storedKey.getBytes("UTF-8"));
obj = SerializableUtil.deSerializable(bytes);
} catch (Exception e) {
isBroken = true;
} finally {
release(jedis, isBroken);
}
return obj;
}
public void setHashField(String redisKey, String itemKey, String value)
{
boolean isBroken = false;
Jedis jedis = null;
try {
jedis = getJedis();
jedis.hset(redisKey, itemKey, value);
} catch (JedisException e) {
isBroken = true;
LogUtils.error("redis执行失败", e, null, new Object[0]);
} finally {
release(jedis, isBroken);
}
}
public void setHashMap(String key, Map<String, String> map, int cacheSeconds)
{
boolean isBroken = false;
Jedis jedis = null;
if ((map != null) && (map.size() > 0))
try {
jedis = getJedis();
jedis.hmset(key, map);
if (cacheSeconds >= 0)
jedis.expire(key, cacheSeconds);
}
catch (JedisException e) {
isBroken = true;
LogUtils.error("redis执行失败,setHashMap(" + key + "," + map.toString() + "," + cacheSeconds + ")", e, null, new Object[0]);
}
finally
{
release(jedis, isBroken);
}
}
public Map<String, String> getHashMapByKey(String key)
{
boolean isBroken = false;
Jedis jedis = null;
Map valueMap = null;
try {
jedis = getJedis();
valueMap = jedis.hgetAll(key);
} catch (JedisException e) {
isBroken = true;
LogUtils.error("redis执行失败,getHashMapByKey(" + key + ")", e, null, new Object[0]);
} finally {
release(jedis, isBroken);
}
return valueMap;
}
public String getItemFromMap(String redisKey, String itemKey)
{
boolean isBroken = false;
Jedis jedis = null;
String result = "";
try {
jedis = getJedis();
result = jedis.hget(redisKey, itemKey);
} catch (JedisException e) {
isBroken = true;
LogUtils.error("redis执行失败,getItemFromMap", e, null, new Object[0]);
} finally {
release(jedis, isBroken);
}
return result;
}
public long removeItemFromHashMap(String redisKey, String itemKey)
{
boolean isBroken = false;
Jedis jedis = null;
try {
jedis = getJedis();
long l = jedis.hdel(redisKey, new String[] { itemKey }).longValue();
return l;
}
catch (JedisException e)
{
isBroken = true;
LogUtils.error("redis执行失败,removeItemFormHashMap(" + redisKey + "," + itemKey + ")", e, null, new Object[0]);
}
finally {
release(jedis, isBroken);
}
return 0L;
}
public void setString(String key, String value, int cacheSeconds)
{
Jedis jedis = null;
boolean isBroken = false;
try {
jedis = getJedis();
jedis.set(key, value);
if (cacheSeconds >= 0)
jedis.expire(key, cacheSeconds);
}
catch (JedisException e) {
isBroken = true;
LogUtils.error("redis执行失败;" + key + ":" + value, e, null, new Object[0]);
} finally {
release(jedis, isBroken);
}
}
public long deleteJedisByKey(String key)
{
boolean isBroken = false;
Jedis jedis = null;
try {
jedis = getJedis();
long l = jedis.del(key).longValue();
return l;
}
catch (Exception e)
{
isBroken = true;
LogUtils.error("redis执行,移除key:" + key + ",失败。", e, null, new Object[0]);
} finally {
release(jedis, isBroken);
}
return 0L;
}
public boolean existKey(String key)
{
Jedis jedis = null;
boolean isBroken = false;
try {
jedis = getJedis();
boolean bool1 = jedis.exists(key).booleanValue();
return bool1;
}
catch (Exception e)
{
isBroken = true;
LogUtils.error("existKey异常!", e, null, new Object[0]);
} finally {
release(jedis, isBroken);
}
return false;
}
public Long expire(String key, int seconds)
{
Long result = null;
boolean isBroken = false;
Jedis jedis = null;
try {
jedis = getJedis();
result = jedis.expire(key, seconds);
} catch (Exception e) {
isBroken = true;
LogUtils.error("expire异常:", e, null, new Object[0]);
} finally {
release(jedis, isBroken);
}
return result;
}
public void release(Jedis jedis, boolean isBroken) {
if (jedis != null)
if (isBroken)
this.jedisPool.returnBrokenResource(jedis);
else
this.jedisPool.returnResource(jedis);
}
public void setJedisPool(JedisPool jedisPool)
{
this.jedisPool = jedisPool;
}
}
发表评论
-
c3p0代码动态切换数据源
2018-08-06 17:54 1074public class PARPDatasource imp ... -
sql 优化开多个线程跑
2018-07-11 09:54 678select /*+ parallel(8) */ * fr ... -
redis 事物限制频率和获得令牌
2018-07-11 02:50 926package com.dongnaoedu.tony.ser ... -
Redis分布式锁解决抢购问题
2018-07-11 02:39 1327废话不多说,首先分享一个业务场景-抢购。一个典型的高并发问题, ... -
StringWriter 接收异常信息
2018-07-05 18:42 444try { int a=1/0; } catch (E ... -
jedis 操作redis
2018-06-26 09:13 369//连接redis ,redis的默认端口是6379 Je ... -
多线程缓存优化思想
2018-06-06 15:33 3621.背景 题库 随机生成N张试卷,每张试卷M个题目,每个题目要 ... -
网络编程之使用HttpClient批量上传文件
2018-05-28 01:12 541网络编程之使用HttpClient批量上传文件(一) 2014 ... -
oracle 正则表达式 替换 ‘’:
2018-05-18 18:04 579select /*+ parallel(8) */ t.na ... -
java web 导出 下拉 excle
2018-05-15 17:03 457@RequestMapping(value = "/ ... -
Java Socket编程
2016-12-28 23:28 339对于Java Socket编程而言,有两个概念,一个是Serv ... -
Java多线程学习(吐血超详细总结)
2016-12-27 17:15 415目录(?)[-] 1.一扩展javalangThread类 2 ... -
JAVA多线程实现的三种方式
2016-12-27 17:16 418Java多线程实现方式主要有三种:继承Thread类、实现Ru ... -
Maven 入门菜鸟教程
2016-12-02 10:02 1175学习maven的使用,看到一篇很实用的入门教程(菜鸟级入门) ... -
Java 读写Properties配置文件
2016-08-22 15:00 402Java 读写Properties配置文件 1.Pro ... -
JAVA前端与后端参数传递方法小结
2016-07-26 10:54 46561,从Action中传值到JSP页面的方法 ①在Actio ... -
苟富贵
2013-02-25 09:43 0额梵蒂冈过v梵蒂冈北方多汇报地方环保 -
Request的getParameter和getAttribute方法的区别
2013-01-22 10:01 649HttpServletRequest.getParameter ... -
Eclipse快捷键小结
2012-12-26 11:26 735Eclipse快捷键小结 Eclipse ... -
JAVA去空格
2012-12-20 16:53 652String ccc=” he l l o , w o r l ...
相关推荐
ta_lib-0.5.1-cp312-cp312-win32.whl
课程设计 在线实时的斗兽棋游戏,时间赶,粗暴的使用jQuery + websoket 实现实时H5对战游戏 + java.zip课程设计
ta_lib-0.5.1-cp310-cp310-win_amd64.whl
基于springboot+vue物流系统源码数据库文档.zip
GEE训练教程——Landsat5、8和Sentinel-2、DEM和各2哦想指数下载
知识图谱
333498005787635解决keil下载失败的文件.zip
【微信机器人原理与实现】 微信机器人是通过模拟微信客户端的行为,自动处理消息、发送消息的程序。在Python中实现微信机器人的主要库是WeChatBot,它提供了丰富的接口,允许开发者方便地进行微信消息的接收与发送。这个项目标题中的"基于python实现的微信机器人源码"指的是使用Python编程语言编写的微信机器人程序。 1. **Python基础**:Python是一种高级编程语言,以其简洁的语法和强大的功能深受开发者喜爱。在实现微信机器人时,你需要熟悉Python的基本语法、数据类型、函数、类以及异常处理等概念。 2. **微信API与WeChatBot库**:微信为开发者提供了微信公共平台和微信开放平台,可以获取到必要的API来实现机器人功能。WeChatBot库是Python中一个用于微信开发的第三方库,它封装了微信的API,简化了消息处理的流程。使用WeChatBot,开发者可以快速搭建起一个微信机器人。 3. **微信OAuth2.0授权**:为了能够接入微信,首先需要通过OAuth2.0协议获取用户的授权。用户授权后,机器人可以获取到微信用户的身份信息,从而进行
基于springboot实验室研究生信息管理系统源码数据库文档.zip
张力控制,色标跟踪,多轴同步,电子凸轮,横切等工艺控制案例。
在Python编程环境中,处理Microsoft Word文档是一项常见的任务。Python提供了几个库来实现这一目标,如`python-docx`,它可以让我们创建、修改和操作.docx文件。本教程将重点介绍如何利用Python进行Word文档的合并、格式转换以及转换为PDF。 1. **合并Word文档(merge4docx)** 合并多个Word文档是一项实用的功能,特别是在处理大量报告或文档集合时。在Python中,可以使用`python-docx`库实现。我们需要导入`docx`模块,然后读取每个文档并将其内容插入到主文档中。以下是一个基本示例: ```python from docx import Document def merge4docx(file_list, output_file): main_doc = Document() for file in file_list: doc = Document(file) for paragraph in doc.paragraphs: main_doc.add_paragraph(paragraph.text) m
基于springboot+Javaweb的二手图书交易系统源码数据库文档.zip
基于springboot餐品美食论坛源码数据库文档.zip
基于springboot亚运会志愿者管理系统源码数据库文档.zip
使用WPF的数据样式绑定,切换对象数据值来完成控件动态切换背景渐变动画效果。 使用动画样式渲染比线程修改性能消耗更低更稳定
基于SpringBoot的企业客源关系管理系统源码数据库文档.zip
基于springboot+vue的桂林旅游网站系统源码数据库文档.zip
基于springboot嗨玩旅游网站源码数据库文档.zip
基于springboot的流浪动物管理系统源码数据库文档.zip
基于springboot课件通中小学教学课件共享平台源码数据库文档.zip