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