zoukankan      html  css  js  c++  java
  • 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  相关使用
    }
    
  • 相关阅读:
    多层次子查询的sql执行顺序的问题
    RestTemplate不落地中转文件
    Gitbook从安装到使用【转】
    Linux离线安装依赖包技巧
    CentOS7 配置环境变量断开ssh后失效
    分页查询排序问题
    地图坐标的转换
    FeatureLayer图层的属性查询方式(query的使用方法)
    使用LayerView.effect进行点的高亮显示
    DQL + 排序
  • 原文地址:https://www.cnblogs.com/javaDeveloper/p/5410032.html
Copyright © 2011-2022 走看看