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