Redis Windows版安装及整合Spring
2016-05-30 17:05
519 查看
简介
1.Redis 是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据库。
2.Redis支持数据的持久化,可以将内存中的数据保持在磁盘中,重启的时候可以再次加载进行使用。
3.Redis不仅仅支持简单的key-value类型的数据,同时还提供list,set,zset,hash等数据结构的存储。
4.Redis支持数据的备份,即master-slave模式的数据备份。
安装
Redis官方是不支持windows的,只是 Microsoft Open Tech group 在 GitHub上开发了一个Win64的版本,项目地址是:
https://github.com/MSOpenTech/redis
下载下来解压,双击redis-server.exe,即启动redis服务。
相关的配置可以修改redis.windows.conf。
可视化工具
推荐使用RedisDesktopManager。
整合Spring
需要jar:
redis.clients:jedis:2.8.1
org.springframework.data:spring-data-redis:1.6.4.RELEASE
Spring配置:
Spring环境下的Redis事务
RedisTemplate可以使用multi, exec, and discard 命令来控制Redis的事务。
1.Redis 是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据库。
2.Redis支持数据的持久化,可以将内存中的数据保持在磁盘中,重启的时候可以再次加载进行使用。
3.Redis不仅仅支持简单的key-value类型的数据,同时还提供list,set,zset,hash等数据结构的存储。
4.Redis支持数据的备份,即master-slave模式的数据备份。
安装
Redis官方是不支持windows的,只是 Microsoft Open Tech group 在 GitHub上开发了一个Win64的版本,项目地址是:
https://github.com/MSOpenTech/redis
下载下来解压,双击redis-server.exe,即启动redis服务。
相关的配置可以修改redis.windows.conf。
可视化工具
推荐使用RedisDesktopManager。
整合Spring
需要jar:
redis.clients:jedis:2.8.1
org.springframework.data:spring-data-redis:1.6.4.RELEASE
Spring配置:
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> <property name="hostName" value="127.0.0.1"/> <property name="port" value="6379"/> <property name="usePool" value="true"/> </bean> <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"> <property name="connectionFactory" ref="jedisConnectionFactory"/> <property name="enableTransactionSupport" value="true"/> </bean> <bean id="stringRedisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate"> <property name="connectionFactory" ref="jedisConnectionFactory"/> </bean>
Spring环境下的Redis事务
RedisTemplate可以使用multi, exec, and discard 命令来控制Redis的事务。
//execute a transactionList<Object> txResults = redisTemplate.execute(new SessionCallback<List<Object>>() { public List<Object> execute(RedisOperations operations) throws DataAccessException { operations.multi(); operations.opsForSet().add("key", "value1"); // This will contain the results of all ops in the transaction return operations.exec(); }});System.out.println("Number of items added to set: " + txResults.get(0));
Spring Data 通过SessionCallback 这个接口来保证多次操作时都会是用一个连接(connection)。 当RedisTemplate 启用事务管理后,会将Redis纳入到Spring的事务管理中。
<property name="enableTransactionSupport" value="true"/>
相关文章推荐
- redis安装问题小结
- 一个jar包里的网站
- 一个jar包里的网站之文件上传
- 一个jar包里的网站之返回对媒体类型
- Spring和ThreadLocal
- Spring Boot 开发微服务
- Spring整合Quartz(JobDetailBean方式)
- Spring整合Quartz(JobDetailBean方式)
- 使用 Redis 和 Python 构建一个共享单车的应用程序
- Redis偶发连接失败案例实战记录
- Redis中实现查找某个值的范围
- win 7 安装redis服务【笔记】
- redis的hGetAll函数的性能问题(记Redis那坑人的HGETALL)
- Redis和Memcached的区别详解
- 分割超大Redis数据库例子
- Redis总结笔记(一):安装和常用命令
- Redis sort 排序命令详解
- 用Redis实现微博关注关系
- Redis实现信息已读未读状态提示