zoukankan      html  css  js  c++  java
  • Spring RedisTemplate操作-xml配置(1)

     网上没能找到全的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> 
      
  • 相关阅读:
    代码审计变成CTF
    updatexml()报错注入
    一道综合渗透题引发的updatexml()注入思考
    Visual Studio 调试技巧---指针,元素个数
    在Visual Studio中调试时,如何检查有关进程令牌的详细信息?
    在调试时,有什么更好的方法可以监视最后一个win32错误?
    从WinDbg中的转储查看操作系统版本和SP详细信息
    可以使用WinDbg将PE映像作为转储文件打开
    常见WinDbg问题及解决方案
    在崩溃转储中查找所有可能的上下文记录
  • 原文地址:https://www.cnblogs.com/aoeiuv/p/6760710.html
Copyright © 2011-2022 走看看