JedisPool pool = new JedisPool(poolConfig, IP, PORT, timeout);
public String set(String key,String value) {
Jedis jedis = null;
boolean success = true;
try {
jedis = this.pool.getResource();
return jedis.set(key, value);
}catch (JedisException e) {
success = false;
if(jedis != null){
//jedis异常,销毁
pool.returnBrokenResource(jedis);
}
throw e;
}catch (Exception e) {
system.out.println("jedis exception");
}finally{
if(success && jedis != null){
//需要还回给pool
this.pool.returnResource(jedis);
}
}
}

------------------------jedis序列化RedisSerializeUtil --------------

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class RedisSerializeUtil {
//序列化
public static byte[] serialize(Object object){
ObjectOutputStream objectOutputStream = null;
ByteArrayOutputStream byteArrayOutputStream = null;
try {
byteArrayOutputStream = new ByteArrayOutputStream();
objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeObject(object);
byte[] bytes = byteArrayOutputStream.toByteArray();
return bytes;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
// 反序列化
public static Object deSeialize(byte[] bytes) {
ByteArrayInputStream byteArrayOutputStream = null;
try {
byteArrayOutputStream = new ByteArrayInputStream(bytes);
ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayOutputStream);
return objectInputStream.readObject();
} catch (Exception e) {
system.out.println("deserialize exception"); }
return null;
}
public static void main(String[] args) {
String str = "tobytes";
System.out.print(RedisSerializeUtil.deSeialize(RedisSerializeUtil.serialize(str)));
}
}

Jedis Client的使用以及序列化的更多相关文章

  1. Jedis和JAVA对象的序列化和反序列化的使用

    1. Jedis版本: jedis-2.6.2.jar 背景:现在系统提供portal接口服务,使用JDBC直接查询数据库,使用jedis提供的缓存功能,在JDBC前面加上Redis,先从Redis中 ...

  2. jedis访问redis学习笔记

    最近在学习redis,在网上查了些文章,利用他人已有的知识,总结写下了这篇文章,大部分内容还是引用别人的文章内容.经过测试发现spring-data-redis现在有的版本只能支持reids 2.6和 ...

  3. springboot(七).springboot整合jedis实现redis缓存

    我们在使用springboot搭建微服务的时候,在很多时候还是需要redis的高速缓存来缓存一些数据,存储一些高频率访问的数据,如果直接使用redis的话又比较麻烦,在这里,我们使用jedis来实现r ...

  4. Jedis操作Redis实例

    简介 Jedis Client是Redis官网推荐的一个面向java客户端,库文件实现了对各类API进行封装调用. Jedis源码工程地址:https://github.com/xetorthio/j ...

  5. Redis客户端开发包:Jedis学习-高级应用

    事务 Jedis中事务的写法是将redis操作写在事物代码块中,如下所示,multi与exec之间为具体的事务. jedis.watch (key1, key2, ...); Transaction ...

  6. Jedis编程设计:连接池

        Jedis作为redis的最佳客户端,它提供了连接池的特性,"连接池"在通常情况下可以有效的提高应用的通信能力,并且这是一种良好的设计模式.Jedis的连接池设计基于apa ...

  7. redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool

    超时 Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: jav ...

  8. 使用Redis的Java客户端Jedis

    转载自:http://aofengblog.blog.163.com/blog/static/631702120147298317919/ 前一篇文章<Redis命令指南>讲解了通过命令行 ...

  9. [转载] 使用Redis的Java客户端Jedis

    转载自http://aofengblog.blog.163.com/blog/static/631702120147298317919/ 在实际的项目开发中,各种语言是使用Redis的客户端库来与Re ...

随机推荐

  1. 【Cocos2d-X开发学习笔记】第28期:游戏中音乐和音效的使用

    本系列学习教程使用的是cocos2d-x-2.1.4(最新版为3.0alpha0-pre) ,PC开发环境Windows7,C++开发环境VS2010 UI在游戏中占有很重要的地位,但吸引玩家的除了这 ...

  2. JS、JQury - 文本框内容改变事件

    例子: 效果: 前端代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="De ...

  3. 基于visual Studio2013解决面试题之0304镜像二叉树

     题目

  4. Python 生成的页面中文乱码问题

    第一 保证 程序源文件里的中文的编码格式,如我们把 源文件的编码设置成utf8的. reload(sys) sys.setdefaultencoding('utf-8') 第二, 告诉浏览器,我们须要 ...

  5. NYOJ 1066 CO-PRIME(数论)

    CO-PRIME 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描写叙述 This problem is so easy! Can you solve it? You are ...

  6. Qt之设置QWidget背景色(QStyleOption->drawPrimitive(QStyle::PE_Widget)方法比较有趣)

    QWidget是所有用户界面对象的基类,这意味着可以用同样的方法为其它子类控件改变背景颜色. Qt中窗口背景的设置,下面介绍三种方法. 1.使用QPalette2.使用Style Sheet3.绘图事 ...

  7. uva 357 Let Me Count The Ways(01背包)

    题目连接:357 - Let Me Count The Ways 题目大意:有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值. 解题思路:和uva674是一 ...

  8. EditTex属性

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tool ...

  9. #pragma 预处理指令详解

    源地址:http://blog.csdn.net/jx_kingwei/article/details/367312 #pragma  预处理指令详解              在所有的预处理指令中, ...

  10. Automatic logon configuration on Linux OS

    Automatic logon configuration on Linux OS 1. Regarding to DSA: a) ssh-keygen -t dsa  b) cat ~/.ssh/i ...