DZ - 设置区 - 神采飞扬网 - Powered by Discuz!
分享到:
发表于 2018-11-16 12:42:28 | 显示全部楼层 |阅读模式
环境配置6 E3 x* U7 @, `

4 Z" }8 g( |& X' q
( T  t2 j$ o+ B0 @http://www.discuz.net/forum.php? ... amp;highlight=REDIS
关注微信公众号《神采飞扬网》,即可获取最新回复通知!
 楼主| 发表于 2018-11-16 12:43:33 | 显示全部楼层
http://www.discuz.net/forum.php? ... 648&highlight=REDIS2 }9 e. H" c# Y9 ]) s- b6 {
无意间测试 单机状态 redis相当给力 测试1000请求/s  单纯的 get 和set 居然只用了 0.01秒 当时我惊呆了/ h2 L8 s( F7 h9 m

: w, A/ q: k" x" Ghttp://www.discuz.net/forum.php? ... 731&highlight=REDIS1 E  u9 Y, ^2 N! p$ Q

- E1 D' k/ u6 f* ^https://wenku.baidu.com/view/265a5ce176a20029bc642d0b.html
/ W" J5 c3 E6 @. O4 b5 C2 A1 Q# B# D) v. {" m- M7 w4 o
=======================================
8 b6 a: T9 S: }3 K
  1. 连接上 ssh0 ?2 k! X+ N- z3 y+ G

  2. 3 t9 I, t" P1 [0 u. \5 q

  3. 8 t3 V# p$ K8 y3 \. m2 F% O
  4. 第一步:下载redis
    & @1 f- S( Z1 p- G1 J) A1 f
  5. # wget http://redis.googlecode.com/files/redis-2.6.10.tar.gz7 ^8 Z. o7 |$ B% J
  6. # tar zxvf redis-2.6.10.tar.gz
    ' A' r4 r/ p$ C# s/ x+ c8 x
  7. # cd redis-2.6.10, u7 M" {5 E( s/ ]1 N5 p6 S: l1 {
  8. # make
    2 @2 r; A5 m7 w
  9. # make install  
    8 x- s0 W  \9 x' p# s
  10. #cp redis.conf  /etc/ #复制配置文件到etc目录下面2 _4 V4 f% G7 h# o8 G
  11. 第二步:修改配置  i$ g, M; ?2 i9 S& `* s/ g
  12. #vi /etc/redis.conf
    ( |- Y/ Y, v. X2 ?
  13. ######################下面是无措的配置文件 复制过去就成#########9 s' @7 c3 Z0 o# T  f
  14. # Redis configuration file example% J6 a9 u: s7 T  C

  15. ! }- d8 ~: z8 U, i' D
  16. # Note on units: when memory size is needed, it is possible to specify$ j3 X2 `* w2 S  X6 v
  17. # it in the usual form of 1k 5GB 4M and so forth:; [6 g0 r" E3 U. b( K
  18. #
    4 ]! K- L; T  _8 m6 L& ~  f
  19. # 1k => 1000 bytes0 A( \0 f. h+ _$ g) P% J6 l0 s
  20. # 1kb => 1024 bytes
    8 |4 @2 K% c! X5 p4 Z0 ~
  21. # 1m => 1000000 bytes( X6 ~, U7 L7 J# t9 [8 l$ C
  22. # 1mb => 1024*1024 bytes
    7 o( n4 t2 ]+ r+ W2 v( F
  23. # 1g => 1000000000 bytes* P$ h8 \+ b+ Z" k. P
  24. # 1gb => 1024*1024*1024 bytes" U7 G. M6 C' L
  25. #8 ^% `* J5 O5 b" m0 r+ O/ Q! v9 l  D
  26. # units are case insensitive so 1GB 1Gb 1gB are all the same.
    % f! V6 d- ^+ m- Z+ c, m0 l
  27. , h7 g3 Q0 {9 I$ k
  28. # By default Redis does not run as a daemon. Use 'yes' if you need it.; }! y1 \! @. s" c" g# W
  29. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
    / c* e! @' t) R. \$ ]
  30. daemonize yes5 t2 ]% O3 g5 Z4 L9 N

  31.   D9 L4 x6 ], ]3 Y( A9 L  Z
  32. # When running daemonized, Redis writes a pid file in /var/run/redis.pid by7 h, L6 k* c. T& E# c4 F
  33. # default. You can specify a custom pid file location here.1 X2 p# C7 B( L: p, b' F
  34. pidfile /var/run/redis.pid
    9 L. U  d: d9 z! {$ ^
  35. 1 g* Q: u) f0 h  g6 e3 |& ~% ~  t
  36. # Accept connections on the specified port, default is 6379.
    ' P  b; L4 c% R7 }' g  M  {$ _
  37. # If port 0 is specified Redis will not listen on a TCP socket.
    8 O+ b4 K5 K8 A
  38. port 6379% f: ~/ I* ]( h- h
  39. 0 q7 n- A$ N; y6 G; C# k& F
  40. # If you want you can bind a single interface, if the bind option is not
    : _5 x6 z% G3 x% t' A7 A
  41. # specified all the interfaces will listen for incoming connections.6 b; m7 P+ C) V. |
  42. #
    1 X: _9 M* Y' y4 y8 d9 {
  43. # bind 127.0.0.1! E7 e; l' P) X% g. z

  44. % g/ K$ F( }, E, N0 ]: ?7 K: a+ t! x9 T
  45. # Specify the path for the unix socket that will be used to listen for9 X7 w* r1 \4 |/ |7 b( c
  46. # incoming connections. There is no default, so Redis will not listen
    6 F7 l3 k" N5 o3 ~1 ?' T4 a
  47. # on a unix socket when not specified.
    3 c5 \+ k5 U8 |: n8 A" ^- l  ]
  48. #; J. X7 _2 F% B7 c
  49. # unixsocket /tmp/redis.sock
    & c/ |! r1 ?, a3 J( m! \' ~
  50. # unixsocketperm 7555 z3 E% M4 b, V7 _9 i6 j

  51. # b) ?* G$ C6 g3 u# `
  52. # Close the connection after a client is idle for N seconds (0 to disable)* T% n' n, T' a6 \
  53. timeout 300
    ' d# M* ^5 W5 W9 Q2 T8 }) b7 r

  54. . z4 x* w  ~8 n4 ^6 n6 ]
  55. # TCP keepalive.% i$ i% _3 N- m
  56. #
    8 A9 D. B! c6 \$ E9 I% t+ `
  57. # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence: a; v4 Q% @5 {/ H* x$ D" v
  58. # of communication. This is useful for two reasons:
    , t% h; m; h: Y" K) W4 A
  59. #) V2 H6 p4 A0 w+ `' k
  60. # 1) Detect dead peers.) J3 O" ]; b: P) J! b9 c+ ?! n' s
  61. # 2) Take the connection alive from the point of view of network3 k% y4 o8 ]. O! d; _+ B
  62. #    equipment in the middle.
    5 K7 a) |- I% D/ I- w3 I) R; n
  63. #; h4 q% j5 N$ w6 T$ U. A3 T
  64. # On Linux, the specified value (in seconds) is the period used to send ACKs.0 q  |- _- i$ H. k$ q
  65. # Note that to close the connection the double of the time is needed.
    : s$ y. B9 c0 t  \) x' i
  66. # On other kernels the period depends on the kernel configuration.
    3 m4 P$ @# Y, i2 i  k
  67. #( g9 W! t; F) S  R" f8 M1 m
  68. # A reasonable value for this option is 60 seconds.
    % C. m+ [7 m, T9 k: S$ ]
  69. tcp-keepalive 0
    5 v* }0 F( S& _- [# ~

  70. 5 ~2 D8 _# T) L" L' a7 g* S0 B
  71. # Specify the server verbosity level.
    . f8 D. W0 D! |, R
  72. # This can be one of:
    / w+ l1 s/ g7 _8 ]9 U% h1 h& S. L
  73. # debug (a lot of information, useful for development/testing)0 J' B# G+ E$ ^$ y
  74. # verbose (many rarely useful info, but not a mess like the debug level)" O. k" G( k0 r, ~0 a
  75. # notice (moderately verbose, what you want in production probably)9 T: C$ M% f; q# ~9 T
  76. # warning (only very important / critical messages are logged)
    , E5 W, ^& U6 }+ c) J, M
  77. loglevel warning
    ( C7 O5 r6 T: V- g, o0 g- m1 V' Y
  78. % O2 k4 W, ?$ X1 P% k& a# V; H2 E" u2 {
  79. # Specify the log file name. Also 'stdout' can be used to force( b: Z9 u$ O8 ?! [) |1 X& |
  80. # Redis to log on the standard output. Note that if you use standard
    / e( n) {4 y3 q: n% V' j* f5 s
  81. # output for logging but daemonize, logs will be sent to /dev/null" a# x" }5 q, _# e  E. o! R8 \
  82. logfile /var/log/redis.log6 n9 w3 Q! y8 H2 f: T& B: Z
  83. . [  Q5 W# @6 ]5 @% l
  84. # To enable logging to the system logger, just set 'syslog-enabled' to yes,, V0 C5 h; O$ ^6 ~' I, M" c
  85. # and optionally update the other syslog parameters to suit your needs.- F+ f) w6 k3 a
  86. syslog-enabled yes
    # J0 w: q1 R! N& r2 e
  87. , D$ q7 ]1 @0 m) C6 [
  88. # Specify the syslog identity.
    # [2 A- P& U) r5 |! F: I1 r: x
  89. # syslog-ident redis
      L# u3 e9 f# S$ X% X
  90. * [6 n4 x# n* V8 v7 i9 n0 z0 B
  91. # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
    2 H/ t3 Y# }0 b8 b' n3 |3 g5 D
  92. syslog-facility local03 D1 B/ ~3 K- v. H
  93. 2 Q. b! q" k: [* I. Z  n
  94. # Set the number of databases. The default database is DB 0, you can select
    ! W( z) d5 P  q% S0 d3 \- A
  95. # a different one on a per-connection basis using SELECT <dbid> where
    4 Y4 ?: x+ a1 |! ?0 p
  96. # dbid is a number between 0 and 'databases'-1* e; L; e; L# }' Y0 n
  97. databases 162 t0 r) V4 `% ?, j

  98. 0 F% s$ L$ T% K. O8 Y" V  ^' r
  99. ################################ SNAPSHOTTING  #################################) Y1 p* P! {# W% y  s* ~! k6 u
  100. #9 Y9 a1 B4 e* W* K6 q
  101. # Save the DB on disk:. c" d- w$ J" K6 K3 h( K7 y, N& n4 M
  102. #
    6 C' p) \5 c- ~
  103. #   save <seconds> <changes>
    " B0 y, \4 a, a  @5 q2 ?
  104. #
    $ z) g* J# U2 g7 T: O
  105. #   Will save the DB if both the given number of seconds and the given& O2 k, ^9 j7 N  e4 H# j& i
  106. #   number of write operations against the DB occurred.- _/ E! ^! Z; j. C4 T" L& D" L
  107. #
    ) w! n# A# B+ ]0 w7 `- V  v
  108. #   In the example below the behaviour will be to save:1 a  r: c; `0 z& a# z# j- R0 g5 Y) T
  109. #   after 900 sec (15 min) if at least 1 key changed
    ! ?- S! t- D# \% C: J
  110. #   after 300 sec (5 min) if at least 10 keys changed$ }$ p+ u5 _* ^. Y; z, s# }1 e& e
  111. #   after 60 sec if at least 10000 keys changed
    ( E# O9 p( y9 t; d8 _# @5 U+ E
  112. #
      ~+ i- X% U( B. S$ a0 m. L5 F9 ?; l
  113. #   Note: you can disable saving at all commenting all the "save" lines.. w/ S2 E" `; A: s+ o$ ~
  114. #
    ' \7 h# I+ l. L8 v
  115. #   It is also possible to remove all the previously configured save
    5 }" a6 a5 z/ _* ~6 p6 }
  116. #   points by adding a save directive with a single empty string argument# d/ \; O. l+ a3 i: I
  117. #   like in the following example:6 L- D. {+ a: C9 y, r5 o0 m2 J
  118. #
    0 {% Y6 F4 W, `
  119. #   save ""
    / F! @) J9 J3 q6 l
  120. + V* M. |$ s0 K6 J) x/ `
  121. save 900 1+ p/ v3 }) e; H1 @2 V' n
  122. save 300 10
    7 B( m4 R5 q& s& ~7 L7 L5 |9 h
  123. save 60 10000/ Q( C& ?( p4 e  J

  124. + p& w6 Z8 X1 f5 R8 M  e
  125. # By default Redis will stop accepting writes if RDB snapshots are enabled
    - ], Y: M4 _: t( Z# o# @' F0 S4 Y% I
  126. # (at least one save point) and the latest background save failed.
    ' ?2 e0 N: V8 `2 w% d/ v
  127. # This will make the user aware (in an hard way) that data is not persisting9 h0 \2 F7 a( z. s% U( F5 Q
  128. # on disk properly, otherwise chances are that no one will notice and some6 G6 ]3 g, J: q1 K' {
  129. # distater will happen.5 c1 g9 `8 v8 `9 e* B; c
  130. #
    9 g! n5 P% J7 @8 k7 u
  131. # If the background saving process will start working again Redis will2 J  E1 ^8 G' a# p' m
  132. # automatically allow writes again.
    ) v- W: j: d, Y, N& ?0 P
  133. #+ {0 B9 i- t; u1 B6 ^' z
  134. # However if you have setup your proper monitoring of the Redis server
    % i9 \  {- T: D* m7 ^+ t2 M
  135. # and persistence, you may want to disable this feature so that Redis will
    " P+ T3 b& B. H. P" _( a; M1 E
  136. # continue to work as usually even if there are problems with disk,
    * i# b% Z: f2 f3 N1 p8 s
  137. # permissions, and so forth.8 u' m3 J9 r# @# A/ N/ H
  138. stop-writes-on-bgsave-error yes; r' ~$ Q8 G% {+ d9 h

  139. ' j2 M5 i6 _; W4 [4 D0 w5 K
  140. # Compress string objects using LZF when dump .rdb databases?
    1 f* C4 P3 }  {
  141. # For default that's set to 'yes' as it's almost always a win.7 h# P8 Z- s3 X7 r4 w
  142. # If you want to save some CPU in the saving child set it to 'no' but
    / M4 P$ ^: S* f2 E  F
  143. # the dataset will likely be bigger if you have compressible values or keys.. G7 s3 @) P) I* R
  144. rdbcompression yes
    4 j. J: s# x& Z
  145. 8 W$ C& R  h" H2 r: R
  146. # Since version 5 of RDB a CRC64 checksum is placed at the end of the file.& g% e# Q& R4 ~# [/ R
  147. # This makes the format more resistant to corruption but there is a performance
    9 l# q0 Q5 A) J$ ^5 o3 q
  148. # hit to pay (around 10%) when saving and loading RDB files, so you can disable it) f( ^8 o: \2 ^; P  e- b0 q) N
  149. # for maximum performances.! N* e6 u7 e! ^& C% A* m! k
  150. #
    / o& Q! P' }/ h. b
  151. # RDB files created with checksum disabled have a checksum of zero that will
    % E" w* O% O- c6 m* e
  152. # tell the loading code to skip the check.% }$ [% J4 r% t& B. R. M$ W
  153. rdbchecksum yes
    * R4 m3 e. ^; |$ {9 X( L6 Q

  154. / t* V9 o: @& a: [, L7 T
  155. # The filename where to dump the DB
    ; j+ Y; h) T2 b2 j9 K
  156. dbfilename dump.rdb
    7 t% f, {5 n8 t0 B0 m; n$ m% {

  157. % A! o, M  v5 |: L# k
  158. # The working directory.
    , Y8 N$ l7 I6 P6 I9 `$ b- j: |
  159. #
    . `0 `  ~7 Q5 g0 P3 b
  160. # The DB will be written inside this directory, with the filename specified
    % a, f7 p: z) N/ E
  161. # above using the 'dbfilename' configuration directive.
    4 P& r/ g5 ~: o
  162. #
    + H4 U% j6 B6 E! i
  163. # The Append Only File will also be created inside this directory.
    2 A/ J( X% j  L$ r
  164. #   v6 g# {) ^' p) ?  \2 Q
  165. # Note that you must specify a directory here, not a file name.! M8 a; T! S5 p; `3 m  ?4 T# B3 H
  166. dir /var/db/redis
    - @% {; i+ c4 J  L# v% t

  167. + V/ k/ H, i# S5 ^( G
  168. ################################# REPLICATION #################################6 l0 g2 |; B/ y

  169. ; I/ j3 j& i. Q$ Z2 s1 F
  170. # Master-Slave replication. Use slaveof to make a Redis instance a copy of
    , }5 e5 h- c' t8 [
  171. # another Redis server. Note that the configuration is local to the slave' s& Z0 B5 M9 M
  172. # so for example it is possible to configure the slave to save the DB with a
    ; j" U+ n) [) f# t, I
  173. # different interval, or to listen to another port, and so on.
    " b- G, V3 {2 x
  174. #2 }5 z6 q; @) I" O1 d4 {8 k, Z
  175. # slaveof <masterip> <masterport>
    2 s8 b# r8 {# w

  176. 7 ]4 w6 _+ l0 {7 ~* ^, ]9 @
  177. # If the master is password protected (using the "requirepass" configuration
    6 A% `7 {; X2 Y8 W3 L( T
  178. # directive below) it is possible to tell the slave to authenticate before
    * h) o* q2 o* R5 W9 s
  179. # starting the replication synchronization process, otherwise the master will# `/ j; S$ [9 K, J2 F1 f
  180. # refuse the slave request.) E5 Q; l3 g/ Y2 b
  181. #% K) _2 R& z9 x$ o! t7 N
  182. # masterauth <master-password>
    * O4 m, H/ c- `0 U3 t9 M9 N

  183. ) R5 A8 z& Q! z* C# b
  184. # When a slave loses its connection with the master, or when the replication* _& F$ R3 C  k& x/ B4 R' S/ w
  185. # is still in progress, the slave can act in two different ways:6 y  A) ~* R! o
  186. #
    * Q4 c; K* ~% y
  187. # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will
    - g" p; I( @; p! F1 p1 Q! M
  188. #    still reply to client requests, possibly with out of date data, or the. m" j1 b& `* J" a' ]! |$ g
  189. #    data set may just be empty if this is the first synchronization.
    $ C2 W: }# I% C) s0 n
  190. #7 L7 H0 k1 w9 |2 d, I% h# P% h
  191. # 2) if slave-serve-stale data is set to 'no' the slave will reply with
    * D, m& \; @) m& }6 A( T
  192. #    an error "SYNC with master in progress" to all the kind of commands" Q( `, g, M  `9 r* l8 M9 S$ g
  193. #    but to INFO and SLAVEOF.
    , `" z2 N: m$ l% }6 @
  194. #
    . h! m4 l, A& M; ?9 V1 H
  195. slave-serve-stale-data yes+ o% X4 m# N# v9 c) W

  196. , o: s2 O: X# H' D7 m. j! ]- n  o
  197. # You can configure a slave instance to accept writes or not. Writing against
    ' o2 Z0 n: i# q( }+ }
  198. # a slave instance may be useful to store some ephemeral data (because data
    , w; A/ a. v0 }9 @. I  g. h
  199. # written on a slave will be easily deleted after resync with the master) but' k2 Y+ ^  |3 n+ g, W+ ~+ q
  200. # may also cause problems if clients are writing to it because of a
    ( ?1 N; B# t' v% T6 W
  201. # misconfiguration.- T: _; t7 C3 M/ w
  202. #
    ) t! G  H8 e; t. V
  203. # Since Redis 2.6 by default slaves are read-only.2 _: ^9 P- [6 e3 i/ j6 j
  204. #
    % s* W9 W3 \" B& J
  205. # Note: read only slaves are not designed to be exposed to untrusted clients& O0 P9 E# X/ @& g: c& q" U! R
  206. # on the internet. It's just a protection layer against misuse of the instance./ s: a; Y; _# \: e! }
  207. # Still a read only slave exports by default all the administrative commands/ Z1 U, ~: ?$ U: o6 Y
  208. # such as CONFIG, DEBUG, and so forth. To a limited extend you can improve' m% ^9 q2 W. a5 }
  209. # security of read only slaves using 'rename-command' to shadow all the! O5 \3 D; S) b$ A! g# h; z6 U
  210. # administrative / dangerous commands." r; g% L# V1 Y' s! b% P! ]% _
  211. slave-read-only yes4 k& `4 Y; c) O
  212. 7 @1 V4 u/ E; L+ ^, w) q% e
  213. # Slaves send PINGs to server in a predefined interval. It's possible to change& h1 p; K, {' |. @
  214. # this interval with the repl_ping_slave_period option. The default value is 10
    3 d3 r: P4 x3 P* y5 q: g
  215. # seconds.8 n4 |7 l$ s) O
  216. #9 D% ~: Z+ o) b2 @0 D0 _- ?( n
  217. # repl-ping-slave-period 103 G4 y9 }' F0 u. k2 Q4 j

  218. / e5 [  _9 ~. b5 p( {: F) W* P- t
  219. # The following option sets a timeout for both Bulk transfer I/O timeout and* f* P  u% f: J" m( B& p! Y9 t
  220. # master data or ping response timeout. The default value is 60 seconds.5 o' H, |3 z3 c; f+ w" F
  221. #
    ( m! B2 }( q4 a1 o& z. i$ Y! y4 _$ [
  222. # It is important to make sure that this value is greater than the value+ B# Y% G( G% s1 I
  223. # specified for repl-ping-slave-period otherwise a timeout will be detected5 E9 E3 R: h% w) l
  224. # every time there is low traffic between the master and the slave.
    & ~/ j' m- r* `7 b1 t
  225. #
    7 r' t5 L6 J, C5 f4 ^1 o) f  P
  226. # repl-timeout 60
    0 e; y: \+ P1 ~- b$ @

  227. , Z* I: l6 {0 O8 [
  228. # Disable TCP_NODELAY on the slave socket after SYNC?
    1 P+ N/ G: R1 J, G! \$ f  X7 Q) N
  229. #' r& p. |2 F. u7 ]
  230. # If you select "yes" Redis will use a smaller number of TCP packets and9 G2 G; q" j* F
  231. # less bandwidth to send data to slaves. But this can add a delay for/ m# T4 r8 }: k6 N
  232. # the data to appear on the slave side, up to 40 milliseconds with3 @$ z8 s/ [/ `
  233. # Linux kernels using a default configuration.
    ( Z; ^# q- u" _. {# `
  234. #
    ) T6 U7 g: T' s
  235. # If you select "no" the delay for data to appear on the slave side will! r3 h% V/ C* i! M: d2 ?8 \/ ~- ~
  236. # be reduced but more bandwidth will be used for replication.
    - x* l1 m9 g  s$ x# K3 X% y( ?  z
  237. #1 y$ b0 k5 k8 W/ T7 I0 y' Z
  238. # By default we optimize for low latency, but in very high traffic conditions
    ; h( J# z! e. V% B+ L2 R% i( [
  239. # or when the master and slaves are many hops away, turning this to "yes" may$ x% ~: c' t8 k! p3 }2 N  @
  240. # be a good idea.1 m- s$ F  l' `6 F. F
  241. repl-disable-tcp-nodelay no. M2 v* m; k6 C# s. e
  242. 8 V; \* ?) ~. H3 M$ G
  243. # The slave priority is an integer number published by Redis in the INFO output.
    2 X/ j' [; t% E- Y% s
  244. # It is used by Redis Sentinel in order to select a slave to promote into a
      g' M& y6 f  n7 Z
  245. # master if the master is no longer working correctly.9 P( e- K3 q6 f( d- c- K* Y# J
  246. #* a/ X  m+ j9 m6 |6 ^  A( t. k( C
  247. # A slave with a low priority number is considered better for promotion, so
    2 ^0 f8 f4 ]& T9 s3 i. V$ j
  248. # for instance if there are three slaves with priority 10, 100, 25 Sentinel will) K! K3 v3 z7 m7 c
  249. # pick the one wtih priority 10, that is the lowest.$ W8 {0 G; \- m& N/ G
  250. #
    ( F5 m7 [0 b5 K& Y
  251. # However a special priority of 0 marks the slave as not able to perform the
    ; `4 N" j0 G/ _6 r+ h
  252. # role of master, so a slave with priority of 0 will never be selected by
    4 o7 X* P8 m8 e
  253. # Redis Sentinel for promotion.2 O5 y/ X0 V- H+ p
  254. #
    , |" H" c. |' N4 Z
  255. # By default the priority is 100.. O* H% ^: ?, k0 g
  256. slave-priority 100" F# B" t, B7 H; b& R0 x9 {

  257. * G- Z* u" A3 n9 _3 u- @
  258. ################################## SECURITY ###################################
    6 _# L# c6 ~& x) C9 b

  259. & M- |) ]/ l% \/ b6 x7 E
  260. # Require clients to issue AUTH <ASSWORD> before processing any other
    & w2 l+ z/ a! n% d* B
  261. # commands.  This might be useful in environments in which you do not trust
    / Y- i/ c- F- d# Z* [+ o( b5 [7 _
  262. # others with access to the host running redis-server./ x4 M3 X- @9 u6 K
  263. #9 Y1 u$ _4 r% h" a
  264. # This should stay commented out for backward compatibility and because most
    5 o1 Q$ N* @$ r" ^( ]0 q4 @+ t
  265. # people do not need auth (e.g. they run their own servers).
    7 Z; w4 g/ C4 u9 J
  266. #
    $ J3 m+ A" h# w) C. |* q  I
  267. # Warning: since Redis is pretty fast an outside user can try up to
    - ?, i! I. b) H7 W  ?
  268. # 150k passwords per second against a good box. This means that you should8 z* K. f3 L* [+ R2 C7 C# c4 \5 y
  269. # use a very strong password otherwise it will be very easy to break.
    8 z9 t+ `  S% x
  270. #
    2 Z) n6 I! ?+ F
  271. # requirepass foobared
    0 Z$ B( O8 x: X+ |

  272. ( g" v2 _8 v4 s8 d8 x% K
  273. # Command renaming.- |3 j1 t% c/ [  Y8 m. o. ?) M
  274. #
    $ P# Y; V$ z6 P( j; Z/ ~5 K
  275. # It is possible to change the name of dangerous commands in a shared8 J, l. z: }" W' }/ o+ S
  276. # environment. For instance the CONFIG command may be renamed into something- U& I; @$ L7 C! w# B% n3 r* S5 t
  277. # hard to guess so that it will still be available for internal-use tools
    ( u+ X: |) R4 j& H
  278. # but not available for general clients.1 S1 k2 Z; T  u  @+ `
  279. #
    & Z, K9 O& c/ C
  280. # Example:' M5 t% ?8 E8 B! }, |" x
  281. #& r7 ?# o( @  q; F# ?
  282. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52  n: \& v7 _7 ?: a/ P& U8 `2 s' S0 s5 x
  283. #$ O. {0 n$ X  d. ?! b0 |
  284. # It is also possible to completely kill a command by renaming it into7 ^" S/ k& ?+ N5 ^# p( _
  285. # an empty string:% t) l0 [* Q# _$ J
  286. #$ z- E8 _+ W1 W0 l( a! F* M
  287. # rename-command CONFIG ""
    4 l7 n0 v- h0 M
  288. # i! I& b: N! h3 y1 E  }
  289. ################################### LIMITS ####################################
    , m6 O7 G. R3 w3 @

  290. 9 B, w+ x3 P" \& \; Z
  291. # Set the max number of connected clients at the same time. By default/ B9 t4 \. F, X# S; e8 `4 Q2 E: d
  292. # this limit is set to 10000 clients, however if the Redis server is not
    ) ]1 v# S8 w. m9 G5 T
  293. # able to configure the process file limit to allow for the specified limit+ `: N5 H/ _- u7 W
  294. # the max number of allowed clients is set to the current file limit
    : Z  \( c- {$ k. A, F5 z
  295. # minus 32 (as Redis reserves a few file descriptors for internal uses).& p. Q7 Q+ K1 ?% h0 I) S
  296. #
    8 B( I% P4 t* k) |6 a
  297. # Once the limit is reached Redis will close all the new connections sending# d: j$ U4 \+ t+ H4 Y7 S; N
  298. # an error 'max number of clients reached'.
    ; w) o8 }$ D5 k" z
  299. #
    1 p, `2 D, z7 ]) J
  300. maxclients 500$ f5 ]5 G5 Y# ?
  301. ( u% X  M) N* Z  `# [+ u
  302. # Don't use more memory than the specified amount of bytes.$ z- L  j$ R$ w) t
  303. # When the memory limit is reached Redis will try to remove keys1 f; h) m8 q* ]) j; f1 A2 K
  304. # accordingly to the eviction policy selected (see maxmemmory-policy).: S' O4 X: I+ z
  305. #7 f5 p" ]/ g/ F  W+ s
  306. # If Redis can't remove keys according to the policy, or if the policy is
    ) Z9 e; u; N# p1 k  e
  307. # set to 'noeviction', Redis will start to reply with errors to commands; s2 Y! L9 n9 u& ^, k' T
  308. # that would use more memory, like SET, LPUSH, and so on, and will continue3 f, K" X! `  i
  309. # to reply to read-only commands like GET.
      k% x0 _4 S$ a
  310. #; r; v$ v5 i% K$ W+ D" H$ B
  311. # This option is usually useful when using Redis as an LRU cache, or to set
    1 V6 ~. o6 R6 `7 I' G. V! k- j& d
  312. # an hard memory limit for an instance (using the 'noeviction' policy).
    , S, {+ s$ L- y6 {/ O8 q
  313. #
    % I$ Z( Z' U6 l. V+ J
  314. # WARNING: If you have slaves attached to an instance with maxmemory on,( ~/ w& z6 p1 C& @5 t# o0 W- y
  315. # the size of the output buffers needed to feed the slaves are subtracted' ~1 Y! ?: r4 f3 ]+ X2 V
  316. # from the used memory count, so that network problems / resyncs will
    - i+ ?, c7 ^1 H+ ]9 T! s" u- N
  317. # not trigger a loop where keys are evicted, and in turn the output
    / _  s0 U$ M% F
  318. # buffer of slaves is full with DELs of keys evicted triggering the deletion/ X2 v: m" u/ Q
  319. # of more keys, and so forth until the database is completely emptied.
    7 |/ S  g9 j) w7 Q. a0 \; _4 e- C
  320. #
    ) C7 i0 X% {$ V/ M! t# A
  321. # In short... if you have slaves attached it is suggested that you set a lower' ?8 A2 i- A, X' T9 q. U
  322. # limit for maxmemory so that there is some free RAM on the system for slave+ \4 Y2 N6 j& Z' G" J( t
  323. # output buffers (but this is not needed if the policy is 'noeviction').
    2 S( M0 w- N2 b& g
  324. #
    ! X7 H7 r: R/ c* D
  325. maxmemory 128000000' z/ p1 U* k9 |/ A+ O& y
  326. 0 |4 s$ A3 K/ h. K
  327. # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
    0 b3 w4 J8 d5 g- W$ a: Q' B7 {" t, p
  328. # is reached. You can select among five behaviors:
    & G% f' b8 `9 M1 m5 Y. I
  329. # % l6 C$ L9 C. H0 @: B4 }
  330. # volatile-lru -> remove the key with an expire set using an LRU algorithm- c. J6 o/ ~  Z( I$ K+ g1 K
  331. # allkeys-lru -> remove any key accordingly to the LRU algorithm3 ^, t$ A% D% X* E) U
  332. # volatile-random -> remove a random key with an expire set
    , c: V, P/ c' x3 h( Z- t& x* C
  333. # allkeys-random -> remove a random key, any key
    0 a# M% b8 T3 f- R; ]6 e1 s1 \
  334. # volatile-ttl -> remove the key with the nearest expire time (minor TTL)4 t+ z5 M& f- ?, j# B
  335. # noeviction -> don't expire at all, just return an error on write operations4 ?1 f6 g0 G7 X/ I. S
  336. # 6 b* G) X. B8 H; f
  337. # Note: with any of the above policies, Redis will return an error on write
    & P( @8 d. }$ l! U
  338. #       operations, when there are not suitable keys for eviction.) A6 {3 p" b$ o9 N
  339. #, s% q$ r4 ]  t
  340. #       At the date of writing this commands are: set setnx setex append% E) G0 l* _- \0 o9 \
  341. #       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd( w- v4 G/ q. p1 [
  342. #       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
    * O, R0 B( \1 J& N
  343. #       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby. {6 {3 M" E* i# }; S5 i
  344. #       getset mset msetnx exec sort1 ^) F% x2 M# B# d2 x
  345. #* |$ H3 ]+ a) X" r
  346. # The default is:  Z/ ~7 G) M5 M6 D
  347. #" \6 U2 f0 B3 b' _/ r; f9 t
  348. # maxmemory-policy volatile-lru
    9 {$ q6 A4 i7 Q9 D
  349. : w/ R! g+ Y" H0 Z8 R
  350. # LRU and minimal TTL algorithms are not precise algorithms but approximated( H& q& W' c) w: V/ c
  351. # algorithms (in order to save memory), so you can select as well the sample7 x$ y& \' ^  W7 G9 ^) S# K( F
  352. # size to check. For instance for default Redis will check three keys and
    " o! N& a, }" G# D7 w% n5 y
  353. # pick the one that was used less recently, you can change the sample size. b( I+ [) X4 k* {
  354. # using the following configuration directive.
    * s& J4 d( V  b
  355. #
    # V& A4 Y1 x) z" \( X- F/ `$ b6 ^
  356. # maxmemory-samples 3- W* C/ ~5 x- q' f! a2 ?

  357. ) r& J- f* X$ T; X- Q& o
  358. ############################## APPEND ONLY MODE ###############################: |; ]( {2 O( W* j
  359. + j/ a' n* y: \  H+ a1 g
  360. # By default Redis asynchronously dumps the dataset on disk. This mode is
    % i4 j% c. ]$ S
  361. # good enough in many applications, but an issue with the Redis process or
    ( \- Z  p1 r; t) D8 g5 O
  362. # a power outage may result into a few minutes of writes lost (depending on
    0 F/ b' |( _+ p1 p' q% x7 M
  363. # the configured save points).
    5 q  }$ @, W0 n& j1 G2 h$ h+ ~
  364. #9 Z! _" o% m4 u' T  S
  365. # The Append Only File is an alternative persistence mode that provides6 ~1 q/ b" W; @7 U) [
  366. # much better durability. For instance using the default data fsync policy
    " j# z# {4 \% p  @( `( m  C
  367. # (see later in the config file) Redis can lose just one second of writes in a
    , @' H- k' g6 r) f/ z( g- u
  368. # dramatic event like a server power outage, or a single write if something
    5 }1 N. c2 h$ G! \+ k  r
  369. # wrong with the Redis process itself happens, but the operating system is
    ) g4 Y6 A3 Y4 b) P" c" H6 l! }
  370. # still running correctly.3 t  z0 v9 g6 C0 P8 D* y" q. c
  371. #
    ) k  S5 q# d# w9 I( q8 B: a  y
  372. # AOF and RDB persistence can be enabled at the same time without problems.* X! e. ~/ c; w: m8 C2 V6 H
  373. # If the AOF is enabled on startup Redis will load the AOF, that is the file% K; @' z( N5 c& |" u- U3 r
  374. # with the better durability guarantees.* g7 t) o$ J# M4 c2 ]) t+ T
  375. #8 w+ Q5 A. s2 c+ d" u( R: A: W
  376. # Please check http://redis.io/topics/persistence for more information.# i1 T1 ~3 p* A! _7 T4 ~! L, R
  377. 2 `% v1 \6 r. O" k- @; n
  378. appendonly no/ o4 X) y: v1 k( W

  379. ; Y0 |# H6 {" W$ Y; ~/ m
  380. # The name of the append only file (default: "appendonly.aof")
    + I2 W* u+ J8 K9 ~, J0 W
  381. # appendfilename appendonly.aof) I! _' ]6 g1 d- z) O

  382. 3 O: i3 J$ @. z& L7 P
  383. # The fsync() call tells the Operating System to actually write data on disk
    $ K" G/ H' s2 [: e; Q6 |( T6 E$ k
  384. # instead to wait for more data in the output buffer. Some OS will really flush
    ( E- ?' c' k3 S5 L
  385. # data on disk, some other OS will just try to do it ASAP.
    " ?+ k8 `. _+ y( y
  386. #0 e% y4 a( C. |) u
  387. # Redis supports three different modes:; r$ `1 R6 v6 ~
  388. #% ~8 J/ u+ |) g
  389. # no: don't fsync, just let the OS flush the data when it wants. Faster.
    / m4 c9 m- \9 S% @% U0 p5 v# J; t
  390. # always: fsync after every write to the append only log . Slow, Safest.# e3 R, H9 t5 K/ e) d
  391. # everysec: fsync only one time every second. Compromise.
    4 u9 K7 O4 N. n& f
  392. #+ k9 y- [+ z6 b2 Z% q, ?! v6 o
  393. # The default is "everysec", as that's usually the right compromise between
    " K+ V5 F0 O0 `; m! J
  394. # speed and data safety. It's up to you to understand if you can relax this to
    6 N8 f  j: V/ W) ]* o
  395. # "no" that will let the operating system flush the output buffer when
    / g0 w, ~# G7 V, u" l
  396. # it wants, for better performances (but if you can live with the idea of8 v* w$ y& j+ o+ k
  397. # some data loss consider the default persistence mode that's snapshotting),% X& i9 w  H" z* d
  398. # or on the contrary, use "always" that's very slow but a bit safer than. {5 |( @! ~$ X/ c2 |9 f
  399. # everysec.
    + j! F* Q" `5 w+ g+ t: \
  400. #  u! k- P5 \% {4 e. ]
  401. # More details please check the following article:
    # D3 G5 T2 x; P/ q. C
  402. # http://antirez.com/post/redis-persistence-demystified.html
    , {2 U* y1 n: \* N- V
  403. #1 |" m* d; s4 o& Y4 }
  404. # If unsure, use "everysec"., X' E/ r+ |+ D$ _' c; i
  405. 8 V4 w4 e, \6 w( e9 Z; |
  406. # appendfsync always4 w* q  s) a- K% H. E
  407. appendfsync everysec& E7 }' R" r9 y
  408. # appendfsync no% k; o% R7 c4 ^  K. w" H2 d# w: ]

  409. & B2 a1 B3 ~% n0 ^% _. x
  410. # When the AOF fsync policy is set to always or everysec, and a background
      v% P! u6 b; ]4 a
  411. # saving process (a background save or AOF log background rewriting) is  r# r6 X/ Q% ]9 K. K
  412. # performing a lot of I/O against the disk, in some Linux configurations8 T4 [) }, R6 S) k( \
  413. # Redis may block too long on the fsync() call. Note that there is no fix for8 V, A7 I' _+ y" S; e- Q
  414. # this currently, as even performing fsync in a different thread will block: W5 F1 T9 s& a3 S7 }! F2 \
  415. # our synchronous write(2) call.. ]  U  Q4 p0 v
  416. #  c' k5 o& h' C# \/ c1 ]! P+ ]
  417. # In order to mitigate this problem it's possible to use the following option# ~  Y- q1 j: d. j( h
  418. # that will prevent fsync() from being called in the main process while a
    4 [* P$ K6 O1 Z& }: s1 ^  l
  419. # BGSAVE or BGREWRITEAOF is in progress.2 Q2 c/ v9 z1 ^7 L
  420. #
    5 Y" s; @8 m5 `; i* S+ s
  421. # This means that while another child is saving, the durability of Redis is
    2 |! b% E/ ?/ I  z, {: q" e. e" {+ ~
  422. # the same as "appendfsync none". In practical terms, this means that it is
      o8 w% C: C& U+ F8 h! l3 V5 i& L
  423. # possible to lose up to 30 seconds of log in the worst scenario (with the
    ( u* R3 Y# {) c
  424. # default Linux settings).( j  p7 u0 p) N3 o8 y' @+ ^
  425. # " h  {4 o0 L1 M. k( @) S
  426. # If you have latency problems turn this to "yes". Otherwise leave it as4 o2 F" A+ V0 ]- l$ D$ F& j7 E
  427. # "no" that is the safest pick from the point of view of durability.
    ; N3 z% K! G% M% U. F
  428. no-appendfsync-on-rewrite no8 K: o% F2 [5 w' P4 n
  429. ( B! l# p+ B2 }. P4 S4 ?2 t9 V  m
  430. # Automatic rewrite of the append only file.
    ) }# I! K% j, N( C6 O, [& G
  431. # Redis is able to automatically rewrite the log file implicitly calling! L% }3 T, d+ U
  432. # BGREWRITEAOF when the AOF log size grows by the specified percentage.
    0 I9 p! n, q9 X$ g! C, O
  433. #
    4 i* a: T& e7 k% e' Y2 a- C
  434. # This is how it works: Redis remembers the size of the AOF file after the' j* c  ]  a1 @5 R3 t3 ?- r( B" v
  435. # latest rewrite (if no rewrite has happened since the restart, the size of  ]' H) b  O) C7 B( O" i  u: Q/ O
  436. # the AOF at startup is used).7 t2 W/ b+ _  X& @$ \' X
  437. #' y# g) U) }4 I& d; d8 V. i
  438. # This base size is compared to the current size. If the current size is' S8 o" W) n5 T* z# O4 T% E
  439. # bigger than the specified percentage, the rewrite is triggered. Also# r+ {* [5 S3 ^7 P) s, _
  440. # you need to specify a minimal size for the AOF file to be rewritten, this& o+ j. r6 S! I) L1 p% d
  441. # is useful to avoid rewriting the AOF file even if the percentage increase
    ! r* c; f5 W; V' I
  442. # is reached but it is still pretty small.: m+ ?: I3 T, k% v6 o1 q
  443. #
    9 Q+ K) v) V+ y
  444. # Specify a percentage of zero in order to disable the automatic AOF
    ) }- h* ]. ?- v, ]
  445. # rewrite feature.) F. r( x  O+ q% h3 j
  446. 6 n/ f( `- l8 l
  447. auto-aof-rewrite-percentage 100: e+ p( O  W: I3 |
  448. auto-aof-rewrite-min-size 64mb
    " v1 {$ T4 |1 D! `

  449. 2 m7 v* {; S) O, f/ M  K4 c( V
  450. ################################ LUA SCRIPTING  ###############################
    / E! N: X$ }0 w- [/ i

  451. + l+ R" D+ s, K! z, t
  452. # Max execution time of a Lua script in milliseconds.
    + A2 e9 U9 }' N  b( B+ S
  453. #: d) t, k) E) {& v, T% c
  454. # If the maximum execution time is reached Redis will log that a script is
    2 D& C. o2 v8 }$ _; J, p
  455. # still in execution after the maximum allowed time and will start to
    3 ?0 o& e$ U1 Y; Q) [$ ^; `2 T% k
  456. # reply to queries with an error.: k. U: R2 H$ e$ e/ i) t5 d
  457. #
    . S5 V5 y$ U. {# q- ]7 v
  458. # When a long running script exceed the maximum execution time only the
    1 \7 ]7 T) {5 S
  459. # SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be( y6 J8 r$ }7 k. n
  460. # used to stop a script that did not yet called write commands. The second
    : A3 q6 ^* G5 N  A" i
  461. # is the only way to shut down the server in the case a write commands was7 @1 _2 J6 X6 W& t  C' c1 I
  462. # already issue by the script but the user don't want to wait for the natural
    3 C7 F8 j# K. F( E8 f! b
  463. # termination of the script.
    7 s9 \+ ?$ ]  ^# `
  464. #
    + w5 m" a  W) ]% u! Y4 s
  465. # Set it to 0 or a negative value for unlimited execution without warnings.
    ! w; i4 N% w* R& L" h
  466. lua-time-limit 5000
    5 B9 K+ U+ L6 m% }

  467. ) Y' W" R+ X4 Z  Z' h9 ^( Z/ Y( s
  468. ################################## SLOW LOG ###################################" `$ c) ]: s, d: b& W7 c& |
  469. $ S) F( O$ r3 L$ J
  470. # The Redis Slow Log is a system to log queries that exceeded a specified
    $ L+ l! x$ ^0 |3 X  j7 ?! e  `
  471. # execution time. The execution time does not include the I/O operations9 m, e- u& O! M/ t" s/ @* u% m
  472. # like talking with the client, sending the reply and so forth,
    4 x" j0 z  d: U
  473. # but just the time needed to actually execute the command (this is the only
    2 y/ s6 f5 n& p, z7 @# w2 Y
  474. # stage of command execution where the thread is blocked and can not serve: q  s3 J& G* b; ^4 S7 w
  475. # other requests in the meantime).
    3 K/ J! Q. I# E- M* a2 ?- t
  476. # 0 o$ z# \+ @' b3 g
  477. # You can configure the slow log with two parameters: one tells Redis3 i% K0 m+ M0 ~+ h+ R& }
  478. # what is the execution time, in microseconds, to exceed in order for the# O" H! P+ g4 f$ @6 p
  479. # command to get logged, and the other parameter is the length of the
    & x. `- [% F# x+ d1 q6 O
  480. # slow log. When a new command is logged the oldest one is removed from the  a1 M' j, C" V/ \( s$ @7 S
  481. # queue of logged commands.' L& j/ y' L6 {4 N9 N
  482.   |% K* S, f% r3 F6 I
  483. # The following time is expressed in microseconds, so 1000000 is equivalent
    % M0 m# A& L" Q$ k
  484. # to one second. Note that a negative number disables the slow log, while# d, j0 O  i7 I( ?& O* e
  485. # a value of zero forces the logging of every command.4 u( a, |1 e3 r
  486. slowlog-log-slower-than 10000
    7 }" H- E) n) m4 k- i4 g

  487. " T; g1 @( Q! b! F- e
  488. # There is no limit to this length. Just be aware that it will consume memory." W  L8 S2 M) s+ ^9 X. }
  489. # You can reclaim memory used by the slow log with SLOWLOG RESET.
    . F1 W# i# Z" ~  S
  490. slowlog-max-len 1280 l6 I# C: R, j/ q( z3 y2 U

  491. 4 M  g5 l1 Y# y
  492. ############################### ADVANCED CONFIG ###############################
    ! ^4 U, Q' c: n

  493. : o9 ~" J) ?. p) x' R$ u* ^
  494. # Hashes are encoded using a memory efficient data structure when they have a
    : j% d) h9 V9 o5 @2 Z& `
  495. # small number of entries, and the biggest entry does not exceed a given' J/ }7 P8 H1 d
  496. # threshold. These thresholds can be configured using the following directives.2 {( U+ `: x! t: B+ t8 c0 q: q
  497. hash-max-ziplist-entries 512) X* m, N: J8 P5 W
  498. hash-max-ziplist-value 641 p8 Z9 n5 ^7 M; r# q

  499. 2 C! U4 K8 i$ E. v
  500. # Similarly to hashes, small lists are also encoded in a special way in order* v! ]! g7 ]& K  i. z
  501. # to save a lot of space. The special representation is only used when# ^) M4 j5 S; {  w: O" |
  502. # you are under the following limits:* R. b* C0 Z' N! p
  503. list-max-ziplist-entries 512
    - X9 G* A( I: Y7 @7 w$ H6 s
  504. list-max-ziplist-value 645 R1 G6 N+ Q5 P+ [8 t; T

  505. : q6 Z$ \' K0 @  q! m% C
  506. # Sets have a special encoding in just one case: when a set is composed( K7 H) q: x0 @
  507. # of just strings that happens to be integers in radix 10 in the range2 x& m) K: i2 [# d1 d* q3 R
  508. # of 64 bit signed integers.
    & ^/ ?- r$ n! z/ q4 h
  509. # The following configuration setting sets the limit in the size of the; h& R/ g' G* L
  510. # set in order to use this special memory saving encoding.+ R1 e5 S7 c1 _2 d
  511. set-max-intset-entries 512
    6 C( P" ^( I: a

  512. / G. Y" h; d) u3 T3 X
  513. # Similarly to hashes and lists, sorted sets are also specially encoded in
    , Q4 ]8 G  Y2 c7 O
  514. # order to save a lot of space. This encoding is only used when the length and
    $ f  j1 X6 [7 }1 a
  515. # elements of a sorted set are below the following limits:
    ; S% S1 \+ `2 e. F
  516. zset-max-ziplist-entries 1284 X) S9 |8 n* U% b- L
  517. zset-max-ziplist-value 64( \  [( N3 q) _) K) M6 h

  518. , G. e! R4 y5 K9 u0 Z5 {
  519. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in" L  B" ]8 W) ~6 c* @4 j3 H
  520. # order to help rehashing the main Redis hash table (the one mapping top-level
    % t) ]* C/ F  g" k$ q) f
  521. # keys to values). The hash table implementation Redis uses (see dict.c)
    ( T7 X6 f9 s2 @0 M# z
  522. # performs a lazy rehashing: the more operation you run into an hash table
    / k: Y3 E. u& y1 [! u2 O" c
  523. # that is rehashing, the more rehashing "steps" are performed, so if the
    ( l0 |0 D8 w3 J# c! `' q$ X. V
  524. # server is idle the rehashing is never complete and some more memory is used0 I, X3 i- b& L' z. a" [
  525. # by the hash table.
    , G4 r( ]& b/ C  s; {
  526. #   I3 h7 d% H. n# f/ O. \2 R
  527. # The default is to use this millisecond 10 times every second in order to& t2 S' f8 B/ x$ n6 v
  528. # active rehashing the main dictionaries, freeing memory when possible.7 Q* v4 h8 h7 C
  529. #
    2 {* N3 n9 J/ e- X8 L, m9 Y
  530. # If unsure:
    1 j8 }2 H+ U3 r+ W+ L
  531. # use "activerehashing no" if you have hard latency requirements and it is
    8 ]- j" ]0 a7 j& \, B
  532. # not a good thing in your environment that Redis can reply form time to time4 q. _% Z  ?+ \1 C! C! R" B, a6 W
  533. # to queries with 2 milliseconds delay.! X2 H& _; U5 P9 H
  534. #
    % n1 J* `8 j7 m1 m. }) [3 Z6 F* e
  535. # use "activerehashing yes" if you don't have such hard requirements but! _( s7 O* @+ a& M; x7 \: t' A( ^
  536. # want to free memory asap when possible./ t. f' _& \1 Y" T/ S
  537. activerehashing yes: L2 f* P( b  v% S

  538. - ]$ \6 `  u8 {$ R. a% O0 t
  539. # The client output buffer limits can be used to force disconnection of clients
    ( E& N2 `9 ?* m. U: |$ ]  s8 V: i
  540. # that are not reading data from the server fast enough for some reason (a( D, Z7 h, }+ [7 c$ ^# ?! j/ I
  541. # common reason is that a Pub/Sub client can't consume messages as fast as the- `* }8 C) X: T/ g! p, t
  542. # publisher can produce them).( Q5 W! @+ D# U  k% Q# Y1 }: l' @" a
  543. #3 d* L1 ], F) C7 Q
  544. # The limit can be set differently for the three different classes of clients:
    4 x4 t" G7 o3 T
  545. #
    . I" ]) h, u3 }* j
  546. # normal -> normal clients3 a+ N5 }' Q! r; Z& E5 D3 {
  547. # slave  -> slave clients and MONITOR clients
    * g) I+ P" p! E& M5 M" ]
  548. # pubsub -> clients subcribed to at least one pubsub channel or pattern' B! [2 k# H* g5 u& x) u5 o1 B
  549. #
    9 }9 H5 j2 e% Z& M2 g
  550. # The syntax of every client-output-buffer-limit directive is the following:) Z1 x0 B9 G* f0 l- r' m$ o
  551. #* E) E# t( c8 q0 x/ O3 a" ~6 Z
  552. # client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>
    1 ?; {( M2 m: R
  553. #
    5 {0 L2 o5 M. I( G
  554. # A client is immediately disconnected once the hard limit is reached, or if
      E! Q! f% m) M( S6 r
  555. # the soft limit is reached and remains reached for the specified number of' N( \5 v6 Z7 ~1 G+ G4 p
  556. # seconds (continuously).  p  A$ J, C* I: L$ W
  557. # So for instance if the hard limit is 32 megabytes and the soft limit is
    . r8 H" Z/ Z6 [$ j) M
  558. # 16 megabytes / 10 seconds, the client will get disconnected immediately, _& I3 d) p% ^
  559. # if the size of the output buffers reach 32 megabytes, but will also get0 c% B8 C) |7 O; S( ~  p0 Y
  560. # disconnected if the client reaches 16 megabytes and continuously overcomes; V  W- W( x$ s+ Y
  561. # the limit for 10 seconds.
    & M% m: ]" [- j' }8 Y
  562. #
    / ]4 A1 [( P' v1 v- D7 Y" D
  563. # By default normal clients are not limited because they don't receive data+ q/ u+ R% K" H1 D/ V( \+ y
  564. # without asking (in a push way), but just after a request, so only, T3 p. B7 o2 M+ a2 b3 h7 s
  565. # asynchronous clients may create a scenario where data is requested faster7 R2 c7 |( ]" O3 h$ e% e6 \
  566. # than it can read.
    1 s7 d, y, h& s; m9 p& T  T6 f( F
  567. #
    % V4 r" v$ C2 r
  568. # Instead there is a default limit for pubsub and slave clients, since
    ( N, y) B1 |* O  w% F0 X
  569. # subscribers and slaves receive data in a push fashion.! f# D1 S9 x' h
  570. #
    7 r4 [# p3 g+ r8 I" S9 k
  571. # Both the hard or the soft limit can be disabled by setting them to zero.4 @" h# ?' z) U( v
  572. client-output-buffer-limit normal 0 0 0
    : u1 @# p" J2 w9 u# Z! H% F9 _
  573. client-output-buffer-limit slave 256mb 64mb 600 _) c2 Q- ?9 j1 a/ i. f3 t
  574. client-output-buffer-limit pubsub 32mb 8mb 60
      I5 F* {; x% M" O( h$ _9 t

  575. 2 d* i0 ]7 H: v: g$ b
  576. ################################## INCLUDES ###################################; X! D% V" l4 ]& ?. |- Y
  577. 7 V, K" w+ @; k# Q$ D# e9 d
  578. # Include one or more other config files here.  This is useful if you
    4 F& v# p+ }8 H4 c3 q! O# _; B8 e
  579. # have a standard template that goes to all Redis server but also need/ w4 T" N  G! N
  580. # to customize a few per-server settings.  Include files can include) }& j9 s! h7 w2 y. W1 j, ]
  581. # other files, so use this wisely.1 b0 {# Y9 Z2 a- M
  582. #
    % L5 s% f& @0 ]9 c) z
  583. # include /path/to/local.conf4 U  ]( r! u' [5 a- s
  584. # include /path/to/other.conf        
    ' V3 h/ x$ }& q) e* p
  585. ##########################配置文件结束################################ ' ?/ Z0 \4 d$ y1 S& z! u
  586. 第三步:启动进程
    * U; t; B7 ~- i+ p- p% B
  587. #redis-server /etc/redis.conf
    ! v: P" Z3 J  U( a9 n/ _* |
  588. 查看进程有没有成功启动
    9 ^& z4 L7 q6 ?% M# r1 ^
  589. #ps -ef | grep redis " a+ F5 ]$ w  u$ E: n; o& F6 b
  590. 测试输入一个键值
    4 U* @! K8 g* s7 I4 P
  591. #redis-cli set test "testredis"# Q: `% W  Y4 B% X. _5 X
  592. 获取键值
    4 Z. ?4 ^' a; D& b( Y. M+ b
  593. #redis-cli get test3 y; M- v1 n' r8 f" R- a6 j
  594. 0 e1 n7 l/ B! b1 t* e8 Z

  595. 9 O. {- u- V$ o: v( |) l2 M
  596. 第四步:关闭redis  (这个是更改配置文件后 正常的重启方式  不重新加载redis配置跳过), l! w% d. }) b7 k& H$ h! h1 S6 q
  597. # redis-cli shutdown      //关闭所有   
    ( t0 y' {( d% [. y
  598. 关闭某个端口上的redis    5 \( m: ^# b% s: B8 M
  599. # redis-cli -p 6397 shutdown  //关闭6397端口的redis    ]& Z, w7 Z( X, S$ q
  600. 说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename  dump.rdb  % w5 c0 j& t4 a2 W; p5 J
  601. ! r! I: I6 M0 t# K! J( q1 g
  602. 0 @3 `1 X& @: ]
  603. 第5步:php扩展安装( ~9 I7 I0 g3 {  h
  604. phpredis PHP扩展下载地址 8 U9 G! ?5 g* Z
  605. https://github.com/nicolasff/phpredis/tree/2.2.2
    # @/ M, ]& ^! E6 l( z0 n
  606. 选择最新版本下载zip
    1 e, X8 |& K! G6 R
  607. 3 H: G2 o$ F  C8 A, L) |1 V: f
  608. 然后自己上传zip  用unzip解压到当前目录 unzip 文件名
    + h3 a+ Y( U1 I7 z/ E( G
  609. . l1 ?- g7 X( g
  610. # cd owlient-phpredis-90ecd17/   #打开解压后的文件夹里面  这个解压后的目录 要是不知道 可以输入 "dir" 查看
    - M! r* J5 p5 N2 V8 b* s" u
  611. # /www/nginx_php-5.2.17/bin # X% K/ F1 J' v2 k0 T2 e
  612. # ./configure --with-php-config=/www/nginx_php-5.2.17/bin/php-config% K. f" H; T  M/ _
  613. #make/ Z6 Z4 V( p: B7 A( M) p
  614. #make install   #记录产生的redis.so路径
    . V; K! {4 c# o- R& d$ O2 ]7 f1 \) O
  615. # w- O$ @" V' W. ~
  616. 修改php.ini文件; X' ^9 B4 P" o* R
  617. 在php.ini中添加如下一行:
    ( y8 f5 ^( r7 x& w( G2 i
  618. extension=/?/redis.so  #是刚刚记录的产生redis.so的路 写在 ?那
    3 l, ?/ N8 P9 b+ x0 b5 L
  619. 重启 使之生效:
    + M4 D; G( h) t% Q- a* \! D! M7 j
  620. /usr/local/php/sbin/php-fpm reload7 u; R% W1 R$ m1 X4 K, J5 b7 r
  621. /usr/local/nginx/sbin/nginx -s reload   R5 R* n$ ]% s! }- \$ D
  622.   N& @  Y- ^0 I7 V. K2 n/ @
  623. 将 Redis 作为 Linux 服务随机启动8 E9 `( r# p- p6 A$ _8 J
  624. vi /etc/rc.local, 加入代码:2 t1 L' x; |. q/ g( s  H' Q
  625. /root/redis-2.6.10/src/redis-serve  #路径看情况修改 3 J4 V( A, f  P2 R6 V. w- h. P
  626. $ C8 y& D! _" t2 F
  627. redis-cli -h localhost -p 6379 info  #命令要在redis目录下面执行
    , p3 Q0 F7 ?/ f: ]9 U% i2 q
  628. 提供host为localhost,端口为6379,redis服务的统计信息
    $ I9 ?  M: I7 R" P% M  ^$ H) k' s

  629. , U2 t, E4 n1 {3 U5 J* }
  630.   r6 X( m% b2 J4 d
  631. 就这样你的web服务器就支持redis了 记得要在 给dz 的配置文件 加上12.0.0.1哦/ ?, G& e& D+ s6 E
  632. dz配置文件在 config目录下面的 config_global.php
    ' _2 ?) g5 w' B# z+ s
  633. $_config['memory']['redis']['server'] = '127.0.0.1';
    ) e/ L$ b; g& p- C$ }
  634. $_config['memory']['redis']['port'] = 6379;! ~3 T! o- Y) _! a' x& w% E. f
  635. $_config['memory']['redis']['pconnect'] = 1;
    3 O( r; |+ y) E- K/ `- {9 {8 q
  636. $_config['memory']['redis']['timeout'] = '0';3 g. l1 |+ v9 o' ?
  637. $_config['memory']['redis']['serializer'] = 1;
    6 z# W! G' A+ h% w  `$ f( F
复制代码
关注微信公众号《神采飞扬网》,即可获取最新回复通知!

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

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

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

×温馨提醒:关注《神采飞扬网》公众号,就可以及时接收到回复通知啦!24小时客服微信/电话:13068892088
1、注册用户在神采飞扬网(含旗下所有平台)发表、转载的任何作品仅代表其个人观点,不代表神采飞扬网认同其观点。
2、如果存在违反国家相关法律、法规、条例的行为,我们有权在不经作者准许的情况下删除其在神采飞扬网的所有内容。
3、所有网友请不要盗用有版权要求的作品,转贴请注明来源,否则文责自负。
4、神采飞扬网保护注册用户个人资料,但是因自身原因导致个人资料泄露、丢失、被盗或篡改,神采飞扬网概不负责,也不承担相应法律责任。

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