• spring 配置 redis


    1.maven相关pom.xml

    <dependencies>
    
            <!--spring redis-->
            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-redis</artifactId>
                <version>1.6.0.RELEASE</version>
            </dependency>
     
            <!--client 配置-->
            <dependency>
                <groupId>redis.clients</groupId>
                <artifactId>jedis</artifactId>
                <version>2.7.3</version>
            </dependency>
    </dependencies>
    

    2.application_context.xml相关配置

    	<bean id="jedisConfig" class="redis.clients.jedis.JedisPoolConfig">
    		<property name="maxTotal" value="300"/>
    		<property name="maxIdle" value="100"/>
    		<property name="maxWaitMillis" value="10000"/>
    		<property name="testOnBorrow" value="true"/>
    	</bean>
    
    	<bean id="jedisConnFactory"
    		  class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
    		  p:usePool="true" p:hostName="${host}" p:password="${password}" c:poolConfig-ref="jedisConfig"/>
    
    	<!-- redis template definition -->
    	<bean id="redisTemplate"
    		  class="org.springframework.data.redis.core.RedisTemplate"
    		  p:connectionFactory-ref="jedisConnFactory">
    		<property name="keySerializer">
    			<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
    		</property>
    		<property name="valueSerializer">
    			<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
    		</property>
    		<property name="hashKeySerializer">
    			<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
    		</property>
    		<property name="hashValueSerializer">
    			<bean class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>
    		</property>
    	</bean>
    

    3.相关调用

    @Service("sessionService")
    public class SessionService {
    
        @Autowired
        private RedisTemplate<String, Map<String, Object>> redisTemplate;
    
        //todo redisTemplate  相关使用
    }
    
  • 相关阅读:
    输出控制符的详解
    printf函数的讲解
    关于字节、Ascll码、字符的存储的讲解
    1.2
    1.1
    OS模块学习笔记
    time时间模块总结
    编译py为exe
    python计算excel平均值和标准差
    Python与Excel交互--Xlwings
  • 原文地址:https://www.cnblogs.com/javaDeveloper/p/5410032.html
Copyright © 2020-2023  润新知