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