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