(出处: about云开发)
问题导读
1.RDB有哪些优缺点?
2.AOF有哪些优缺点?
3.什么是THP?
简介
经过上次轻松搭建了一个Redis的环境并用Java代码调通后,这次我们要来看看Redis的一些坑以及Redis2.8以后带来的一个新的特性即支持高可用特性功能的Sentinel(哨兵)。
Redis的一些坑
Redis是一个很优秀的NoSql,它支持键值对,查询方便,被大量应用在Internet的应用中,它即可以用作Http Session的分离如上一次举例中的和Spring Session的结合,还可以直接配置在Tomcat中和Tomcat容器结合并可以自动使用Redis作Session盛载器,同时它也可以作为一个分布式缓存。
Redis是单线程工作的
这边的单线程不是指它就是顺序式工作的,这边的单线程主要关注的是Redis的一个很重要的功能即“持久化”工作机制。Redis一般会使用两种持久化工作机制,这种工作机制如果在单个Redis Node下工作是没有意义的,因此你必须要有两个Redis Nodes,如:
1
2
3
4
5
6
|
object
=
queryFromCache
(
)
;
if
(
object
=
=
null||queryFromCache throw any exception
)
{
object
=
queryFromDB
(
)
;
}
|
1
|
echo never
>
/
sys
/
kernel
/
mm
/
transparent_hugepage
/
enabled
|
1
|
echo
1
>
/
proc
/
sys
/
vm
/
overcommit_memory
|
1
|
sysctl
-
p
|
1
2
|
*
soft nofile
=
65535
*
hard nofile
=
65535
|
1
|
ulimit
-
n
65535
|
1
2
3
|
make
PREFIX
=
/
usr
/
local
/
redis
1
install
make
PREFIX
=
/
usr
/
local
/
redis
2
install
make
PREFIX
=
/
usr
/
local
/
redis
-
sentinel install
|
1
2
3
4
5
6
7
|
port
26379
daemonize
yes
logfile
"/var/log/redis/sentinel.log"
sentinel monitor master
1
192.1
68.5
6.1
01
7001
1
sentinel
down
-
after
-
milliseconds master
1
1000
sentinel failover
-
timeout master
1
5000
#sentinel can-failover master1 yes #remove from 2.8 and aboved version
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
daemonize
yes
pidfile
"/var/run/redis/redis1.pid"
port
7001
tcp
-
backlog
511
timeout
0
tcp
-
keepalive
0
loglevel notice
logfile
"/var/log/redis/redis1.log"
databases
16
save
900
1
save
300
10
save
60
10000
stop
-
writes
-
on
-
bgsave
-
error
no
rdbcompression
yes
rdbchecksum
yes
dbfilename
"dump.rdb"
dir
"/usr/local/redis1/data"
slave
-
serve
-
stale
-
data
yes
slave
-
read
-
only
yes
#slave只读,当你的应用程序试图向一个slave写数据时你会得到一个错误
repl
-
diskless
-
sync
no
repl
-
disable
-
tcp
-
nodelay
no
slave
-
priority
100
maxmemory
0
appendonly
no
# The name of the append only file (default: "appendonly.aof")
appendfilename
"appendonly.aof"
# appendfsync always
#appendfsync everysec
appendfsync
no
#关闭AOF
no
-
appendfsync
-
on
-
rewrite
yes
auto
-
aof
-
rewrite
-
percentage
100
auto
-
aof
-
rewrite
-
min
-
size
64
mb
aof
-
load
-
truncated
yes
lua
-
time
-
limit
5000
slowlog
-
log
-
slower
-
than
10000
slowlog
-
max
-
len
128
latency
-
monitor
-
threshold
0
notify
-
keyspace
-
events
"gxE"
hash
-
max
-
ziplist
-
entries
512
hash
-
max
-
ziplist
-
value
64
list
-
max
-
ziplist
-
entries
512
list
-
max
-
ziplist
-
value
64
set
-
max
-
intset
-
entries
512
zset
-
max
-
ziplist
-
entries
128
zset
-
max
-
ziplist
-
value
64
hll
-
sparse
-
max
-
bytes
3000
client
-
output
-
buffer
-
limit normal
0
0
0
client
-
output
-
buffer
-
limit slave
256
mb
64
mb
60
client
-
output
-
buffer
-
limit pubsub
32
mb
8
mb
60
hz
10
|
1
|
slaveof
192.1
68.5
6.1
01
7001
|
1
|
redis
-
cli
-
p
26379
-
h
192.1
68.5
6.1
01
|
1
|
redis
-
cli
-
p
7001
-
h
192.1
68.5
6.1
01
|
1
|
redis
-
cli
-
h
192.1
68.5
6.1
01
-
p
7002
|
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
<
project xmlns
=
"http://maven.apache.org/POM/4.0.0"
xmlns
:
xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
xsi
:
schemaLocation
=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<
modelVersion
>
4.0
.
0
<
/
modelVersion
>
<
groupId
>
webpoc
<
/
groupId
>
<
artifactId
>
webpoc
<
/
artifactId
>
<
version
>
0.0
.
1
-
SNAPSHOT
<
/
version
>
<
packaging
>
war
<
/
packaging
>
<
properties
>
<
project.build.sourceEncoding
>
UTF
-8
<
/
project.build.sourceEncoding
>
<
java.
version
>
1.8
<
/
java.
version
>
<
jetty.
version
>
9.3
.
3.
v
20150827
<
/
jetty.
version
>
<
slf
4
j.
version
>
1.7
.
7
<
/
slf
4
j.
version
>
<
spring.
version
>
4.2
.
1.
RELEASE
<
/
spring.
version
>
<
spring.session.
version
>
1.0
.
2.
RELEASE
<
/
spring.session.
version
>
<
javax.servlet
-
api.
version
>
2.5
<
/
javax.servlet
-
api.
version
>
<
activemq_version
>
5.8
.
0
<
/
activemq_version
>
<
poi_version
>
3.8
<
/
poi_version
>
<
/
properties
>
<
dependencies
>
<
!
-- poi start -->
<
dependency
>
<
groupId
>
org.apache.poi
<
/
groupId
>
<
artifactId
>
poi
<
/
artifactId
>
<
version
>
$
{
poi_version
}
<
/
version
>
<
/
dependency
>
<
dependency
>
<
groupId
>
org.apache.poi
<
/
groupId
>
<
artifactId
>
poi
-
ooxml
-
schemas
<
/
artifactId
>
<
version
>
$
{
poi_version
}
<
/
version
>
<
/
dependency
>
<
dependency
>
<
groupId
>
org.apache.poi
<
/
groupId
>
<
artifactId
>
poi
-
scratchpad
<
/
artifactId
>
<
version
>
$
{
poi_version
}
<
/
version
>
<
/
dependency
>
<
dependency
>
<
groupId
>
org.apache.poi
<
/
groupId
>
<
artifactId
>
poi
-
ooxml
<
/
artifactId
>
<
version
>
$
{
poi_version
}
<
/
version
>
<
/
dependency
>
<
!
-- poi end -->
<
!
-- active mq start -->
<
dependency
>
<
groupId
>
org.apache.activemq
<
/
groupId
>
<
artifactId
>
activemq
-
all
<
/
artifactId
>
<
version
>
5.8
.
0
<
/
version
>
<
/
dependency
>
<
dependency
>
<
groupId
>
org.apache.activemq
<
/
groupId
>
<
artifactId
>
activemq
-
pool
<
/
artifactId
>
<
version
>
$
{
activemq_version
}
<
/
version
>
<
/
dependency
>
<
dependency
>
|