1、Redis安装
下载地址:https://github.com/dmajkic/redis/downloads
安装步骤:
解压redis安装包,将redis安装文件放到c:\redis下;
打开cmd窗口,使用cd指令找到c:\redis,输入指令:cd c:\redis;
找到redis文件目录,打开服务端,输入指令:redis-server.exe redis.conf;
不要关闭此窗口,此刻就可以访问服务器端;
新窗口,找到redis文件目录,然后输入指令:redis-cli.exe -h 127.0.0.1 -p 6379
2、常用指令
打开目录:cd c:\redis
启动服务: redis-server.exe redis.conf
访问redis:redis-server.exe -h 127.0.0.1 -p 6379
设置键值对:set key302
获取键值对:get key302
清空数据 :flushDB
删除键值对:del key302
是否存在:exists key302
设置过期时间:expire key302 1 (键名 单位秒)
新增多个键值对:mset key01 abc key02 def
3、缓存实例
通过maven 下载redis客户端jar包,分为为:jedis-2.9.0.jar、commons-pool2-2.4.2.jar
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-pool2/2.4.2 -->
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.4.2</version>
</dependency>