1、redis安装html
为了简单,本文就简单在windows上安装redis。在windows上安装步骤很简单。在官网上下载合适的版本,下载网址:https://github.com/dmajkic/redis/downloads。git
下载解压,文件夹中有3二、64位两个版本。根据本身的环境选择一个版本。各个文件做用以下:github
redis-server:服务器端redis
redis-cli:客户端spring
redis.conf:基本属性配置文件。密码、每过多长时间写一次硬盘、最大链接客户端数、管理内存数目等参数陪着孩子文件。经常使用参数配置见附件2.windows
dump.rdb:数据存储文件。数据刷到硬盘的存储文件。bash
详情参考附件1.服务器
读写示例:app
server端以下:框架
client端以下:
2、基础项目环境搭建
项目基础框架:SpringMVC + redis
jar包依赖
<!-- redis start --> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-redis</artifactId> <version>1.0.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>3.1.2.RELEASE</version> <scope>test</scope> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.1.0</version> </dependency> <!-- redis end -->
applicationContext.xml配置以下:
<context:property-placeholder location="classpath:redis.properties" /> <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig"> <property name="maxIdle" value="${redis.maxIdle}" /> <property name="maxActive" value="${redis.maxActive}" /> <property name="maxWait" value="${redis.maxWait}" /> <property name="testOnBorrow" value="${redis.testOnBorrow}" /> </bean> <bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:host-name="${redis.host}" p:port="${redis.port}" p:password="${redis.pass}" p:pool-config-ref="poolConfig"/> <bean id="stringRedisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate"> <property name="connectionFactory" ref="connectionFactory" /> <property name="defaultSerializer"> <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/> </property> <property name="valueSerializer"> <bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/> </property> </bean>
redis.properties
# Redis settings redis.host=localhost redis.port=6379 redis.pass= redis.maxIdle=300 redis.maxActive=600 redis.maxWait=1000 redis.testOnBorrow=true
项目源码参考:https://git.oschina.net/Michael_Feng/cache-demo
3、经常使用接口介绍
一、常规的key、value操做
二、list操做
三、hash操做
四、set操做
五、pub、sub操做
4、参看文档
一、http://www.redis.net.cn/tutorial/3503.html
二、http://www.cnblogs.com/linjiqin/archive/2013/05/27/3102040.html