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