Spring整合redis
Redis  /  管理员 发布于 4年前   530
<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 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..路人 在
php中使用hyperf框架调用讯飞星火大模型实现国内版chatgpt功能示例中评论 教程很详细,如果加个前端chatgpt对话页面就完美了..Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号