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