分享到:
发表于 2018-11-16 12:42:28 | 显示全部楼层 |阅读模式
环境配置
" K1 K" I' s* _3 B" t5 i. t, y( t0 w% p0 P! w+ \( j! k) Q3 L
9 R/ R7 F' y' s. U
http://www.discuz.net/forum.php? ... amp;highlight=REDIS
关注微信公众号《神采飞扬网》,即可获取最新回复通知!
 楼主| 发表于 2018-11-16 12:43:33 | 显示全部楼层
http://www.discuz.net/forum.php? ... 648&highlight=REDIS
. M8 Z& a" r! j" w" l. l. ~7 ~9 l4 f无意间测试 单机状态 redis相当给力 测试1000请求/s  单纯的 get 和set 居然只用了 0.01秒 当时我惊呆了
5 b0 i( c1 b  D
. T% l2 f+ M: E* D4 J- |http://www.discuz.net/forum.php? ... 731&highlight=REDIS
; v8 A  k9 |' z* H+ f4 N! Y: f8 L6 ?% Y( `% G; q: o/ B- ]
https://wenku.baidu.com/view/265a5ce176a20029bc642d0b.html
, |  o/ g5 q- z4 d5 r
) i: m- A6 n' g0 v+ H! U+ j7 {=======================================; p  O% O4 e' c$ |1 o7 i& Z
  1. 连接上 ssh& h- U+ `& D7 ]
  2. 9 z2 w, O( U9 [8 y$ s* s
  3. ( X/ V  C& j4 c( x
  4. 第一步:下载redis% U' i# A) h6 K( n, x+ d- k
  5. # wget http://redis.googlecode.com/files/redis-2.6.10.tar.gz# I; R, G# S' V7 F# m* ^% m
  6. # tar zxvf redis-2.6.10.tar.gz
    3 M! F# B4 J! g4 |4 a) i/ B: j/ A
  7. # cd redis-2.6.10
    / f; x; \+ p; p6 J. b
  8. # make
    1 f& [- `" p& O, d/ M8 B
  9. # make install  
    , V5 D  x2 Z" Q4 R1 k$ O$ J' e
  10. #cp redis.conf  /etc/ #复制配置文件到etc目录下面' @2 B1 o; r( O  S2 |" N; e- t
  11. 第二步:修改配置- J5 i5 I& D: j! L% q7 w( u% T
  12. #vi /etc/redis.conf/ W4 _' x" j2 S# n8 j4 c1 ~
  13. ######################下面是无措的配置文件 复制过去就成#########
    ; K7 Y+ `% D2 R" p% O# Y, p
  14. # Redis configuration file example
    ; x4 J) i2 i0 J" S$ G! J3 f

  15. 2 ?$ l5 ^1 Z+ ]" S
  16. # Note on units: when memory size is needed, it is possible to specify
    2 j; ^* i9 D; T$ a; L9 E
  17. # it in the usual form of 1k 5GB 4M and so forth:+ ?: }/ C( N5 t1 e0 P
  18. ## o$ d- Y& R: @; \( A+ t
  19. # 1k => 1000 bytes
    7 m9 t6 z8 w  @  B' y) G
  20. # 1kb => 1024 bytes
    . N) f+ b' c% u7 m( T
  21. # 1m => 1000000 bytes& S( g* W% L1 E$ |" p! u
  22. # 1mb => 1024*1024 bytes2 \7 g; S- H6 q1 ~* h+ t: j1 V& ?' J6 ]
  23. # 1g => 1000000000 bytes# x9 J2 s5 \+ w
  24. # 1gb => 1024*1024*1024 bytes9 X2 Z, |% b5 f& |
  25. #  t' k; E) q! v4 a! W- t
  26. # units are case insensitive so 1GB 1Gb 1gB are all the same.7 `- ~) e9 Z( V) l6 F
  27. ! D" k. W" P/ b0 P7 `2 W2 [
  28. # By default Redis does not run as a daemon. Use 'yes' if you need it.
    ; t( N5 G3 U: U" \6 d2 P
  29. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
    6 _3 o& e: g' O3 W! E! K& S5 A4 M
  30. daemonize yes
    & i3 G0 k' P; M" i( l/ q# V/ T

  31. . h% a+ L7 B2 p* V  q2 P' O: p
  32. # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
    # d5 U- _& i! S: p, e. J
  33. # default. You can specify a custom pid file location here.
    7 R8 }, L% U1 q
  34. pidfile /var/run/redis.pid0 @! G9 v: b7 t1 A. Y
  35. 1 Y9 [& J' l. c" T* i. j
  36. # Accept connections on the specified port, default is 6379.
    % ^5 P' ^  M& m8 S! z
  37. # If port 0 is specified Redis will not listen on a TCP socket.
      H: x$ n" p- Z# a5 J, {
  38. port 6379
    6 i, f6 d/ _- W

  39. / m' A$ v7 h6 R! k7 Z, K! l
  40. # If you want you can bind a single interface, if the bind option is not9 U, G, X/ h% A2 M! I" y1 Y/ \' V
  41. # specified all the interfaces will listen for incoming connections.
    3 r! W) W! g+ }7 F- C
  42. #7 `8 {2 k. U# L" _, G  h! F4 H
  43. # bind 127.0.0.1/ z, o  e- f" m" a# p3 s5 _- K

  44. 3 h9 |; C2 B+ @" T) h' k
  45. # Specify the path for the unix socket that will be used to listen for+ t8 Y0 ~- j( i: c9 U( {
  46. # incoming connections. There is no default, so Redis will not listen
    ; I8 E# s8 [7 f" E
  47. # on a unix socket when not specified.
    - \! j/ D2 c2 s( ^
  48. #$ M0 o1 A& }/ w/ o
  49. # unixsocket /tmp/redis.sock
    . o1 H: l  C# I  [. r9 F) Z
  50. # unixsocketperm 7553 Q' Y$ ]. i1 L7 w

  51. : A+ \/ S" d: C1 M
  52. # Close the connection after a client is idle for N seconds (0 to disable)
    % c- D% f) E" K; `( T0 `5 Q
  53. timeout 300
    3 B4 A5 r: C1 ^4 A: L' X) q  T
  54. % z9 d: O) |' V. \
  55. # TCP keepalive.
    * i( q+ t# \, V- c4 E4 ~
  56. #1 S4 K- X* `$ F2 }$ u. z
  57. # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence+ g1 f6 W: K9 g5 K1 |# V: R1 }
  58. # of communication. This is useful for two reasons:4 S9 G0 ]/ `5 e' y
  59. #5 F' S4 T' v& p) @
  60. # 1) Detect dead peers.
    1 P% r, X8 w/ e
  61. # 2) Take the connection alive from the point of view of network
    6 e( P( L# u$ I
  62. #    equipment in the middle.9 |+ s+ O2 y) X  X
  63. #* o8 \% e; N; ?1 Z: |$ b
  64. # On Linux, the specified value (in seconds) is the period used to send ACKs.8 @; m2 G5 E0 S& v/ Y9 o6 V6 v: i& L
  65. # Note that to close the connection the double of the time is needed.5 Z4 s4 t. Q. W1 H) N# |, M$ P, L
  66. # On other kernels the period depends on the kernel configuration.
    : y5 J5 ?3 V% }/ w
  67. #
    8 O) o* n5 q* a
  68. # A reasonable value for this option is 60 seconds.
    * x& N& g! C& l' i* n/ ?
  69. tcp-keepalive 0; |8 n/ q: c, d1 ^0 P+ k
  70. + C: m; u  G- H! h
  71. # Specify the server verbosity level.
    0 C5 ]3 N; }* ^8 w' g" j
  72. # This can be one of:' n, p- F9 m! J( Y- n# C2 L
  73. # debug (a lot of information, useful for development/testing)! j) r$ M% ^; e/ H! w
  74. # verbose (many rarely useful info, but not a mess like the debug level)
      E; {. ^7 E  H8 p; |4 F
  75. # notice (moderately verbose, what you want in production probably)
    9 D- ^+ ~' r$ _5 c8 [
  76. # warning (only very important / critical messages are logged)
    + P9 L& j5 S; ]; J. b
  77. loglevel warning
    ( m: V; v1 l7 [1 H$ i; T
  78. , l0 |" x5 u1 h6 q, ?5 |
  79. # Specify the log file name. Also 'stdout' can be used to force8 [0 e* i" G7 Y3 k
  80. # Redis to log on the standard output. Note that if you use standard
    - F3 L7 [* e' \2 @5 d# N2 V9 }) y
  81. # output for logging but daemonize, logs will be sent to /dev/null
    ; Z/ X7 I) Q) P# ~4 F1 m9 e4 K' {
  82. logfile /var/log/redis.log' N( V; \2 c1 ?# V( T
  83. & ]& _! V! p2 E7 x
  84. # To enable logging to the system logger, just set 'syslog-enabled' to yes,
    ' C  L$ z/ Q, g7 V; f
  85. # and optionally update the other syslog parameters to suit your needs.7 D8 g* |/ s+ J" e/ N$ M, Z4 r
  86. syslog-enabled yes% W' o- W: k% y9 W. {' V
  87. 8 Y# O0 w  R; S' {: V' v
  88. # Specify the syslog identity.0 o+ w/ C; m* ?- \$ w
  89. # syslog-ident redis$ p8 _! K1 X- L8 T5 t
  90. ; q( W" f2 o) }4 h2 w$ a
  91. # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.8 Y) _# g- |, V: @( O& N& \! {% d
  92. syslog-facility local0( H( h  P: i7 t. O4 [1 A  u

  93. ; e6 L, L# M  _) q) S# s8 s9 Q/ q
  94. # Set the number of databases. The default database is DB 0, you can select
    - T* B1 y7 j$ g3 U# M8 k  _0 l4 {
  95. # a different one on a per-connection basis using SELECT <dbid> where
    6 C- |, M4 F6 X' s- ^( H, A5 g
  96. # dbid is a number between 0 and 'databases'-1
    - |: i6 Q/ N' y
  97. databases 16
    ! R; H3 F1 A: A, N0 m
  98. 5 O: M+ W2 A- y
  99. ################################ SNAPSHOTTING  #################################8 R- W0 H1 H7 W" f& }& \0 R* I4 X
  100. #
    + m, r8 Z7 X( I* E. Z
  101. # Save the DB on disk:' L) e$ n) s0 m9 H
  102. #
    9 q3 C1 C* M  ]# r. n
  103. #   save <seconds> <changes>! A7 c! X$ \$ s( J3 @2 i  Z& P
  104. #. f. _* n$ ~- |% k
  105. #   Will save the DB if both the given number of seconds and the given
    / O2 j6 i" X" t3 g) H! U
  106. #   number of write operations against the DB occurred.
    7 V5 b. y; ^3 B4 `% T
  107. #' W: U  D$ A3 G7 l0 K, R
  108. #   In the example below the behaviour will be to save:
    * q- e; N# x* n, V. y3 M& h& O
  109. #   after 900 sec (15 min) if at least 1 key changed3 K6 M6 ]3 c" b
  110. #   after 300 sec (5 min) if at least 10 keys changed
    6 _2 Z/ K, X, S( |* A. c+ J9 v- J
  111. #   after 60 sec if at least 10000 keys changed9 R3 P/ {' g3 d5 Q( q' a- v
  112. #
    , e- v$ E, v3 J% `# W+ i: n
  113. #   Note: you can disable saving at all commenting all the "save" lines.1 b  G) r" U/ A3 [% v5 c( l
  114. #- s1 E$ N( i2 }/ V
  115. #   It is also possible to remove all the previously configured save
    + R! s# P3 T8 g# n" S
  116. #   points by adding a save directive with a single empty string argument
    + U3 D. P* I' W7 T
  117. #   like in the following example:$ R  A- Q% y/ r4 Y" D, S( B
  118. #- b+ ~2 I+ A" z+ y  @1 v
  119. #   save "", [, c9 O: [9 T9 C9 ^8 ]8 J
  120. 6 C: `8 g8 r7 x  i
  121. save 900 1/ [% C5 j, l* u+ W
  122. save 300 10
      M+ f6 }6 `' g
  123. save 60 10000
    + b5 s/ P( G  ]8 T/ v

  124. & z3 _# R# V# S6 |* K" e, B
  125. # By default Redis will stop accepting writes if RDB snapshots are enabled; F2 {9 q) R$ W" G
  126. # (at least one save point) and the latest background save failed.
      c) k! {# l) @, P% C8 {
  127. # This will make the user aware (in an hard way) that data is not persisting0 k) @% O1 H# A: l8 x" \
  128. # on disk properly, otherwise chances are that no one will notice and some
    7 r0 T+ B8 [$ w. M
  129. # distater will happen.: b- w3 t, q6 A6 ^( {* O
  130. #7 i* j5 k3 O+ U) K( e, U
  131. # If the background saving process will start working again Redis will
    8 V2 r% \/ }( B( E
  132. # automatically allow writes again./ W$ ?. A1 \, h
  133. #3 k3 F: _8 E$ A
  134. # However if you have setup your proper monitoring of the Redis server8 z; T: I5 X) F8 A
  135. # and persistence, you may want to disable this feature so that Redis will
    . i" N+ x; M7 V* q  m
  136. # continue to work as usually even if there are problems with disk,# x6 H, J3 a( B& w, }3 ^4 g
  137. # permissions, and so forth.
    8 v. R/ g& m3 d7 Z
  138. stop-writes-on-bgsave-error yes
    ) V2 K% d& ^1 a5 l' n- s
  139. % t0 ~9 z/ g( }+ h: `. f: v
  140. # Compress string objects using LZF when dump .rdb databases?) k7 I, U5 D& U9 i6 z( k
  141. # For default that's set to 'yes' as it's almost always a win.6 V* s1 ~# m: L' j- b
  142. # If you want to save some CPU in the saving child set it to 'no' but: G* j5 y2 k( }% U
  143. # the dataset will likely be bigger if you have compressible values or keys." B) E2 w- L% C- s2 h7 j7 }
  144. rdbcompression yes8 i6 d. A; M2 e3 t2 `2 C

  145. 7 C4 ~0 ~9 ]' f4 m2 f8 H$ V
  146. # Since version 5 of RDB a CRC64 checksum is placed at the end of the file.
    0 o2 Z2 ]' k0 {; @3 D
  147. # This makes the format more resistant to corruption but there is a performance+ m" O1 y8 m% ^3 o+ Q2 B+ B6 z
  148. # hit to pay (around 10%) when saving and loading RDB files, so you can disable it! A8 W8 T2 ^: b  r4 }% m
  149. # for maximum performances.* S, Z! a. f$ a$ }- K/ h2 Q
  150. #$ l6 y! b" p: N- V: B- C
  151. # RDB files created with checksum disabled have a checksum of zero that will
    # i1 \% D( w- s; [
  152. # tell the loading code to skip the check.
    % G1 R' S2 c! E3 r0 R; ~( @
  153. rdbchecksum yes4 T; W0 c$ U/ C: ^
  154. ' \6 X4 o) |* u/ `  ?
  155. # The filename where to dump the DB
    5 G% L. P) b1 b. G- a, K( ?4 U
  156. dbfilename dump.rdb- H) d' ]6 e! ]# M6 \5 V
  157. . D3 O5 }# u9 o# {" Y
  158. # The working directory.
    3 K8 B: ~% {& R* n) R. S. W0 T
  159. #0 S" I) {/ b8 B! l% l. S2 ~: N
  160. # The DB will be written inside this directory, with the filename specified- g$ X1 `5 t7 H* Z
  161. # above using the 'dbfilename' configuration directive.
    0 @5 \8 a4 U& Z* Z
  162. # 0 Q6 L0 R. u/ o. ]' g2 N; [( l$ b
  163. # The Append Only File will also be created inside this directory.
    1 A7 \, c7 b2 ^
  164. # / A2 `, c8 [1 }1 D7 l, g& b+ [# c0 B% |
  165. # Note that you must specify a directory here, not a file name.
    , h( j- Q5 Y0 m3 o8 b
  166. dir /var/db/redis2 |5 J' z+ k& X% c3 x9 Z1 h

  167. , K9 |9 t! I3 j' E0 |3 y
  168. ################################# REPLICATION #################################
    2 z- j7 C  |5 ]3 Z) s, l# c' z
  169. 2 X2 U" V* [6 b* g8 n5 ]
  170. # Master-Slave replication. Use slaveof to make a Redis instance a copy of
    : u& y7 c( X$ X4 L  @
  171. # another Redis server. Note that the configuration is local to the slave% u) `8 l- o; s
  172. # so for example it is possible to configure the slave to save the DB with a
    % P7 _) C. I, e, R7 Z4 }
  173. # different interval, or to listen to another port, and so on.
    # R3 i9 r/ `0 {% p: A0 x1 M
  174. #9 Y7 p2 t8 X% V/ A' {; t7 x4 C( I% q
  175. # slaveof <masterip> <masterport>
    + {" g- G* H1 k  c* z
  176. $ G" ~0 B1 H2 w) X, ~6 E- k" f
  177. # If the master is password protected (using the "requirepass" configuration3 e7 P( _  O# G8 n- @% x
  178. # directive below) it is possible to tell the slave to authenticate before
    * v( @, ]: \3 H( a/ R
  179. # starting the replication synchronization process, otherwise the master will
    ! S* C" r" P& c8 e! x
  180. # refuse the slave request." C# ~( H' g0 ^; O
  181. #
    7 {: A/ f5 Z# N2 C! O/ E& B9 H
  182. # masterauth <master-password>
    ) D! g4 s% ^5 n' @5 K; v5 o. G. g5 _# e

  183. . x: R: w3 T! I) u
  184. # When a slave loses its connection with the master, or when the replication9 ^0 Z( N2 h1 S2 L+ l
  185. # is still in progress, the slave can act in two different ways:5 c! i3 O/ b6 i* g) K7 |
  186. #
    : @2 z# K1 m7 w7 P
  187. # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will8 r3 U  ~* _2 q
  188. #    still reply to client requests, possibly with out of date data, or the
    ( V8 F9 j- P0 Y' T: Q
  189. #    data set may just be empty if this is the first synchronization./ J' O  @7 Y9 i9 F% \6 Y# I
  190. #1 z5 E; ~5 }" I5 m% B
  191. # 2) if slave-serve-stale data is set to 'no' the slave will reply with
    ' K1 L) r$ Z9 X9 W6 K( n
  192. #    an error "SYNC with master in progress" to all the kind of commands
    ( e4 T2 M1 L. [3 J
  193. #    but to INFO and SLAVEOF./ k: {* `( @8 G8 L
  194. #
    1 }- Y" V7 f" _/ e' N
  195. slave-serve-stale-data yes5 a3 z; \0 H% l( Z' k9 ^2 z3 t
  196.   W8 f4 t" g# m( }3 R4 @% _
  197. # You can configure a slave instance to accept writes or not. Writing against& ^# j# g* M3 [; V7 p* L
  198. # a slave instance may be useful to store some ephemeral data (because data
    0 k1 Y, r2 _9 `* [1 ~
  199. # written on a slave will be easily deleted after resync with the master) but
    ! F( e9 F* [) H1 Q9 I8 p
  200. # may also cause problems if clients are writing to it because of a
    # G# k% s8 q8 |0 R$ k7 A2 h. R& Q
  201. # misconfiguration.. p- Y4 D" U& W9 X2 D  U. x3 X) r: ]1 v
  202. #
    ) b* J. C1 Q, `/ R9 s$ R+ ]7 B
  203. # Since Redis 2.6 by default slaves are read-only.
    # x: e7 R/ E, N9 c
  204. #; N+ \9 l9 ~( k2 u
  205. # Note: read only slaves are not designed to be exposed to untrusted clients+ I/ i. W8 q( n  P
  206. # on the internet. It's just a protection layer against misuse of the instance.
    , B0 w! U: W/ g( B  B5 n( O- ~
  207. # Still a read only slave exports by default all the administrative commands
    - y  e5 ]" [9 A& h
  208. # such as CONFIG, DEBUG, and so forth. To a limited extend you can improve  ]( y. X, i3 Y: R
  209. # security of read only slaves using 'rename-command' to shadow all the
    ! ^# x4 q& t0 ~
  210. # administrative / dangerous commands.
    . \2 }  @2 B( x
  211. slave-read-only yes' x* Q9 r5 N$ W$ O: s* ~

  212. , s8 _; x: G, ?7 k8 Y/ u- Z& P
  213. # Slaves send PINGs to server in a predefined interval. It's possible to change! j  S# l9 X  [
  214. # this interval with the repl_ping_slave_period option. The default value is 109 n2 F* t* W" ~( D: E
  215. # seconds.6 e% z" i1 c& b! N- s6 S
  216. #
    2 }! I' h% E# A
  217. # repl-ping-slave-period 10
    ! O. }, ~# I# s% O6 O, [

  218. 0 f  C" _3 j- y9 _+ g/ x
  219. # The following option sets a timeout for both Bulk transfer I/O timeout and- q2 y! Q1 m' h, a
  220. # master data or ping response timeout. The default value is 60 seconds.$ r3 }$ \0 G8 E9 o- n, ^  I/ g* j3 L
  221. #
    ( A& T  S1 i; S& N. W4 N
  222. # It is important to make sure that this value is greater than the value' Y. E0 V. U( l, o" c
  223. # specified for repl-ping-slave-period otherwise a timeout will be detected' z8 ^. e: t+ e* ~- B# c5 c
  224. # every time there is low traffic between the master and the slave.
    6 R4 \& s- R+ R% Z
  225. #
    ( Y3 O$ E8 h' a+ e* j
  226. # repl-timeout 60. _4 F! @- X# L) j

  227.   Q7 e6 j* D1 F# H7 O- f8 g
  228. # Disable TCP_NODELAY on the slave socket after SYNC?
    7 `' s8 @. |( Z" \
  229. #6 d$ ^  Z% v0 ], v' v/ n. o
  230. # If you select "yes" Redis will use a smaller number of TCP packets and
    / }3 j# k1 f! D# ^( d% B* u% G
  231. # less bandwidth to send data to slaves. But this can add a delay for
    . c* T" x: }" `
  232. # the data to appear on the slave side, up to 40 milliseconds with+ R1 d# f. W) n( b/ _+ b. R
  233. # Linux kernels using a default configuration.; v4 v0 Q, }; ?) V
  234. ## ^  ]. A1 j- t! r9 o& ~
  235. # If you select "no" the delay for data to appear on the slave side will
    1 C& m3 I, K. I6 c( K
  236. # be reduced but more bandwidth will be used for replication., i+ ?% |$ D& U: ?
  237. #4 W# z& q# J0 p# w
  238. # By default we optimize for low latency, but in very high traffic conditions2 [! e! c, }) A9 r
  239. # or when the master and slaves are many hops away, turning this to "yes" may
    4 r# I/ K* S/ G( N
  240. # be a good idea.
    5 w% j4 y4 w" [/ X3 p) j
  241. repl-disable-tcp-nodelay no
    ; \" E& ^  h% B. g. y3 ^* r6 e! H+ f

  242. 7 C7 l; }( M* {# g1 h4 O
  243. # The slave priority is an integer number published by Redis in the INFO output.2 k! l; w8 V$ ]" p' w( B0 w
  244. # It is used by Redis Sentinel in order to select a slave to promote into a
    ( ~# j7 A# @% ~7 B
  245. # master if the master is no longer working correctly.
    ; y) U9 O- z' u5 t7 Z
  246. #7 J" ~$ l# g) ]$ @/ ~6 ~+ W
  247. # A slave with a low priority number is considered better for promotion, so
    * J4 |9 X- X/ o2 v3 ~! O
  248. # for instance if there are three slaves with priority 10, 100, 25 Sentinel will
    ( \/ |; T8 p; m  \  h$ I- ^
  249. # pick the one wtih priority 10, that is the lowest.6 X  Q1 n- r# L7 J
  250. #
    2 l5 f2 o2 a9 r$ b
  251. # However a special priority of 0 marks the slave as not able to perform the! _0 _! u3 x' I4 \2 ^* j  s
  252. # role of master, so a slave with priority of 0 will never be selected by& ^0 F  |8 s, |# t; f! P
  253. # Redis Sentinel for promotion.
    . v/ X3 f; w: T% F" f
  254. #
    8 E" {; z! {: |0 q/ ^( f" ~1 `
  255. # By default the priority is 100.# C. f! X8 h( W  i& Q* ?
  256. slave-priority 100
    ; ^# z$ k" t, C' @
  257.   J' H! X8 J) Y
  258. ################################## SECURITY ###################################5 h+ k- B8 ]8 u

  259. . T) J* p' c. N- Z( ^9 l
  260. # Require clients to issue AUTH <ASSWORD> before processing any other
    5 o& ]& h0 X+ W+ k' ?; ~
  261. # commands.  This might be useful in environments in which you do not trust
    4 q( V0 U: C/ A- ]9 I; ?
  262. # others with access to the host running redis-server./ y$ K$ v8 |- @5 B0 S
  263. #8 o1 `: i' Q& ]
  264. # This should stay commented out for backward compatibility and because most
    7 i0 x6 {. F. v9 }* y$ ^
  265. # people do not need auth (e.g. they run their own servers).
      G( `. z0 G8 A3 g' d
  266. #
    6 O# T3 x9 ~& Y* @( z. T7 E
  267. # Warning: since Redis is pretty fast an outside user can try up to
    ( w' B6 _: v8 p, _) ]$ Y# ]" y
  268. # 150k passwords per second against a good box. This means that you should
    1 q% F4 Y7 F, [
  269. # use a very strong password otherwise it will be very easy to break.- ?. d4 Q! X% z
  270. #
      F4 K4 K7 C9 @" G( T  ~
  271. # requirepass foobared* K5 _- `4 u) T* w

  272. 2 }# H- I7 Z0 a5 p& m; ^" ?
  273. # Command renaming.% ?% G+ o; N. a8 s: ]
  274. #
    ( |8 a& B% V/ q/ ]  E& j9 D' d# j( ^
  275. # It is possible to change the name of dangerous commands in a shared
    6 W+ ^& G, |$ e$ Y$ e
  276. # environment. For instance the CONFIG command may be renamed into something
    7 e5 q4 Q4 V. o1 ^
  277. # hard to guess so that it will still be available for internal-use tools
    6 b4 n' D' N5 n9 B
  278. # but not available for general clients.
    6 i, e, f- r( I" {1 }
  279. #! E& f; `% G2 B3 Z+ d
  280. # Example:$ ?1 t3 |4 w) A' N
  281. #
    ! X5 H9 T3 m! |! w* X" F
  282. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
    5 @! o2 X- D( M
  283. #4 f. m! i/ J1 {7 X1 f4 m1 k
  284. # It is also possible to completely kill a command by renaming it into" v3 n/ x. D  N! H
  285. # an empty string:
    $ \3 n( W& `* z7 ^
  286. #" i2 p  p* {0 y# |# W
  287. # rename-command CONFIG ""& j6 w' b1 w; W: V
  288. " x: X, H5 |) E1 N* m
  289. ################################### LIMITS ####################################7 |' |( c* \& S: E2 H

  290. $ J8 ^5 w0 ?& ^7 U# I
  291. # Set the max number of connected clients at the same time. By default
    3 F) Z6 w! z( q. d  [
  292. # this limit is set to 10000 clients, however if the Redis server is not
    ; r( C; b+ A4 s1 ^& m! G9 }
  293. # able to configure the process file limit to allow for the specified limit
    ( Z# m# t' ^# U2 h/ q* ^( w
  294. # the max number of allowed clients is set to the current file limit
    / `+ g' [) x. Y  M9 |: g
  295. # minus 32 (as Redis reserves a few file descriptors for internal uses).0 Y" F; s4 r3 P! f
  296. #
    , H! Z' e8 n. T- Q
  297. # Once the limit is reached Redis will close all the new connections sending
    ' k" |& g* a" q
  298. # an error 'max number of clients reached'., o/ w- d- |7 ?' z' o( f8 g
  299. #
    ; b/ h, |$ F- [7 A9 t3 ?1 @8 x
  300. maxclients 500
    ( y! `& V  a" N

  301.   R; L- P6 i; C6 n" U3 w
  302. # Don't use more memory than the specified amount of bytes.
    # H% ]* y+ U2 z) [* o& b% C5 y% h% B
  303. # When the memory limit is reached Redis will try to remove keys
    2 ?' C2 W0 J5 K0 W. A, M/ O
  304. # accordingly to the eviction policy selected (see maxmemmory-policy).
    ' ~3 g7 e. o# T; W( j
  305. #
    : R" z; B0 `, ?4 Y
  306. # If Redis can't remove keys according to the policy, or if the policy is
    & ^7 O! M; t8 M  E
  307. # set to 'noeviction', Redis will start to reply with errors to commands+ q* j0 y, n: ^5 \+ V$ C( @  s
  308. # that would use more memory, like SET, LPUSH, and so on, and will continue, ?- L0 ]/ m9 j" K/ n
  309. # to reply to read-only commands like GET.# m6 `* w9 c0 T& j
  310. #( [0 J2 w0 C: e) L, K8 j$ S/ E
  311. # This option is usually useful when using Redis as an LRU cache, or to set. E! m! X4 _# |* e# `5 Q7 ^" h
  312. # an hard memory limit for an instance (using the 'noeviction' policy).
    ! w4 {/ ]! r! @5 l& ^7 i
  313. #9 V+ O8 q7 \8 b7 `4 b6 w8 H4 L
  314. # WARNING: If you have slaves attached to an instance with maxmemory on,# A/ D7 C. g; U# o7 H5 j
  315. # the size of the output buffers needed to feed the slaves are subtracted
    $ L2 I' T! F9 q9 t5 _$ C& p: ]
  316. # from the used memory count, so that network problems / resyncs will5 H& C# ~& u' @3 C, n; P1 d6 j4 C4 D
  317. # not trigger a loop where keys are evicted, and in turn the output
      R- t: U& I+ Y9 x
  318. # buffer of slaves is full with DELs of keys evicted triggering the deletion
    0 h3 y! P2 E7 r
  319. # of more keys, and so forth until the database is completely emptied.
    - G2 X. i9 z. v8 x0 {
  320. #
    , r8 x; z9 U% m
  321. # In short... if you have slaves attached it is suggested that you set a lower
    . L9 l5 R0 a2 t4 ~5 U, S/ m
  322. # limit for maxmemory so that there is some free RAM on the system for slave
    & F2 S5 b. B; b
  323. # output buffers (but this is not needed if the policy is 'noeviction').5 c* d! c9 K! n1 y& k
  324. #
    ) }; y( g, n% x: w+ b; r- c
  325. maxmemory 128000000. e9 ^/ Z! i7 }2 o0 ^
  326. 5 B& Y3 r% E3 W, h3 }9 \  o
  327. # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
    1 L/ n: I0 T7 u1 C* w1 D
  328. # is reached. You can select among five behaviors:
    9 b* F1 o# J8 `6 @0 ^& ^0 P
  329. # 8 D. {) e) X! f7 K4 e" r# x7 N
  330. # volatile-lru -> remove the key with an expire set using an LRU algorithm( V8 I7 l2 ]4 W7 ]
  331. # allkeys-lru -> remove any key accordingly to the LRU algorithm$ v% h" U6 y; F
  332. # volatile-random -> remove a random key with an expire set
    ( V. P0 k, m1 n) u
  333. # allkeys-random -> remove a random key, any key
    " s8 d& k0 y2 l) B. H9 \3 n4 S
  334. # volatile-ttl -> remove the key with the nearest expire time (minor TTL)
    7 \1 T$ a9 a, d7 }! T  v  b
  335. # noeviction -> don't expire at all, just return an error on write operations
      w( G. h# _5 w, S7 M
  336. # / `, a$ x/ N: r# j0 q6 r9 q
  337. # Note: with any of the above policies, Redis will return an error on write
    : U7 T# `! a. `/ Y
  338. #       operations, when there are not suitable keys for eviction.
    ) `3 |$ S  x! ~# l  Q
  339. #% U. c' b$ p! f" c2 p! W7 u
  340. #       At the date of writing this commands are: set setnx setex append- ?7 q7 ^  w9 w) P8 M
  341. #       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd8 s# I* ~& Q- K2 d7 I
  342. #       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
    $ {" [2 T, F+ H6 H+ C
  343. #       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby. u6 S: F, ~4 R
  344. #       getset mset msetnx exec sort4 H8 h* H8 Y+ c
  345. #1 G+ ~9 h( Y* y5 i5 Y
  346. # The default is:
    ; ]. I6 a: p1 _3 g9 {
  347. #  P# O4 ]$ G5 g3 F! D; g" u- q
  348. # maxmemory-policy volatile-lru
    5 F& K+ B: v) A- V. O, N
  349. ; O- H3 J- R" W  ?0 z
  350. # LRU and minimal TTL algorithms are not precise algorithms but approximated1 R3 D* S: Y" S
  351. # algorithms (in order to save memory), so you can select as well the sample) L1 K9 `( U, @9 p( r
  352. # size to check. For instance for default Redis will check three keys and
    : M4 C  C9 r' {( \$ |2 P
  353. # pick the one that was used less recently, you can change the sample size* E; c7 o9 {1 S. g$ W2 ?) L/ P
  354. # using the following configuration directive.0 B$ V& o! c/ Z' g& {) |% h5 [
  355. #) D4 z! Z4 {( ?5 f
  356. # maxmemory-samples 3" u4 r$ r( o, n: K& O0 C7 q. j

  357. 2 ]1 `- z. l$ N
  358. ############################## APPEND ONLY MODE ###############################* |- d2 o! U; M

  359. 1 [' J" ?% L; Z. K
  360. # By default Redis asynchronously dumps the dataset on disk. This mode is- u- o) y5 Z1 H
  361. # good enough in many applications, but an issue with the Redis process or# }; M- W9 x* Y' f+ h
  362. # a power outage may result into a few minutes of writes lost (depending on
    0 o5 V1 g, p6 P  r& B
  363. # the configured save points).
    + J+ \6 O" V! ?+ e# r
  364. #
    / P& L5 \3 j+ ~. ]8 w" g' a
  365. # The Append Only File is an alternative persistence mode that provides8 M& y$ a0 P/ _6 E* _
  366. # much better durability. For instance using the default data fsync policy
    0 i8 ~/ V0 R1 X& W
  367. # (see later in the config file) Redis can lose just one second of writes in a
    " Z6 G# e4 B  H6 q. E
  368. # dramatic event like a server power outage, or a single write if something
    + r9 `4 R) ~' P8 B9 b
  369. # wrong with the Redis process itself happens, but the operating system is
    # p* K  W# m3 _/ {4 c" I( Y
  370. # still running correctly.
    1 O; ]% l2 G6 m/ G
  371. #8 S$ l" M- l/ F9 W5 D" G
  372. # AOF and RDB persistence can be enabled at the same time without problems.$ _/ s1 s" }# Q3 ]) {3 I
  373. # If the AOF is enabled on startup Redis will load the AOF, that is the file
    - f3 F. ]! h3 r  ~9 E" E
  374. # with the better durability guarantees.
    , [8 B: M$ t! A- @
  375. #) x: e( u- o+ ]  Z6 N
  376. # Please check http://redis.io/topics/persistence for more information.. B' R/ [8 P2 o- r1 ^

  377. : Q. m' u* T8 Q5 q  Q7 g: a; K
  378. appendonly no3 @7 [! t! {8 U/ C1 P

  379. ; ~& W# S/ @% d* g. p( N* a
  380. # The name of the append only file (default: "appendonly.aof")9 J6 M7 S" Z' g
  381. # appendfilename appendonly.aof- S: K, ~5 r, S+ s
  382. , t( T4 q2 A& Z/ O
  383. # The fsync() call tells the Operating System to actually write data on disk
    # y5 U; N5 v' S# Y
  384. # instead to wait for more data in the output buffer. Some OS will really flush   Y. D5 a$ d( c& R2 e# \. Q# Y: Q
  385. # data on disk, some other OS will just try to do it ASAP.
    , m4 `9 p5 D* y  i! E, y4 C% f
  386. #
    4 K% O" g% R2 T
  387. # Redis supports three different modes:
    / B9 L3 j# X, a0 }' y
  388. #+ l6 F  N1 r' R& [
  389. # no: don't fsync, just let the OS flush the data when it wants. Faster.
    3 w) ?/ }0 y2 C2 n2 s7 l
  390. # always: fsync after every write to the append only log . Slow, Safest.
    7 S. n9 ?" k4 I
  391. # everysec: fsync only one time every second. Compromise.
    , W4 ~6 Q6 Y/ Q8 a( \" x
  392. #" f, P, S' G9 g  M
  393. # The default is "everysec", as that's usually the right compromise between
    2 g4 K) B8 t8 {' w) ~4 s7 w/ N: b
  394. # speed and data safety. It's up to you to understand if you can relax this to! L# P% r4 P( ]
  395. # "no" that will let the operating system flush the output buffer when
    0 ^1 P, ~" o( x3 C; J5 V( ]
  396. # it wants, for better performances (but if you can live with the idea of
    4 w: j3 s) e# q
  397. # some data loss consider the default persistence mode that's snapshotting),
    6 K4 d  M6 l' O3 `
  398. # or on the contrary, use "always" that's very slow but a bit safer than  V0 ?- }9 h% D
  399. # everysec.$ W4 g# I- g9 D/ c9 C
  400. #
    ' x/ P9 T( N0 q5 P5 G/ U- h
  401. # More details please check the following article:0 ]) A9 W, ~" u" L: z. q5 t6 M4 t
  402. # http://antirez.com/post/redis-persistence-demystified.html/ h& U4 N* s0 X* m; Z. C4 H
  403. #+ Y* ~7 E  [- m% q1 I  S
  404. # If unsure, use "everysec".# E+ S  t8 ?# e. b2 i
  405. : C7 j$ t! q& H7 D& |' \
  406. # appendfsync always4 A4 q1 n+ q2 ]' t0 I
  407. appendfsync everysec
    & d0 M, x9 x! F9 v  q
  408. # appendfsync no' n# ], q  [' R. Z

  409. 9 ?  o$ |! y* X. G3 y. ]% c8 P7 Q, D! f
  410. # When the AOF fsync policy is set to always or everysec, and a background
    ( n6 k& q2 [% M+ x( v
  411. # saving process (a background save or AOF log background rewriting) is4 {  j( t' U% x7 R) N
  412. # performing a lot of I/O against the disk, in some Linux configurations' R/ P+ ]+ }5 ~
  413. # Redis may block too long on the fsync() call. Note that there is no fix for- O" x+ a7 I. m! r
  414. # this currently, as even performing fsync in a different thread will block" M$ H1 K- y1 G6 M$ o8 g: l+ A
  415. # our synchronous write(2) call.
    ; @# p7 G, y5 c! g: \3 e4 @
  416. #, A/ n& N5 B& C& Y+ y- I3 Z
  417. # In order to mitigate this problem it's possible to use the following option
    # ]9 d; N  ~9 q" D% q1 c6 c7 C: R! V
  418. # that will prevent fsync() from being called in the main process while a8 r" y2 [* z# j0 A2 }6 P
  419. # BGSAVE or BGREWRITEAOF is in progress.3 a0 A" q* P8 O4 v# D3 k9 `9 R
  420. #
    4 D  R" M' E/ S
  421. # This means that while another child is saving, the durability of Redis is
    ( B1 x4 h2 e, \$ W4 P$ t% [
  422. # the same as "appendfsync none". In practical terms, this means that it is
    4 b. A- F- @0 h
  423. # possible to lose up to 30 seconds of log in the worst scenario (with the
    . t% z8 t" N$ @. f' R( f
  424. # default Linux settings).
      a2 z, ]" B, G% j9 G, `3 j
  425. #
    ( r1 R5 f7 Y! W+ A" g- l
  426. # If you have latency problems turn this to "yes". Otherwise leave it as" ?" F. l/ g) S# A, t
  427. # "no" that is the safest pick from the point of view of durability.8 T, B# [3 d/ Z# @9 Y
  428. no-appendfsync-on-rewrite no* ]5 f6 d* W3 ]5 l5 [/ l

  429. 2 J; u; P3 }  s! F3 N
  430. # Automatic rewrite of the append only file.
    2 |1 t2 J% a. f7 }
  431. # Redis is able to automatically rewrite the log file implicitly calling! U+ L, D; I, e, c7 i. u
  432. # BGREWRITEAOF when the AOF log size grows by the specified percentage.! }, ~$ L1 N. r4 N# U% K  z! L  y
  433. # 4 I7 Q5 b) g4 A4 k
  434. # This is how it works: Redis remembers the size of the AOF file after the
    # x, \2 O9 a* C  t
  435. # latest rewrite (if no rewrite has happened since the restart, the size of7 K1 D8 M$ L$ Q' V, d# }
  436. # the AOF at startup is used).' h9 B% k2 j9 A& l' y
  437. #; b5 b: Z3 M# i5 v* c
  438. # This base size is compared to the current size. If the current size is1 E6 i$ N: G2 R/ V2 O5 F& i* ?+ X+ G) Z
  439. # bigger than the specified percentage, the rewrite is triggered. Also% p8 P. r' p: ]3 @( e* `/ a5 _% p
  440. # you need to specify a minimal size for the AOF file to be rewritten, this* s& H% L% r7 F( P# W1 f  X' K! ^! ^- r9 w
  441. # is useful to avoid rewriting the AOF file even if the percentage increase: s0 [, g) n& a" [
  442. # is reached but it is still pretty small.
    " a0 R5 T+ O" P- j
  443. #+ W3 g$ |$ p0 s- K" p4 n
  444. # Specify a percentage of zero in order to disable the automatic AOF
    & P5 Q. a2 _7 O& H& a" |7 j; ~
  445. # rewrite feature.( m! _  D8 ~* _# |% b6 A
  446. 5 j$ e! n0 d' ^. z4 n4 l
  447. auto-aof-rewrite-percentage 100
    / E2 g" B) m) x* o9 s+ b* ]1 N- j
  448. auto-aof-rewrite-min-size 64mb
    0 G# T9 p5 n* E2 P% l8 |( P$ F8 \
  449. 7 u3 a! w) i5 k  u2 a2 \+ @
  450. ################################ LUA SCRIPTING  ###############################
    : B3 I$ r2 l: |1 @
  451. - z: R8 o( d4 F4 z3 Q  s8 c2 L7 k$ h
  452. # Max execution time of a Lua script in milliseconds.
    0 f" n% R3 o$ P$ I
  453. #) X5 E, f1 c/ G! w( r4 F! ?
  454. # If the maximum execution time is reached Redis will log that a script is1 x; Y% X7 h" }; |. H
  455. # still in execution after the maximum allowed time and will start to
    + ~. F& ^' ^1 }
  456. # reply to queries with an error.
    ; e0 ]3 b+ \3 r) N" |9 v3 e
  457. #1 M. {- H; q( e2 y
  458. # When a long running script exceed the maximum execution time only the
    / [) i0 P) y" o9 @  E: Z# G
  459. # SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be
    & e5 \  M" n  }9 Z* G
  460. # used to stop a script that did not yet called write commands. The second! k  P) W( [: h: Z8 f9 P# ~
  461. # is the only way to shut down the server in the case a write commands was
    ( T$ B8 k+ Q) h9 N" `8 _
  462. # already issue by the script but the user don't want to wait for the natural/ r/ k9 g1 i/ r0 ]; b, |
  463. # termination of the script.
    % M6 _) }) K- D3 N. N& k; ]' W) _4 G
  464. #* H* x4 I7 u1 y* c* }4 e9 x
  465. # Set it to 0 or a negative value for unlimited execution without warnings.. M$ ^5 C# R, J7 t0 a* W
  466. lua-time-limit 5000# L0 r# Z# h3 D7 l5 x6 t* @
  467. - F- f- {' H' K2 y) A5 N- A- o
  468. ################################## SLOW LOG ###################################- V0 e' a9 f- `: T7 ?! q

  469. ) M( h& X9 [6 W" B9 v8 c
  470. # The Redis Slow Log is a system to log queries that exceeded a specified
    % t& f# A- q/ I5 `8 d1 Q+ e
  471. # execution time. The execution time does not include the I/O operations
    * q- r" Y0 a0 H9 n4 ]/ h
  472. # like talking with the client, sending the reply and so forth,9 e, u5 [9 ?, L7 _% s" c
  473. # but just the time needed to actually execute the command (this is the only/ E. }4 @1 s8 N- t- F9 U
  474. # stage of command execution where the thread is blocked and can not serve/ C, K7 O0 W* Z9 T7 W8 `
  475. # other requests in the meantime).- ]# o3 @  \: N
  476. # + j1 J9 ^  V' m7 f
  477. # You can configure the slow log with two parameters: one tells Redis
    # c" [. j/ ~6 W: i: B/ h
  478. # what is the execution time, in microseconds, to exceed in order for the
    4 z) l* {% {) f! V2 f) R
  479. # command to get logged, and the other parameter is the length of the
    " p% y' ?( u+ ]( h2 ^& D
  480. # slow log. When a new command is logged the oldest one is removed from the4 [# b5 r" u+ _1 S, A; W6 i7 K* \
  481. # queue of logged commands.: t9 l/ h" m9 e3 v

  482. # t+ s# w' s4 _# R# s
  483. # The following time is expressed in microseconds, so 1000000 is equivalent5 a+ x: i; l# V, F, U* i/ Z, o* y$ h
  484. # to one second. Note that a negative number disables the slow log, while- n% {" j' ]5 G
  485. # a value of zero forces the logging of every command.) `. E* n/ L6 a' Q3 J2 @; x' e
  486. slowlog-log-slower-than 100009 s: P& g, d3 g+ n, r% x4 h' S

  487. 0 m$ m- `. C% w
  488. # There is no limit to this length. Just be aware that it will consume memory.8 D: I8 c  z. [: q
  489. # You can reclaim memory used by the slow log with SLOWLOG RESET.
    ! N* j, [: Y- u" g+ E0 L1 h6 u# c
  490. slowlog-max-len 128
    / `2 e. Z4 \, s4 X* I

  491. " f. e0 [) V- L! e* g; G) \
  492. ############################### ADVANCED CONFIG ###############################
    - d2 z' M6 g8 {/ K2 X7 q4 U+ Z

  493. 5 Y- `( Q) `; w  t) X# L, M  @
  494. # Hashes are encoded using a memory efficient data structure when they have a
    , W0 ]  h# w) |* u
  495. # small number of entries, and the biggest entry does not exceed a given& l' L. P/ ~: X) {5 J5 W
  496. # threshold. These thresholds can be configured using the following directives.. i* l3 Z7 u, B5 ~1 s! S
  497. hash-max-ziplist-entries 512, t, S- h, ^" x) F& o0 o$ j$ \2 `
  498. hash-max-ziplist-value 64% H. R; ?7 b; N; X( l; X

  499. / W* Z' w/ }8 V- Z  q
  500. # Similarly to hashes, small lists are also encoded in a special way in order3 _7 U. ?" b2 [% X
  501. # to save a lot of space. The special representation is only used when) l7 ?. n  B' O
  502. # you are under the following limits:/ b. I. g' ?2 y* a
  503. list-max-ziplist-entries 512# `0 n: j- _" E% Z  S
  504. list-max-ziplist-value 64
      b5 R0 I% g5 h( T

  505.   z5 `4 D. `, [3 L9 l4 B
  506. # Sets have a special encoding in just one case: when a set is composed; \5 p- f7 i% Q
  507. # of just strings that happens to be integers in radix 10 in the range
    ! ?  U; a+ P% _  a8 ]' K
  508. # of 64 bit signed integers.
    # o9 g0 @# l6 Z
  509. # The following configuration setting sets the limit in the size of the" Z7 _5 F4 l0 T: W% p2 D% ?0 ^
  510. # set in order to use this special memory saving encoding.
    1 V$ }; V5 h, P. ^! ~( E
  511. set-max-intset-entries 512
    , Z; P2 c+ k% s" o, K' a6 h4 [& ^" g
  512. + P: h+ n1 S9 e& r( x
  513. # Similarly to hashes and lists, sorted sets are also specially encoded in5 ~: p4 p! k1 B, S4 J% ?- `
  514. # order to save a lot of space. This encoding is only used when the length and
    # f, P  ?' o8 D% T
  515. # elements of a sorted set are below the following limits:
    % f" g6 J% m5 O% n: o  n
  516. zset-max-ziplist-entries 128( w  G. q# n. {8 r  @6 F7 I
  517. zset-max-ziplist-value 64$ k, x8 ?  M3 l' C

  518. - [! h5 |3 c1 J! z( L8 h! N& t
  519. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in0 ]" \% P2 {* e( M
  520. # order to help rehashing the main Redis hash table (the one mapping top-level
    - P3 C7 {7 q  P3 }
  521. # keys to values). The hash table implementation Redis uses (see dict.c), \6 k* f& L; R
  522. # performs a lazy rehashing: the more operation you run into an hash table! M, Q$ {4 s2 U' p) g3 t
  523. # that is rehashing, the more rehashing "steps" are performed, so if the
      C% C7 B- \% [+ v
  524. # server is idle the rehashing is never complete and some more memory is used
    9 T3 g5 k9 D6 N1 t6 a
  525. # by the hash table.
    * i8 }$ N+ F7 R  |5 n9 f) R% A! J
  526. #
    + [9 g- \/ P- V- J
  527. # The default is to use this millisecond 10 times every second in order to  i  |. |! V( y3 ?9 n$ m2 n; J
  528. # active rehashing the main dictionaries, freeing memory when possible.
    4 Z$ e( q( O: I3 `6 v
  529. #0 i9 j7 E0 r2 \: k) J8 J- y
  530. # If unsure:9 d& o; p6 s5 Y9 n' D
  531. # use "activerehashing no" if you have hard latency requirements and it is* v2 Q9 _& C  @
  532. # not a good thing in your environment that Redis can reply form time to time
    ) w: b! @1 ], s& a4 l1 l' a+ d* D
  533. # to queries with 2 milliseconds delay.
    1 c5 Z. m+ [! f% j4 r0 W  N9 D& y' F
  534. #' R+ I( P4 K0 |
  535. # use "activerehashing yes" if you don't have such hard requirements but7 i& v, C% ~6 Q" X5 Y
  536. # want to free memory asap when possible.8 `7 ~7 m! Q% x+ a
  537. activerehashing yes5 C. W' F& X4 S- a3 C1 P% x

  538. 3 ^; e" @1 E/ S2 ]6 {, U
  539. # The client output buffer limits can be used to force disconnection of clients
    ; w/ \0 j" r1 r* N4 l4 J) {4 m/ `
  540. # that are not reading data from the server fast enough for some reason (a. x4 i/ M! \0 d! Y1 q9 O/ g+ d
  541. # common reason is that a Pub/Sub client can't consume messages as fast as the
    & a' x* l9 K9 t+ Y1 O' q
  542. # publisher can produce them).& a& f) H$ G* h4 d& I, P
  543. #
    / g4 f0 J& S& M: O6 w* G
  544. # The limit can be set differently for the three different classes of clients:
    5 z3 Z/ R5 [+ ^( b  r7 e
  545. #% V( X; c3 X7 G! m1 F
  546. # normal -> normal clients
    4 H" @, ?3 q* h/ ?
  547. # slave  -> slave clients and MONITOR clients" k6 r0 z/ A7 ?2 r6 Y
  548. # pubsub -> clients subcribed to at least one pubsub channel or pattern
    ) A. [& N) Y! I2 `* |
  549. #0 X( i  a3 |5 U4 y: X) a
  550. # The syntax of every client-output-buffer-limit directive is the following:
    4 |% H2 m6 z; p0 z3 W% r+ l
  551. #
    ( q0 q  N% ~# }0 z; ^- C# b
  552. # client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>
    ) @9 R( P. ?+ U# e+ a6 l, }+ p
  553. #
    " @2 e" g2 L5 D  {# i0 |( g4 a
  554. # A client is immediately disconnected once the hard limit is reached, or if
    8 k8 @: t/ s4 w  A. l9 N7 x
  555. # the soft limit is reached and remains reached for the specified number of) X- p1 U9 @6 y  Q
  556. # seconds (continuously).
    * b8 B; [" ?1 m8 S  V) O- N
  557. # So for instance if the hard limit is 32 megabytes and the soft limit is
    ' S# R$ q5 ?" o8 v2 J5 K) M* z
  558. # 16 megabytes / 10 seconds, the client will get disconnected immediately1 a6 e' {5 e" ~
  559. # if the size of the output buffers reach 32 megabytes, but will also get
    $ R0 B& J3 _/ E2 V  e- q$ i  u: h
  560. # disconnected if the client reaches 16 megabytes and continuously overcomes1 Q0 P7 z5 P8 `- D( H* ~
  561. # the limit for 10 seconds.
    + y# H8 D* ~/ y( a6 d
  562. #  G+ r' b* F. ^; t
  563. # By default normal clients are not limited because they don't receive data
    " A$ d- I. e+ x: K
  564. # without asking (in a push way), but just after a request, so only
    1 X9 ^& r/ C3 X& o( ?, D0 n% y
  565. # asynchronous clients may create a scenario where data is requested faster
    7 r- J4 [4 c9 T; O. b4 n
  566. # than it can read.
    1 s3 U& u0 V1 ?' E$ ?
  567. #( H/ J: y+ n1 i& H! d# k
  568. # Instead there is a default limit for pubsub and slave clients, since
    % v% A4 n2 B8 _% M
  569. # subscribers and slaves receive data in a push fashion.
    % V& ]* {) z- h6 N
  570. #: ?' I3 J" T; b0 M5 R) w4 f- j# h: ?) u
  571. # Both the hard or the soft limit can be disabled by setting them to zero.1 v" P2 Z. ~0 k2 S+ Y+ P# v
  572. client-output-buffer-limit normal 0 0 0
    " E/ x; [4 A) T. d' X$ ?% ^
  573. client-output-buffer-limit slave 256mb 64mb 60
    ' {3 V. W1 |+ V, y
  574. client-output-buffer-limit pubsub 32mb 8mb 60
    5 [4 B" ?7 S: {1 H6 q1 V
  575. % m# T, E! |6 Y0 q# O
  576. ################################## INCLUDES ###################################& M& Z* k/ `, [* f

  577. 7 y7 m( ^1 s( E* a7 a3 m
  578. # Include one or more other config files here.  This is useful if you" ], \" W8 L" O4 F6 ^% e" E
  579. # have a standard template that goes to all Redis server but also need
    : b/ i& p; Z: q4 t% Q2 K
  580. # to customize a few per-server settings.  Include files can include
    " a! c2 E5 p) ~
  581. # other files, so use this wisely.2 @! v) M9 ?3 t% ^1 X
  582. #
    , ^, d. b: ^. P. l1 {
  583. # include /path/to/local.conf% w$ m9 X. R4 K6 F  H' }2 \% t0 V
  584. # include /path/to/other.conf        
    . W) U  \& F! V/ l6 a. R; D2 P9 a
  585. ##########################配置文件结束################################
    ; w( u1 x! c( X* F
  586. 第三步:启动进程3 |8 T0 s2 m8 D* t1 v! U9 |
  587. #redis-server /etc/redis.conf
    5 F2 V7 J, c& `" h$ x
  588. 查看进程有没有成功启动+ F1 {2 |! [% s8 z. |$ c+ z5 \+ V# d
  589. #ps -ef | grep redis 8 ]9 X: T7 t% T: c4 O
  590. 测试输入一个键值0 N& J8 N1 d! `
  591. #redis-cli set test "testredis"4 C. u! F. N2 f( X0 ^
  592. 获取键值0 C# w0 X) W' K; o2 v3 V" s2 c
  593. #redis-cli get test, `: [8 c0 z$ {/ m

  594. ) T( w) S' z- Z) `( g

  595. 3 E7 T9 ^. ~2 \& E  F
  596. 第四步:关闭redis  (这个是更改配置文件后 正常的重启方式  不重新加载redis配置跳过)( W$ E) g% h* F. a% k) `' _
  597. # redis-cli shutdown      //关闭所有   
    8 x& S7 X4 ~9 H/ K  f
  598. 关闭某个端口上的redis   
    : M1 q9 Q  {2 b9 n2 k2 I4 V
  599. # redis-cli -p 6397 shutdown  //关闭6397端口的redis  5 \. d/ p( J! x6 V
  600. 说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename  dump.rdb  
    1 A! b% {  w) {6 o9 d" `! o+ b
  601. . L2 N; `: p8 V" d/ s" x3 N

  602. 6 S2 a( U! y1 h& Q0 Q
  603. 第5步:php扩展安装
    # |# ?) t3 U9 s4 \
  604. phpredis PHP扩展下载地址 ; H& d) ?: }$ _3 O- N+ @
  605. https://github.com/nicolasff/phpredis/tree/2.2.2 5 z" |# O: Z# ^8 n" e1 a2 r5 g
  606. 选择最新版本下载zip
    % h- P3 [. o: o+ i/ v

  607. ; \7 _+ P0 Z- ^( X' H
  608. 然后自己上传zip  用unzip解压到当前目录 unzip 文件名
    : H& d4 c9 \8 u7 @+ Q- ?( c
  609. ! \' ^2 _- l! T8 U; A0 ^* _$ e
  610. # cd owlient-phpredis-90ecd17/   #打开解压后的文件夹里面  这个解压后的目录 要是不知道 可以输入 "dir" 查看4 J  t2 L9 R& C) L. y' R
  611. # /www/nginx_php-5.2.17/bin # h* d" G  [1 u$ ~7 l
  612. # ./configure --with-php-config=/www/nginx_php-5.2.17/bin/php-config8 W9 }& @3 _; F: j. y. J8 q
  613. #make
    ) g- ~4 m8 v4 @# b5 E" C  p
  614. #make install   #记录产生的redis.so路径
    0 t" C2 j0 C5 _; y

  615. , j4 N: T0 N0 \' d4 g, l( |
  616. 修改php.ini文件4 s+ k5 a6 Z* q/ r$ x+ G, P
  617. 在php.ini中添加如下一行:! J9 v# K) W6 j
  618. extension=/?/redis.so  #是刚刚记录的产生redis.so的路 写在 ?那
    : i% M9 k1 R) I- k. r
  619. 重启 使之生效:! a- f; F4 ?6 y: o" _# \5 F
  620. /usr/local/php/sbin/php-fpm reload. K, E. F, e" K7 J2 _
  621. /usr/local/nginx/sbin/nginx -s reload
    - P9 g+ n# t  ~, Q/ f
  622. 5 d0 e: m- j: H$ i; N9 |) h
  623. 将 Redis 作为 Linux 服务随机启动
    : r/ \' ]# p6 s0 L1 |
  624. vi /etc/rc.local, 加入代码:- H% _6 L- l$ _4 x7 A, |* s
  625. /root/redis-2.6.10/src/redis-serve  #路径看情况修改
    , z: z% l0 ^; A  |- T
  626. / P6 i, I4 Q, `
  627. redis-cli -h localhost -p 6379 info  #命令要在redis目录下面执行1 g, s5 E6 f% B  J3 d
  628. 提供host为localhost,端口为6379,redis服务的统计信息
    . N+ K: ^( s+ {# U/ i

  629. ( V  M8 X- N( F

  630. 9 E  _; J. W& B# |, W, X* u
  631. 就这样你的web服务器就支持redis了 记得要在 给dz 的配置文件 加上12.0.0.1哦9 b1 x- _! w& ~% |& b" d
  632. dz配置文件在 config目录下面的 config_global.php- M: s7 `- h% j
  633. $_config['memory']['redis']['server'] = '127.0.0.1';# t* \3 o. a% h: v: P+ t
  634. $_config['memory']['redis']['port'] = 6379;
    ( v, p/ A3 H  b1 z4 o
  635. $_config['memory']['redis']['pconnect'] = 1;/ m  b3 z8 ?7 e& T. G. z
  636. $_config['memory']['redis']['timeout'] = '0';$ J5 l9 `5 ?2 F% @# A' N( k& _. Z
  637. $_config['memory']['redis']['serializer'] = 1;/ h0 A! a' |5 S" _) V) [
复制代码
关注微信公众号《神采飞扬网》,即可获取最新回复通知!

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

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

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

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

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