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