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