Spring整合redis
Redis  /  管理员 发布于 2年前   191
<dependencies><!-- Spring Data - Redis Library --><dependency><groupId>org.springframework.data</groupId><artifactId>spring-data-redis</artifactId><version>1.4.0.RELEASE</version></dependency><!-- Jedis Driver Library --><dependency><groupId>redis.clients</groupId><artifactId>jedis</artifactId><version>2.6.0</version></dependency><!-- Spring Core --><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>4.1.1.RELEASE</version></dependency> <!-- spring-data-redis --><dependency><groupId>org.springframework.data</groupId><artifactId>spring-data-redis</artifactId><version>1.4.1.RELEASE</version></dependency></dependencies>
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:p="http://www.springframework.org/schema/p"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"><!-- Scanning the Spring Beans --><context:component-scan base-package="com.ljn.beans"></context:component-scan> <bean id="propertyConfigurerRedis" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:redis.properties</value> </list> </property> </bean><bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"><property name="maxTotal" value="${redis.pool.maxTotal}" /><property name="maxIdle" value="${redis.pool.maxIdle}" /><property name="maxWaitMillis" value="${redis.pool.maxWaitMillis}" /></bean><!-- Redis Connection Factory --><bean id="jedisConnFactory"class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"><property name="hostName" value="${redis.ip}" /><property name="port" value="${redis.port}" /><property name="poolConfig" ref="jedisPoolConfig" /></bean><!-- Redis Template --><bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"p:connection-factory-ref="jedisConnFactory" /></beans>
redis.pool.maxTotal=1024redis.pool.maxIdle=200redis.pool.maxWaitMillis=3000redis.pool.testOnBorrow=trueredis.ip=10.75.201.3redis.port=63790
import org.springframework.beans.factory.annotation.Autowired;import org.springframework.data.redis.core.RedisTemplate;import org.springframework.stereotype.Component;@Componentpublic class RegistrationBean {@Autowiredprivate RedisTemplate<String,User> redisTemplate;public RedisTemplate<String, User> getRedisTemplate() {return redisTemplate;}public void setRedisTemplate(RedisTemplate<String, User> redisTemplate) {this.redisTemplate = redisTemplate;}}
RegistrationBean bean = (RegistrationBean)context.getBean("registrationBean");// Persisting Inside the Hash User objectbean.getRedisTemplate().opsForHash().put("{a}UserA", user.hashCode(),user);// Retrieving the User object from the Redis by using the suggested keyUser x = (User)bean.getRedisTemplate().opsForHash().get("{b}UserA", user.hashCode());System.out.println(x.getFullName());
user.setFullName("ljn"); bean.getRedisTemplate().opsForHash().put("{b}UserA", user.hashCode(),user); // Retrieving the User object from the Redis by using the suggested key User y = (User)bean.getRedisTemplate().opsForHash().get("{b}UserA", user.hashCode()); System.out.println(y.getFullName());
阿凡达123 在
golang 怎么做热更新中评论 也可以看看这个:https://github.com/edwingeng/hot..博主 在
hyperf框架常用命令-在centos7中退出命令及在docker容器中退出命令中评论 @路过的靓仔:cdn静态资源被墙,已修复..GGGGGGGGG 在
layui框架常用输入框介绍中评论 写的很好解决问题..路过的靓仔 在
hyperf框架常用命令-在centos7中退出命令及在docker容器中退出命令中评论 剩下好多 wait 状态的..激光豆芽 在
为什么你不能安逸?国内996为什么没有国外955香?中评论 国内现在无意义的内卷太多了..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号