分享到:
发表于 2018-11-16 12:42:28 | 显示全部楼层 |阅读模式
环境配置7 o$ ^$ P8 }2 C% G2 u& s/ F4 p

. B8 h7 k3 K, K. [  {" g
5 i4 k. r5 S. W) z! ?! Z4 bhttp://www.discuz.net/forum.php? ... amp;highlight=REDIS
关注微信公众号《神采飞扬网》,即可获取最新回复通知!
 楼主| 发表于 2018-11-16 12:43:33 | 显示全部楼层
http://www.discuz.net/forum.php? ... 648&highlight=REDIS  T& e- l+ K" ?/ m% \9 S
无意间测试 单机状态 redis相当给力 测试1000请求/s  单纯的 get 和set 居然只用了 0.01秒 当时我惊呆了0 r  G' s9 p' h3 D, N

; S) }  y. l: E" f& d' Jhttp://www.discuz.net/forum.php? ... 731&highlight=REDIS& U" D* i& Y7 v. j) r- X
2 u, L5 b- L; O* a3 B0 c
https://wenku.baidu.com/view/265a5ce176a20029bc642d0b.html
7 F8 i" ~: i7 I: H0 |8 s& I0 I6 x) l9 a
=======================================
4 Z: R: f- Q0 M( Y
  1. 连接上 ssh" c! q. Q: z- s2 M1 y

  2. 9 x5 E+ O, E7 d1 L% o$ S- N6 H
  3. + z0 Z, w% c2 N# U
  4. 第一步:下载redis
    % `' k# u* X% U- l' G
  5. # wget http://redis.googlecode.com/files/redis-2.6.10.tar.gz' F+ f) p. ]1 Z/ T
  6. # tar zxvf redis-2.6.10.tar.gz
    # R4 q, h* }8 u+ p0 N8 K* \
  7. # cd redis-2.6.10
    " ^+ Q9 `5 a$ `5 k; h6 U
  8. # make # Y/ i# O9 Q$ f
  9. # make install  2 G3 ^7 L" V+ J) D
  10. #cp redis.conf  /etc/ #复制配置文件到etc目录下面* D' U; L. |( v) Y
  11. 第二步:修改配置9 q; k' P6 j( ?
  12. #vi /etc/redis.conf9 |; F) M7 N8 Z/ F, m; h
  13. ######################下面是无措的配置文件 复制过去就成#########3 F* V) @# \) p: n3 d) M, T# _( w
  14. # Redis configuration file example  b  l  N. a" ]8 C/ e$ b# ^, d

  15. : r6 H/ ~2 f% m
  16. # Note on units: when memory size is needed, it is possible to specify) j/ i6 l) _( F  a/ ?
  17. # it in the usual form of 1k 5GB 4M and so forth:
    7 _2 U' w& G! z! A9 D
  18. #, p" |) A% W& g, Z9 o4 \& p! l. J9 h
  19. # 1k => 1000 bytes0 @* v- F& n8 b# l
  20. # 1kb => 1024 bytes
    ) o7 J3 l( j; I% M) B, c: d
  21. # 1m => 1000000 bytes
    , p# P/ d  {  D
  22. # 1mb => 1024*1024 bytes
    1 o, y. R8 ~9 i. Q
  23. # 1g => 1000000000 bytes
    ( |! ]5 B- X* @. _
  24. # 1gb => 1024*1024*1024 bytes
    ( ?% C5 J  w0 x. B  Q9 u
  25. #
    - A3 ?( N, p* r3 u7 _
  26. # units are case insensitive so 1GB 1Gb 1gB are all the same.6 u, W% s9 B2 B+ s- p5 D

  27. # ^- Y$ M  r5 f. L; D
  28. # By default Redis does not run as a daemon. Use 'yes' if you need it.8 P# ]6 I+ W3 o
  29. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
    0 Q$ _; d0 |, p( g) K) K( c
  30. daemonize yes
    6 w! ?; s3 B; V# [$ H

  31. ) j5 u/ s5 @/ }: @$ M; N
  32. # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
    ! @: b9 B4 E9 @" l+ K7 w
  33. # default. You can specify a custom pid file location here., h. u" E3 |, |- n
  34. pidfile /var/run/redis.pid, ~0 r* g) P8 v

  35. ( @0 I% X3 d: J9 U. \! r% |
  36. # Accept connections on the specified port, default is 6379.  h" G) j1 f$ ~! q% R8 d0 X- P
  37. # If port 0 is specified Redis will not listen on a TCP socket.
    + ^) t0 z3 J$ l- |/ ^4 L; G5 g
  38. port 6379
    1 B6 W* ~& h1 ~4 l% Y5 V! q. U

  39. 0 ?% s6 z9 `# d1 r. P0 g7 S* g: M
  40. # If you want you can bind a single interface, if the bind option is not* b* e3 i( T" p$ `
  41. # specified all the interfaces will listen for incoming connections.
    / V9 R5 d, ~1 [0 B1 i2 a, ]
  42. #
    ) X2 W1 @6 U4 J0 I" T8 U
  43. # bind 127.0.0.1
    $ R( I* |' ?; d0 t' h

  44. , [5 _8 j3 j5 k' C
  45. # Specify the path for the unix socket that will be used to listen for  j; E, I. E7 m; U/ ^
  46. # incoming connections. There is no default, so Redis will not listen5 p$ f7 v! Y, a7 j: }* m
  47. # on a unix socket when not specified.
    7 O5 A" j8 o# v  s! m3 }/ i: {
  48. #
      \$ N; [7 f3 r& N2 D5 E
  49. # unixsocket /tmp/redis.sock
    4 R  ?5 |* J3 H& t0 q! ?5 Y
  50. # unixsocketperm 7557 u/ _& [( ]3 Y$ w# u$ L! d
  51. 2 D( y: [4 F! _8 `0 ?4 {
  52. # Close the connection after a client is idle for N seconds (0 to disable)
    . Z1 g) {+ n* y# g
  53. timeout 3005 U- U3 n4 |; A1 _
  54. 5 Q2 V  f% G+ V1 E) ]! m6 n) Q
  55. # TCP keepalive.
    . {9 M3 s: N9 B9 X, o% d/ z
  56. #
    0 K3 G: r; Y: y0 M. r1 g' d, G# I
  57. # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
    0 Q$ r  }6 U+ r- R# Z
  58. # of communication. This is useful for two reasons:
    " i8 V! f$ e9 E; ]
  59. #
    2 o7 K" B% s  h# l
  60. # 1) Detect dead peers.
    8 L6 l! P6 y( l4 P- L: l. }
  61. # 2) Take the connection alive from the point of view of network
    2 g" S5 d) D' V; o* n6 M7 d' A
  62. #    equipment in the middle.- B) F9 Q4 f; |' `
  63. #
    9 X& n. F, T$ \0 }
  64. # On Linux, the specified value (in seconds) is the period used to send ACKs.8 ^) t9 {# F7 [6 M7 L$ f
  65. # Note that to close the connection the double of the time is needed.; N8 D/ o1 {0 K7 T
  66. # On other kernels the period depends on the kernel configuration.- J1 m* L: C( N. d( q) Q. ~1 p
  67. #' A5 P+ u5 z. [* Y
  68. # A reasonable value for this option is 60 seconds.4 ?" Y  j5 [* r: V# f+ K) l4 {
  69. tcp-keepalive 0! n3 _: Q. s& m  A$ P2 z6 b. Z

  70. ; i, T9 O& n, F5 k! h* [# Q$ @, \1 S
  71. # Specify the server verbosity level.
    2 R0 ^+ E$ r  Z$ R
  72. # This can be one of:" i- z% A, r/ y4 _+ @9 L+ d
  73. # debug (a lot of information, useful for development/testing)
    % a( {- ]2 M/ X3 R
  74. # verbose (many rarely useful info, but not a mess like the debug level)* t& U! m* y5 ~0 E$ j
  75. # notice (moderately verbose, what you want in production probably)
    9 h. F. P/ m% T9 Z! i( @  X
  76. # warning (only very important / critical messages are logged); j( c; R/ E8 Z# j
  77. loglevel warning. O" T( _9 i0 c# _' K- e7 @0 t

  78. $ ~$ [4 N0 b" h# g+ x& t
  79. # Specify the log file name. Also 'stdout' can be used to force
    + z: j6 Y  J- X+ B" e+ U* N
  80. # Redis to log on the standard output. Note that if you use standard
    5 q2 O% u' a9 P; f) q
  81. # output for logging but daemonize, logs will be sent to /dev/null0 d" H  I: E$ Z7 o5 L
  82. logfile /var/log/redis.log" I8 S7 l. K! i3 K
  83. " K: s5 x/ [) e1 ~
  84. # To enable logging to the system logger, just set 'syslog-enabled' to yes,
    0 S$ B0 \5 g( S, k' Z7 t
  85. # and optionally update the other syslog parameters to suit your needs.6 y7 ^0 _! w$ Q$ q/ B
  86. syslog-enabled yes* Q3 g; O5 Z5 }% B! \0 F

  87. 3 k/ v* |3 l/ Y: g% U
  88. # Specify the syslog identity.
    2 S2 b5 E- B  y; v
  89. # syslog-ident redis
    % G0 _7 ?" H# \5 P
  90. 0 b5 B7 _% J$ {3 f( h; d( S# K* _
  91. # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7./ B" x' r# N4 ~" q2 I
  92. syslog-facility local0' B4 ?0 k: \3 n) x( Y% g1 ~8 H' M
  93. , _% f3 h5 w! f: w3 V% y& u
  94. # Set the number of databases. The default database is DB 0, you can select& D: s# h- h$ C( ]5 k8 c& c+ l* i1 m+ X
  95. # a different one on a per-connection basis using SELECT <dbid> where/ ?& g% S' ]2 T3 h1 j# e$ o8 Z2 i
  96. # dbid is a number between 0 and 'databases'-15 l1 s, e3 w* I+ n
  97. databases 16/ o* }5 Q8 q" T: y' |# W, j

  98. 6 `6 V9 ~) W& X5 Q0 O6 _) Y
  99. ################################ SNAPSHOTTING  #################################
    * {+ i* z* c0 R* T- U" H8 G! b. L4 Q
  100. #( O6 \: P- ?1 y8 S! I) s% ]
  101. # Save the DB on disk:) p: Q% Y' A( s
  102. #, Q% Q, ]" p3 |& \' {" f
  103. #   save <seconds> <changes>
    ' R$ {$ F  D& a5 w4 l
  104. #% w+ Z! [8 V3 F  u+ ^2 j! r6 t
  105. #   Will save the DB if both the given number of seconds and the given
    ! g, Q2 {* j8 ~' V4 U
  106. #   number of write operations against the DB occurred.
    ! k9 r* _0 r9 ~
  107. #$ x) {5 R6 U7 j: O
  108. #   In the example below the behaviour will be to save:% E8 a$ Q& Q' n+ t$ ~
  109. #   after 900 sec (15 min) if at least 1 key changed
    $ i" d; c6 W4 u; D  M
  110. #   after 300 sec (5 min) if at least 10 keys changed
    : h$ _0 \0 E+ h' X9 g0 F
  111. #   after 60 sec if at least 10000 keys changed
    2 E$ |' @  G, j5 ~3 b. i  F3 n
  112. #1 U& p4 e& W6 Y; ]+ ]6 ]4 ]/ j% n! p& b2 I
  113. #   Note: you can disable saving at all commenting all the "save" lines.0 d2 {3 q, a  c: |. x
  114. #
    6 C5 ~' G  I7 d
  115. #   It is also possible to remove all the previously configured save
    / T. G: |* F- h( h( \0 S
  116. #   points by adding a save directive with a single empty string argument% I4 T$ E, @4 G# Q9 H' K
  117. #   like in the following example:% ]" f8 W3 V6 j$ l1 c: Q
  118. #) r; i0 ?/ Z9 }  e3 e' j( h
  119. #   save ""
    ; q5 e, s7 P/ \: x) ?/ |! |4 \9 N2 S

  120. . x$ [& U7 [5 _$ o" z, Z" Y; R
  121. save 900 1+ F! t+ O  A! W, ~. D
  122. save 300 10+ f2 A5 O. O6 U6 G- h. _: O6 x
  123. save 60 100008 ~# X* ~. f' P8 N
  124. * G4 s# f$ h5 m- x
  125. # By default Redis will stop accepting writes if RDB snapshots are enabled8 F7 b; K9 Q9 O+ k  u
  126. # (at least one save point) and the latest background save failed.2 n$ x8 r+ i& b/ [! l
  127. # This will make the user aware (in an hard way) that data is not persisting
    2 Q& g+ y/ j* q7 l1 v5 e# _! Z0 o
  128. # on disk properly, otherwise chances are that no one will notice and some
    - E$ A% T# h& ~  B. H1 L
  129. # distater will happen." ~+ j2 M8 W/ X. q" h( m
  130. #
    ! U# F' ~4 x: e* u6 g
  131. # If the background saving process will start working again Redis will7 [. T& G1 I% V4 H7 G
  132. # automatically allow writes again.
    ) q9 e  a$ \) `+ M
  133. #
    + C( r9 o7 x/ v8 O" _# ]
  134. # However if you have setup your proper monitoring of the Redis server, E* J$ i6 M) ]% P* o  M) ?
  135. # and persistence, you may want to disable this feature so that Redis will! q) Y$ d. ]" O. l6 \2 w7 ]
  136. # continue to work as usually even if there are problems with disk,
    9 ]* B/ z8 W# q6 C- a4 ^
  137. # permissions, and so forth.
    & D+ p, Q5 Z; t. o5 P/ V9 B5 d- c4 }
  138. stop-writes-on-bgsave-error yes8 \, C$ e: F; s9 H( _! C
  139. + i( k" B) J; S" O; ~3 h3 z
  140. # Compress string objects using LZF when dump .rdb databases?5 m% J0 j$ ^" }2 b3 `
  141. # For default that's set to 'yes' as it's almost always a win.
    4 o  y  k- S  c2 S1 d
  142. # If you want to save some CPU in the saving child set it to 'no' but
    1 \+ ~3 X5 ^- I; p# }$ |# p
  143. # the dataset will likely be bigger if you have compressible values or keys.
    8 W0 s: `3 D: \% B
  144. rdbcompression yes& t- U: O0 j$ O9 D% H. h6 h! Q! s
  145. % u- B1 G1 \* g
  146. # Since version 5 of RDB a CRC64 checksum is placed at the end of the file., u% k8 M8 \$ p5 [. r+ m) l
  147. # This makes the format more resistant to corruption but there is a performance
    / O6 x6 ?# k- \+ Q! o6 N; k
  148. # hit to pay (around 10%) when saving and loading RDB files, so you can disable it
    ' z1 t3 p, A6 E- Q7 {
  149. # for maximum performances.* v6 ?5 n6 S  w4 l! f% q5 H- X7 ]
  150. #
    * y; `6 H+ y3 a9 l* C* k' Z# b2 ^2 a
  151. # RDB files created with checksum disabled have a checksum of zero that will7 G5 |% N7 ?: @7 ?5 v7 J( J0 u
  152. # tell the loading code to skip the check.
    ! M1 _+ T: u3 L6 ^1 f
  153. rdbchecksum yes6 h9 g8 A3 ~: F+ C
  154. 0 X  z( I6 x& G8 r( Q
  155. # The filename where to dump the DB
    ) @) A- f! j) v
  156. dbfilename dump.rdb
    ) F5 Q6 l. c2 X+ A* p' z
  157. ) I' _6 f5 ]* e. g2 I
  158. # The working directory.
    6 I5 f" {5 ?  S8 _; E4 S! A
  159. #
    2 H" C$ V4 B2 e- \) B8 G
  160. # The DB will be written inside this directory, with the filename specified
    7 F# r5 j+ ]/ Y" b9 T. \/ y
  161. # above using the 'dbfilename' configuration directive.- |$ ^/ f5 Q3 s% `5 H; E/ K. T
  162. #
    1 l' }$ F3 y3 a0 x
  163. # The Append Only File will also be created inside this directory.) j6 F) @# {& D
  164. #
    5 N  J( |8 n* s
  165. # Note that you must specify a directory here, not a file name.9 i0 @+ f# T- D( X
  166. dir /var/db/redis, w( _9 A2 ?* _, L
  167. + r% |3 }2 r% l
  168. ################################# REPLICATION #################################, N) W! ~" Q8 J

  169. : a, i8 i, _; [0 _6 w+ z6 t
  170. # Master-Slave replication. Use slaveof to make a Redis instance a copy of
    4 i- i7 W* k( F. p! N$ j& E
  171. # another Redis server. Note that the configuration is local to the slave+ H; c. R9 H; t/ g4 J
  172. # so for example it is possible to configure the slave to save the DB with a
    - u, v' [; y2 C; C* d( O( o4 j
  173. # different interval, or to listen to another port, and so on.
    3 G) a/ _# L6 K) X4 b- O1 C5 s: Q
  174. #
    ( I9 w* |1 C5 G
  175. # slaveof <masterip> <masterport>
    % D" T' k. n0 x8 ?! d! Q

  176. 3 u- A2 e9 s" o3 {2 R3 e! s
  177. # If the master is password protected (using the "requirepass" configuration/ Z2 P! p% A# y4 g- y
  178. # directive below) it is possible to tell the slave to authenticate before7 n- T2 X$ v) ^0 h
  179. # starting the replication synchronization process, otherwise the master will
    $ E. w' E6 l# c1 q1 Y! t# D
  180. # refuse the slave request.
    * y. i$ Z% F6 b. D4 Y! M, g$ S
  181. #
    " ]; T! v' o. ?9 o/ l7 E, y1 B) z3 T
  182. # masterauth <master-password>, g9 T, X! A. D5 }( O8 ^

  183. / U% {5 A4 E, a
  184. # When a slave loses its connection with the master, or when the replication, _2 V$ S$ T# [7 I
  185. # is still in progress, the slave can act in two different ways:# |1 E0 ~: \- x/ W6 a2 z# q$ F& E' p
  186. #
    . u7 Z/ w7 g# l; ?$ J) E
  187. # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will5 D" C& A' a7 T
  188. #    still reply to client requests, possibly with out of date data, or the2 {6 `6 Y" [) C; S
  189. #    data set may just be empty if this is the first synchronization.
      i$ g' C/ L1 H( P3 c" m8 A
  190. #4 B+ T$ V7 I1 U7 ~& ]) s( p; n4 I* }
  191. # 2) if slave-serve-stale data is set to 'no' the slave will reply with, {5 S# M( @7 j1 q# i5 M1 a6 W7 N
  192. #    an error "SYNC with master in progress" to all the kind of commands
    * w$ K; I: Z/ h5 w0 s
  193. #    but to INFO and SLAVEOF.
    3 ~7 V+ O. w0 `$ W2 v+ G& Q8 _
  194. #! \& h& v6 q5 @, ?8 L0 |
  195. slave-serve-stale-data yes+ v- s' {1 R8 U! r" `8 O8 _

  196. / i/ }. g+ K! s# r; B+ A9 v
  197. # You can configure a slave instance to accept writes or not. Writing against. b5 `5 \- P% n
  198. # a slave instance may be useful to store some ephemeral data (because data
    9 `/ e; l! ~! {( T
  199. # written on a slave will be easily deleted after resync with the master) but+ H" d  O( c+ V, ^" X! \+ F
  200. # may also cause problems if clients are writing to it because of a
    9 a* [1 g3 c7 D8 z
  201. # misconfiguration.
    & K7 ~1 ?* y# j; |. ~4 ?
  202. #
    1 r! x% S4 E: e* k' K2 h
  203. # Since Redis 2.6 by default slaves are read-only.
    ( v! f1 E& m  A4 e0 e
  204. #
    & S. M4 M% W. `$ a* e
  205. # Note: read only slaves are not designed to be exposed to untrusted clients, |8 ~# z" r  x+ [
  206. # on the internet. It's just a protection layer against misuse of the instance.9 L+ n3 ]2 @3 H
  207. # Still a read only slave exports by default all the administrative commands
    # ~2 T% ?: ~* ^$ X
  208. # such as CONFIG, DEBUG, and so forth. To a limited extend you can improve
    * c  }& r4 ?% y! R/ T/ H
  209. # security of read only slaves using 'rename-command' to shadow all the9 X- u( Y' i) G) m8 [
  210. # administrative / dangerous commands.
    9 P' \: L( ]" M% ^  Y
  211. slave-read-only yes3 D! f& M1 p, M' g

  212. $ R  |; s8 O% d  C3 U
  213. # Slaves send PINGs to server in a predefined interval. It's possible to change# K. N+ ]; O4 d* u8 H+ v
  214. # this interval with the repl_ping_slave_period option. The default value is 10; g) ~; A! r# H. Y9 f' E% O
  215. # seconds.
    & s1 q2 [6 L- X( p- p0 G
  216. #
    8 p; Y) i5 W7 d
  217. # repl-ping-slave-period 10$ n0 k' @# X# ~" \* N$ Z3 ]3 p, k
  218. 7 J! n* s3 M5 C. y
  219. # The following option sets a timeout for both Bulk transfer I/O timeout and
    $ ^9 W! U! f# u6 }6 ~
  220. # master data or ping response timeout. The default value is 60 seconds.
    2 L, p0 h9 {/ Q! [! }. p
  221. #8 I* r' N+ Z4 F0 R- U
  222. # It is important to make sure that this value is greater than the value
    - f* B/ E& k, C0 V
  223. # specified for repl-ping-slave-period otherwise a timeout will be detected' u% f' ]4 y: h+ L7 j" S* N
  224. # every time there is low traffic between the master and the slave.
    ; u, `; j0 E& C  `2 |0 l4 Z
  225. #4 d8 W' u  s5 Y
  226. # repl-timeout 60
    " d7 u) `: ~/ L, I3 \4 k
  227. 4 S% U& y5 F( N2 F$ g/ A/ ]
  228. # Disable TCP_NODELAY on the slave socket after SYNC?
    - s' S: C) w- T6 \8 L" p- I
  229. #3 m* u7 n. B, o' W
  230. # If you select "yes" Redis will use a smaller number of TCP packets and  p$ K4 \4 v4 W- i
  231. # less bandwidth to send data to slaves. But this can add a delay for+ p+ D; m# q1 U9 c- K
  232. # the data to appear on the slave side, up to 40 milliseconds with0 i4 }5 t. Q% J; V' ~
  233. # Linux kernels using a default configuration.. B: {# }, E8 p2 v, D+ _1 A
  234. #
    1 V' b# R1 M* `1 _( u1 E) v) N# y
  235. # If you select "no" the delay for data to appear on the slave side will1 }! K$ |4 B/ B! v9 N# h
  236. # be reduced but more bandwidth will be used for replication./ ?+ l0 t' N' e3 w: J7 c
  237. #
    % a7 e4 F# H, w7 Z+ {8 c
  238. # By default we optimize for low latency, but in very high traffic conditions; Z& O1 z+ C2 O8 u! k* J5 X# b. p# M
  239. # or when the master and slaves are many hops away, turning this to "yes" may! K$ d; l  ]- |
  240. # be a good idea.
    6 ]( U- F5 g4 O' D3 q  {! S, i
  241. repl-disable-tcp-nodelay no6 L2 _( {& z3 ~
  242. * Y& |/ c4 \. h2 m. t
  243. # The slave priority is an integer number published by Redis in the INFO output.4 l4 b) F2 R" z( F- H
  244. # It is used by Redis Sentinel in order to select a slave to promote into a
    4 }' v% \2 n; @8 T2 \- X
  245. # master if the master is no longer working correctly.
    % j5 H6 ^" \0 a
  246. #8 N' p. o" x$ b9 }
  247. # A slave with a low priority number is considered better for promotion, so2 u' Y9 Z$ G$ |6 b& t( j. k
  248. # for instance if there are three slaves with priority 10, 100, 25 Sentinel will
    4 o: c! L- F7 ]4 l$ c: i
  249. # pick the one wtih priority 10, that is the lowest.
    0 ^# W0 I% W. f8 X
  250. #* V/ `5 }$ L7 `* ]
  251. # However a special priority of 0 marks the slave as not able to perform the
      |/ J/ F9 i( [: q- ~; Y
  252. # role of master, so a slave with priority of 0 will never be selected by
    , ^$ L! _! @2 K" h# B
  253. # Redis Sentinel for promotion.8 W3 V; o; T/ c, z
  254. #) \. ]8 ^% O2 i5 Z/ H$ d
  255. # By default the priority is 100.
    2 R: z, L; O9 B( Z- D2 `
  256. slave-priority 100, Y3 p( b7 g! r  d, s* L& [' C
  257. + J  _3 D1 h- P
  258. ################################## SECURITY ###################################. R$ k) y# [' x1 \
  259. 0 c6 v4 E* X- b; Z
  260. # Require clients to issue AUTH <ASSWORD> before processing any other
    + ?7 |% d1 c) K& C. b% \" c8 A
  261. # commands.  This might be useful in environments in which you do not trust
    # }$ l9 d% R2 f+ o- d& R' t
  262. # others with access to the host running redis-server.
    7 P' y! v, {1 g
  263. #& N* z/ }7 N7 t' _- y& y8 O) G, |
  264. # This should stay commented out for backward compatibility and because most
    9 L6 m# u" J% }( t* v
  265. # people do not need auth (e.g. they run their own servers).. K2 T2 d0 Q" N* N2 ^
  266. # 5 `1 J+ n* b7 G6 r
  267. # Warning: since Redis is pretty fast an outside user can try up to
    : Y2 V* s6 ]" u$ a% B# d, u
  268. # 150k passwords per second against a good box. This means that you should, Q( }+ |% ^; M  i
  269. # use a very strong password otherwise it will be very easy to break.5 ?4 o. A, p/ y% ^
  270. #
    0 p: a% o, X  }
  271. # requirepass foobared; f8 K2 V% |' Y8 f: W- H! Y0 ~+ n( u

  272. " E) Q* r# y9 y; z7 Y! M! M
  273. # Command renaming.
    ' Q: u% }9 C$ E) t
  274. #2 a2 T' f/ j- R- \2 U7 [
  275. # It is possible to change the name of dangerous commands in a shared
    & t; K- u  a- i: g  R! w" h
  276. # environment. For instance the CONFIG command may be renamed into something
    ! M. g# Y0 T  r. ]  {/ b
  277. # hard to guess so that it will still be available for internal-use tools5 g, q% x$ d- F0 g; U6 ]. h
  278. # but not available for general clients.& I  ]+ s6 `$ i: V! X2 N; p
  279. #
    6 p1 L5 Z- I. R: z, |% b
  280. # Example:
    % U4 h' r% V' Q; i3 D& v" a
  281. #% m6 Q& E3 H0 \) o; O% C
  282. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
    ( q# {" D# F3 E3 D. _
  283. #, d3 Y$ X; w. s6 n( \) S
  284. # It is also possible to completely kill a command by renaming it into7 _4 s% [: O6 Y9 O* m
  285. # an empty string:( ^: J8 J# c% @; W1 g& H/ z
  286. #% @/ V5 O+ H" I0 B" g. |% N
  287. # rename-command CONFIG ""
    . K6 f3 H7 y3 s  {/ E3 {$ Y5 |

  288. ; w( f  d; g/ O6 p: g. l. D1 `; y
  289. ################################### LIMITS ####################################" W# @' @& @8 X' @4 V

  290.   V4 [/ z4 G6 \0 C7 W, u6 N
  291. # Set the max number of connected clients at the same time. By default
    / f# d$ ?& k& T2 |/ d
  292. # this limit is set to 10000 clients, however if the Redis server is not
    , {+ Y, a8 A: D  \+ }
  293. # able to configure the process file limit to allow for the specified limit9 G4 a5 T2 ]5 k0 z
  294. # the max number of allowed clients is set to the current file limit0 U- U: S  R& N( X. j! ?' t
  295. # minus 32 (as Redis reserves a few file descriptors for internal uses).. V' N4 ^& D2 {; V
  296. #
    : V0 D9 j% E$ K, ]
  297. # Once the limit is reached Redis will close all the new connections sending. T6 B; h9 t/ I8 ~6 M. ?
  298. # an error 'max number of clients reached'./ p: e9 T6 i0 m$ `/ ^6 I: R# [
  299. #2 }; W0 c6 O7 ]- A
  300. maxclients 500
    # u& u  ]4 W) O- z/ _" A

  301. ! I) \5 S! B- |; N; g
  302. # Don't use more memory than the specified amount of bytes.* v( u6 y6 d3 i" e" j7 }
  303. # When the memory limit is reached Redis will try to remove keys
    " L' @) M: C1 A4 i3 c7 ?
  304. # accordingly to the eviction policy selected (see maxmemmory-policy).
    : B. D  s7 x' c7 b
  305. #2 a& G6 V  z/ c
  306. # If Redis can't remove keys according to the policy, or if the policy is
    . g# J4 j. W2 c. Y! Q6 \1 I* H
  307. # set to 'noeviction', Redis will start to reply with errors to commands7 P" y" H! x( b$ b0 D# B
  308. # that would use more memory, like SET, LPUSH, and so on, and will continue
    " W. u0 l: R/ P6 h2 Q  E+ T
  309. # to reply to read-only commands like GET.
    9 M6 j, \( [+ m% y
  310. #2 U0 G$ v6 U. u, c, [% l
  311. # This option is usually useful when using Redis as an LRU cache, or to set
    5 ^/ W3 ~, D+ m. o+ E+ c% d
  312. # an hard memory limit for an instance (using the 'noeviction' policy).
    * [. Y  j. n0 V; _
  313. #! F3 H4 [0 g- d* r
  314. # WARNING: If you have slaves attached to an instance with maxmemory on,( H, K7 i% e: @9 W/ o
  315. # the size of the output buffers needed to feed the slaves are subtracted
    ) s; `5 X/ {% h
  316. # from the used memory count, so that network problems / resyncs will
    8 o$ k* Z: _/ I8 W! O: [. |
  317. # not trigger a loop where keys are evicted, and in turn the output
    ( j0 G3 d( p1 r' L3 D. y% \: f$ ~
  318. # buffer of slaves is full with DELs of keys evicted triggering the deletion
    8 l! p5 u; f8 }  _
  319. # of more keys, and so forth until the database is completely emptied." y, `& L" O" f0 H1 ?5 I
  320. #
    6 O; q# M9 T6 ], g
  321. # In short... if you have slaves attached it is suggested that you set a lower
    & L; r' s5 R2 a
  322. # limit for maxmemory so that there is some free RAM on the system for slave
    " }/ K* @0 _. W9 F4 M2 `! W% B
  323. # output buffers (but this is not needed if the policy is 'noeviction').
    " Z$ o& B5 r0 K) i" d# U
  324. #" [% B2 d$ y( U" q6 \) s
  325. maxmemory 128000000! I- ]4 @4 ~; q
  326. , f& U7 H% t1 m. ], T; P
  327. # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
    * r( M0 J0 ^+ l0 S
  328. # is reached. You can select among five behaviors:4 z  j: Z  C7 `7 o' Q2 G
  329. #
    ) n4 L5 [3 }9 X
  330. # volatile-lru -> remove the key with an expire set using an LRU algorithm
    - R  \& ?, O# f8 R- }* P# G3 ?8 P
  331. # allkeys-lru -> remove any key accordingly to the LRU algorithm5 F5 R7 e" t. L0 [7 c
  332. # volatile-random -> remove a random key with an expire set. }; j$ l' L  ]/ s# k
  333. # allkeys-random -> remove a random key, any key: s1 g9 K% _& k4 y: [5 N! f# ?* d
  334. # volatile-ttl -> remove the key with the nearest expire time (minor TTL)
    ! \. v( z2 _# e% I6 ^6 U; n$ W
  335. # noeviction -> don't expire at all, just return an error on write operations, Y. Q7 l) W( K  o( C) N  M
  336. #
    + M$ E/ M; I2 R9 U
  337. # Note: with any of the above policies, Redis will return an error on write& V7 f8 q9 n6 l
  338. #       operations, when there are not suitable keys for eviction.
    3 ?, H) J. B9 L& R( C8 x9 w0 B; p
  339. #
      y7 R: g1 r" ]- c5 a
  340. #       At the date of writing this commands are: set setnx setex append% b- u& {3 T5 S! y/ y9 j8 Q
  341. #       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd: W& ~! A0 n8 f' r* q2 M
  342. #       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby' f6 B' q  g- Y0 A! [0 L4 H
  343. #       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby" Y5 u- \$ a) p' ]# b; d! ?
  344. #       getset mset msetnx exec sort/ B8 a% S5 N! K9 ~2 T1 d% ]
  345. #
    8 z$ _1 f* p7 ^' F# j
  346. # The default is:
    & I* `" ~8 {9 Z  k% _7 L; H
  347. #$ y7 y7 `4 e. b: i+ S0 t
  348. # maxmemory-policy volatile-lru
    & Z! a! C9 l6 k' o1 I
  349. 6 n5 F! I9 W0 X/ \/ Y2 @) B0 F! b
  350. # LRU and minimal TTL algorithms are not precise algorithms but approximated
    5 I9 @( k3 s! k& \6 L4 A2 }
  351. # algorithms (in order to save memory), so you can select as well the sample
    $ s) Q7 m, w6 m5 s' I1 b
  352. # size to check. For instance for default Redis will check three keys and
    4 h. m% \; I; K+ x* o
  353. # pick the one that was used less recently, you can change the sample size
    $ A: I  w5 ]; v  ?, J+ M8 P
  354. # using the following configuration directive.' U$ s# E0 C, O' d" _  S' Z
  355. #
    - k" p6 O2 f# J  c3 u0 p( P# m5 c
  356. # maxmemory-samples 3
    ( t. |+ M0 B, ]

  357. - H7 e, |/ B, ~+ r: H" f0 _
  358. ############################## APPEND ONLY MODE ###############################
    ( T, w( s! x2 q" a8 s

  359. 8 c" O/ g, Q$ {) V/ h6 Z
  360. # By default Redis asynchronously dumps the dataset on disk. This mode is( w( _8 g' i$ N( P9 O: y1 O- y
  361. # good enough in many applications, but an issue with the Redis process or
    ; x& X4 l  R9 S+ ?. @$ ^' c$ V
  362. # a power outage may result into a few minutes of writes lost (depending on
    & b3 q0 _' }6 {8 x/ ^4 d& s3 Y
  363. # the configured save points).
    % u$ Q, f4 y. O/ c
  364. #
    ; u- r% i2 p- ~* _
  365. # The Append Only File is an alternative persistence mode that provides- K4 \' W# t8 c$ b* `% F# Y
  366. # much better durability. For instance using the default data fsync policy: ~6 c/ |0 g* q
  367. # (see later in the config file) Redis can lose just one second of writes in a$ D4 k' a# [9 G
  368. # dramatic event like a server power outage, or a single write if something* c5 J9 K5 i/ A; \$ f/ a
  369. # wrong with the Redis process itself happens, but the operating system is; }" q3 O8 ^1 j2 R( `/ i- {7 x
  370. # still running correctly.
    7 W) }# X0 _# A, u) J, {% [3 t
  371. #
    1 j2 Q0 k7 |" b2 A; Q6 _
  372. # AOF and RDB persistence can be enabled at the same time without problems.7 }5 r) R' a5 M8 a3 P3 X- N
  373. # If the AOF is enabled on startup Redis will load the AOF, that is the file* D" M& c; }4 W. R- s
  374. # with the better durability guarantees.
      d$ H! H" c" T" @7 q5 y3 T) p
  375. #7 ?9 B1 {$ W( ]: n% C2 \
  376. # Please check http://redis.io/topics/persistence for more information.
    0 x0 E7 E: ]6 f- h2 D7 f
  377. - N4 A% q3 S4 ?+ N  v
  378. appendonly no; k2 _" t. g) S  h/ k8 k

  379. , @8 ^; @5 }  T6 g: R# V' o) J
  380. # The name of the append only file (default: "appendonly.aof")( P6 t. t, Z, o2 f9 h% x" h
  381. # appendfilename appendonly.aof  {+ |  W; E5 e9 b0 l2 H
  382. % u0 a0 d0 w8 a
  383. # The fsync() call tells the Operating System to actually write data on disk
    : ^8 Z; d$ C9 L1 V
  384. # instead to wait for more data in the output buffer. Some OS will really flush ! l. @% D  ]- T$ `& c. p
  385. # data on disk, some other OS will just try to do it ASAP.
    & p: A9 w" B. m6 e0 g8 c3 L
  386. #+ h+ l2 _/ s8 T: H3 Q$ w
  387. # Redis supports three different modes:9 z( R- R, O' o2 _8 b1 u" r0 H
  388. #2 d( }: G" O5 I% K1 i6 h
  389. # no: don't fsync, just let the OS flush the data when it wants. Faster., c0 d2 ]/ b' l/ a
  390. # always: fsync after every write to the append only log . Slow, Safest.
    . {) g/ a, X# i9 y. x! {5 f. R
  391. # everysec: fsync only one time every second. Compromise.
    3 ?7 g/ Z9 j) n! O" y9 q- b! y4 N" u
  392. #! L* }! P" l( y# ]
  393. # The default is "everysec", as that's usually the right compromise between$ _$ i" U9 F4 {  ~  I7 ~5 ^7 N  T
  394. # speed and data safety. It's up to you to understand if you can relax this to$ V/ Z: ~8 E; Y# ?* ^( i+ @
  395. # "no" that will let the operating system flush the output buffer when
    2 y- u( Y9 c4 [0 X% J) m
  396. # it wants, for better performances (but if you can live with the idea of% L/ x1 F( L6 m& b- i- @
  397. # some data loss consider the default persistence mode that's snapshotting),
    . f( q/ F  D$ X# a
  398. # or on the contrary, use "always" that's very slow but a bit safer than
    0 S) M& p, q6 l& Q/ J1 ?: L
  399. # everysec.4 A- p+ M$ }$ j, b" p
  400. #
    : V( D  E6 B/ B, l
  401. # More details please check the following article:
    * \; E' Y+ E3 T) {# ?0 I4 y" N; ^% J
  402. # http://antirez.com/post/redis-persistence-demystified.html
    1 }! R: A: y$ e  @$ g/ T: J
  403. #/ q6 L& i' b9 F! ^% E+ T: h
  404. # If unsure, use "everysec".
    4 w$ j1 x6 p7 S0 Z
  405.   z1 O( H, }  \8 k* b, m
  406. # appendfsync always
    6 A, E- o' ?% ~  E4 u. G
  407. appendfsync everysec
    ' v$ b4 E+ B' F+ }+ u: D, {
  408. # appendfsync no
    2 O5 ]0 \( f' Q4 g
  409. / g  b7 b) D( F) h4 X4 V; ]
  410. # When the AOF fsync policy is set to always or everysec, and a background
    5 T) o  D5 b4 f7 C9 T  B
  411. # saving process (a background save or AOF log background rewriting) is
    5 g1 i# p% e0 E  N
  412. # performing a lot of I/O against the disk, in some Linux configurations, e' F2 k7 Y/ |' O7 a# W
  413. # Redis may block too long on the fsync() call. Note that there is no fix for* M5 U2 v) O% E9 n, W0 X
  414. # this currently, as even performing fsync in a different thread will block
    & M' ?& F$ H* d) G1 d5 `
  415. # our synchronous write(2) call.& m$ N! K7 U( v% ?1 z
  416. #
    4 @0 Y4 D4 K2 L5 x% r
  417. # In order to mitigate this problem it's possible to use the following option) h6 S' G6 ^& a3 M# O
  418. # that will prevent fsync() from being called in the main process while a
    ; F  r* C* \+ ?
  419. # BGSAVE or BGREWRITEAOF is in progress.
    6 Z) y# h5 v+ T& |
  420. #
    ' d8 |; ]! Q; O9 J( p6 x4 j
  421. # This means that while another child is saving, the durability of Redis is
    # y* ?0 l8 h0 R  G2 s
  422. # the same as "appendfsync none". In practical terms, this means that it is) \" A; O! Q: C
  423. # possible to lose up to 30 seconds of log in the worst scenario (with the
    ) X' F8 ^. l. N0 K4 q
  424. # default Linux settings).5 L! M( R8 b. {7 J
  425. #
    9 B7 W5 ~8 r/ I$ ~1 T
  426. # If you have latency problems turn this to "yes". Otherwise leave it as( f, e' W- j: O( J2 g
  427. # "no" that is the safest pick from the point of view of durability.3 T: T. _: Q  V3 H/ h! W
  428. no-appendfsync-on-rewrite no$ h, B7 `0 M6 b% M  n7 W

  429.   _8 T# _' V; }* m$ x
  430. # Automatic rewrite of the append only file.
    7 r5 c  I2 S3 c% E/ A
  431. # Redis is able to automatically rewrite the log file implicitly calling
    % O: c0 m# Q: i0 O* D5 I
  432. # BGREWRITEAOF when the AOF log size grows by the specified percentage.8 h% o6 ~# W* Q0 p4 q$ u' u: l
  433. # 0 R4 X4 s8 [" o0 x4 D
  434. # This is how it works: Redis remembers the size of the AOF file after the; D; J  o: |6 s6 v- J
  435. # latest rewrite (if no rewrite has happened since the restart, the size of. m# E( a$ [' m/ G
  436. # the AOF at startup is used).* H/ V2 M" L$ ~0 T$ I$ i8 b# N
  437. #
    ! j1 C3 U2 J0 g1 k
  438. # This base size is compared to the current size. If the current size is
    9 ~, {* c$ w- U% K2 l6 j. G& n/ D* h
  439. # bigger than the specified percentage, the rewrite is triggered. Also
    " c9 z6 P# E' `, Q2 E% j! F
  440. # you need to specify a minimal size for the AOF file to be rewritten, this
    6 u, F7 N! s4 ]& }5 k
  441. # is useful to avoid rewriting the AOF file even if the percentage increase
    9 |) Z1 a# W& T! [6 x! J  N  \
  442. # is reached but it is still pretty small.
    2 s6 \$ H& |; z$ T: e6 X
  443. #
    . H: q7 F  W4 w+ `+ }
  444. # Specify a percentage of zero in order to disable the automatic AOF3 S3 g4 _6 Y/ |7 D5 l: i% b
  445. # rewrite feature.
    ' x5 b6 z1 c; R
  446. $ u! g2 K. n! d) ~
  447. auto-aof-rewrite-percentage 100
    . k* U  o9 [3 R( V: J- v
  448. auto-aof-rewrite-min-size 64mb  ^# Z, N  s  F5 ^  X' `7 ~+ s+ U
  449. " q8 |: d5 c' B/ \% m
  450. ################################ LUA SCRIPTING  ###############################
    2 s& B1 c4 G" p
  451. $ V, X2 X7 ]4 D6 D; |0 c
  452. # Max execution time of a Lua script in milliseconds.0 t1 e4 @0 e( P9 t
  453. #
    5 h6 t5 ~- L, g3 G" ?
  454. # If the maximum execution time is reached Redis will log that a script is
    * v' i5 k' d& G! Z$ j# [2 @  E) w* g
  455. # still in execution after the maximum allowed time and will start to; K  p; k: b, I! I% o( \
  456. # reply to queries with an error.
    8 J2 B: w0 @2 f: h; O6 a4 Q2 }
  457. #+ ?9 G( s% D, q; S1 E9 H$ G: `4 k
  458. # When a long running script exceed the maximum execution time only the5 N/ |& p9 q1 o: {+ ?/ j
  459. # SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be
    : n; O; A! ^5 L% A+ o- U+ V( K4 r  T
  460. # used to stop a script that did not yet called write commands. The second
    & r. c6 \  R) W& P4 V( L; ~
  461. # is the only way to shut down the server in the case a write commands was6 A" q$ p: C% L, O
  462. # already issue by the script but the user don't want to wait for the natural' A  b" T9 p$ ~, e
  463. # termination of the script.
    . [0 [0 ]$ u" ~+ M3 H3 E$ z
  464. #
      K( f# ^/ J; F1 `; F/ V
  465. # Set it to 0 or a negative value for unlimited execution without warnings.2 i# Y" M. r+ K: v
  466. lua-time-limit 5000
    - e0 ?4 e5 e1 b# t7 ^6 i6 [4 B
  467. , K0 C5 }: J9 T
  468. ################################## SLOW LOG ###################################
      S3 c$ q0 C" W& X: i8 N
  469. , d. c2 }' T5 _' l5 O9 i% [8 ^
  470. # The Redis Slow Log is a system to log queries that exceeded a specified
    6 o4 @9 W9 G8 r# B
  471. # execution time. The execution time does not include the I/O operations; U: w8 g. H/ o2 W- e0 _
  472. # like talking with the client, sending the reply and so forth,
    ' h# x9 F$ ~, Z
  473. # but just the time needed to actually execute the command (this is the only
    5 H; S! ~' |& P3 Z9 T9 p6 c
  474. # stage of command execution where the thread is blocked and can not serve
    " B( A- j* d% ~
  475. # other requests in the meantime).
    2 Y" h  e2 r5 W, g9 J5 R
  476. #
    * X4 e* A3 g/ {) J+ F, u$ V
  477. # You can configure the slow log with two parameters: one tells Redis
    9 V$ W& h3 N- e5 M) H& O
  478. # what is the execution time, in microseconds, to exceed in order for the) m: C$ X" {$ o; }
  479. # command to get logged, and the other parameter is the length of the
    ! Z" q7 _; ~2 R- D. x  Y
  480. # slow log. When a new command is logged the oldest one is removed from the/ d  m; E" [5 d
  481. # queue of logged commands.
    " h. P  y* H( h$ K. d3 f
  482. : x) Y; [; ^. r4 e
  483. # The following time is expressed in microseconds, so 1000000 is equivalent, z9 `/ K- ^& h+ P9 ?, K
  484. # to one second. Note that a negative number disables the slow log, while
    , ?9 z$ V( I2 w- N7 H
  485. # a value of zero forces the logging of every command.+ T/ i$ v4 u2 F0 _5 G+ {/ G7 S
  486. slowlog-log-slower-than 10000. L; n5 L3 o  ]: F" J" K) p7 ~# A

  487. 8 V; k9 Z& w6 _( r6 |% \" S
  488. # There is no limit to this length. Just be aware that it will consume memory.9 d" g; b+ b7 L; d0 ?
  489. # You can reclaim memory used by the slow log with SLOWLOG RESET.! L1 g7 s2 {- h% {5 e: T
  490. slowlog-max-len 128
    * N/ \* A$ x, Z) ~9 I
  491. ( l  ~3 Y6 i9 I8 c* {* A$ `/ P9 K
  492. ############################### ADVANCED CONFIG ###############################
    $ p1 s: C/ d6 T; W
  493. . U5 x7 F" W7 _: \
  494. # Hashes are encoded using a memory efficient data structure when they have a2 B  |* h* M! A1 w$ T# j+ j# }3 o
  495. # small number of entries, and the biggest entry does not exceed a given6 }9 C- ]5 t1 x/ [
  496. # threshold. These thresholds can be configured using the following directives.
    2 J, @1 |1 }5 n: z! c  f* |  W/ D# Q7 z
  497. hash-max-ziplist-entries 512+ e* Y# V8 `2 h2 I
  498. hash-max-ziplist-value 64
    " B& `1 |3 g1 {; z- p! D( m
  499. , ]4 l1 x- ?" H0 i; t* [
  500. # Similarly to hashes, small lists are also encoded in a special way in order! I& a( }: V: Q
  501. # to save a lot of space. The special representation is only used when0 m$ b8 w+ N  h" r/ A8 }, F, `; |
  502. # you are under the following limits:+ n: p% X# U6 D
  503. list-max-ziplist-entries 5121 |2 y; a: X& W$ M
  504. list-max-ziplist-value 64
    . \* m1 D- J8 Z: D" o# X) ?1 p
  505. - |  s4 W% r* }' E) d
  506. # Sets have a special encoding in just one case: when a set is composed2 d7 l9 K( H% ]
  507. # of just strings that happens to be integers in radix 10 in the range# Q6 ]/ J* u( x' @% f1 ]3 U
  508. # of 64 bit signed integers.
    2 a- |5 x5 a! T, m1 @4 D
  509. # The following configuration setting sets the limit in the size of the
    9 L7 O  b% w9 g. n
  510. # set in order to use this special memory saving encoding.
    ) W4 B0 v$ `7 r/ Q' i5 q
  511. set-max-intset-entries 512+ h/ `* G4 i1 x' z4 Q$ E+ u3 `

  512. ( [$ X& p0 V+ z; K+ Y* O
  513. # Similarly to hashes and lists, sorted sets are also specially encoded in
    ; l. H+ b* E$ J
  514. # order to save a lot of space. This encoding is only used when the length and
    * _* _9 d3 I. d/ d5 w- `* p
  515. # elements of a sorted set are below the following limits:' @2 t$ a1 p; f  w/ t: R- `
  516. zset-max-ziplist-entries 128
    : {. C( j1 ~: Y3 Y3 v$ m' V
  517. zset-max-ziplist-value 64
    7 w! G$ t5 D/ s5 H

  518. 4 q" \! X  ~* }& {0 t1 H+ u: ?
  519. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in: }" L+ M' @% N$ d2 ?7 w! l
  520. # order to help rehashing the main Redis hash table (the one mapping top-level' z2 v$ o2 N) g) c$ p" ]+ p  r7 y
  521. # keys to values). The hash table implementation Redis uses (see dict.c)) _& `6 G, H. K) y( `" U
  522. # performs a lazy rehashing: the more operation you run into an hash table' G4 z1 L$ y; G7 p
  523. # that is rehashing, the more rehashing "steps" are performed, so if the
    " m- \$ P+ z0 ?$ u9 B3 |
  524. # server is idle the rehashing is never complete and some more memory is used2 g. `  J1 t1 |+ L  u2 O/ g" j
  525. # by the hash table.
    ' g% [! d' N: t  U* |* W
  526. # # y; p, m+ G& f, y- ^
  527. # The default is to use this millisecond 10 times every second in order to. v- }* b9 E8 B2 i
  528. # active rehashing the main dictionaries, freeing memory when possible.9 ~' I7 _/ N" ?- T/ ]% r
  529. #0 ]/ \' E  u- ~) t2 ~/ Y
  530. # If unsure:
    8 ^+ j, _; B8 o; d! @# B
  531. # use "activerehashing no" if you have hard latency requirements and it is* I- }' j: n" z3 ^0 _2 x9 W# Q, x1 F
  532. # not a good thing in your environment that Redis can reply form time to time
    & }' k. e6 D# g7 B5 H0 \( V) [" |
  533. # to queries with 2 milliseconds delay., ~5 {! m9 P2 q- f
  534. #
    - ~# f: F2 u/ g$ I8 L( l' X& f5 G
  535. # use "activerehashing yes" if you don't have such hard requirements but, O3 c1 Y; g9 _; v' c
  536. # want to free memory asap when possible.
    3 q* f1 @6 b2 T/ B8 b1 |5 d
  537. activerehashing yes
    7 g& M: G0 W& n" I

  538. * G5 M% ^8 i. H. s+ y! H* l
  539. # The client output buffer limits can be used to force disconnection of clients3 i# M8 f. q, d- }% f
  540. # that are not reading data from the server fast enough for some reason (a8 f  _4 j& L- k5 X2 ?) f: M5 F
  541. # common reason is that a Pub/Sub client can't consume messages as fast as the4 M0 k- Z4 d9 Z# h; a8 |. q) P
  542. # publisher can produce them).$ ~% v8 ?" p0 P
  543. #8 r) O. K3 u) m: h& H
  544. # The limit can be set differently for the three different classes of clients:
    1 n5 s7 D5 b& |- x/ w
  545. #
    8 n! o; ]8 J1 d; v- u$ a- r
  546. # normal -> normal clients
    9 P1 x; G. w5 G9 w5 N
  547. # slave  -> slave clients and MONITOR clients+ P! r: @1 F, h6 W
  548. # pubsub -> clients subcribed to at least one pubsub channel or pattern
    , x( l5 c4 W  @
  549. #
    7 C. u' C( [  b5 ?2 E
  550. # The syntax of every client-output-buffer-limit directive is the following:
    - `% `0 a' ?6 g# x* d* {* [3 N
  551. #
    , Z3 j( |+ {& a8 i5 r. M5 e4 u
  552. # client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>
    $ B- }* N* r% T- J1 U# `7 z
  553. #
    # n% g4 Q/ ?6 ^* i1 `% v
  554. # A client is immediately disconnected once the hard limit is reached, or if$ t" \4 X) J6 v8 _- x& Q
  555. # the soft limit is reached and remains reached for the specified number of' F* ^3 N. @7 e; J6 t) M! |* v+ M
  556. # seconds (continuously).
    ) Y/ _$ A  b! L- c& K4 o2 O: S
  557. # So for instance if the hard limit is 32 megabytes and the soft limit is9 v; Z4 Z9 G+ ~6 G
  558. # 16 megabytes / 10 seconds, the client will get disconnected immediately
    : I7 E# n2 s+ {6 c8 [; S
  559. # if the size of the output buffers reach 32 megabytes, but will also get
    8 [# n6 m* x2 d; s$ f* _
  560. # disconnected if the client reaches 16 megabytes and continuously overcomes
    4 a1 K  P' }' a
  561. # the limit for 10 seconds.
    - ]( E) q8 h, \+ ]
  562. #
    5 ?# z1 x3 \; t  o. z6 _+ H
  563. # By default normal clients are not limited because they don't receive data5 y( S; E: M  u! u; o1 K, ^
  564. # without asking (in a push way), but just after a request, so only
    7 e" k& n4 t; M- O
  565. # asynchronous clients may create a scenario where data is requested faster
    4 s+ [! c# K  X
  566. # than it can read.* q. U7 l& K7 m2 s; p0 l
  567. #
    3 t5 \% x0 ^0 _9 {5 A, I( c5 E- ?
  568. # Instead there is a default limit for pubsub and slave clients, since) Y% s  t& A( g8 b* o$ l
  569. # subscribers and slaves receive data in a push fashion.
    0 q6 l! y% i- q6 X! L# g
  570. #
    3 c5 {: [, T4 y, C) L
  571. # Both the hard or the soft limit can be disabled by setting them to zero.) d, C0 {, w& Q1 u3 Z- p
  572. client-output-buffer-limit normal 0 0 0
    ( [' @% f8 R+ k8 d4 N
  573. client-output-buffer-limit slave 256mb 64mb 606 e( ?* W: {  d8 o3 l( X
  574. client-output-buffer-limit pubsub 32mb 8mb 60
    ) K1 G- Y) y' T1 `
  575. 4 L$ ?; r+ G. X7 p  {% T3 }5 B" ]
  576. ################################## INCLUDES ###################################/ J% @+ Q4 e  o/ A" {: L4 X1 }, k

  577. " S3 A. u3 n& ?& `* F6 a' A$ B1 a, y
  578. # Include one or more other config files here.  This is useful if you
    7 G: Q) [/ q8 |
  579. # have a standard template that goes to all Redis server but also need
    ( \+ J* m) z* u* Y! b
  580. # to customize a few per-server settings.  Include files can include
    ; Q; ?% d4 W- i8 R+ O
  581. # other files, so use this wisely.; H+ u, q2 e3 |" t3 e
  582. #- l7 d4 ]; `: Z8 E7 g
  583. # include /path/to/local.conf
    8 s7 ]/ k' `* _# Z7 h+ V+ {
  584. # include /path/to/other.conf        ' x; P& W7 A- m7 G- |
  585. ##########################配置文件结束################################ 1 I) t4 \) q% n# H
  586. 第三步:启动进程! p& P. H; i5 ^2 L! d+ q
  587. #redis-server /etc/redis.conf
    0 I  E( p5 R* s) ]9 B- {
  588. 查看进程有没有成功启动* s1 I" y+ V$ D9 c
  589. #ps -ef | grep redis
    ) {( i! c& U# e% a1 h' j' U+ a& P
  590. 测试输入一个键值" [; j+ b8 Z, _+ k
  591. #redis-cli set test "testredis"
    4 N3 B0 C$ e' I
  592. 获取键值
    4 x2 a8 }8 z" I8 a( g  O' p# u. m
  593. #redis-cli get test
    2 Y, v! \# n( x$ {2 Q* E

  594. . C( C8 Q. s: u4 ?; ]

  595. ; u% O4 L+ {' `" x1 s) M
  596. 第四步:关闭redis  (这个是更改配置文件后 正常的重启方式  不重新加载redis配置跳过)
    % k% I8 G0 Y8 C, }; j  G! F* l/ X
  597. # redis-cli shutdown      //关闭所有    . f2 A. b# b% |
  598. 关闭某个端口上的redis   
    ' s  B4 Q) b) N* t& ]1 F1 d. F* k
  599. # redis-cli -p 6397 shutdown  //关闭6397端口的redis  9 h! Y) F- B+ f1 y
  600. 说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename  dump.rdb  2 \5 k% {0 S1 A; h, d! y

  601. / X. l  \% p& N6 E

  602. & Q9 b; @- T1 d
  603. 第5步:php扩展安装
    + [2 |* T+ L* a6 Z5 E0 {
  604. phpredis PHP扩展下载地址
    9 X$ L1 J2 @( X
  605. https://github.com/nicolasff/phpredis/tree/2.2.2 ' x/ q7 R5 p  @& A  [5 G  q: |
  606. 选择最新版本下载zip
    ) L/ x1 ^8 y# M. c! b! ^# k& _

  607. ! F. y! O  k3 a$ W! ^! b
  608. 然后自己上传zip  用unzip解压到当前目录 unzip 文件名/ q$ G1 s% p2 P
  609. 6 t7 Z! M- Z' Q- V
  610. # cd owlient-phpredis-90ecd17/   #打开解压后的文件夹里面  这个解压后的目录 要是不知道 可以输入 "dir" 查看9 g& D/ f% R$ K( i9 {' U! q
  611. # /www/nginx_php-5.2.17/bin
    1 F! q6 G; U8 d- z" w
  612. # ./configure --with-php-config=/www/nginx_php-5.2.17/bin/php-config9 X  L. F' t2 M! P/ Q1 D5 |
  613. #make$ G3 l9 x) w4 R  R
  614. #make install   #记录产生的redis.so路径
    $ T: c" U9 A5 \& r3 t: _  c7 j
  615. 5 }4 J* ]8 f) O* Z/ a. A$ p
  616. 修改php.ini文件& z! N3 a4 A9 l9 W0 `* g
  617. 在php.ini中添加如下一行:; L) d' ?9 X* D1 W; X
  618. extension=/?/redis.so  #是刚刚记录的产生redis.so的路 写在 ?那
    * v( B! Y# k5 k, }( f, ?1 G
  619. 重启 使之生效:6 n8 Q/ j, |! m$ w; r# v- p
  620. /usr/local/php/sbin/php-fpm reload
    & h, _1 g2 ^, D: E+ Z: L1 g
  621. /usr/local/nginx/sbin/nginx -s reload : r9 L: [( o& N$ P

  622. # P' x, g5 I  _7 y0 O* q
  623. 将 Redis 作为 Linux 服务随机启动0 A/ O) M' E" |
  624. vi /etc/rc.local, 加入代码:1 B9 D6 L1 |" i9 C) ^! [
  625. /root/redis-2.6.10/src/redis-serve  #路径看情况修改 ; @( [, l: u4 d  y6 ]: o
  626.   J: y# B+ U1 c
  627. redis-cli -h localhost -p 6379 info  #命令要在redis目录下面执行9 f  {7 f5 C, \0 o! _2 J8 i3 S& l
  628. 提供host为localhost,端口为6379,redis服务的统计信息
    7 J8 S9 ]/ P/ q* u" ]* n* K
  629. ( g2 g# |) J1 V' I$ ]4 K
  630. ) r7 i  W# l+ i# q& X: ]
  631. 就这样你的web服务器就支持redis了 记得要在 给dz 的配置文件 加上12.0.0.1哦
    + Y1 ?7 u3 E  t
  632. dz配置文件在 config目录下面的 config_global.php
    $ |6 R! m8 M7 ~/ ?' ?
  633. $_config['memory']['redis']['server'] = '127.0.0.1';+ y* w- Q8 i4 |  u% ]. C
  634. $_config['memory']['redis']['port'] = 6379;
    ( h" u; J' u/ r2 }/ v$ t
  635. $_config['memory']['redis']['pconnect'] = 1;
    1 m1 s" N3 S+ ]! w$ N
  636. $_config['memory']['redis']['timeout'] = '0';# E- E9 C$ P) R
  637. $_config['memory']['redis']['serializer'] = 1;5 |9 Q/ O' u# y- G8 K+ o5 E
复制代码
关注微信公众号《神采飞扬网》,即可获取最新回复通知!

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

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

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

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

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