Spring Data Redis快速使用
2017-07-12 12:58
399 查看
Spring Data Redis的快速使用
官网地址:http://projects.spring.io/spring-data-redis/
快速使用分三步:
1. 引用获取
The recommended way to get started using spring-data-redis in your project is with a dependency management system – the snippet below can be copied and pasted into your build. Need help? See our getting started guides on building with Maven and Gradle.
初始使用 spring-data-redis,建议在你的应用中使用一个依赖管理系统,这样你就可以直接粘贴下面的内容到你的工程来使用。如果需要另外的帮助,请查看我们利用Maven 和 Gradle创建的指导。
2. 配置RedisTemplete
3. 注入并使用 RedisTemplate 或其他 opsForX()实例
官网地址:http://projects.spring.io/spring-data-redis/
快速使用分三步:
1. 引用获取
The recommended way to get started using spring-data-redis in your project is with a dependency management system – the snippet below can be copied and pasted into your build. Need help? See our getting started guides on building with Maven and Gradle.
初始使用 spring-data-redis,建议在你的应用中使用一个依赖管理系统,这样你就可以直接粘贴下面的内容到你的工程来使用。如果需要另外的帮助,请查看我们利用Maven 和 Gradle创建的指导。
<dependencies> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-redis</artifactId> <version>1.8.4.RELEASE</version> </dependency> </dependencies>
2. 配置RedisTemplete
<bean id="jedisConnFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:use-pool="true"/> <!-- redis template definition --> <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate" p:connection-factory-ref="jedisConnFactory"/>
3. 注入并使用 RedisTemplate 或其他 opsForX()实例
public class Example { // inject the actual template @Autowired private RedisTemplate<String, String> template; // inject the template as ListOperations // can also inject as Value, Set, ZSet, and HashOperations @Resourc 4000 e(name="redisTemplate") private ListOperations<String, String> listOps; public void addLink(String userId, URL url) { listOps.leftPush(userId, url.toExternalForm()); // or use template directly redisTemplate.boundListOps(userId).leftPush(url.toExternalForm()); } }
相关文章推荐
- 在spring data jpa中使用redis的通用list及entity存储方法
- spring-data-redis 使用过程中需要注意的一点
- 使用Spring-data-redis操作Redis的Sentinel
- spring-data-redis 使用
- 使用Spring Data Redis实现缓存遇到的一些问题
- 使用Spring Data +Redis实现缓存
- 使用Spring-Data-Redis存储对象(redisTemplate)
- 使用spring-data-redis开发redis应用
- 【Redis基础】SSH 中Spring-data-redis使用体验
- 使用spring-data-redis操作redis
- Spring+redis,spring-data-redis使用
- 6、redis之使用spring-data-redis的Template
- 五分钟学会使用spring-data-cassandra快速实现数据的访问
- jedis,spring-redis-data 整合使用,版本问题异常以及解决。
- 使用spring-data-redis操作redis
- 【Redis基础】SSH 中Spring-data-redis使用体验
- spring data redis使用示例
- spring data redis 集群(sentinel实现)和simple spring memcached分布式初使用
- Spring-data-redis配置及使用示例
- spring-data-redis的使用优化