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