网上没能找到全的spring redistemplate操作例子,故特意化了点时间做了接口调用练习,基本包含了所有redistemplate方法。

该操作例子是个系列,该片为spring xml配置,方便后面做各个数据类型的操作。

Redis是一个开源(BSD许可),内存存储的数据结构服务器,可用作数据库,高速缓存和消息队列代理。它支持字符串、哈希表、列表、集合、有序集合,位图,hyperloglogs等数据类型。内置复制、Lua脚本、LRU收回、事务以及不同级别磁盘持久化功能,同时通过Redis Sentinel提供高可用,通过Redis Cluster提供自动分区。

<context:annotation-config />

    <!-- 把非@Controller注解的类转换为bean -->
<context:component-scan base-package="tk.tankpao" /> <cache:annotation-driven /> <context:property-placeholder
location="classpath:conf/properties/redis.properties" /> <aop:aspectj-autoproxy proxy-target-class="true"/> <!-- jedis 配置 -->
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="${redis.maxIdle}" />
<property name="maxWaitMillis" value="${redis.maxWait}" />
<property name="maxTotal" value="${redis.maxActive}" />
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
</bean> <!-- redis服务器中心 -->
<bean id="redisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="poolConfig" ref="poolConfig" />
<property name="port" value="${redis.port}" />
<property name="hostName" value="${redis.host}" />
<property name="password" value="${redis.password}" />
<property name="timeout" value="${redis.timeout}"></property>
</bean> <bean id="redisTemplate" name="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="redisConnectionFactory" />
<property name="keySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="jackson2JsonRedisSerializer" />
<!-- <property name="enableTransactionSupport" value="true"/> -->
</bean> <bean id="jdkredisTemplate" name="jdkredisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="redisConnectionFactory" />
<property name="keySerializer" ref="jdkSerializationRedisSerializer" />
<property name="valueSerializer" ref="jdkSerializationRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="jackson2JsonRedisSerializer" />
</bean> <bean id="jacksonredisTemplate" name="jacksonredisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="redisConnectionFactory" />
<property name="keySerializer" ref="jackson2JsonRedisSerializer" />
<property name="valueSerializer" ref="jackson2JsonRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="hashValueSerializer" ref="jackson2JsonRedisSerializer" />
</bean> <bean id="stringRedisSerializer"
class="org.springframework.data.redis.serializer.StringRedisSerializer" />
<bean id="jackson2JsonRedisSerializer"
class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer" />
<bean id="jdkSerializationRedisSerializer"
class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" /> <!-- 配置缓存 -->
<bean id="cacheManager" class="org.springframework.data.redis.cache.RedisCacheManager">
<constructor-arg ref="jdkredisTemplate" />
</bean> <bean id="topicContainer" class="org.springframework.data.redis.listener.RedisMessageListenerContainer" destroy-method="destroy">
<property name="connectionFactory" ref="redisConnectionFactory"/>
<property name="messageListeners">
<map>
<entry key-ref="sub">
<bean class="org.springframework.data.redis.listener.ChannelTopic">
<constructor-arg value="dddchannel"/>
</bean>
</entry>
<entry key-ref="sub2">
<bean class="org.springframework.data.redis.listener.ChannelTopic">
<constructor-arg value="dddchannel"/>
</bean>
</entry>
<entry key-ref="sub3">
<bean class="org.springframework.data.redis.listener.ChannelTopic">
<constructor-arg value="cccchannel"/>
</bean>
</entry>
</map>
</property>
</bean>
  

Spring RedisTemplate操作-xml配置(1)的更多相关文章

  1. Spring IOC-基于XML配置的容器

    Spring IOC-基于XML配置的容器 我们先分析一下AbstractXmlApplicationContext这个容器的加载过程. AbstractXmlApplicationContext的老 ...

  2. Spring 入门 web.xml配置详解

    Spring 入门 web.xml配置详解 https://www.cnblogs.com/cczz_11/p/4363314.html https://blog.csdn.net/hellolove ...

  3. spring之pom.xml配置

    spring之pom.xml配置 <?xml version="1.0" encoding="UTF-8"?> <project xmlns= ...

  4. 这一次搞懂Spring Web零xml配置原理以及父子容器关系

    前言 在使用Spring和SpringMVC的老版本进行开发时,我们需要配置很多的xml文件,非常的繁琐,总是让用户自行选择配置也是非常不好的.基于约定大于配置的规定,Spring提供了很多注解帮助我 ...

  5. Spring Ioc容器xml配置

    Spring Ioc容器xml配置基本结构: <?xml version="1.0" encoding="UTF-8"?> <beans xm ...

  6. Spring 使用AOP——xml配置

    目录 AOP介绍 Spring进行2种实现AOP的方式 导入jar包 基于schema-based方式实现AOP 创建前置通知 创建后置通知 修改Spring配置文件 基于schema-based方式 ...

  7. Spring AOP之xml 配置实现

    首先这个配置模式估计现在已经不用了,因为我在我们公司的项目里面并没有看到这么配置AOP相关的东西.不过,这个就和学习spring的控制反转(IOC)和依赖注入(DI)一样,刚刚开始的时候,都是从简单的 ...

  8. 关于Spring中applicationContext.xml配置错误“org/springframework/transaction/interceptor/TransactionInterceptor”的问题解决

    问题描述: 在配置spring的applicationContext.xml中的默认事务管理器的时候可能会出现这样的错误: Error occured processing XML 'org/spri ...

  9. Spring学习之xml配置Bean总结

    学习Spring时,我用的是Maven来管理jar包,先看看maven的pom.xml: pom.xml <project xmlns="http://maven.apache.org ...

随机推荐

  1. vs2017 用 nuget发布包时报错

    安装了 vs2017后, 发布nuget 时报错: Failed to load msbuild Toolset 未能加载文件或程序集"Microsoft.Build, Version=14 ...

  2. harbor使用和管理

    一.上传本地镜像到harbor中 先在harbor 中创建testdocker 项目 因为我们本地没有镜像,我们先拉取一个镜像,然后进行下面的操作 查看nginx 镜像 2.下载nginx镜像到本地 ...

  3. Android 测试之Monkey

    一.什么是Monkey Monkey是Android中的一个命令行工具,可以运行在模拟器里或实际设备中.它向系统发送伪随机的用户事件流(如按键输入.触摸屏输入.手势输入等),实现对正在开发的应用程序进 ...

  4. Mabatis中#{}和${}的区别

    动态 sql 是 mybatis 的主要特性之一,在 mapper 中定义的参数传到 xml 中之后,在查询之前 mybatis 会对其进行动态解析.mybatis 为我们提供了两种支持动态 sql ...

  5. Data Plane

    2015-2018,部分关于SDN数据平面的故障恢复文献粗读 SHEAR: A highly available and flexible network architecture marrying ...

  6. Linux命令(十八) 压缩或解压缩文件和目录 gzip gunzip

    目录 1.命令简介 2.常用参数介绍 3.实例 4.直达底部 命令简介 和 zip 命令类似,gzip 用于文件的压缩,gzip压缩后的文件扩展名为 ".gz",gzip默认压缩后 ...

  7. dx、aapt工具

    1.DX命令: Dalvik虚拟机不能直接运行Java代码编译出来的文件,只能运行.dex文件,所以需要将.class,.jar等文件通过DX工具转换成.dex文件. 2.AAPT命令 一个Andro ...

  8. Bootstrap中datetimepicker日期控件1899年问题解决

    Bootstrap中datetimepicker日期控件1899年问题解决 最近在开发项目的过程中,遇到一个很尴尬的问题.我们项目一直采用的是angular+bootstrap,日期控件用的是boot ...

  9. 利用Attribute和IErrorHandler处理WCF全局异常

    在处理WCF异常的时候,有大概几种方式: 第一种是在配置文件中,将includeExceptionDetailInFaults设置为true <behavior name="servi ...

  10. 【刷题】LOJ 6122 「网络流 24 题」航空路线问题

    题目描述 给定一张航空图,图中顶点代表城市,边代表两个城市间的直通航线.现要求找出一条满足下述限制条件的且途经城市最多的旅行路线. 从最西端城市出发,单向从西向东途经若干城市到达最东端城市,然后再单向 ...