分享到:
发表于 2018-11-16 12:42:28 | 显示全部楼层 |阅读模式
环境配置0 f. q, J1 g) g2 U; t
* c+ |, ~+ f2 P6 f% a: v

- k3 h: Y0 S: d+ m5 i) Ihttp://www.discuz.net/forum.php? ... amp;highlight=REDIS
关注微信公众号《神采飞扬网》,即可获取最新回复通知!
 楼主| 发表于 2018-11-16 12:43:33 | 显示全部楼层
http://www.discuz.net/forum.php? ... 648&highlight=REDIS
6 h/ `& R  P6 `5 _无意间测试 单机状态 redis相当给力 测试1000请求/s  单纯的 get 和set 居然只用了 0.01秒 当时我惊呆了
! F& B! Y% {6 }% F  D8 ~6 k4 E  a# A$ E
http://www.discuz.net/forum.php? ... 731&highlight=REDIS
6 N" w7 e/ @" c* L) a. [
' S6 E- K  E) F8 }https://wenku.baidu.com/view/265a5ce176a20029bc642d0b.html
$ \% S$ C2 F1 F; q! ?9 U1 Y2 |8 F' j! I0 t; F' O
=======================================
. _5 D. X* m8 d" H# P+ a
  1. 连接上 ssh
    2 ^4 a# b! S/ G1 l. N
  2. 0 v. a6 @4 T; S& f( b2 B2 L
  3. 9 \2 Y6 |+ ?: e
  4. 第一步:下载redis
    ( E8 K7 b( U/ o7 U1 t
  5. # wget http://redis.googlecode.com/files/redis-2.6.10.tar.gz
    6 y! S& N* E) s
  6. # tar zxvf redis-2.6.10.tar.gz ' }- e" N: r- j3 T: ^
  7. # cd redis-2.6.10% m0 {) ]( u7 A8 \8 l
  8. # make
    & U3 B) z( |/ {6 V! Y- S6 j
  9. # make install  
    * Z2 h6 a, ?( a' ^& Q2 C; y
  10. #cp redis.conf  /etc/ #复制配置文件到etc目录下面* i' T( U8 C6 f
  11. 第二步:修改配置
    , ^% \/ T6 ^% A# q1 h. y4 t( @
  12. #vi /etc/redis.conf5 x  Z% O1 F5 L. a7 u, L$ E; ~& g
  13. ######################下面是无措的配置文件 复制过去就成#########( x" R) F7 q$ U6 V! L4 J
  14. # Redis configuration file example
    7 C* b  x2 C( k& M9 S2 @- A* ?

  15. * h1 ]; a* D0 {% ~
  16. # Note on units: when memory size is needed, it is possible to specify6 l. \9 p, I; D$ _, D! @. @% x
  17. # it in the usual form of 1k 5GB 4M and so forth:/ ?! G) n7 ]7 K/ f/ Q" h7 E
  18. #9 s! A% J5 e0 d2 }
  19. # 1k => 1000 bytes5 A/ x8 E, K+ k9 u& b* E) Q: b9 E. P
  20. # 1kb => 1024 bytes
      U0 D" N8 }% B% L/ p: l' w
  21. # 1m => 1000000 bytes
    9 N+ q$ F4 v* X1 P  R" H5 `
  22. # 1mb => 1024*1024 bytes
    - ?. m4 M8 d- f! C' Q% D
  23. # 1g => 1000000000 bytes/ x  ^3 U2 Y; b$ `- S8 X" q
  24. # 1gb => 1024*1024*1024 bytes
      w; Z" [1 Y1 K  B4 @+ n9 F& c# V$ ]
  25. #! q$ n% b" @( i5 Z& I0 N
  26. # units are case insensitive so 1GB 1Gb 1gB are all the same.
    ( f0 M" P- M5 x: I4 v4 \

  27. 7 N- a6 k8 w. A4 C+ P
  28. # By default Redis does not run as a daemon. Use 'yes' if you need it.. \3 }5 h. |( s' v& c- f2 ]
  29. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.: M( E. }3 Y' z  f
  30. daemonize yes
    # u: ]# X9 [0 U; z" Z5 `. u
  31. 6 ^& w8 A+ B6 V
  32. # When running daemonized, Redis writes a pid file in /var/run/redis.pid by  ]5 a9 P7 `; ^" [5 q9 Y5 E
  33. # default. You can specify a custom pid file location here.
    8 Q: T1 Y% G" T: B  W3 o
  34. pidfile /var/run/redis.pid& g$ E; i' I9 Y3 D

  35. 1 v9 C1 q2 o9 m  o9 n0 ]8 d
  36. # Accept connections on the specified port, default is 6379.
    % t/ W/ A' g$ x
  37. # If port 0 is specified Redis will not listen on a TCP socket.3 I: w5 E; O8 W. x. |; I
  38. port 6379
    ) W/ y4 B+ ]- |$ v8 L7 Y1 q

  39. # U3 Q7 h- G8 U& a& m' l( r  @5 `
  40. # If you want you can bind a single interface, if the bind option is not
    4 e" Q/ c; _& y2 @
  41. # specified all the interfaces will listen for incoming connections.
    / Z. Q( N' N: K8 S9 @: u2 w! Z
  42. #
    - [9 t% U' Z! Y" H% F% i/ K
  43. # bind 127.0.0.1* C1 [/ J$ [4 v3 N$ [7 L

  44. - F$ o8 X" X; k* t
  45. # Specify the path for the unix socket that will be used to listen for1 h9 a1 E9 `# e* r" ~' w
  46. # incoming connections. There is no default, so Redis will not listen7 V0 x% G; r: M% x/ `+ x
  47. # on a unix socket when not specified.9 O- f5 T! ?6 Q2 N
  48. #: B1 [/ x6 E# x; G6 P" z; ~% U
  49. # unixsocket /tmp/redis.sock
    5 `9 I( U1 Y0 n$ q. @' Q
  50. # unixsocketperm 7557 O2 R) {  I. D& D  Z2 C# @
  51. $ J6 N' p6 U7 y5 w( h
  52. # Close the connection after a client is idle for N seconds (0 to disable)- ?' o# ~6 \* e3 d2 z
  53. timeout 300
    ! {1 z* Y' D7 g, v- }4 J. ^- i0 x+ r% \

  54. 4 }6 O0 w& L( b* r; _8 Z
  55. # TCP keepalive.$ O% k) g' ^  D* E% J3 B/ I
  56. #
    $ ^+ ~& Z5 v' S
  57. # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
    : n4 n. ~& ]% b$ ^" F# e+ i1 Q
  58. # of communication. This is useful for two reasons:, v' a2 P" ?$ _6 F; M
  59. #3 x! c: C! R; m1 _8 F- R0 c) g( F
  60. # 1) Detect dead peers.
    ) ~- o  b% s  ]* u
  61. # 2) Take the connection alive from the point of view of network
    : j" S1 V4 H1 Q
  62. #    equipment in the middle.
    * I: ?( J2 {- _. w  O1 L3 x9 N
  63. #2 h+ o- Y2 ~) f9 H# o" o
  64. # On Linux, the specified value (in seconds) is the period used to send ACKs.
    4 M, L6 T7 h* G5 u& p$ ^
  65. # Note that to close the connection the double of the time is needed.* b: T0 f& i$ ~. P. M/ u0 M
  66. # On other kernels the period depends on the kernel configuration.8 l8 M: @+ |! j; i0 t5 ^: e/ B9 z& n
  67. #
    7 m/ q' [. B! Z/ P7 M
  68. # A reasonable value for this option is 60 seconds.' {- x* d$ O, |# z; O
  69. tcp-keepalive 0
    4 A0 w! C3 ]1 K8 G% p
  70. 8 h" b* N! n+ }3 E% V# a# v
  71. # Specify the server verbosity level.- c# k5 Z1 x7 o6 f+ l4 n1 J
  72. # This can be one of:* m9 g0 b% c, o. z8 v- ?
  73. # debug (a lot of information, useful for development/testing)' R& @- \! A0 V& S) R
  74. # verbose (many rarely useful info, but not a mess like the debug level)& ?1 r8 g! w! b( h
  75. # notice (moderately verbose, what you want in production probably)
    - C) b- c- [/ i' r
  76. # warning (only very important / critical messages are logged)
    : t4 B" B% ]3 Y$ G
  77. loglevel warning; \' o4 s) h- S5 P4 V& B* y" Y3 ?

  78. & m' c3 i+ q$ }0 |& e. u
  79. # Specify the log file name. Also 'stdout' can be used to force: e% d" g$ w8 u% t! _
  80. # Redis to log on the standard output. Note that if you use standard
      O. }  o& {/ r% Z, r% ?/ n& Y
  81. # output for logging but daemonize, logs will be sent to /dev/null
    ( \2 g& K! y$ U# E
  82. logfile /var/log/redis.log4 F* y8 `8 E" }, K
  83. 5 [- n" b( o4 C& B+ q& e
  84. # To enable logging to the system logger, just set 'syslog-enabled' to yes,
      p. {% \' \! n( E
  85. # and optionally update the other syslog parameters to suit your needs.
    ! A& Q$ h: s' O3 U' P0 ~2 F
  86. syslog-enabled yes0 ^/ a. \+ X. o# j1 i
  87. 2 b( c9 M  w/ m7 v+ j
  88. # Specify the syslog identity.# z$ k4 ?/ K& z; y7 \6 m5 \
  89. # syslog-ident redis1 H) _! D! M7 N; c& J' U
  90. 0 y+ W5 m* A/ \* @9 ?  x; j
  91. # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
    ' e3 E9 c% y0 ~# B; S
  92. syslog-facility local0% F$ e( P- \# X- d% a: j& i
  93. # m0 c  y+ F: h! Y
  94. # Set the number of databases. The default database is DB 0, you can select
    5 F/ ?9 y1 @) y
  95. # a different one on a per-connection basis using SELECT <dbid> where4 X9 w5 _. n& _7 ^# F
  96. # dbid is a number between 0 and 'databases'-1
    6 U  D& E2 ?+ ?, }% K7 ]
  97. databases 163 r8 n( |/ P" p5 p" Y

  98. 8 u' {7 ^5 T! z7 o0 o
  99. ################################ SNAPSHOTTING  #################################! v$ f. r/ F: J6 _- A
  100. #  F0 C4 B$ Q) f/ X1 ]! C# |9 k1 |
  101. # Save the DB on disk:
    ' T4 n% X! s: ?9 j
  102. #
    0 Q; r  B: q' p& O  k" P9 r
  103. #   save <seconds> <changes>: [/ u5 }; R$ l. C; H. t
  104. #8 J- x  _$ z( l6 K, C, s
  105. #   Will save the DB if both the given number of seconds and the given
    / ]" A, t& G' n" ]; C9 G) ^
  106. #   number of write operations against the DB occurred.
    ; Z- C$ I1 W; m' r- ?8 s3 O  K1 p
  107. #
    1 U* O8 ?8 m9 x1 _! E; N+ H; g
  108. #   In the example below the behaviour will be to save:
    5 t  ^" o0 Q% ~1 ]( d3 p- h
  109. #   after 900 sec (15 min) if at least 1 key changed
    : S+ K! d" j, \; j6 T  J, W9 T+ N
  110. #   after 300 sec (5 min) if at least 10 keys changed
    " [! o# M7 X  Q! F3 W* \) N+ _
  111. #   after 60 sec if at least 10000 keys changed! @* Z7 F8 w! S, q  ~
  112. #
    ! ^# c6 s4 E. U3 Y
  113. #   Note: you can disable saving at all commenting all the "save" lines.$ P1 j4 a# f1 D1 `2 ^
  114. #9 K) w7 |9 r/ M" V, a
  115. #   It is also possible to remove all the previously configured save
    & X2 Z( N6 K" B: m7 y! t2 a
  116. #   points by adding a save directive with a single empty string argument
    - V/ c* E$ O: N# s( T: T
  117. #   like in the following example:
    + v" R# Y$ r# P& L
  118. #
    & b+ U; y7 ]9 u
  119. #   save ""1 m5 b: R% |( h5 _

  120. 0 U8 a" ~" _: r/ e! g
  121. save 900 1- M1 {7 p* c4 m: V4 w
  122. save 300 10
    5 i" I0 f/ Q5 u8 [7 H7 n" Z0 J' B
  123. save 60 10000
    ) x* Y, b/ z9 O, x

  124. * H* a2 f. [6 P9 P. ^; {0 v1 x- L* Q
  125. # By default Redis will stop accepting writes if RDB snapshots are enabled
    7 r4 k7 V! o. G6 V0 L. i
  126. # (at least one save point) and the latest background save failed.. n, q: E6 F$ T2 C( M
  127. # This will make the user aware (in an hard way) that data is not persisting  k% Q" e( i5 H# }
  128. # on disk properly, otherwise chances are that no one will notice and some& @8 h) @% V; }/ f+ A- k
  129. # distater will happen.
    ' [; B1 F1 B% j. V( Y
  130. #
    : H7 j( y: \& g3 A
  131. # If the background saving process will start working again Redis will
    ' T2 Y) _+ t/ J, @
  132. # automatically allow writes again.
      @' E, Q: V: {/ L0 e
  133. #
    . }" M2 P! H1 L
  134. # However if you have setup your proper monitoring of the Redis server8 _& G9 c  S: X; L
  135. # and persistence, you may want to disable this feature so that Redis will' U# |) Y8 N  Q# a$ c; I& s
  136. # continue to work as usually even if there are problems with disk,( v1 v; x! K" e- h% Z4 M
  137. # permissions, and so forth.' \6 Q( m. @+ J! I# [# j" t
  138. stop-writes-on-bgsave-error yes& H) G* Q  h. K) U& o. d  P

  139. 2 S" N4 ^: q* }$ b
  140. # Compress string objects using LZF when dump .rdb databases?
    3 ~8 l  h$ A: v/ y
  141. # For default that's set to 'yes' as it's almost always a win.
    / `1 z, W3 b1 Z' D0 w
  142. # If you want to save some CPU in the saving child set it to 'no' but
    + `$ N( y( x  M2 z; b2 S7 V# I: e; T& g4 `
  143. # the dataset will likely be bigger if you have compressible values or keys.! c0 }3 s8 y& Y: Q- \
  144. rdbcompression yes
    # G! F# ]6 y* f' X5 J
  145. * V7 ^6 W: ]" _
  146. # Since version 5 of RDB a CRC64 checksum is placed at the end of the file.
    1 z1 @& @/ b+ j3 m& [6 ]. x+ a5 K
  147. # This makes the format more resistant to corruption but there is a performance' J$ r/ F( v; Y, x" k5 f$ J$ R
  148. # hit to pay (around 10%) when saving and loading RDB files, so you can disable it6 _5 x  u6 E6 U1 Z/ s6 v5 t5 F# V, B8 `
  149. # for maximum performances.
    2 n# V! p& }1 \9 }8 V3 K
  150. #6 X- J$ i5 V( D9 o$ Z! l
  151. # RDB files created with checksum disabled have a checksum of zero that will
    1 x+ z2 a  n7 P
  152. # tell the loading code to skip the check.
    % i0 g4 a  \# @) S
  153. rdbchecksum yes8 w* `5 d9 g+ u( }3 _
  154. % f1 v! t( K: ]0 e
  155. # The filename where to dump the DB
    . Y" O+ c# b" P! E$ m* M7 V1 Q& i
  156. dbfilename dump.rdb( ~% C! d6 {+ P# O
  157. ' T# \7 Z/ }" D  `& U; n! c6 X% U7 Z% N% M
  158. # The working directory.
    % i5 u6 j( `' F3 {5 a7 J+ l$ B
  159. #
    4 |! ]- J* ?1 D% g/ k5 e, m* R
  160. # The DB will be written inside this directory, with the filename specified* |2 [2 }- D  f5 D/ Y9 B9 H3 T
  161. # above using the 'dbfilename' configuration directive.
    5 `9 H$ S3 i. G) R+ \2 K9 _5 J7 d
  162. # $ F- p+ y% \" a" b2 m& i" T: f
  163. # The Append Only File will also be created inside this directory.
    * Z$ Z2 O" B* y
  164. #
    , {8 N- _1 ~- E# S1 I! f
  165. # Note that you must specify a directory here, not a file name.+ ~4 J# X$ w% d& q  {
  166. dir /var/db/redis
    % ^7 H: `! l) h( ~1 [

  167. : d/ Q2 b  n7 i" _! r3 R3 O! X
  168. ################################# REPLICATION #################################
    9 T" X5 F7 B& N+ H4 x# w- |
  169. 3 ~5 J  ^% n  W, B6 _& b, f9 w6 U
  170. # Master-Slave replication. Use slaveof to make a Redis instance a copy of+ m; X, o# ]9 d, \/ d
  171. # another Redis server. Note that the configuration is local to the slave
    + {4 R3 k; ]1 F1 H, H! K
  172. # so for example it is possible to configure the slave to save the DB with a
    & }2 m4 A0 e0 q0 t2 Q# h- A
  173. # different interval, or to listen to another port, and so on.* R, Y* K- y! r% Z
  174. #5 k: E0 Q% K( ~8 A' X  z5 i
  175. # slaveof <masterip> <masterport>- J- ~) C1 C: y: B% |
  176. % \. h# ]1 j2 R' Y- Z6 n( ?3 d
  177. # If the master is password protected (using the "requirepass" configuration( m' t: u  N. x8 x* Y
  178. # directive below) it is possible to tell the slave to authenticate before
    2 w& a2 [! G& v/ F! W) |
  179. # starting the replication synchronization process, otherwise the master will* c0 y) E+ Y# z2 Y" W; K- n
  180. # refuse the slave request.
    " g3 J3 u' y+ c3 G) h4 R3 j- Q
  181. #
    ; |6 Y( L$ U! u- s
  182. # masterauth <master-password>5 r( {, s# J* @) O) R* H

  183. 3 L( A; Z5 H5 H* O1 o) h% N
  184. # When a slave loses its connection with the master, or when the replication
    & {' i' m0 K' [( q" J7 a
  185. # is still in progress, the slave can act in two different ways:3 V5 G# T) P6 I2 J4 ?% [
  186. #
    $ @* n3 E7 y& H* M, j0 G) W
  187. # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will
    / _5 T; o: Z. i& i
  188. #    still reply to client requests, possibly with out of date data, or the6 ]* G) z! L# |7 h4 J) g
  189. #    data set may just be empty if this is the first synchronization.
    % f; Z- t2 t+ j- }+ {
  190. #1 [/ h5 G' w/ W* w
  191. # 2) if slave-serve-stale data is set to 'no' the slave will reply with) s) X2 U4 w. k
  192. #    an error "SYNC with master in progress" to all the kind of commands
    * n9 @5 P( n% c/ @! l6 x7 r' T; l
  193. #    but to INFO and SLAVEOF.# R: V; \1 M+ D- s" W) P
  194. #
    ) t, W, a% I: [6 \& r+ J
  195. slave-serve-stale-data yes
    ( w* H  m. _1 E  U4 O3 N
  196. * R+ M$ }3 P  d& o/ y& J8 i
  197. # You can configure a slave instance to accept writes or not. Writing against2 R1 }' ^9 z# |. H$ V( W# Y
  198. # a slave instance may be useful to store some ephemeral data (because data
    7 J& n+ p' r. I
  199. # written on a slave will be easily deleted after resync with the master) but
    3 x0 P9 ~7 @! Z* C8 N
  200. # may also cause problems if clients are writing to it because of a
    ( `9 Q* S* F+ B! X. ]! e
  201. # misconfiguration., u8 y" C$ t; L, s! t
  202. #
    ' Q0 b2 R  j$ H) t+ t7 v
  203. # Since Redis 2.6 by default slaves are read-only.3 ^: Q6 K6 x/ L2 W
  204. #" u5 A' {9 U3 b3 m. s4 @* D, s
  205. # Note: read only slaves are not designed to be exposed to untrusted clients* c7 d) B3 j& U9 ]
  206. # on the internet. It's just a protection layer against misuse of the instance./ x0 m1 j4 [4 p3 d9 g9 ~
  207. # Still a read only slave exports by default all the administrative commands1 ]/ Y* C: o: _; [! o1 n; ]$ j% N- G
  208. # such as CONFIG, DEBUG, and so forth. To a limited extend you can improve
    7 Z( p/ z$ M( b
  209. # security of read only slaves using 'rename-command' to shadow all the" }* ?% ^* x# Z) I# x8 I" h" m
  210. # administrative / dangerous commands.9 W+ s/ K4 t& i& E+ ]0 V( l& m
  211. slave-read-only yes
    0 Q/ H" e4 M% C, O9 B2 V
  212. 4 h6 k" u' T& I3 o# m
  213. # Slaves send PINGs to server in a predefined interval. It's possible to change
    " v$ e$ u$ n4 R& {1 }
  214. # this interval with the repl_ping_slave_period option. The default value is 10
    + b8 V& X) n+ y( Q
  215. # seconds.
    * U# `6 B' q5 ?  P
  216. #
    2 D4 D  G. D4 I( T4 v- @
  217. # repl-ping-slave-period 10
    6 j( D9 T& Q2 P7 o2 h

  218. 3 }4 h  y4 {7 P0 ^& u% V0 F1 G/ ~
  219. # The following option sets a timeout for both Bulk transfer I/O timeout and; i, |2 x; V) }" d
  220. # master data or ping response timeout. The default value is 60 seconds.
    5 d& @% D# e0 q; D
  221. #. w+ I& M8 Z/ U2 F7 r( U
  222. # It is important to make sure that this value is greater than the value& m' L) [  j0 |! [3 U
  223. # specified for repl-ping-slave-period otherwise a timeout will be detected
    . G, d8 N! b3 U  ~, C
  224. # every time there is low traffic between the master and the slave.$ L% [: z1 P  S3 H/ K2 M* [) g
  225. #
    . z- ^% m* {! j! [8 c
  226. # repl-timeout 60
    0 v: V* q1 m6 k

  227. 8 s. W8 h& Q. _- |
  228. # Disable TCP_NODELAY on the slave socket after SYNC?
    5 L7 Q- R# G) m# G2 U- Y- G6 Q0 d. X
  229. #
    " X$ r  |1 w+ t" t
  230. # If you select "yes" Redis will use a smaller number of TCP packets and
    ! b0 W% ~& G5 |" ]  S) J1 X
  231. # less bandwidth to send data to slaves. But this can add a delay for+ K- I1 s! S2 R! [
  232. # the data to appear on the slave side, up to 40 milliseconds with( b9 f2 d5 ?: E
  233. # Linux kernels using a default configuration.
    6 F) m/ J8 J- h' H( [
  234. #
    , ~' x& d, ~) V2 u9 O" ?1 H
  235. # If you select "no" the delay for data to appear on the slave side will: q0 ?- g/ E$ L' u; U  G7 L& g+ S5 _
  236. # be reduced but more bandwidth will be used for replication.$ L' A3 A0 v8 Q, `8 F0 T
  237. #
    - ?) @2 m# m- Z6 u0 P2 K! o4 k1 I
  238. # By default we optimize for low latency, but in very high traffic conditions
    7 g" ~. m) s* r3 w" p/ J" }
  239. # or when the master and slaves are many hops away, turning this to "yes" may) o0 b; j8 Q* O
  240. # be a good idea.
    ' p6 h8 X- o+ U/ ~' n
  241. repl-disable-tcp-nodelay no
    : \: b) t3 ?' h6 p0 x7 o
  242. ; _/ q6 N4 _: P5 x/ C
  243. # The slave priority is an integer number published by Redis in the INFO output.
    $ y# ?) d9 L* I: U$ d8 z
  244. # It is used by Redis Sentinel in order to select a slave to promote into a
    6 m% F$ I7 t& m
  245. # master if the master is no longer working correctly.# a/ D! M7 ?$ H1 [+ N
  246. #
    ( h. I( b8 p8 }# E' T
  247. # A slave with a low priority number is considered better for promotion, so
    $ F+ l/ N, u; Z4 F' O
  248. # for instance if there are three slaves with priority 10, 100, 25 Sentinel will
    + H& k1 j: j* i
  249. # pick the one wtih priority 10, that is the lowest.% I& E  E; @- g" n
  250. #, d2 C9 k( ~( f  v4 p4 M% U5 a7 I
  251. # However a special priority of 0 marks the slave as not able to perform the
    ) u; A1 o; B, m$ S
  252. # role of master, so a slave with priority of 0 will never be selected by8 \5 q# }7 U3 J% e5 F! m* X' r
  253. # Redis Sentinel for promotion.
    ( V. c$ m& v' P6 ?" }; _: T
  254. #
    2 \5 |0 S7 J( X: `0 d: f4 h( b
  255. # By default the priority is 100.
    . i9 ]6 F& p0 ]6 L) r- b
  256. slave-priority 100- N, t3 C5 m# N8 S6 G3 q, C+ P
  257. 4 V3 @$ T8 e  z, `5 q. s
  258. ################################## SECURITY ###################################
    5 o9 M/ s& {: n7 V$ ]4 o
  259. $ V* n: g$ T7 r1 [
  260. # Require clients to issue AUTH <ASSWORD> before processing any other7 y0 B2 |4 x# G: z8 _9 y5 w6 x% V/ y
  261. # commands.  This might be useful in environments in which you do not trust4 K8 n7 c8 a7 H5 h
  262. # others with access to the host running redis-server.
    - ~+ @4 w9 O0 y& e2 A8 w0 v
  263. #- g3 X8 G; ^7 Q  [: S% m
  264. # This should stay commented out for backward compatibility and because most
    1 C9 x/ D. e/ V: j  x& p
  265. # people do not need auth (e.g. they run their own servers).
    . T; Q7 t! j& y' V! q
  266. #
    ! |! H4 O/ E( B( r2 P4 J
  267. # Warning: since Redis is pretty fast an outside user can try up to: ^/ f  j7 B3 f, t, O9 _
  268. # 150k passwords per second against a good box. This means that you should9 v" g. n, M, q  q
  269. # use a very strong password otherwise it will be very easy to break.. q% C4 v# R5 y
  270. #
    - b& d$ ?# u9 S0 j0 P3 ~
  271. # requirepass foobared
    ( X  R" \5 {7 L4 l/ M

  272. 3 K9 M+ M# b" n
  273. # Command renaming.+ R: t/ P3 v8 j( w5 h) B+ h  Q
  274. #
    6 z- O6 n  E1 Q# Z
  275. # It is possible to change the name of dangerous commands in a shared. g$ Y4 ]1 G1 ~% _. t" V  K9 ^
  276. # environment. For instance the CONFIG command may be renamed into something: m1 [2 N+ _" r) \+ l
  277. # hard to guess so that it will still be available for internal-use tools$ S+ \  M1 o% r# M# j6 M; N% ^
  278. # but not available for general clients.
    3 f4 b4 V" v/ k% j
  279. #6 l& c) a4 U( |
  280. # Example:
    9 M/ \6 U  i6 g
  281. #. B7 i" ?7 t% J  }
  282. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
      a- E- q8 R8 v, \
  283. #5 I- i' z0 T& O& I
  284. # It is also possible to completely kill a command by renaming it into
    " X0 f/ ~6 v9 V; g% R2 H& d% U
  285. # an empty string:- O3 [2 s8 _3 d
  286. #" a$ W/ P% C! _+ n6 e
  287. # rename-command CONFIG ""9 w5 \! W% w6 ]) p$ D- s: L

  288. . _$ V& A6 {7 _: U; F
  289. ################################### LIMITS ####################################$ J% D8 S* Y/ c- t

  290. ) Q9 j4 ^2 m2 p, }1 y5 z& |2 V$ W
  291. # Set the max number of connected clients at the same time. By default
    8 E. l4 y' D" T1 i( ]0 A
  292. # this limit is set to 10000 clients, however if the Redis server is not
    " E: `8 a! W7 ]- n( t2 w! N
  293. # able to configure the process file limit to allow for the specified limit# ?$ e. X2 e+ G7 f' O  r, m. m& Y
  294. # the max number of allowed clients is set to the current file limit# t. z! r8 E% P% H7 i, B
  295. # minus 32 (as Redis reserves a few file descriptors for internal uses).  o0 I; s/ ]9 v, S5 G! f
  296. #
    . O* v1 |) T1 ^2 j( s& y2 n% |
  297. # Once the limit is reached Redis will close all the new connections sending
    # R7 W; x" e6 y, j
  298. # an error 'max number of clients reached'.& w1 r, }, `0 u
  299. #
    + W$ h' y. @5 E. H
  300. maxclients 500
    / y' c1 w# Y9 U

  301. % c  s$ ^$ d  X
  302. # Don't use more memory than the specified amount of bytes.
    ( \+ o6 W3 {7 `6 M. V2 u
  303. # When the memory limit is reached Redis will try to remove keys
    / w& U9 A4 \5 c& F) Y% T0 X6 L
  304. # accordingly to the eviction policy selected (see maxmemmory-policy).
    1 K2 _$ v& o% F: U3 a7 g
  305. #8 b  z& s( d1 }7 W" g) h
  306. # If Redis can't remove keys according to the policy, or if the policy is
    # k# ^  ^$ j* o9 k' _( ~
  307. # set to 'noeviction', Redis will start to reply with errors to commands
    # I2 p/ b( {8 H4 b
  308. # that would use more memory, like SET, LPUSH, and so on, and will continue/ q) J) i; }: [, @# `
  309. # to reply to read-only commands like GET.& o/ P, B6 j$ f2 P1 g
  310. #$ D3 c3 L$ ?) K9 @9 W
  311. # This option is usually useful when using Redis as an LRU cache, or to set1 I3 l- w; g* A% x; ^8 q/ z
  312. # an hard memory limit for an instance (using the 'noeviction' policy).
    + I: j& l3 |" g) L
  313. #, d/ g/ g( h! n- O" J  h
  314. # WARNING: If you have slaves attached to an instance with maxmemory on,
    % p6 r4 n. y- x
  315. # the size of the output buffers needed to feed the slaves are subtracted, X7 G  P5 x4 s; @% ^5 J
  316. # from the used memory count, so that network problems / resyncs will( c, i0 Z/ t% y9 C6 ]8 L
  317. # not trigger a loop where keys are evicted, and in turn the output* d3 i4 y! e+ P, j& [0 q" G
  318. # buffer of slaves is full with DELs of keys evicted triggering the deletion. |" o) L9 y6 }. r" Y
  319. # of more keys, and so forth until the database is completely emptied.
    % d( ^' e% ]" R! L: s+ L+ e
  320. #
    % z3 w. v0 ]: H# }/ S" G% O
  321. # In short... if you have slaves attached it is suggested that you set a lower
    8 L6 V! }1 K! r" g- B+ m$ y
  322. # limit for maxmemory so that there is some free RAM on the system for slave
    + P+ A  }/ h- d% G1 d2 I: v
  323. # output buffers (but this is not needed if the policy is 'noeviction').% J1 `9 k! _8 n
  324. #
    0 }4 r$ I* Z2 b5 c% Y6 V% U. M
  325. maxmemory 128000000( Y. f, l" U1 Q; |# Z% E
  326. ! ^0 m' _) m# G* {# t
  327. # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory6 _9 m% g+ ]! t# g3 I# i
  328. # is reached. You can select among five behaviors:& u1 R- s! n* N% ?+ t- V
  329. # 4 A7 ?) h  M. x5 b7 q4 Y" N
  330. # volatile-lru -> remove the key with an expire set using an LRU algorithm
    0 A4 W/ o5 }, z& p2 R" P" m
  331. # allkeys-lru -> remove any key accordingly to the LRU algorithm
    ' z; j( {7 p1 U$ R$ w8 \! G
  332. # volatile-random -> remove a random key with an expire set+ N, n0 h3 F) K1 |) H) P
  333. # allkeys-random -> remove a random key, any key- `4 t* l7 {4 A9 @
  334. # volatile-ttl -> remove the key with the nearest expire time (minor TTL)
    / r3 X" z* O: R8 n( z; P
  335. # noeviction -> don't expire at all, just return an error on write operations9 r. n/ M+ g$ ^
  336. # 1 E0 {% v3 s9 D' F  k# y. Q
  337. # Note: with any of the above policies, Redis will return an error on write; ?; x* {" _2 |" {/ a: A
  338. #       operations, when there are not suitable keys for eviction.
    3 s4 z- v* @% i: r
  339. #% r% ?4 E- t+ Z% h+ p1 ^
  340. #       At the date of writing this commands are: set setnx setex append+ E, }% a5 {; N( V) C# h6 g3 A
  341. #       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
    " h8 I6 m9 j( G' Q* L( e. {7 T) M
  342. #       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
    % }( p8 D, ~; {3 T
  343. #       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby* s5 |9 g8 d* Z! ^, E( |
  344. #       getset mset msetnx exec sort
    8 S: y  f6 ~: b, U7 H
  345. #7 m! m: U0 h# s6 Y
  346. # The default is:1 ~4 x! ]! o) `8 K% ^" k1 k6 B
  347. #
    $ v/ o0 ^) O2 d! z! v
  348. # maxmemory-policy volatile-lru
    7 L& r$ z' B! T, {& J: Z

  349. ( R8 @4 C1 E- Z  t; p4 S1 y% k
  350. # LRU and minimal TTL algorithms are not precise algorithms but approximated6 M7 b7 Y6 ^7 A
  351. # algorithms (in order to save memory), so you can select as well the sample
    7 h3 ?" Q# g& ?. u; i. M' i
  352. # size to check. For instance for default Redis will check three keys and3 l( Q4 I) N3 w- q7 h
  353. # pick the one that was used less recently, you can change the sample size6 q- o1 w1 I6 ^) ?" A0 `
  354. # using the following configuration directive.- b6 n) b0 G$ q  {- q$ ]4 S
  355. #% Y4 M. P- ]/ A4 v  ]/ u; y/ G
  356. # maxmemory-samples 3
    ' U: Y4 Z; ^( C5 D9 u1 y

  357. % X1 ]( S- u! {7 a& p
  358. ############################## APPEND ONLY MODE ###############################
    " W% ^. M! n% G( w- W# u

  359. ' x: l" a2 q+ [4 G( q! s
  360. # By default Redis asynchronously dumps the dataset on disk. This mode is  G0 |# m; K8 m" I
  361. # good enough in many applications, but an issue with the Redis process or
    " O6 f  B$ o. X1 C! [' P* w) [) x
  362. # a power outage may result into a few minutes of writes lost (depending on
    9 y( g7 ]# e) H+ p
  363. # the configured save points).
    + l, d  K  z$ R) D, z: G
  364. #
    4 O$ r) G- |4 ^% d! i( W& H' l4 c
  365. # The Append Only File is an alternative persistence mode that provides
    9 t. Z( X9 L" K
  366. # much better durability. For instance using the default data fsync policy9 Q  c$ Q" }9 V8 ?( @
  367. # (see later in the config file) Redis can lose just one second of writes in a. N( C, [5 W5 C  h8 o
  368. # dramatic event like a server power outage, or a single write if something
    + Q" f8 ?: W, }5 @
  369. # wrong with the Redis process itself happens, but the operating system is. J* F/ Q, j" }; \7 I" ~3 v
  370. # still running correctly./ ]+ g" a: @% Q' F; ^
  371. #
    - W$ Q  i( V+ S8 C: }4 Q0 P- @( V( T
  372. # AOF and RDB persistence can be enabled at the same time without problems.
    : ?/ ^9 n1 Y. m
  373. # If the AOF is enabled on startup Redis will load the AOF, that is the file
    4 L4 ^4 L5 y2 v
  374. # with the better durability guarantees.# {3 U# N. y0 q  }/ H
  375. #
    " ~7 G6 ]! C$ C+ c( m, P0 S
  376. # Please check http://redis.io/topics/persistence for more information.
    7 i2 f" U# a8 l+ P6 r9 E  Q% ~/ C

  377. + g9 t2 T8 j; l* e+ k5 B* f$ p" f
  378. appendonly no; E* }$ t, v# {4 t

  379. 1 `. |4 n. U3 ~$ _2 {
  380. # The name of the append only file (default: "appendonly.aof")
    9 F1 O/ Y1 i1 a
  381. # appendfilename appendonly.aof/ i  \" Q4 s" j0 I7 C* }

  382. & R. B* u$ n2 c9 a3 w
  383. # The fsync() call tells the Operating System to actually write data on disk
      O  l* m7 K8 q. C3 B. h' ~
  384. # instead to wait for more data in the output buffer. Some OS will really flush 6 n, T+ B: w* M  s4 J
  385. # data on disk, some other OS will just try to do it ASAP.
    8 y( P- Y4 ~) W# N2 d9 j; |9 V0 L
  386. #$ j, {4 I8 S2 I" f5 _4 }
  387. # Redis supports three different modes:+ n" X4 z& |3 y% U' Y, t
  388. #5 M, s7 a$ y/ G3 m* ~3 }4 m5 ]
  389. # no: don't fsync, just let the OS flush the data when it wants. Faster./ U+ T5 w4 S( ?" ~' n
  390. # always: fsync after every write to the append only log . Slow, Safest.
    + ^' Z0 I+ N2 M) b4 |+ M# B& T
  391. # everysec: fsync only one time every second. Compromise.
    " L* S* F$ i# |/ s- w
  392. #
    : `' e3 Y5 j' M# I) Q0 v! |$ [  Y, i
  393. # The default is "everysec", as that's usually the right compromise between
    & G& x2 O; q$ I3 w1 N+ ?
  394. # speed and data safety. It's up to you to understand if you can relax this to# Y. E8 F+ t# F5 t
  395. # "no" that will let the operating system flush the output buffer when7 Q- @$ E; e( M
  396. # it wants, for better performances (but if you can live with the idea of
    ; g. K; j; Q  H! V# {
  397. # some data loss consider the default persistence mode that's snapshotting),
    ; e; }. t+ C* `$ o6 J' h
  398. # or on the contrary, use "always" that's very slow but a bit safer than6 _& V. D. o. ?" S6 u6 ~
  399. # everysec.& `5 y/ D' k2 M& x# I
  400. #  O' v( @& H1 z4 \
  401. # More details please check the following article:
    6 {4 ^8 S4 m$ K( K. ~, c
  402. # http://antirez.com/post/redis-persistence-demystified.html% n# u6 t2 k4 f/ n# j5 k3 k
  403. #" C4 [  o# }# M# }* X6 |) s
  404. # If unsure, use "everysec".( J" C% ?6 T9 P

  405. % Q, d! B# u! {, K
  406. # appendfsync always: D! S# J4 _0 S9 H8 |0 {& r) [
  407. appendfsync everysec
    # F4 |2 e6 Z; h+ \! A
  408. # appendfsync no
    & j# `8 j( b& b  M
  409. 4 m- `! N' [  L
  410. # When the AOF fsync policy is set to always or everysec, and a background
    7 L4 v5 B- P- H! B% _
  411. # saving process (a background save or AOF log background rewriting) is8 J6 {( L7 n* o" j
  412. # performing a lot of I/O against the disk, in some Linux configurations
    / Y1 \( o# Y$ ]6 B9 M
  413. # Redis may block too long on the fsync() call. Note that there is no fix for
    0 j% {2 v' D% h8 Z, f
  414. # this currently, as even performing fsync in a different thread will block
    & {, K- B" O! s
  415. # our synchronous write(2) call.
    ; G7 ?( W  z$ m; t
  416. #
    8 i! ?9 ^3 H2 e0 [; n7 `% a
  417. # In order to mitigate this problem it's possible to use the following option5 {8 Q% }# ?1 I+ j* A1 b
  418. # that will prevent fsync() from being called in the main process while a! J8 `4 j/ K( |
  419. # BGSAVE or BGREWRITEAOF is in progress.
    / V. f( H, B8 R
  420. #7 T. a8 a  R7 L* a
  421. # This means that while another child is saving, the durability of Redis is
    % q. G; {1 W4 K
  422. # the same as "appendfsync none". In practical terms, this means that it is& ~! s; A+ ?  X" B% X/ N' F
  423. # possible to lose up to 30 seconds of log in the worst scenario (with the
    . p) i0 S- x/ X% k8 m- I+ Q; z
  424. # default Linux settings)./ v1 W' {2 R- ~
  425. #
    8 c- C( r% O  E# e9 y1 g2 O
  426. # If you have latency problems turn this to "yes". Otherwise leave it as5 n) M+ [  a3 N4 x. ~
  427. # "no" that is the safest pick from the point of view of durability.
    & |, q9 g& A) |% b5 [  R( v
  428. no-appendfsync-on-rewrite no6 C- I% o: h. c, ]
  429. 4 b$ l9 B' y$ E" D
  430. # Automatic rewrite of the append only file.; A$ I5 V% W$ a/ b
  431. # Redis is able to automatically rewrite the log file implicitly calling$ N1 @, \$ H4 x
  432. # BGREWRITEAOF when the AOF log size grows by the specified percentage.
    ; s% Y8 m  l& `/ ?5 |1 ?; j' \
  433. # ) _1 I) i+ o3 B/ G9 b+ m
  434. # This is how it works: Redis remembers the size of the AOF file after the3 \9 E) @  _; }. @
  435. # latest rewrite (if no rewrite has happened since the restart, the size of
    0 O- O( j6 s# z( s! l
  436. # the AOF at startup is used).; I# S* U" x8 v3 G0 {7 G
  437. #
    : h9 x+ ]/ L! s+ C+ M1 O9 c
  438. # This base size is compared to the current size. If the current size is+ v3 M3 U) D/ J$ W( L7 l
  439. # bigger than the specified percentage, the rewrite is triggered. Also. E' N. n6 `( f* D% E. p
  440. # you need to specify a minimal size for the AOF file to be rewritten, this
    8 M; c; h) d- Z/ J4 s% n( |
  441. # is useful to avoid rewriting the AOF file even if the percentage increase3 n3 k) R1 E) O' M% Q( u( H6 ^
  442. # is reached but it is still pretty small.
    / s5 }- F# h/ C( {* @2 V) p
  443. #  B% h% ^" b1 g! p# V1 }
  444. # Specify a percentage of zero in order to disable the automatic AOF6 x" |! w$ c% H  A* o  W
  445. # rewrite feature.
    7 m/ k! }( X- E' p) s
  446. + d1 J$ Q: _0 ?8 G
  447. auto-aof-rewrite-percentage 100$ O0 T3 C) P# J) G3 [
  448. auto-aof-rewrite-min-size 64mb, L. y$ [$ N; M2 _
  449. 0 K& F! ~( j2 |: r$ K  d6 `5 v) y
  450. ################################ LUA SCRIPTING  ###############################+ q$ [% h; s1 `" p% ~
  451. " |" V; r9 q/ g+ A8 Q/ G: |& z
  452. # Max execution time of a Lua script in milliseconds.) U' d; Z* b' v2 P2 h1 G8 }
  453. #8 R8 b8 m* Z+ b  h* ?% s
  454. # If the maximum execution time is reached Redis will log that a script is
    + ?0 F1 t2 T. q$ |! f
  455. # still in execution after the maximum allowed time and will start to
    $ X1 Z$ v+ g/ q0 H
  456. # reply to queries with an error.
    ; h# T" Y+ I6 w/ E
  457. #
    5 C) N4 w5 Z( m0 J' j
  458. # When a long running script exceed the maximum execution time only the6 o/ k* b2 b) m, v+ A' M/ P, F
  459. # SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be/ U# C$ t! U' I; v+ m! k: P* M
  460. # used to stop a script that did not yet called write commands. The second' p8 j2 n/ t1 Y- K
  461. # is the only way to shut down the server in the case a write commands was
    / G" h7 A. R6 e0 t
  462. # already issue by the script but the user don't want to wait for the natural
    ) R: }: ~- v: j+ S& R. l
  463. # termination of the script.# z4 c% |+ z0 ~  S
  464. #
      ~5 J% I' P2 H
  465. # Set it to 0 or a negative value for unlimited execution without warnings.4 c3 W3 a1 K1 E# u( X0 X$ b: c
  466. lua-time-limit 5000
      u; q0 p+ u! E1 a

  467. 4 ?8 D& P, k0 O$ E/ }2 D
  468. ################################## SLOW LOG ###################################
    % W! x0 m* S( t
  469. 3 k2 ~, {0 A" m# {
  470. # The Redis Slow Log is a system to log queries that exceeded a specified
    6 {- c4 @* U: m; V; n
  471. # execution time. The execution time does not include the I/O operations; c! a' P! S+ k: H1 U* D
  472. # like talking with the client, sending the reply and so forth,
    ( n, [; `! I# E/ Y
  473. # but just the time needed to actually execute the command (this is the only
    % W- A4 x/ R0 o9 {" c" f) f4 G
  474. # stage of command execution where the thread is blocked and can not serve' P: g! u4 S9 Y. s0 V! D* u) r
  475. # other requests in the meantime).
    % j" P0 l- D# X4 e1 Q
  476. # * N8 I' S. [2 c, `1 ?" Y5 ]: N2 D
  477. # You can configure the slow log with two parameters: one tells Redis$ C( r# W; ^& `5 ]
  478. # what is the execution time, in microseconds, to exceed in order for the" Z4 E3 k- s2 g: k9 q) Y' H
  479. # command to get logged, and the other parameter is the length of the
    2 r1 I; H  A7 P: N+ o5 W
  480. # slow log. When a new command is logged the oldest one is removed from the5 q/ D+ t; k' J0 N( ?/ w
  481. # queue of logged commands.
    : @6 S/ @7 |& G0 o
  482. 8 F; g2 W6 P8 k
  483. # The following time is expressed in microseconds, so 1000000 is equivalent. H& I! o& G6 }5 K  ^( S
  484. # to one second. Note that a negative number disables the slow log, while1 X9 u% o/ ], c& K
  485. # a value of zero forces the logging of every command.: a. B, p' P' z* Z& H; @
  486. slowlog-log-slower-than 10000( G# i1 Z. i+ Q; r8 u, ]% a' A$ M

  487. 0 e- J: v& F8 `, x' B6 ?
  488. # There is no limit to this length. Just be aware that it will consume memory.
    3 Z  }6 a. R, }2 d& L6 N0 p6 O
  489. # You can reclaim memory used by the slow log with SLOWLOG RESET.
    : R  A# Q' \/ I3 d
  490. slowlog-max-len 1287 b; p& |  ~6 W  r
  491. ; D# X. F1 _; I- G8 u- W- {
  492. ############################### ADVANCED CONFIG ###############################
    # n  P' `& O0 n3 c
  493. + r1 q" \, f( o3 x: p
  494. # Hashes are encoded using a memory efficient data structure when they have a
    2 I$ `; Z9 |9 o! Q3 e$ E( P
  495. # small number of entries, and the biggest entry does not exceed a given0 D- l0 l& {; x2 T$ n
  496. # threshold. These thresholds can be configured using the following directives.
    9 M- T4 k; `4 J) ]: H
  497. hash-max-ziplist-entries 512
    ; A+ m8 e# S5 D2 O  ]. j8 x
  498. hash-max-ziplist-value 64
    7 o, [  z# T: X( G
  499. " U/ X* X9 o* `8 D6 V! f' J
  500. # Similarly to hashes, small lists are also encoded in a special way in order
      o( B8 G1 w: B. m7 T6 R9 n+ }" T
  501. # to save a lot of space. The special representation is only used when
    7 }; V1 U/ o$ [. K) t9 K9 ?
  502. # you are under the following limits:
    5 Z$ D1 }: U# W, l% A; [: i. b1 B
  503. list-max-ziplist-entries 512
    * @, H7 |+ Q0 P
  504. list-max-ziplist-value 64
    : `: m5 c" |  E$ K* a
  505. 0 J/ t6 I- V0 T+ r
  506. # Sets have a special encoding in just one case: when a set is composed
    / h& j) k( B' N+ T& s
  507. # of just strings that happens to be integers in radix 10 in the range
    4 [6 p9 Y! U) \: l) @' {" j
  508. # of 64 bit signed integers.+ S1 [; H' |; y9 e( d, Y* e
  509. # The following configuration setting sets the limit in the size of the
    / b: w2 `/ S3 @: L3 U
  510. # set in order to use this special memory saving encoding.
    ; a. N$ F1 L7 G5 i% b
  511. set-max-intset-entries 512
    4 B5 j3 m' B& {! z( [/ ?
  512. 9 Q: w2 ^4 P" W2 x$ T
  513. # Similarly to hashes and lists, sorted sets are also specially encoded in7 B' u0 }$ l7 J
  514. # order to save a lot of space. This encoding is only used when the length and
    5 \- W  u& h8 x2 Z; E( p
  515. # elements of a sorted set are below the following limits:
    % S% ]/ f/ g! n8 p: g6 V4 [2 c
  516. zset-max-ziplist-entries 128, t+ i5 k3 R/ D% d$ L
  517. zset-max-ziplist-value 64
    " v7 r. A* U7 h- F% y1 Z. Q
  518. 1 s/ N0 Y4 j6 W# p" F
  519. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
    9 u% A5 N) [: b5 N1 b4 b0 P* k
  520. # order to help rehashing the main Redis hash table (the one mapping top-level
    / C' c! n& H+ A5 p( y2 D9 n; M
  521. # keys to values). The hash table implementation Redis uses (see dict.c)) R1 y# T: f- N% s2 h
  522. # performs a lazy rehashing: the more operation you run into an hash table
    $ w1 E. ]4 ?2 n8 x" K( b- D
  523. # that is rehashing, the more rehashing "steps" are performed, so if the
    9 U( k8 f3 W7 z+ n
  524. # server is idle the rehashing is never complete and some more memory is used8 @& O* w( a6 A0 x
  525. # by the hash table.8 y# ^# L2 s  l+ U
  526. # " i! i/ R- O6 t: Z3 }
  527. # The default is to use this millisecond 10 times every second in order to
    " u1 C# l0 T# T: _+ D4 q. L
  528. # active rehashing the main dictionaries, freeing memory when possible.
    ; ]+ |5 n# J5 C
  529. #9 d, T- u' n# h% N, i5 m
  530. # If unsure:
    0 \' U% A% T# R! A' L4 @5 |$ {
  531. # use "activerehashing no" if you have hard latency requirements and it is
    5 k# T. p( X7 b
  532. # not a good thing in your environment that Redis can reply form time to time
    + Q; d: j- o. X$ q& {. f
  533. # to queries with 2 milliseconds delay.) M  M/ m) X8 k  P7 Z3 C& N
  534. #% t5 u& ^" U( H3 A3 G
  535. # use "activerehashing yes" if you don't have such hard requirements but
    ' p# S. b4 S6 d3 M
  536. # want to free memory asap when possible.$ T' v( P. Z6 q$ D& |# z- n  U3 w, h
  537. activerehashing yes9 I* `: x1 u" e1 v
  538. 5 f4 Z8 i# S# r2 K
  539. # The client output buffer limits can be used to force disconnection of clients' }2 K  z+ b6 p4 t
  540. # that are not reading data from the server fast enough for some reason (a
    0 ]% [( y; V# w: p; D* u( e# Y
  541. # common reason is that a Pub/Sub client can't consume messages as fast as the
    6 e7 S; f- I6 p! {7 v/ J8 n6 e
  542. # publisher can produce them).
    ! p: Z5 R1 J6 g; f! v
  543. #+ I: Z, `3 g" u6 E
  544. # The limit can be set differently for the three different classes of clients:
    ; T: T6 R* r& O6 e' U# Y( \
  545. #
    / ]# i+ z0 H0 J: t  k
  546. # normal -> normal clients
    4 X# F3 W4 ]3 M  D3 F
  547. # slave  -> slave clients and MONITOR clients2 E2 r6 Z# E' ^. m& x2 W
  548. # pubsub -> clients subcribed to at least one pubsub channel or pattern
    % A  _5 h0 }2 `8 t
  549. #$ Y$ m; W# c5 Q2 S
  550. # The syntax of every client-output-buffer-limit directive is the following:! ~$ m0 D' f% d$ ~; [( f
  551. #3 ^' e( h) C( ?- l
  552. # client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>2 _: q/ v* U8 k  Z+ o$ y
  553. #
    7 h5 r+ @' i" G( R8 s" \& t" Y+ w
  554. # A client is immediately disconnected once the hard limit is reached, or if
    ) T5 a# C$ W+ t+ A& Q. y
  555. # the soft limit is reached and remains reached for the specified number of
    2 @9 f" V# O/ s( [+ t' {! x  g+ @/ v! s
  556. # seconds (continuously).
    ! F4 o5 z. k) m) I- T' v( D5 M
  557. # So for instance if the hard limit is 32 megabytes and the soft limit is; h$ H  i8 I' c$ K5 @' [' i
  558. # 16 megabytes / 10 seconds, the client will get disconnected immediately
    . s, B' S5 L$ J' |( D7 o6 s
  559. # if the size of the output buffers reach 32 megabytes, but will also get3 w( B/ k# O# x9 i- Y1 S* D% l
  560. # disconnected if the client reaches 16 megabytes and continuously overcomes
    - R" v; N+ L. j7 P) Y! H
  561. # the limit for 10 seconds.% B; h+ m% F. K( F
  562. #
    6 ~' S  a' n3 Y9 j3 L/ ~+ E
  563. # By default normal clients are not limited because they don't receive data
    , l* O' Q$ y" B0 _# ]9 r
  564. # without asking (in a push way), but just after a request, so only
    6 E  T3 G8 p! n$ M
  565. # asynchronous clients may create a scenario where data is requested faster
    . G: P8 ^) Y3 Z' r1 T' K
  566. # than it can read.( E: ~1 Y  z6 s' _$ I
  567. #9 K* {+ D/ u# q: Q% M
  568. # Instead there is a default limit for pubsub and slave clients, since
    4 h+ Y4 L5 h  |$ e( Q1 _
  569. # subscribers and slaves receive data in a push fashion.
    - s7 b8 M, V7 c' ~5 a2 z; n
  570. #
      N1 s- M8 ]: \. M7 C
  571. # Both the hard or the soft limit can be disabled by setting them to zero.8 A, Q: x  w- g) k& Y* w
  572. client-output-buffer-limit normal 0 0 06 g6 N/ @, x+ O# {0 o: G
  573. client-output-buffer-limit slave 256mb 64mb 603 k( C% y. {9 j, J+ D6 C( z
  574. client-output-buffer-limit pubsub 32mb 8mb 60
    / Y% l3 T9 L  u5 ~9 ~7 a4 }
  575. 0 I' z- x+ s0 f4 n) Y, k
  576. ################################## INCLUDES ###################################. E( s3 Y2 j1 X0 ^3 S
  577. 3 T) ^- \( o  ^% M: E
  578. # Include one or more other config files here.  This is useful if you
    / N. A3 y1 I0 y: j5 [& Y1 j! x! l
  579. # have a standard template that goes to all Redis server but also need
    0 a  q, m9 x; S3 ?! H/ D, D
  580. # to customize a few per-server settings.  Include files can include
    / U) \6 @+ {) K, k$ k
  581. # other files, so use this wisely.
    $ o9 K" w! f9 d4 d
  582. #
    4 {# c8 ?) ?# U
  583. # include /path/to/local.conf
    6 `2 p& f2 I) U
  584. # include /path/to/other.conf        % f+ b+ m6 R- G, h1 H7 N5 K) D8 z
  585. ##########################配置文件结束################################ 6 E9 S1 O4 \7 f4 ?
  586. 第三步:启动进程. I( j0 s  b' f8 z2 U) v
  587. #redis-server /etc/redis.conf6 X* |" ]: M1 Q9 _
  588. 查看进程有没有成功启动
    * s2 L) c" V9 C3 [
  589. #ps -ef | grep redis
    9 G: C* r7 _' u& E; F* i" p( M
  590. 测试输入一个键值
    ; U$ g% A' B) [
  591. #redis-cli set test "testredis", _3 ^# p! J/ Y- E9 E( R
  592. 获取键值
    * e5 t& g' M- \0 h) V0 \- I
  593. #redis-cli get test
    2 Y6 u9 @1 u# [5 k" I( E) i! T

  594. % h' l) v# }  M' @; a" S& r

  595. 1 n, ^7 ?9 U7 j# k1 |! ?. `
  596. 第四步:关闭redis  (这个是更改配置文件后 正常的重启方式  不重新加载redis配置跳过)3 A, o& b8 G1 Z2 ]
  597. # redis-cli shutdown      //关闭所有    , S, G6 e6 @6 s
  598. 关闭某个端口上的redis    7 `9 q" E  f. K) K3 p* |
  599. # redis-cli -p 6397 shutdown  //关闭6397端口的redis  , c3 L. v  x3 H: u. g
  600. 说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename  dump.rdb  
    5 c( x  q9 Y* s5 ]

  601. ' s4 \5 i, h* a% F6 I/ Y& E" x

  602. & h- }$ c# ~. [7 T1 ]
  603. 第5步:php扩展安装
    : l- W  D% F) t4 [
  604. phpredis PHP扩展下载地址 9 P' v& g* w8 Q8 S9 i* {
  605. https://github.com/nicolasff/phpredis/tree/2.2.2
    : Q/ h  j9 k  ^' G) ]/ t" [
  606. 选择最新版本下载zip
    0 e1 A/ V, H) q2 j& ^; s6 J
  607. ; V# s& Y5 R8 d
  608. 然后自己上传zip  用unzip解压到当前目录 unzip 文件名$ V) r9 }0 j; M' R' t% {

  609. 6 w$ O6 d! X+ B3 j3 z3 e
  610. # cd owlient-phpredis-90ecd17/   #打开解压后的文件夹里面  这个解压后的目录 要是不知道 可以输入 "dir" 查看
    # V/ _( M, j7 @/ D' ]3 [- g- l
  611. # /www/nginx_php-5.2.17/bin
    ; l) p, o# m+ d( ?3 v4 a' z
  612. # ./configure --with-php-config=/www/nginx_php-5.2.17/bin/php-config
    ' V1 z0 `- W/ S* C
  613. #make6 j0 n" u$ g. T5 a2 j1 X6 f
  614. #make install   #记录产生的redis.so路径
    6 _& h) t9 a- d+ Y

  615. * W) R- F1 Y, P6 |5 u* E
  616. 修改php.ini文件. M6 V3 y; \4 W4 C3 S' Y7 y* ]" t* l
  617. 在php.ini中添加如下一行:7 \, X2 S  O5 H5 e
  618. extension=/?/redis.so  #是刚刚记录的产生redis.so的路 写在 ?那. J# [- `# B' |
  619. 重启 使之生效:) T$ I- P7 [9 f7 I" p, [
  620. /usr/local/php/sbin/php-fpm reload, i+ W/ l; `* Y
  621. /usr/local/nginx/sbin/nginx -s reload 8 |- s7 P3 H  [' B+ c: j
  622. 4 P& S; M5 D2 R, R3 H
  623. 将 Redis 作为 Linux 服务随机启动
    " t5 N' P, z! ~( I
  624. vi /etc/rc.local, 加入代码:
    6 H1 b* W% Z* H5 R
  625. /root/redis-2.6.10/src/redis-serve  #路径看情况修改 + Z$ q; c6 G" }* w

  626. * ~$ ]  H% Y% \& Z  e9 F
  627. redis-cli -h localhost -p 6379 info  #命令要在redis目录下面执行4 g+ e* u* r0 a0 V" E
  628. 提供host为localhost,端口为6379,redis服务的统计信息0 N7 P- t, Q0 V1 O2 S2 j/ K

  629. : T  J# _4 T* P8 w
  630. 5 T7 c6 w' ?6 U5 m' ]
  631. 就这样你的web服务器就支持redis了 记得要在 给dz 的配置文件 加上12.0.0.1哦. M- _, F1 W* w
  632. dz配置文件在 config目录下面的 config_global.php. O: `. ^  C0 u/ [
  633. $_config['memory']['redis']['server'] = '127.0.0.1';
    3 i6 }/ X- F" }9 @4 A' i
  634. $_config['memory']['redis']['port'] = 6379;
    7 ]: b4 c& R! m$ z
  635. $_config['memory']['redis']['pconnect'] = 1;
    2 r1 v0 d+ d: r3 F0 F2 ~- Z
  636. $_config['memory']['redis']['timeout'] = '0';, _; |/ d3 y3 {1 |
  637. $_config['memory']['redis']['serializer'] = 1;
      ?/ y' N, R# |1 g$ o5 d
复制代码
关注微信公众号《神采飞扬网》,即可获取最新回复通知!

使用高级回帖 (可批量传图、插入视频等)快速回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则   Ctrl + Enter 快速发布  

发帖时请遵守我国法律,网站会将有关你发帖内容、时间以及发帖IP地址等记录保留,只要接到合法请求,即会将信息提供给有关政府机构。
快速回复 返回顶部 返回列表