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