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