|
|
楼主 |
发表于 2018-11-16 12:43:33
|
显示全部楼层
http://www.discuz.net/forum.php? ... 648&highlight=REDIS
& p0 W' @$ Q+ T: z无意间测试 单机状态 redis相当给力 测试1000请求/s 单纯的 get 和set 居然只用了 0.01秒 当时我惊呆了: d& L: j8 v% G" e
7 C$ U6 X0 o& v$ J! E: U) Yhttp://www.discuz.net/forum.php? ... 731&highlight=REDIS! i' M: i$ @6 Y
9 ?) `" b- e. |$ d) Ghttps://wenku.baidu.com/view/265a5ce176a20029bc642d0b.html
) `6 F$ }# z7 O% T
1 I# A: O: H1 \6 }+ i& J=======================================+ J" h" I( d- R+ `3 `8 f
- 连接上 ssh
% Q! R" _ Q5 T! X# L
4 h0 _$ v. r' p% v# [8 q2 K
% `" |/ r' ^" H& D8 M0 p9 N' b1 N- 第一步:下载redis
+ X; k) D" T& E- B' g6 \ - # wget http://redis.googlecode.com/files/redis-2.6.10.tar.gz
" k; P/ G, f1 @( U - # tar zxvf redis-2.6.10.tar.gz
9 D4 ]3 q: Q9 i0 Z9 \ - # cd redis-2.6.10& Q1 c: v) k" x9 m
- # make / k O; V6 y. Z$ @: A' l2 p
- # make install
2 Y( L* c) Z/ n' a$ T/ l - #cp redis.conf /etc/ #复制配置文件到etc目录下面) _+ ^ H/ V* C6 W: x2 z1 U
- 第二步:修改配置+ h8 c2 b$ J! S9 E2 l, ]; b$ K7 j, o
- #vi /etc/redis.conf) [3 k8 |- K/ M) W* ^# s
- ######################下面是无措的配置文件 复制过去就成#########1 {) I9 L: q! d2 i% O! ^- I
- # Redis configuration file example
$ i1 j/ r) {; R. M( W, e8 \ - 1 g' S! H" B3 R( ~( _9 |
- # Note on units: when memory size is needed, it is possible to specify* l% M! @. D3 t0 g G6 M
- # it in the usual form of 1k 5GB 4M and so forth:: t( c0 o# V! n' A
- #
3 E/ k! |; Q; X2 B - # 1k => 1000 bytes. z6 j* @* w+ s8 b- Y8 F
- # 1kb => 1024 bytes" k; \4 K# Y, l
- # 1m => 1000000 bytes9 A, O0 h% B1 u( S7 B! B' |2 t
- # 1mb => 1024*1024 bytes4 y6 U" P$ ~8 l" r
- # 1g => 1000000000 bytes. G) n' o \- G5 z$ W9 C
- # 1gb => 1024*1024*1024 bytes
% f& ]; ?! y$ k" ?5 _ - #' V% m: r$ |( w* j
- # units are case insensitive so 1GB 1Gb 1gB are all the same.
& f# ~2 {3 V0 w* N
$ x* W1 k, `3 e6 l( }- T- # By default Redis does not run as a daemon. Use 'yes' if you need it.5 A& p0 s1 Y* y2 H
- # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.! f1 t2 @2 s: D! P
- daemonize yes; |7 y4 U# \0 X
4 Y8 O9 ~# F: u/ c7 z6 `) u- # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
" W$ U1 l) B4 ?" c0 H$ y - # default. You can specify a custom pid file location here.
6 N) V& O, b0 o6 j6 J - pidfile /var/run/redis.pid
) U4 N3 q% j/ I1 j% M4 e
% h1 M$ g$ f6 H; W- # Accept connections on the specified port, default is 6379.
/ U/ T' q m$ B - # If port 0 is specified Redis will not listen on a TCP socket., k$ d( g+ ]0 K7 u- y& v8 o
- port 6379
8 E4 h, ~' V9 D. G2 x# C$ { - 4 s" X" m/ x+ U0 k
- # If you want you can bind a single interface, if the bind option is not5 ~0 J& E- B( q- v% W
- # specified all the interfaces will listen for incoming connections.4 Q7 F; Y2 @0 W' L- b( l* Z, }
- #
: h0 S5 ^# ~" o& p - # bind 127.0.0.1& b! V. J+ Z/ q6 x5 h
& d( K+ a4 b0 y( Z& H- # Specify the path for the unix socket that will be used to listen for- ~" ^4 t5 j7 B+ A+ s% Y" O
- # incoming connections. There is no default, so Redis will not listen
' i2 o: X% |2 [2 U - # on a unix socket when not specified.
& p9 v+ z6 u2 i: N/ Y& R - #
6 S9 \1 M- D2 W - # unixsocket /tmp/redis.sock
. m5 r5 C1 @( {$ l( O# t3 z0 K - # unixsocketperm 755# h+ i% i7 Y- U; ^8 t
5 ^5 ~9 p, H- K9 \- # Close the connection after a client is idle for N seconds (0 to disable)7 c9 F1 l/ m* _8 n6 w% Q- C) r- d
- timeout 300% z6 X# B& z- f3 f/ G! K
- & O. c: }2 n' x/ i. Q( j
- # TCP keepalive.
: `/ G: U2 K! U5 V5 D+ V - #& z# r. l, T9 k* V" Z* q+ D
- # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
" R4 Z+ D; U# Y4 W. r: n - # of communication. This is useful for two reasons:. Y; U) C/ }4 Z" ~/ G& B5 U( l
- #
; ^/ r' o* B" s# d* Y# e6 C* o5 n - # 1) Detect dead peers.7 A/ ~5 G% k+ [' ]5 ~) B+ U% M
- # 2) Take the connection alive from the point of view of network
- N; r' J6 W1 i/ m" E2 d! D& B - # equipment in the middle.
& S) U# p7 }+ x+ ] v" h, E - #: b4 |) w! K# d; |; U# p
- # On Linux, the specified value (in seconds) is the period used to send ACKs.
; c, P" r: T5 ]* @7 F! }, m4 @; z - # Note that to close the connection the double of the time is needed.
- q( q5 x) U- K) [; w - # On other kernels the period depends on the kernel configuration.
) _- i8 D: P4 @ - #8 n4 e3 z& P/ s/ k, q0 |$ {; l. o
- # A reasonable value for this option is 60 seconds.
?. V0 v; j" G1 o; }4 o8 B+ D - tcp-keepalive 0
6 U9 p$ F1 o" v1 v% C4 Q - 4 ?: X/ [ d5 ?( `
- # Specify the server verbosity level.
+ B3 ]2 ~9 y/ }; _ - # This can be one of:
2 D7 [9 y3 s$ h1 t7 O - # debug (a lot of information, useful for development/testing) \8 k$ t! W( b1 q1 F7 ~
- # verbose (many rarely useful info, but not a mess like the debug level)
! z9 W* x+ C) J: M3 {( [ - # notice (moderately verbose, what you want in production probably)
6 k1 T/ F$ M: G. b L - # warning (only very important / critical messages are logged)4 y2 t, E$ m1 Y* P
- loglevel warning! ?) q) E8 ~( D: H6 G8 w2 t
- ) [1 w8 i! K6 ~6 x X4 c# C! Q" p
- # Specify the log file name. Also 'stdout' can be used to force
+ M# Y' n' i$ X! F( z - # Redis to log on the standard output. Note that if you use standard. Y, Z, }5 A2 T( {; V$ ]" T
- # output for logging but daemonize, logs will be sent to /dev/null2 d8 x9 k" c* c( i) I# U1 ^
- logfile /var/log/redis.log2 ^1 s- A2 |8 | `
- 3 l& S, J' n% G/ a
- # To enable logging to the system logger, just set 'syslog-enabled' to yes,
5 t0 g% h& r* a% W - # and optionally update the other syslog parameters to suit your needs.0 n( n& F/ Z9 o+ R5 w6 p
- syslog-enabled yes1 B) H! \& z, T
- ) S/ z4 j) ^' A' F
- # Specify the syslog identity.
' @' _8 p- |3 j% {: p0 ^ - # syslog-ident redis* }/ e7 q( V" f5 o" ~; x+ o6 v* ^* Z
7 r4 @' R% @, ]0 d( Z- # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
3 u" `) D2 b/ l/ c - syslog-facility local01 u: x; r1 m+ U' W F y- _
- & J7 J9 @0 ^. _1 ^& }" a/ F( f
- # Set the number of databases. The default database is DB 0, you can select, O+ I8 r. S- t! J0 K5 U) j
- # a different one on a per-connection basis using SELECT <dbid> where0 [) Q% V, I4 t: A9 M( Y
- # dbid is a number between 0 and 'databases'-1
6 ^/ X9 }# M c7 j; k - databases 16
* a" ?; I" x. q4 k1 X" \$ T s
. v4 k3 {& ]/ C$ e- ################################ SNAPSHOTTING #################################; Y7 ]2 R0 s7 D- ~8 Y
- #
$ G6 n( v8 w4 d: c - # Save the DB on disk:
6 [2 l" `5 I' P1 T - #
7 s- f6 Z# T$ W v8 V' T6 @4 H3 S - # save <seconds> <changes>
& e! P2 L. h" e( y3 q4 @ - #
1 L+ _5 O1 d& S% C - # Will save the DB if both the given number of seconds and the given& |5 ]3 K% b* Y$ C. z8 K- ?
- # number of write operations against the DB occurred.% b) I* `% N3 }! G, L8 V# k
- #
5 ^! w6 m% s+ X6 u- B2 Z) F - # In the example below the behaviour will be to save:5 F0 v: p; |- Y) {0 n0 S/ }1 `
- # after 900 sec (15 min) if at least 1 key changed
) L u- Q; l% }, g - # after 300 sec (5 min) if at least 10 keys changed
" _/ f' |9 y+ p$ z; F - # after 60 sec if at least 10000 keys changed
1 L" D6 b: b1 D4 O8 g" U( _ - #/ H, _4 ^% t/ I- q: j. m0 g' g
- # Note: you can disable saving at all commenting all the "save" lines.9 O p0 l# O7 O' T. i4 f/ j
- #
+ a0 R# T% ^! d I# ^2 ?8 S - # It is also possible to remove all the previously configured save2 { W, \ c5 ^: O8 ^$ b) g. p- f
- # points by adding a save directive with a single empty string argument* ^) ^7 f- A6 H; I; M
- # like in the following example:
5 z( `: B6 h4 O- M2 [8 u - #
4 S0 ~$ F3 [3 \ - # save ""
8 J6 u9 L) e4 U4 m- E o
3 n0 f7 A$ y( ?0 `- save 900 1
+ i0 F {3 t: _. x+ d - save 300 10 O( s- g: r8 d3 y; ?0 s8 Q5 R& u
- save 60 10000
0 c( Z2 F! S# f: ~. P6 l+ ^- a - 2 ]% \6 W9 u' u/ r
- # By default Redis will stop accepting writes if RDB snapshots are enabled! S! ^7 G5 y/ |; R* Y( Y4 R
- # (at least one save point) and the latest background save failed.
! T; x1 O2 h" y9 ~ - # This will make the user aware (in an hard way) that data is not persisting
" z& B5 Y6 G1 o( O& C! }# f - # on disk properly, otherwise chances are that no one will notice and some
+ m) |; d; t) A$ L - # distater will happen.: l6 C9 g r5 a D& b
- #
- k, Y8 r7 O' V% R - # If the background saving process will start working again Redis will
& Q4 ^& Z* i& n# u9 T$ F - # automatically allow writes again. V3 m. o7 q6 e$ c& Q
- #% V- ~$ g; L+ }1 y6 c
- # However if you have setup your proper monitoring of the Redis server1 l1 M* [3 q6 @. F) `& N3 ~$ _& o
- # and persistence, you may want to disable this feature so that Redis will6 W. v6 r% y) ~" Q
- # continue to work as usually even if there are problems with disk,8 C& }9 Q/ Q3 y8 t
- # permissions, and so forth.( d0 R5 d" T# h% {6 {: N/ l8 @' \
- stop-writes-on-bgsave-error yes
$ C8 ]/ s# ~8 m( Y) Y7 ]
. j( v! N, W [) }, M- # Compress string objects using LZF when dump .rdb databases?
$ ~+ U. E' T- I' T, T - # For default that's set to 'yes' as it's almost always a win.7 G% H$ O( A# a5 g
- # If you want to save some CPU in the saving child set it to 'no' but
4 r" a. j1 J: n" { - # the dataset will likely be bigger if you have compressible values or keys.
2 }- Y+ y. [5 L! s - rdbcompression yes
0 W- `9 }( a2 I7 s
2 I2 |. p$ l5 l+ w8 a- # Since version 5 of RDB a CRC64 checksum is placed at the end of the file.* O: J _( |1 L
- # This makes the format more resistant to corruption but there is a performance4 Y0 T9 ?. T9 l* l; A& C# p3 h4 C/ [
- # hit to pay (around 10%) when saving and loading RDB files, so you can disable it
! w% y1 _) t$ w# P- e; u - # for maximum performances.
2 E% X3 r5 f, l7 c - #
( s: C& }$ o- E2 Q/ c% s$ g - # RDB files created with checksum disabled have a checksum of zero that will( C. g, Q. {7 H' b4 c0 o Y
- # tell the loading code to skip the check.
# `) r/ {" x0 Z# @; ~2 Q+ x! M4 q7 | - rdbchecksum yes
5 ^: S4 }" U8 C2 x
: {) h7 R& i q+ j- # The filename where to dump the DB
" S. O& [+ \; v6 ^ - dbfilename dump.rdb$ G! f& e, o' p2 @$ y% e& i
- + o, P( M, z7 ?
- # The working directory.0 W- `5 c d @; a7 F9 s
- #& n' b/ o% {* _6 Z: h
- # The DB will be written inside this directory, with the filename specified
2 [ N+ O6 }, B; a8 K( {/ N - # above using the 'dbfilename' configuration directive.6 F8 N3 w7 \) `- H
- #
1 Q$ p6 U7 u3 e" C3 G2 h - # The Append Only File will also be created inside this directory.5 w' L: k$ h% i1 V# F2 l2 u7 m
- # % F* ]) c& [( C% t! T, a
- # Note that you must specify a directory here, not a file name.% ~% {5 ^( D* ~& C/ G
- dir /var/db/redis
7 T0 z5 ^- s; b" A Q2 @, r - & _6 u+ a; p0 W1 C% A& S
- ################################# REPLICATION #################################5 ^5 E; z- e( x' `
/ z+ Q- e U* A/ A! S- # Master-Slave replication. Use slaveof to make a Redis instance a copy of0 q# L7 e8 R) n
- # another Redis server. Note that the configuration is local to the slave
( L5 B8 _( L, w0 _4 ? - # so for example it is possible to configure the slave to save the DB with a
9 E! B1 P3 ^! ~+ e1 M' H& V& a - # different interval, or to listen to another port, and so on.: a* H* G% N; {. F H0 N1 ?- S2 ]/ o
- #
+ F/ {5 H8 N; `2 ~' c+ { - # slaveof <masterip> <masterport>) p; i4 L/ l" h7 e, B; x0 z; t6 n
' Q1 Y& O& h& O: ]0 ] Q/ m E- # If the master is password protected (using the "requirepass" configuration
" j5 P) x; i7 c: U) m+ X4 y - # directive below) it is possible to tell the slave to authenticate before k' U) _' M; B8 m4 o; V
- # starting the replication synchronization process, otherwise the master will. h X/ y9 N6 L* q: s4 o& T
- # refuse the slave request.
( E% F! P; u( v# u - #
0 N. w1 t3 j1 `! A6 n7 ~) M Y - # masterauth <master-password>& d/ ^7 @' E1 _+ T; @0 l+ s" G. Z
* y1 Y; V3 W8 Y( M' T u- # When a slave loses its connection with the master, or when the replication
6 z! D# T2 A8 [4 l( s% K9 C - # is still in progress, the slave can act in two different ways:
' B; ~% B, u8 K K$ Z& O" X6 q - #
: q$ y) U d5 f# `6 H - # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will
0 V1 [( q: q }/ Q - # still reply to client requests, possibly with out of date data, or the0 }1 X+ I9 r- A0 g4 [! F: O
- # data set may just be empty if this is the first synchronization.
! w& l( s/ l" P+ `& [ - #
/ _9 G7 U' F. t! V# _8 ^9 s - # 2) if slave-serve-stale data is set to 'no' the slave will reply with! K b/ x; Q: n4 B
- # an error "SYNC with master in progress" to all the kind of commands
4 }8 J5 B; q$ m - # but to INFO and SLAVEOF.
! L9 @7 I* u6 p/ q5 Y9 k& \ - #9 Q) }: a1 N1 g
- slave-serve-stale-data yes
5 F+ ]. L5 i, s2 f+ C - % y6 ~6 ?* L- {- h- C1 d
- # You can configure a slave instance to accept writes or not. Writing against
0 W" ? s y* R @, s$ d B - # a slave instance may be useful to store some ephemeral data (because data
y- C: T% x! h( A; x9 l - # written on a slave will be easily deleted after resync with the master) but
# ~' h" T+ ~& q V - # may also cause problems if clients are writing to it because of a0 K& n K* {2 ^% W1 ^# t
- # misconfiguration.
* D; S' i; x6 ] - #
, b, \' W8 ?7 d- I' N - # Since Redis 2.6 by default slaves are read-only.
3 r9 m; E. A5 v7 m' _3 t - #3 Q- Y: y2 r7 c% X2 g
- # Note: read only slaves are not designed to be exposed to untrusted clients0 P; w" ^8 E( e0 d6 {: d# J+ l
- # on the internet. It's just a protection layer against misuse of the instance.# ]" Q5 i h- X! v
- # Still a read only slave exports by default all the administrative commands ^$ k9 Z, z; L7 Z7 b& e: h) B
- # such as CONFIG, DEBUG, and so forth. To a limited extend you can improve7 Z( o0 J4 s( O- a
- # security of read only slaves using 'rename-command' to shadow all the
' V# l* a& c; B+ g1 p - # administrative / dangerous commands.
) l/ \. a; X5 V( S! V$ z - slave-read-only yes6 x0 b% I g* S
/ t8 M# k& |% R; E- # Slaves send PINGs to server in a predefined interval. It's possible to change
9 f8 V; v `. B9 p u$ h/ m: {1 d - # this interval with the repl_ping_slave_period option. The default value is 10
8 {0 }) ^; g5 ?( I# Z$ W - # seconds.
/ B8 ~) p0 O, @& b# k2 B - #
( m) @5 | }1 X, X* U4 f - # repl-ping-slave-period 10( ^* o2 m% G, `9 B/ @: ]
, ^ t+ w, z* T( Q; a! l- # The following option sets a timeout for both Bulk transfer I/O timeout and' E# E% v+ f* n$ e$ H
- # master data or ping response timeout. The default value is 60 seconds.
2 a _* S+ C5 x. v+ U: V - #
( C' ~( L; c( J7 X; C - # It is important to make sure that this value is greater than the value9 Y' b- a4 F( K* E% ?9 _
- # specified for repl-ping-slave-period otherwise a timeout will be detected. m3 d9 e5 j0 G7 } H* d9 a" @1 J
- # every time there is low traffic between the master and the slave.( P5 ]; H3 R: Y+ i! \2 `
- #0 m1 F9 \4 b% n
- # repl-timeout 60
& v2 f; X5 x' L1 J) w* U - " u1 `/ X2 v/ Z$ X) c6 b
- # Disable TCP_NODELAY on the slave socket after SYNC?
' W( p: L7 D2 B - #8 O- O& j" L- z5 X6 |" g x
- # If you select "yes" Redis will use a smaller number of TCP packets and
$ C# N( y' `7 S6 P2 J% q - # less bandwidth to send data to slaves. But this can add a delay for
9 A4 p; r/ S8 P5 M! N - # the data to appear on the slave side, up to 40 milliseconds with
( j8 Z! } a1 E: z# m - # Linux kernels using a default configuration. q: C E2 v4 H9 l5 \& L Q
- #
/ l5 H$ L3 X$ ?1 r$ }2 F1 Y - # If you select "no" the delay for data to appear on the slave side will9 \3 J. \ t! V# `- y/ d; T& c
- # be reduced but more bandwidth will be used for replication.
- W2 O B; a- u: v* d* V4 [1 X - #
0 Z' B( ?: A0 s! s - # By default we optimize for low latency, but in very high traffic conditions
. w! e% v. t/ u' w - # or when the master and slaves are many hops away, turning this to "yes" may; p: ~6 K; H6 U: O+ ^
- # be a good idea.
. s/ L- }2 P. u( P1 p( k - repl-disable-tcp-nodelay no
. F. ^' G2 A9 @1 W - 0 c0 t1 N% d+ w v8 I& A
- # The slave priority is an integer number published by Redis in the INFO output.7 D& E: Q: K& c* c3 n4 x$ G
- # It is used by Redis Sentinel in order to select a slave to promote into a
: k0 S/ A: n- A8 ]+ U3 N6 }; M2 ?* Q - # master if the master is no longer working correctly.6 j4 ~3 ?; ?: q
- ## h8 x& N# F: h3 P( p
- # A slave with a low priority number is considered better for promotion, so
2 i; Y! N6 g5 ` - # for instance if there are three slaves with priority 10, 100, 25 Sentinel will. v* _. u5 w; ^6 H1 F5 F* b( D
- # pick the one wtih priority 10, that is the lowest.5 K L& g2 K' S
- #) f! q1 p. u) K6 e; ~
- # However a special priority of 0 marks the slave as not able to perform the% S; @. e2 z5 H' }2 c2 {
- # role of master, so a slave with priority of 0 will never be selected by
. w# X: g; m1 P: ] - # Redis Sentinel for promotion.# J2 }' _% k5 ~3 F
- #
" ]8 A/ A2 h3 I+ S" }6 i$ I; T - # By default the priority is 100.
+ [ m) a9 S6 I" V1 ] |* n - slave-priority 100
- d6 I4 |- M/ R: |4 o. C7 z - " O0 u4 ?5 y/ P! Z
- ################################## SECURITY ###################################
$ u3 L( u2 n0 V0 v; } - * {! o. @' [) G
- # Require clients to issue AUTH <ASSWORD> before processing any other
; u* Q+ ` Z& t! |3 {5 L/ M - # commands. This might be useful in environments in which you do not trust
6 B ?: K& Z+ E) W- V/ P0 e5 R - # others with access to the host running redis-server.+ |& V5 h" C9 X3 D9 W
- #
4 e" z! w) P6 M3 ~! r; K7 W - # This should stay commented out for backward compatibility and because most5 V% F- _, w! ?& r& A) z+ W
- # people do not need auth (e.g. they run their own servers). o' C9 j' T0 r) ] D/ u
- # 5 i" Q& `1 t) C$ Q6 s5 M* e
- # Warning: since Redis is pretty fast an outside user can try up to) }4 b9 `% b; J9 {; Y- c/ Z+ H3 a
- # 150k passwords per second against a good box. This means that you should
. P) V) [ m1 U; _ - # use a very strong password otherwise it will be very easy to break./ q" E; {( {% h
- #3 O7 k0 |. I0 _/ T" R$ T) n
- # requirepass foobared
- C8 \, B8 {6 p6 d1 Y1 X7 X* Y$ z4 A/ F
9 H- W4 }" \% n4 B Z1 m+ X) [- # Command renaming.* L6 p* ]6 J! P' I3 B/ n( H
- #) ]4 c4 A" g" b1 i1 o
- # It is possible to change the name of dangerous commands in a shared
* A! T7 M" d1 h& x9 ^ - # environment. For instance the CONFIG command may be renamed into something% V7 e9 T* C* o1 I, p: z: n8 V' ~# _
- # hard to guess so that it will still be available for internal-use tools
' A: k4 G! J/ ~ - # but not available for general clients.
5 s% h5 E& R3 t3 U' G; J - #
2 f6 C0 F. k6 R$ d - # Example:8 F( E6 O; R- |0 l3 B! {( J/ }
- #! m4 f5 {" T0 _# D l0 v) n3 n
- # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
2 ], R+ C4 Y! z+ f' }* R - #
$ G2 {: }# T. U$ S+ v1 Y - # It is also possible to completely kill a command by renaming it into7 @) ?. c" c$ s+ B E2 [3 O) c6 S
- # an empty string:7 i* D$ o @# K) q- @! E3 q. E
- #$ P. }2 q) P* x+ y& x ^9 @
- # rename-command CONFIG ""2 g4 w2 [! M) }5 l" }* p
- $ V2 J$ T+ w; P" `# L
- ################################### LIMITS ####################################7 B* ^7 A- |4 s! d
- w4 y; V) `6 M+ v- c; h0 C6 i- # Set the max number of connected clients at the same time. By default
5 M0 f& a* X5 ?6 k( ? - # this limit is set to 10000 clients, however if the Redis server is not& C9 s1 t: h( v8 V' l Y- O! R" h
- # able to configure the process file limit to allow for the specified limit
8 O7 O4 V) b" O- V6 Q - # the max number of allowed clients is set to the current file limit% {4 h. G9 [! M0 m7 A2 ?
- # minus 32 (as Redis reserves a few file descriptors for internal uses).5 H7 t P% }8 x6 t! b; P
- #
2 p5 u& f/ [2 @* G- d - # Once the limit is reached Redis will close all the new connections sending1 C, j8 q* L1 H2 k: F
- # an error 'max number of clients reached'.
' T, n6 b! ?0 D0 {- I, ? - #: N7 G2 V, ?7 l1 q. T8 s' x
- maxclients 500
! W! p: h. L8 q" i9 ?' P2 N( ?/ o
# X& ?% ] f, Y. c- # Don't use more memory than the specified amount of bytes.
- |8 e0 U k9 ?2 ` - # When the memory limit is reached Redis will try to remove keys
. ?1 ]# s; w! I9 W; \ - # accordingly to the eviction policy selected (see maxmemmory-policy).- t- J0 Q8 u! }+ F7 d& m
- # T7 H. @3 X" R7 O0 Q
- # If Redis can't remove keys according to the policy, or if the policy is* Q3 ~9 a& K' m
- # set to 'noeviction', Redis will start to reply with errors to commands
! e2 C4 B% `- r' a! X: I1 E - # that would use more memory, like SET, LPUSH, and so on, and will continue
: F0 X' j0 c p" s3 Z4 A# s - # to reply to read-only commands like GET.
' o5 l _& `/ d( Q [5 m- | - #
8 z: g9 A: [4 H; B) Z6 {% m2 ^7 K - # This option is usually useful when using Redis as an LRU cache, or to set& |0 {2 E" `; I, ]) d/ }
- # an hard memory limit for an instance (using the 'noeviction' policy).' L3 h) ]& B6 f. h, N( G
- #
1 j" E) B2 W ~' ^' B- [ - # WARNING: If you have slaves attached to an instance with maxmemory on,
% \0 X) r" @1 Z( b; x - # the size of the output buffers needed to feed the slaves are subtracted, |$ a: w$ \" |* e4 ?, b
- # from the used memory count, so that network problems / resyncs will, X4 ]3 N" q# X
- # not trigger a loop where keys are evicted, and in turn the output
& A6 d- O8 }! @# S5 O3 w - # buffer of slaves is full with DELs of keys evicted triggering the deletion7 i ]$ t3 c* g3 Z4 h6 C
- # of more keys, and so forth until the database is completely emptied.
' l% V1 h+ F& {. Z% H - #+ u; ~" O* g4 u$ K
- # In short... if you have slaves attached it is suggested that you set a lower
+ z; N6 J1 l4 ~+ Z1 H - # limit for maxmemory so that there is some free RAM on the system for slave
9 e8 a0 a7 W! g& h% o - # output buffers (but this is not needed if the policy is 'noeviction').
. r5 S& X2 g& } m2 ^; p& ?! i - #; b' p* ?# a* m, D9 L0 }. s
- maxmemory 128000000
6 e( s) i" u3 K% u1 W7 ?$ m% p9 P: V - ' d0 X/ F5 o( G% K9 R
- # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory5 L( V5 I* N$ w0 u; u& S
- # is reached. You can select among five behaviors:2 x* F% W( x P- k5 [& F' R
- #
* I h+ f) A5 n6 A( Y - # volatile-lru -> remove the key with an expire set using an LRU algorithm% q1 C! A' j" ?! R# V5 y2 x6 i" A
- # allkeys-lru -> remove any key accordingly to the LRU algorithm$ F( h$ @: u5 N1 s
- # volatile-random -> remove a random key with an expire set) {5 g8 o, i9 H
- # allkeys-random -> remove a random key, any key6 {0 Z+ A2 j" v0 K( a9 e7 y+ Y( [
- # volatile-ttl -> remove the key with the nearest expire time (minor TTL) D' a* J0 z' l
- # noeviction -> don't expire at all, just return an error on write operations
- N/ m' w H9 L0 T' V$ v' I - #
8 y# l4 @, z3 ^5 B - # Note: with any of the above policies, Redis will return an error on write& \( y! {& E# _" }
- # operations, when there are not suitable keys for eviction.
1 a! o. s$ `, P9 ?) x - #2 e Q/ _" y% S! v: G8 R" F
- # At the date of writing this commands are: set setnx setex append' R& M/ [9 r" R( X
- # incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
/ T3 m% v2 Q8 y6 j - # sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
' u# z* [% M+ y" [$ w4 X, z% W - # zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby/ |# V6 e. p* G/ t6 @
- # getset mset msetnx exec sort
& c. f& }: _/ q9 A - #! ]6 V( w, ?# v; n, i7 i1 E
- # The default is:
9 U/ M) t6 d, [. x - #
F4 q$ r( E) r% ~$ n$ b+ ?1 u - # maxmemory-policy volatile-lru
: }' b; ]: g) o; m: L - ) Y, V9 u2 d# R
- # LRU and minimal TTL algorithms are not precise algorithms but approximated x3 i7 h, O5 y6 C' W; X; H
- # algorithms (in order to save memory), so you can select as well the sample5 `2 K6 v9 I& G- N
- # size to check. For instance for default Redis will check three keys and$ I2 J! h) @" M0 k
- # pick the one that was used less recently, you can change the sample size7 }. O7 q* v$ {
- # using the following configuration directive.2 W# S1 _/ P9 q
- #- r% [2 \7 t' L' L: f
- # maxmemory-samples 3
! H: z4 j p% L
3 y8 Q3 p, l1 Q: O- n2 h9 x; P- ############################## APPEND ONLY MODE ###############################
8 w3 C0 R7 J% J - # }4 x$ m( _" V! |
- # By default Redis asynchronously dumps the dataset on disk. This mode is3 {5 a+ @) G+ z9 o" }1 @# k2 A
- # good enough in many applications, but an issue with the Redis process or( q2 k" c) q5 e& e% c
- # a power outage may result into a few minutes of writes lost (depending on# Y" c: ~1 ~: c- D
- # the configured save points).
* }& ~3 u3 f+ |2 v9 f$ p4 O - #% s2 p! I4 a* u! N S" K
- # The Append Only File is an alternative persistence mode that provides: V# `% g# t3 e3 }
- # much better durability. For instance using the default data fsync policy
' m0 s$ O ?; Q) n8 V" F6 G - # (see later in the config file) Redis can lose just one second of writes in a
# ^7 [- `5 v* i - # dramatic event like a server power outage, or a single write if something9 }5 o9 T5 ]) w, A( @4 L- I
- # wrong with the Redis process itself happens, but the operating system is3 [. o7 \0 P7 u$ ]' U' n+ D
- # still running correctly.
( f6 W) `0 O, z) `% Z; H( t - #1 d7 X q" z5 T
- # AOF and RDB persistence can be enabled at the same time without problems.% }# l. J ]' R$ @# P9 |$ D$ Z
- # If the AOF is enabled on startup Redis will load the AOF, that is the file
3 J4 ^2 j' `" u - # with the better durability guarantees.8 ?# q% D) B! A) y0 n
- #- W) ~1 x3 F9 m9 \$ c* K
- # Please check http://redis.io/topics/persistence for more information.
+ |6 k4 o7 v3 v- ? r0 v& ^
% q1 Q9 S2 `/ d9 G- appendonly no* l$ `$ }* t+ @( p5 D- W) {
- . `5 u2 `- q( l* c* }/ ~* u: G+ @
- # The name of the append only file (default: "appendonly.aof")) `2 V" }) `, W1 l, R
- # appendfilename appendonly.aof
5 h5 m) p4 R7 f
+ n! U0 H1 i+ w1 t, n1 u8 e- # The fsync() call tells the Operating System to actually write data on disk7 K; X% w: M2 @6 q" t+ D0 @
- # instead to wait for more data in the output buffer. Some OS will really flush ( F; h) t+ x- O3 Y: N1 v9 I" ^
- # data on disk, some other OS will just try to do it ASAP.( G% _) G! k3 e4 J
- #- ^. r$ g* V# r' E- B1 R
- # Redis supports three different modes:: |( b# p: P: T8 _9 A4 R
- #% a9 v" V# s9 I6 |& e8 R( R
- # no: don't fsync, just let the OS flush the data when it wants. Faster.3 {! a1 t q; j
- # always: fsync after every write to the append only log . Slow, Safest.
, j$ Z+ x3 W4 k9 _ - # everysec: fsync only one time every second. Compromise.% k% h. f7 p& y3 R$ z3 E- G
- #
7 f6 c4 x4 \$ n L - # The default is "everysec", as that's usually the right compromise between4 H1 E- x `5 X1 i1 ~% z3 `
- # speed and data safety. It's up to you to understand if you can relax this to
) `) ^$ p" |) z - # "no" that will let the operating system flush the output buffer when
& E8 J% v6 q8 a/ i - # it wants, for better performances (but if you can live with the idea of
. J$ x1 @& T! K O- a6 n - # some data loss consider the default persistence mode that's snapshotting),
$ l. g" N7 Q v9 g - # or on the contrary, use "always" that's very slow but a bit safer than
, Q1 K: X9 Z- y" _ - # everysec.
# b& l- B0 S( E4 A f* v/ Y - #/ a& a2 ]; e1 M, u' p
- # More details please check the following article:
: N' j7 [4 M n% b2 a - # http://antirez.com/post/redis-persistence-demystified.html
+ S. n( ^- Z$ v e+ |' j - #
$ G; {' X' B$ ^5 o - # If unsure, use "everysec".
2 i+ |$ L4 j& P; n$ ]9 q+ d) [
1 n/ |% r* z3 k1 k+ [8 W/ Z+ H5 A- # appendfsync always
+ N) E2 _2 l6 O1 P! _) | - appendfsync everysec
6 }! Z; B! m$ ?: ] - # appendfsync no) P; I+ N4 V3 @! D0 @7 @
- 0 e! w! \4 w7 X& f1 l0 D
- # When the AOF fsync policy is set to always or everysec, and a background
/ ]8 ~0 W& Q* V9 D. t% T - # saving process (a background save or AOF log background rewriting) is6 X; B. q, c( j6 S
- # performing a lot of I/O against the disk, in some Linux configurations4 B& E7 r8 i2 T' `+ N+ d% U
- # Redis may block too long on the fsync() call. Note that there is no fix for1 C% p ~% q3 }& j3 y7 K0 E5 W$ o
- # this currently, as even performing fsync in a different thread will block
- f' d/ n- B+ b D; t3 t - # our synchronous write(2) call.1 d0 @; \* D$ A2 ]% m
- #
. H' C) H' Z9 D; c9 s f& m - # In order to mitigate this problem it's possible to use the following option
# ~% v$ e m. F1 _3 B. u8 Y0 ~! r - # that will prevent fsync() from being called in the main process while a
6 G! X1 {6 u' k! n - # BGSAVE or BGREWRITEAOF is in progress.% j7 D" k! d5 s2 z7 H7 b7 o+ p
- #
7 I; i% t/ E9 _# p3 ]0 @ - # This means that while another child is saving, the durability of Redis is
( k3 ~; z6 J9 }- [& R$ q9 Q" L - # the same as "appendfsync none". In practical terms, this means that it is0 W' ]* N& P$ F+ Q0 ]1 t
- # possible to lose up to 30 seconds of log in the worst scenario (with the. L& @3 r5 F- `( g3 R
- # default Linux settings).
6 A/ z: d& }% N8 m# f - # 0 @9 o% m6 G. [+ ?
- # If you have latency problems turn this to "yes". Otherwise leave it as/ W+ [, d% |% \% [. ]$ G& f
- # "no" that is the safest pick from the point of view of durability.
7 g# Q$ V! t, C' V ~ - no-appendfsync-on-rewrite no8 D- | q. `% N
- - b: B0 T: R# M3 |2 a# N* x$ l
- # Automatic rewrite of the append only file.0 O6 y+ ~5 r7 B' ]( ]' O! i
- # Redis is able to automatically rewrite the log file implicitly calling/ A: Q" J& I1 p% V$ H- o
- # BGREWRITEAOF when the AOF log size grows by the specified percentage.
! Z T9 |, V; d4 G4 n8 V - # + a, y! M- q( c8 p+ ]6 m
- # This is how it works: Redis remembers the size of the AOF file after the
1 i, P( J& U% O& V# ? - # latest rewrite (if no rewrite has happened since the restart, the size of* x9 O: ^8 u; L h+ @
- # the AOF at startup is used).
5 s% R8 l! G6 z - #/ |% W( G) |$ s7 X0 O
- # This base size is compared to the current size. If the current size is
' V- `$ r1 C9 A4 Y - # bigger than the specified percentage, the rewrite is triggered. Also
M# t9 A, H2 n, z, G - # you need to specify a minimal size for the AOF file to be rewritten, this6 t9 \! D$ e( r( f6 z
- # is useful to avoid rewriting the AOF file even if the percentage increase, @7 k4 m* ]$ a1 j( L' Q8 d
- # is reached but it is still pretty small.
) H) Y. d6 a7 _; ^6 P. K - #
' V2 K+ H3 W5 T3 h$ Y4 v7 Q - # Specify a percentage of zero in order to disable the automatic AOF6 T, B8 X4 G7 _1 J
- # rewrite feature.* I* d% m0 \+ u, t. f
/ \# C$ \) p" L' {+ }4 f. G3 U- auto-aof-rewrite-percentage 100
- C. V7 w2 g9 x7 v" V6 M) r- ~* x - auto-aof-rewrite-min-size 64mb o2 f6 T* y& d/ n: c
- 8 L" H9 h& V8 W+ p1 p9 ^9 ?* ]
- ################################ LUA SCRIPTING ###############################9 d& b7 h# B2 [$ z
4 i& U3 ^5 ^* d2 U: [3 q, }5 |- # Max execution time of a Lua script in milliseconds.( J$ H5 }) t' D# l5 `
- #/ J5 C! ]; x" X" v
- # If the maximum execution time is reached Redis will log that a script is
; i& v4 `: u& m. x% N! h - # still in execution after the maximum allowed time and will start to
/ s- M) S# \3 q0 z* W+ x/ o - # reply to queries with an error.7 _% I6 ]5 x7 X# q
- #1 |3 D4 V5 |* L+ d$ l2 N0 L
- # When a long running script exceed the maximum execution time only the
; s2 ~" W$ |8 W0 d - # SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be$ i8 J" V. o' G8 `
- # used to stop a script that did not yet called write commands. The second
9 w4 X. Y ]; _2 o( `% R$ r - # is the only way to shut down the server in the case a write commands was
7 g& _4 k0 e( F& a% i# v1 |6 ^ - # already issue by the script but the user don't want to wait for the natural
; t* l$ J; w. A* M4 J' x( M: [ - # termination of the script./ k; ?+ H# H" A8 H
- #
1 }3 X4 w* Z. f9 ~; K! f - # Set it to 0 or a negative value for unlimited execution without warnings.- Q9 E) Y, S+ c8 S f
- lua-time-limit 5000( e# K0 n& n* _$ J6 P4 ~
- , j3 E1 q9 G8 ^+ U8 b5 f
- ################################## SLOW LOG ###################################
' D5 d& } f3 X. \ - 5 N' F! f, @! l, k
- # The Redis Slow Log is a system to log queries that exceeded a specified8 J6 ~! n# D7 U/ @5 q O. D5 u
- # execution time. The execution time does not include the I/O operations4 L! U" U! D, b- M/ l% O% f5 V8 Z
- # like talking with the client, sending the reply and so forth,% X/ j% q: ~/ s1 h
- # but just the time needed to actually execute the command (this is the only
8 _8 \& l# z v& Z - # stage of command execution where the thread is blocked and can not serve M ^# I5 s- j0 c3 R
- # other requests in the meantime).
+ p6 O+ C1 k/ K, |% O - #
! ~6 S- h" U3 U- C# u8 e$ S# {8 z - # You can configure the slow log with two parameters: one tells Redis* e- f1 u$ R8 R E
- # what is the execution time, in microseconds, to exceed in order for the
! y: {) i3 I( @# ^ s - # command to get logged, and the other parameter is the length of the
! i3 B3 s- G) S1 Z) k% p0 R - # slow log. When a new command is logged the oldest one is removed from the2 Z+ `8 O% G* \: N
- # queue of logged commands.$ G3 F6 N3 k4 y# i9 u; e$ q& q
- 9 {# ~% |9 H1 t) ?( L: i) E
- # The following time is expressed in microseconds, so 1000000 is equivalent0 {* [- d; q8 c- r$ j' {
- # to one second. Note that a negative number disables the slow log, while d R5 W: `" S$ W v! i
- # a value of zero forces the logging of every command.. Q# y, B8 u2 R4 Z( y
- slowlog-log-slower-than 100009 _3 r/ e7 c) N' b$ m/ l: }
- |2 P. F: @8 G1 T- # There is no limit to this length. Just be aware that it will consume memory.
5 s3 o) i& K. y& w: Z& E - # You can reclaim memory used by the slow log with SLOWLOG RESET.! j# {' R: c. O9 B9 E
- slowlog-max-len 128- O+ |% V. }2 ?; Z; i+ \* T
* \: p6 P& |0 x/ n" C& F; P% c9 v- ############################### ADVANCED CONFIG ###############################* V6 q" ^2 j2 k& R) l" B* W
: C5 |8 A8 Y8 C' I- # Hashes are encoded using a memory efficient data structure when they have a s- L n" }! l! S# ~+ [$ D
- # small number of entries, and the biggest entry does not exceed a given
6 {, A' d% u9 I/ m: X - # threshold. These thresholds can be configured using the following directives.
, q+ k0 b' a) u - hash-max-ziplist-entries 5123 B% v; | N8 n; n* q
- hash-max-ziplist-value 64
! K( }0 t* h( I! B8 ]
' a- b3 X0 P! q, |4 r9 y* w- # Similarly to hashes, small lists are also encoded in a special way in order
% [" l8 _* _' d! u7 l - # to save a lot of space. The special representation is only used when' Z' y4 W5 q$ i( Z
- # you are under the following limits:: H/ U" V" B7 S
- list-max-ziplist-entries 5127 J, D: k) j9 F! F$ V |$ E
- list-max-ziplist-value 64
, ?0 h. `3 V' c% h; ]( s
2 W- i6 m7 z/ P$ \- # Sets have a special encoding in just one case: when a set is composed8 c) i% D5 A, u! G7 v
- # of just strings that happens to be integers in radix 10 in the range* @3 d4 u1 q! L) U
- # of 64 bit signed integers./ x( P g+ L. V$ o7 Z& y; K0 q' g5 x
- # The following configuration setting sets the limit in the size of the, z3 i- U3 F+ H" ^
- # set in order to use this special memory saving encoding.
3 ^& C1 H6 |% c: U1 a - set-max-intset-entries 512! W$ i: B6 j G4 ^7 l1 R' b, X
- ( B+ ^$ F6 t) @
- # Similarly to hashes and lists, sorted sets are also specially encoded in$ ^, R; s0 W/ E1 _
- # order to save a lot of space. This encoding is only used when the length and7 o( w1 M, v# ~3 z* M( q/ H
- # elements of a sorted set are below the following limits:( G, r/ k0 q( ?+ r0 g, ?: A
- zset-max-ziplist-entries 128
9 `( T# B4 U1 ?0 f - zset-max-ziplist-value 64, ~& N! w a9 ?, h
- 1 u: k1 f" n4 L) x% D
- # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in: c# Q1 ]2 ^: O: R: C2 a; l' k% z0 o
- # order to help rehashing the main Redis hash table (the one mapping top-level$ \% S3 s& x4 H( P. O& K# @ T
- # keys to values). The hash table implementation Redis uses (see dict.c). M* C3 ]/ r' J' X' {- J$ v
- # performs a lazy rehashing: the more operation you run into an hash table
2 [! Q- u; A) t' H7 `8 z - # that is rehashing, the more rehashing "steps" are performed, so if the
& O& w I( k+ y6 f7 s. r# }* s; d! |+ B: V - # server is idle the rehashing is never complete and some more memory is used- t- T( p5 }5 e
- # by the hash table.$ I/ K) u/ v; s) x. g. A/ m
- #
) T0 d& R% ]7 A% k! K0 m9 o - # The default is to use this millisecond 10 times every second in order to
; H8 A3 L# l% }; D - # active rehashing the main dictionaries, freeing memory when possible. x" ~9 z6 \* b" M' ?* x
- #
y: D/ U0 N$ Q* Q8 t3 u - # If unsure:
5 J+ E) U! a+ v# |8 m5 v( H - # use "activerehashing no" if you have hard latency requirements and it is) Z0 v; U; r" `8 c; V9 R/ ~4 ~
- # not a good thing in your environment that Redis can reply form time to time
7 V* A5 [1 E g9 @: f2 j, I - # to queries with 2 milliseconds delay.+ f+ ]/ D4 H |: x% B3 O; s
- #$ }' f. J) @9 c7 ]) j0 l2 z# h
- # use "activerehashing yes" if you don't have such hard requirements but
# ?/ c+ Q" ^8 p2 z% F" ^& n. T p - # want to free memory asap when possible.4 A, J7 C" x1 e( H1 z
- activerehashing yes
$ A8 E- ~% G- W+ ?
* ]5 A% N j( C2 h ]- # The client output buffer limits can be used to force disconnection of clients
9 [ |/ p, c$ C' Z l- n' O - # that are not reading data from the server fast enough for some reason (a! l% b0 Y8 |3 h1 t
- # common reason is that a Pub/Sub client can't consume messages as fast as the$ M5 f c; `6 B7 @
- # publisher can produce them).
- ~- ~$ N S- x+ I8 r9 C& f2 M - #6 r* y6 |( E# f6 m) e0 l
- # The limit can be set differently for the three different classes of clients:1 f% n" D2 n$ _
- #0 K! u" n* z& f) }
- # normal -> normal clients; l, {& G2 s8 J- J3 x- R
- # slave -> slave clients and MONITOR clients6 [$ y" B2 r) [& C" |( Q8 t2 U
- # pubsub -> clients subcribed to at least one pubsub channel or pattern
, O$ }0 |4 y0 ~$ g" ?. S - #
2 r$ O. h- r( o9 p* [/ V - # The syntax of every client-output-buffer-limit directive is the following:, i7 G L6 G% O( | [' E
- #) f- W7 g& e G0 |8 N0 f
- # client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>
( ~ I/ H% `+ N0 V9 o- J: y - #9 b- |; P5 ~6 z, T1 ~6 v
- # A client is immediately disconnected once the hard limit is reached, or if
' r$ m. o6 B! I# R; G* [2 l: r8 Q - # the soft limit is reached and remains reached for the specified number of' B2 Y- J4 J' Z6 M2 m2 E- M- n7 a* H
- # seconds (continuously).+ `; P1 Z+ f3 a& Q9 e* A4 q
- # So for instance if the hard limit is 32 megabytes and the soft limit is
6 [/ F+ c6 h1 s7 e - # 16 megabytes / 10 seconds, the client will get disconnected immediately
; e% ]4 w; C3 W/ i5 x - # if the size of the output buffers reach 32 megabytes, but will also get" l+ j' `$ B( u* P! v
- # disconnected if the client reaches 16 megabytes and continuously overcomes
/ B2 O- n% D! i; _ - # the limit for 10 seconds.
" P5 o3 ]( ~) z$ w, A5 X - #
- l( {# Q$ n+ _ K% D - # By default normal clients are not limited because they don't receive data; I2 m4 @1 H: o1 u( z
- # without asking (in a push way), but just after a request, so only; s3 R- Q( _4 ^5 w \" t" M0 i
- # asynchronous clients may create a scenario where data is requested faster
& X5 {& R; a1 X( W# Y. U% D - # than it can read.
# S1 w3 N# ^" X6 N+ I3 J4 ^ - #
. B+ z' _; ]8 e4 r% ` y - # Instead there is a default limit for pubsub and slave clients, since
7 A, V+ h' f# a6 V* T - # subscribers and slaves receive data in a push fashion.
- ^, w" w4 e! J5 @ - #
8 @. c; m0 M* N0 j ]( M - # Both the hard or the soft limit can be disabled by setting them to zero.
( F: t& H v: k) |4 b - client-output-buffer-limit normal 0 0 0! S; t+ q9 o1 Z8 t7 S3 ^5 [
- client-output-buffer-limit slave 256mb 64mb 60
9 \* k8 P2 a' G/ | - client-output-buffer-limit pubsub 32mb 8mb 60
2 l; I) A! g: o( T# i, R! [( ?$ z
# H) z# o+ E+ v3 `( r) [; W- ################################## INCLUDES ###################################' g$ M- K# K" Z8 P
) Q. \7 E4 O. n, E2 |) ]8 ~- # Include one or more other config files here. This is useful if you
# U/ Z* m& ?9 S - # have a standard template that goes to all Redis server but also need) W% w. ]; l# I1 u" G3 d; ]
- # to customize a few per-server settings. Include files can include
) n: x( O$ I- w8 p z0 a - # other files, so use this wisely.& `, O- o% M* E& W
- #% O! [. b# [+ U
- # include /path/to/local.conf; H9 e5 g3 a# U5 `6 c4 r
- # include /path/to/other.conf * T/ W% K6 I7 O0 L' \2 X( C
- ##########################配置文件结束################################
4 v0 _6 N. p5 ~9 F, \( V - 第三步:启动进程
: {9 C6 {" U4 J& B" b6 N1 ?/ a - #redis-server /etc/redis.conf
. t) m+ v/ _: h - 查看进程有没有成功启动/ S. X" |3 I4 D& Z
- #ps -ef | grep redis E0 |0 i# `: [7 @& d+ J
- 测试输入一个键值
- \% |) i6 G B, j# O/ A! F - #redis-cli set test "testredis"
+ g+ D- A7 z5 ] - 获取键值
. [! g; h6 k5 `' F - #redis-cli get test7 H; p4 s$ z2 `1 Y* `: ^7 e) O
. @; O3 j+ ]8 p- _- 3 W/ I$ [1 F! d* {+ J
- 第四步:关闭redis (这个是更改配置文件后 正常的重启方式 不重新加载redis配置跳过)8 G/ K+ L! q0 t: G- q' E* f+ v
- # redis-cli shutdown //关闭所有 4 G1 a& j! k$ W. U- c: _. z
- 关闭某个端口上的redis
8 n2 s, W! I0 W* t8 u! h - # redis-cli -p 6397 shutdown //关闭6397端口的redis 7 d! u- k1 r* a3 h- W, D
- 说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename dump.rdb
8 y/ Z! I. j3 ?1 y m. i! z* h! N! d
* |/ W* l; |7 I8 E* W$ O) t, q
8 C# U. m7 @2 G& {- 第5步:php扩展安装5 g& P9 j! A6 I) L& @' y9 x
- phpredis PHP扩展下载地址 ; [' t: b0 t, c9 _* f/ P6 L/ @
- https://github.com/nicolasff/phpredis/tree/2.2.2
5 G! C8 [6 T8 ~1 {5 t - 选择最新版本下载zip 3 E" e: v G" U* i+ T( S6 u. O
- 8 K8 m9 X9 A' K! f, ]& l1 h" b
- 然后自己上传zip 用unzip解压到当前目录 unzip 文件名9 J% h" L1 u$ G4 }1 {
- 0 J- h0 C: O5 k- U! g. A9 T
- # cd owlient-phpredis-90ecd17/ #打开解压后的文件夹里面 这个解压后的目录 要是不知道 可以输入 "dir" 查看" I1 l0 s2 V8 Z' [, N6 R; M7 W
- # /www/nginx_php-5.2.17/bin
# K8 j7 u q e& i, z K - # ./configure --with-php-config=/www/nginx_php-5.2.17/bin/php-config& L! r' L* t/ _5 r6 F* F9 N6 F
- #make
" q& ~5 O! A! ]9 Y - #make install #记录产生的redis.so路径6 N P( [4 d& H' }' p3 `
; G6 E2 d. B0 L0 K- 修改php.ini文件
, h- L+ F, R/ ^ - 在php.ini中添加如下一行:
. }5 t- {9 _. k7 ^! O - extension=/?/redis.so #是刚刚记录的产生redis.so的路 写在 ?那
8 |' ~0 Y/ X/ Q8 ~9 C - 重启 使之生效:, f; V/ F% @3 n: k1 Y! v
- /usr/local/php/sbin/php-fpm reload
% ]+ N, p6 o- {0 G2 d6 K/ g - /usr/local/nginx/sbin/nginx -s reload 6 i( u% j$ M" w" f* M" }1 P) _8 b
- , ^& A4 K) W4 {) S
- 将 Redis 作为 Linux 服务随机启动
0 [! o8 N: S2 O1 T - vi /etc/rc.local, 加入代码:
, \! B- A; V. y% a - /root/redis-2.6.10/src/redis-serve #路径看情况修改
$ m- G, F2 e8 j) J% S
5 |) i- Y* O Q- redis-cli -h localhost -p 6379 info #命令要在redis目录下面执行
4 g( U. z7 J% P% Y( y - 提供host为localhost,端口为6379,redis服务的统计信息
: Q. Z/ K" ~) S: j( S& _+ {
8 c' U j5 {: w) {# @
, G! p" e. T4 L# ?4 y$ j0 {- 就这样你的web服务器就支持redis了 记得要在 给dz 的配置文件 加上12.0.0.1哦% d# P8 w" F4 L3 h
- dz配置文件在 config目录下面的 config_global.php- R. d+ s6 j- [# n. Z
- $_config['memory']['redis']['server'] = '127.0.0.1';& @8 q$ K; }" H+ g2 A+ N
- $_config['memory']['redis']['port'] = 6379;/ h) ]( c- t5 T2 B
- $_config['memory']['redis']['pconnect'] = 1;
+ U8 s2 i6 _7 `' d. S" F+ h7 m - $_config['memory']['redis']['timeout'] = '0';
. ~) M# e0 J/ @3 _1 U# o( Z - $_config['memory']['redis']['serializer'] = 1;9 h ]% q& z4 Y
复制代码 |
|