如果使用的是redis3.x中的集群,在项目中使用jedisCluster。
1、项目结构
2、pom.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4
5 4.0.0
6
7 com.xxx
8 myboot
9 1.0-SNAPSHOT
10
11
12 1.8
13
14
19
20 org.springframework.boot
21 spring-boot-starter-parent
22 1.2.5.RELEASE
23
24
25
37
38
39
40
41 org.springframework.boot
42 spring-boot-starter-web
43
44
45 redis.clients
46 jedis
47
48
49 com.alibaba
50 fastjson
51 1.1.15
52
53
54 org.apache.commons
55 commons-lang3
56 3.3.2
57
58
59
60
61
62
64
65 org.springframework.boot
66 spring-boot-maven-plugin
67
68
69
70
View Code
说明:相对于上一章的代码仅仅引入了jedis的依赖jar。
3、application.properties
1 #user info2 user.id=13 user.username=zhaojigang4 user.password=1235
6 #redis cluster7 redis.cache.clusterNodes=localhost:80808 redis.cache.commandTimeout=59 #unit:second10 redis.cache.expireSeconds=120
View Code
说明:相对于上一章的代码仅仅引入了redis cluster的配置信息
4、Application.java(springboot启动类,与上一章一样)