Jedis Client的使用以及序列化
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的使用以及序列化的更多相关文章
- Jedis和JAVA对象的序列化和反序列化的使用
1. Jedis版本: jedis-2.6.2.jar 背景:现在系统提供portal接口服务,使用JDBC直接查询数据库,使用jedis提供的缓存功能,在JDBC前面加上Redis,先从Redis中 ...
- jedis访问redis学习笔记
最近在学习redis,在网上查了些文章,利用他人已有的知识,总结写下了这篇文章,大部分内容还是引用别人的文章内容.经过测试发现spring-data-redis现在有的版本只能支持reids 2.6和 ...
- springboot(七).springboot整合jedis实现redis缓存
我们在使用springboot搭建微服务的时候,在很多时候还是需要redis的高速缓存来缓存一些数据,存储一些高频率访问的数据,如果直接使用redis的话又比较麻烦,在这里,我们使用jedis来实现r ...
- Jedis操作Redis实例
简介 Jedis Client是Redis官网推荐的一个面向java客户端,库文件实现了对各类API进行封装调用. Jedis源码工程地址:https://github.com/xetorthio/j ...
- Redis客户端开发包:Jedis学习-高级应用
事务 Jedis中事务的写法是将redis操作写在事物代码块中,如下所示,multi与exec之间为具体的事务. jedis.watch (key1, key2, ...); Transaction ...
- Jedis编程设计:连接池
Jedis作为redis的最佳客户端,它提供了连接池的特性,"连接池"在通常情况下可以有效的提高应用的通信能力,并且这是一种良好的设计模式.Jedis的连接池设计基于apa ...
- redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
超时 Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: jav ...
- 使用Redis的Java客户端Jedis
转载自:http://aofengblog.blog.163.com/blog/static/631702120147298317919/ 前一篇文章<Redis命令指南>讲解了通过命令行 ...
- [转载] 使用Redis的Java客户端Jedis
转载自http://aofengblog.blog.163.com/blog/static/631702120147298317919/ 在实际的项目开发中,各种语言是使用Redis的客户端库来与Re ...
随机推荐
- ubuntu 安装maven提示出错 The program 'mvn' can be found in the following packages
问题: I am trying to install apache maven 3 in Ubuntu 12.04 lts. What I did was open the terminal then ...
- MsSqlServer bak文件数据导入
MsSqlServer bak文件数据导入 第一步首先在你的数据库中建立一个空数据库 选中新建的数据库 鼠标右键 任务 还原 数据库 这个时候会弹出这种一个框 之后选择原设备 会弹出 点击加入 找到 ...
- Python Base64转码解码
Python Base64 提供了好几种方法例如: encode, decode, encodestring, decodestring, b64encode, b64decode, standard ...
- Spring Boot Mongodb
Spring注解学习,有助于更好的理解下面代码: @ConditionOnClass表明该@Configuration仅仅在一定条件下才会被加载,这里的条件是Mongo.class位于类路径上 @En ...
- HK共享吧解压密码
HK共享吧解压密码 编号一:kIioOK9* 编号二:www.mfhk8.com_!h0jn3G+t@ 编号三:www.mfhk8.com_rz~NWjU)cZ 编号四:www.mfhk8.com_$ ...
- css Gradients(渐变)
渐变分为4类 1:线性渐变(Linear Gradients)- 向下/向上/向左/向右/对角方向 2:径向渐变(Radial Gradients)- 由它们的中心定义 3:对角渐变 4:角度渐变 以 ...
- REPLACE...IN.....WITH.... 的使用
REPLACE...IN.....WITH.... 的使用,例子用于改变alv的gt_fieldcat_alv LOOP AT gt_fieldcat_alv ASSIGNING <fs_f ...
- dm642在线写EPROM.txt
void wirteEPROM() { //#include <stdio.h> unsigned short bufeprom[30],i,val; FILE *fp; ...
- C++内存管理学习笔记(5)
/****************************************************************/ /* 学习是合作和分享式的! /* Auth ...
- python 多线程一(lock)
''' Created on Jun 17, 2013 @author: smp ''' #-*- coding:utf-8 -*- import threading import time coun ...