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