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