Redis工作笔记-spring整合jedis
目录
概念
代码与实例
概念
这里,一般都是用jedis去搞项目,而不是用spring自带的。
主要是xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"><!-- Spring聚合配置 --><context:property-placeholder location="redis.properties" /><bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig"><property name="maxTotal" value="${redis.maxTotal}" /><property name="maxIdle" value="${redis.maxIdle}" /><property name="minIdle" value="${redis.minIdle}" /></bean><bean id="jedisPool" class="redis.clients.jedis.JedisPool"><constructor-arg name="poolConfig" ref="poolConfig" /><constructor-arg name="host" value="${redis.host}" /><constructor-arg name="port" value="${redis.port}" /><constructor-arg name="timeout" value="${redis.timeout}" /><constructor-arg name="password" value="${redis.password}" /></bean><bean class="redisutil.demo.utils.SpringBeanHolder" /></beans>
Bean加载如下:
package redisutil.demo.utils;import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;public class SpringBeanHolder implements ApplicationContextAware {private static ApplicationContext ac;@Overridepublic void setApplicationContext(ApplicationContext applicationContext) throws BeansException {ac = applicationContext;}public static Object getBean(String beanName){return ac.getBean(beanName);}public static<T> T getBean(Class<T> clazz){return ac.getBean(clazz);}
}
代码与实例
程序运行截图如下:
Redis运行截图如下:
添加了数据后:
另外的数据:
工具类如下:
package redisutil.demo.utils;import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;public class RedisUtils {private static JedisPool jedisPool = null;static {jedisPool = (JedisPool)SpringBeanHolder.getBean("jedisPool");}public static void set(String key, String value){Jedis jedis = null;try {if(jedis == null){jedis = jedisPool.getResource();jedis.set(key, value);}}catch (Exception e){e.printStackTrace();}finally {jedis.close();}}public static void set(String key, String value, int expireTime){Jedis jedis = null;try {if(jedis == null){jedis = jedisPool.getResource();jedis.set(key, value);jedis.expire(key, expireTime);}}catch (Exception e){e.printStackTrace();}finally {jedis.close();}}public static String get(String key, String value){return null;}}
源码打包下载地址:
https://github.com/fengfanchen/Java/tree/master/RedisUtil
Redis工作笔记-spring整合jedis相关推荐
- RabbitMQ,RabbitMQ 的工作模式,Spring 整合 RabbitMQ,Springboot 整合RabbitMQ
什么是RabbitMQ 1.1 MQ概述 MQ全称 Message Queue(消息队列),是在消息的传输过程中保存消息的容器.多用于分布式系统之间进行通信. ⚫ MQ,消息队列,存储消息的中间件 ⚫ ...
- Java工作笔记-Spring Boot封装Jedis实例
目录 基本概念 代码与实例 源码下载 基本概念 SpringBoot提供了一套Redis接口,但个人感觉没Jedis方便(可能是因为本人比较菜的原因吧) 在此封装了相爱Jedis,在部署的时候,同样可 ...
- Redis工作笔记-Jedis的基本使用
目录 使用前的配置 操作 使用前的配置 把conf文件里面绑定去掉,以及保护关闭就可以了: 下面是注释掉bind 操作 pom.xml配置如下: <?xml version="1.0& ...
- spring整合jedis(单节点)
文章目录 1 场景 1.1 版本说明 1.2 代码地址 1.3 项目结构 2 整合步骤 2.1 配置maven依赖 2.2 配置redis配置文件 2.3 引入redis配置文件 2.4 spring ...
- Spring模板对象之RedisTemplate(Spring整合jedis)
Spring模板对象之RedisTemplate 构建maven项目 pom <?xml version="1.0" encoding="UTF-8"?& ...
- Redis工作笔记-spring-data-redis的基本使用
目录 spring 操作 spring 这里使用spring-data-redis,来操作Redis,主要是通过spring来操作的,maven操作如下: pom.xml <?xml versi ...
- camunda视频教程_【Camunda工作流(1)工作笔记:SpringBoot整合Camunda】
Camunda BPM 与 Spring Boot 集成示例 本示例是根据 camunda.org官网Spring Boot集成入门指引创建的. github地址:https://github.com ...
- Java工作笔记-Spring boot中配置文件加密(Jasypt的使用)
Jasypt Spring Boot提供了Spring Boot应用程序配置文件的加密.有下面3种方式在项目中集成jasypt-spring-boot: 1. 在classpath中添加jasypt- ...
- Java工作笔记-Spring Boot中使用Mybatis操作达梦数据库
这里以达梦数据库为例,使用MyBatis对数据库进行增删改查 这里先给出截图 此处为了简单,直接在Controller里面调用dao中数据: 关键代码如下: application.propertie ...
最新文章
- 中国HBase技术社区第一届Meetup资料大合集
- 在全面部署 IPV6 前,你需要了解都在这儿
- windows 远程登录用户管理
- 利用TortoiseSVN获取最新版本的OpenCV源码
- Qt Creator在3D编辑器中工作
- 电脑任务栏跑到右边去了_浙江电脑硬盘维修收费标准,请看
- Python学习week7-文件路径操作
- 【大会】AI能解决哪些问题?
- 【mysql】mysql优化
- Maven私服的简单搭建教程(Nexus)
- node 获取mysql数据类型,node连接mysql获取数据
- Mysql update 使用join更新字段
- 贾跃亭致信债权人:将努力打工还债,请相信我!
- 用于对Compound协议进行无Gas投票和委托的社区工具发布
- RestTemplate异常no suitable HttpMessageConverter found for request type [java.lang.Integer]
- 快速搭建一个端对端加密的在线聊天室
- 苹果id无法登陆_英雄联盟手游苹果id怎么绑定拳头账号?绑定教程介绍[图]-攻略...
- 合天网安的渗透测试考核过程
- Java电商秒杀系统性能优化(八)——流量削峰技术-削峰填谷之神级操作
- JAVA IO流(内存流、管道流、打印流)
热门文章
- JAVA API 中文版
- InstallShield 2011正式发布
- 手把手教你用C语言画“心”!
- Node.js 和 Python之间如何进行选择?教你一招搞定
- 第五节:简单又强大的数据类型:any任意值
- thinkphp5范围查询_ThinkPHP 区间查询
- python文件按行读取变为嵌套列表_迭代两个嵌套的2D列表,其中list2具有list1的行号...
- 64位游戏找call_网络小游戏怎么修改技能满级,满血?教大家一个很简单的修改方法!...
- Adonis结果P值小于0.05,一定代表两组样品物种构成差异显著吗?
- 复现Cell附图 |类器官的单细胞分析