分享到:
发表于 2018-11-16 12:42:28 | 显示全部楼层 |阅读模式
环境配置$ \  `( ?2 W" U$ K

" ^  p. Y7 \$ o. J" x3 B
" I& ?9 R8 t% Ehttp://www.discuz.net/forum.php? ... amp;highlight=REDIS
关注微信公众号《神采飞扬网》,即可获取最新回复通知!
 楼主| 发表于 2018-11-16 12:43:33 | 显示全部楼层
http://www.discuz.net/forum.php? ... 648&highlight=REDIS
  G9 D3 T4 {- V0 V( x( K) w7 Q1 W6 V% A无意间测试 单机状态 redis相当给力 测试1000请求/s  单纯的 get 和set 居然只用了 0.01秒 当时我惊呆了, J* B( D$ f# e9 t; f$ I

  Z$ L7 N$ \& P7 ], F3 C5 Ghttp://www.discuz.net/forum.php? ... 731&highlight=REDIS" |2 ]9 f4 {8 o+ x
/ V" T: ]- Q# v/ E7 _! }
https://wenku.baidu.com/view/265a5ce176a20029bc642d0b.html
( N0 b$ E) H0 d& H/ s9 ~9 e
. S0 b! o8 E2 K* q  p6 N=======================================; r6 ?* _5 d  v  O, O. E* u& h1 H
  1. 连接上 ssh; k3 @9 M6 F( v
  2. 2 d% l- ^- o9 R# ]- X
  3. 7 |5 ^+ @- E+ S
  4. 第一步:下载redis& a+ i9 D# x& Z* d
  5. # wget http://redis.googlecode.com/files/redis-2.6.10.tar.gz
    2 a5 h0 ?/ X' o' k2 X! E
  6. # tar zxvf redis-2.6.10.tar.gz 6 ]- `: f/ I* b
  7. # cd redis-2.6.101 h" }& I. G% |! }# }
  8. # make
    3 a/ C, |! k% V) w& z
  9. # make install  , p0 J& d# K& G7 a! Q. L! `
  10. #cp redis.conf  /etc/ #复制配置文件到etc目录下面1 |3 _$ e- z* K; p
  11. 第二步:修改配置
    3 ~" t  [8 O. p" W8 L
  12. #vi /etc/redis.conf/ `, |1 B; N. E2 G+ t! u# Y5 A
  13. ######################下面是无措的配置文件 复制过去就成#########6 p" b' c+ @% ^0 A
  14. # Redis configuration file example* f& M6 q) G2 A5 A% |, H
  15. ; \( s5 B9 d0 ^/ v
  16. # Note on units: when memory size is needed, it is possible to specify- \$ n8 e9 Q1 R  S
  17. # it in the usual form of 1k 5GB 4M and so forth:
    ' c8 S2 |8 V* {/ P
  18. #- v! }4 o  Z  F: P) J- t/ t9 g8 j
  19. # 1k => 1000 bytes
    5 |4 Y% a& b4 [6 B
  20. # 1kb => 1024 bytes/ ~" z8 n) N) t0 H3 e* r
  21. # 1m => 1000000 bytes( G; }: |8 U: _3 f$ I! B
  22. # 1mb => 1024*1024 bytes
    7 _2 }3 L( p2 T. @7 r
  23. # 1g => 1000000000 bytes& ?3 a; F" y0 b0 b# R$ A
  24. # 1gb => 1024*1024*1024 bytes6 F; R+ Z6 ~3 W6 S, E6 V/ D
  25. #
    % g( O; P( G9 V- \; V" K  ?3 a6 _
  26. # units are case insensitive so 1GB 1Gb 1gB are all the same.4 h) O  a; u6 e2 z
  27. ! a9 W8 O: q, o2 E
  28. # By default Redis does not run as a daemon. Use 'yes' if you need it./ s9 Y; M" I% ]
  29. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.  ?* C; M- Q) o, N
  30. daemonize yes- u) [) H2 T2 S5 W* n
  31. , X$ E0 a' j! G/ {
  32. # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
    $ I) a# b7 i7 o* z& y% i
  33. # default. You can specify a custom pid file location here.
    9 a* t$ S6 Z3 Y2 O3 @1 v+ C
  34. pidfile /var/run/redis.pid
    3 A; |9 r  Q, g9 y3 g' m
  35. , [! ?, P: s+ H( S7 V3 K
  36. # Accept connections on the specified port, default is 6379.
    ( i8 N2 ]+ ?% ]# e/ C# f
  37. # If port 0 is specified Redis will not listen on a TCP socket.
    7 o! H& W* m) K. G% n4 D
  38. port 63793 |- S8 O9 n1 R
  39. 7 H% K5 L, U9 Y1 t, p, a( [% Y  a2 e
  40. # If you want you can bind a single interface, if the bind option is not
    % t1 o% e6 w, a: S
  41. # specified all the interfaces will listen for incoming connections.9 D; V6 i; [  \3 D1 `2 v* ^
  42. #& ?" l! e$ T: t
  43. # bind 127.0.0.1% n, e  m1 D) }; L" u2 h  k' u

  44. $ V3 m$ Q/ B0 y" i. d3 Z
  45. # Specify the path for the unix socket that will be used to listen for, i  m0 \1 X" Z1 E" y/ K
  46. # incoming connections. There is no default, so Redis will not listen1 u) {' d6 |4 B  c( d8 r
  47. # on a unix socket when not specified." N# L+ G# ?5 p! u9 x& q
  48. #
    " P3 d- H# K, t& ^- u0 a  d6 ^
  49. # unixsocket /tmp/redis.sock6 c- O$ e. t4 G" t2 E+ ]
  50. # unixsocketperm 755
    0 t9 E7 E: b" l3 Y3 J( d

  51. 3 Z9 k, S) X* {3 x
  52. # Close the connection after a client is idle for N seconds (0 to disable)1 B1 Y8 {% L8 t5 l5 c5 S0 b! i( A$ D
  53. timeout 3009 t# S; \% ]: E

  54. ( T. z% Y+ I* j6 K& [# s1 ?
  55. # TCP keepalive.! E+ d% h' P1 f* J  l# W* T
  56. #! z; A7 H4 t7 K9 f" @
  57. # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence, G0 l- a3 t) g3 g! A# v5 O
  58. # of communication. This is useful for two reasons:! L& c" c% P7 U; Q
  59. #0 J' ~$ q3 @( M+ ]
  60. # 1) Detect dead peers.
    + H3 A) ?/ o, w8 T) h1 S. ~' z
  61. # 2) Take the connection alive from the point of view of network
    $ g+ i8 D& M. e3 N& Q
  62. #    equipment in the middle.3 c3 S% ~3 k  a& M# \  f3 Q
  63. ## U2 Y& Q+ V' p, c/ w' }9 [
  64. # On Linux, the specified value (in seconds) is the period used to send ACKs.
    6 X' H" y* x( L
  65. # Note that to close the connection the double of the time is needed.* x* _/ f& ~+ z+ @$ F' b. v
  66. # On other kernels the period depends on the kernel configuration.+ f. J6 F1 _+ M, C7 z) A5 V" ]
  67. #- ]' m9 k, b! f2 P: A; X  ]
  68. # A reasonable value for this option is 60 seconds." X2 _0 G% p6 s+ S& r0 t
  69. tcp-keepalive 0
    3 T' N0 k* n: N/ ]! o$ S

  70. 9 R* O$ E, z+ R' D* r3 ^* S
  71. # Specify the server verbosity level.
    % F8 H3 m- z5 }5 G: |7 z$ C, f
  72. # This can be one of:# a# Y3 u5 G! k- T7 O
  73. # debug (a lot of information, useful for development/testing)+ i0 l% o9 I7 ~% b: d
  74. # verbose (many rarely useful info, but not a mess like the debug level); n1 H5 M1 J. l* [
  75. # notice (moderately verbose, what you want in production probably), l$ {: z+ J( q" C' `$ k; j
  76. # warning (only very important / critical messages are logged)
    9 x. }( G/ s) R7 p2 b
  77. loglevel warning6 G1 \1 k, U" `( o7 t% q& D! H

  78. 8 ]% M7 r. Z( S6 A
  79. # Specify the log file name. Also 'stdout' can be used to force
    " d8 R1 M6 Q  ^! I: \
  80. # Redis to log on the standard output. Note that if you use standard/ k0 p8 x! I7 a, z
  81. # output for logging but daemonize, logs will be sent to /dev/null/ M1 `, {  U  P/ p
  82. logfile /var/log/redis.log
      |7 f8 x" O$ V' u$ Z

  83. 2 y; d+ W2 e" U# S
  84. # To enable logging to the system logger, just set 'syslog-enabled' to yes,1 `7 k" H& G6 n6 N( S/ f
  85. # and optionally update the other syslog parameters to suit your needs.7 L. D+ t: T" z- ~4 \  I: Z
  86. syslog-enabled yes  |5 H# L- ]' W' x. f% K
  87. 3 h! b5 N5 N' U  u# e4 j) [- i. I
  88. # Specify the syslog identity.
    $ n* ]6 x4 d( A; q# U
  89. # syslog-ident redis
    * @5 _4 Z7 K. F+ _3 e
  90. 8 ~: W0 L. i$ y
  91. # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.) \3 g& @4 g% [( K- `( K5 j
  92. syslog-facility local0- e1 s# }  W4 x/ ]$ X. d
  93. " z  t# p- u" }
  94. # Set the number of databases. The default database is DB 0, you can select9 ~* ~# Q' E- a& A& D7 v
  95. # a different one on a per-connection basis using SELECT <dbid> where% d3 b/ R* l- R& J3 b
  96. # dbid is a number between 0 and 'databases'-1
    ! @  L6 ~0 O/ L8 N; Q% U3 u
  97. databases 16' k' p. P2 W" u& o- E5 }) v
  98. $ q, c1 `% e- q, A
  99. ################################ SNAPSHOTTING  #################################6 y- J/ V5 i- ?! K' ~/ X% O
  100. #  }( q) q2 Z& l) G$ X! r
  101. # Save the DB on disk:
    % c  O% d8 w! b* m
  102. #  a4 |- p5 q4 \; b/ h4 J
  103. #   save <seconds> <changes>
    0 Q8 @& W$ T" l& ^. X! |* V! k
  104. #
    ; }% r$ S! ^! d! F5 f8 z. }
  105. #   Will save the DB if both the given number of seconds and the given
    6 |. C& e& ~9 W$ f
  106. #   number of write operations against the DB occurred.' M+ a! R/ y* x+ ?4 w. _5 E% o
  107. #, Y/ D+ ]1 v# T, E6 ~4 g, p
  108. #   In the example below the behaviour will be to save:! `$ y- b4 `5 `, F" J6 ^2 ]
  109. #   after 900 sec (15 min) if at least 1 key changed8 M) g! \. q9 z% S, X8 ?5 _
  110. #   after 300 sec (5 min) if at least 10 keys changed
    0 A6 |- V$ w. m( A4 N, R# [4 j; L' a
  111. #   after 60 sec if at least 10000 keys changed
    0 Y3 a) X* ?; q* k- @" H: ]/ L% D
  112. #  h. M5 r, \- n0 O# M
  113. #   Note: you can disable saving at all commenting all the "save" lines.+ ~: H# P, i0 ~. D& d$ t
  114. #
    # y' f. s3 P8 q# q
  115. #   It is also possible to remove all the previously configured save* i" ~( d, P8 |: o" d
  116. #   points by adding a save directive with a single empty string argument# ~0 G9 C6 p) R% R( A% A+ x: @0 [
  117. #   like in the following example:) T6 M$ ^. e/ G6 u% z, d" }" m( y
  118. #
    ( o; J* Z, i! K  @# @
  119. #   save ""
    : J2 l/ b& T: a5 [
  120. 4 e3 k. Q' c# x, P' N8 l
  121. save 900 1  c1 W8 ^- G7 @; v9 S- Q
  122. save 300 109 P; l3 }3 T: T7 b
  123. save 60 100009 Z  N/ i( D: L) B! M& M

  124. / A- F" Z4 _& s1 w  D6 D$ Y1 H
  125. # By default Redis will stop accepting writes if RDB snapshots are enabled
    6 q6 C5 H. F+ G
  126. # (at least one save point) and the latest background save failed.+ ?8 R" G" X( Y4 q+ y+ h/ F! |* z5 V$ `
  127. # This will make the user aware (in an hard way) that data is not persisting
    8 l/ E. C5 s5 E1 y. I7 M9 y
  128. # on disk properly, otherwise chances are that no one will notice and some
    5 n& X0 I$ E6 l5 v2 [
  129. # distater will happen.
    3 ]# t( T6 X/ a3 o# O" l
  130. #
    + p; G. L; ~5 h7 C; e$ I" M9 C
  131. # If the background saving process will start working again Redis will" h0 [& G! M" g. O6 ?
  132. # automatically allow writes again.
      A4 v8 p5 [2 c+ ]
  133. #
    3 P: i6 A! Y* z, ~
  134. # However if you have setup your proper monitoring of the Redis server) p- l' I1 `2 g  o$ m# d
  135. # and persistence, you may want to disable this feature so that Redis will
    9 i" [6 m; k4 o+ w! s! i
  136. # continue to work as usually even if there are problems with disk,
    ' l5 S+ E9 F' b1 v4 n) z! Q
  137. # permissions, and so forth.$ f2 l  C% o* t) n1 L2 F+ s
  138. stop-writes-on-bgsave-error yes
    1 q) @) x4 I$ E

  139. - }. |+ q% V  ^1 [; Y% n2 _
  140. # Compress string objects using LZF when dump .rdb databases?
    # c$ O% i% ]$ j7 f, W, g
  141. # For default that's set to 'yes' as it's almost always a win.$ ~, A, B6 s1 J4 v* P5 N
  142. # If you want to save some CPU in the saving child set it to 'no' but( }: N& n/ [! O7 Q- x7 o
  143. # the dataset will likely be bigger if you have compressible values or keys.9 L' ^) s4 D* O! D0 P4 ]
  144. rdbcompression yes
    $ [. N$ z# `! p3 h

  145. 1 ^" Y1 O( H2 j# Y' C) D& s5 F$ H
  146. # Since version 5 of RDB a CRC64 checksum is placed at the end of the file.5 |% O% y' u. T" }3 X
  147. # This makes the format more resistant to corruption but there is a performance
    - v. p3 d6 H7 K' c
  148. # hit to pay (around 10%) when saving and loading RDB files, so you can disable it
    2 t4 f2 T" m  H& F2 C
  149. # for maximum performances.
    1 d& E% }6 |2 f
  150. #
    - K9 e% L' J7 c5 g) R7 ]1 C$ c. c' k
  151. # RDB files created with checksum disabled have a checksum of zero that will
    6 E/ k5 g( I+ f8 M, K$ j6 e
  152. # tell the loading code to skip the check.7 V. w% V$ {  `( }% b1 u
  153. rdbchecksum yes7 k. o: J1 U0 e; y. K9 f
  154. ; k& Y* G3 M# @9 V! v+ p% X
  155. # The filename where to dump the DB
    7 k0 t2 X" d4 P$ ^7 h/ H
  156. dbfilename dump.rdb
    - Q2 k& o$ n2 z5 Q' a" e) V
  157. 7 M& K/ e; F& y, ~0 k% q% g# o
  158. # The working directory.
    ' c! h8 {  V* k$ ~, j/ X
  159. ## v/ d( ~0 U  M
  160. # The DB will be written inside this directory, with the filename specified7 a/ r" F( H' F  Z9 q/ {" j
  161. # above using the 'dbfilename' configuration directive.
    4 {1 N* \* J- N- c
  162. # $ P3 }, V; {3 g4 y
  163. # The Append Only File will also be created inside this directory.4 y/ |1 g8 \8 t
  164. #
    # u" e' ^) y1 w( C0 h
  165. # Note that you must specify a directory here, not a file name.) w/ `1 p4 t1 C% z; S
  166. dir /var/db/redis
    2 }; G0 `8 t2 y  d/ u5 R6 Q

  167. 1 L- t7 I+ _; A2 M" c; m
  168. ################################# REPLICATION #################################4 E  e, l" W% d$ l

  169. 6 w' \! h* E3 a; `' W
  170. # Master-Slave replication. Use slaveof to make a Redis instance a copy of$ a# \  x: [) w" {1 H* r7 z* I4 ]
  171. # another Redis server. Note that the configuration is local to the slave
    6 @& H2 [6 w8 g
  172. # so for example it is possible to configure the slave to save the DB with a  I6 e. L, o" ~3 c6 e1 E' H* H
  173. # different interval, or to listen to another port, and so on.6 f. ]: y  f2 p9 e9 N6 f! V- G
  174. #
    " l) S7 |' a7 p0 i/ v- g
  175. # slaveof <masterip> <masterport>8 S  Q1 q2 Y2 [

  176. 5 f8 M3 B2 J9 N, z  f+ j+ ]. @$ i
  177. # If the master is password protected (using the "requirepass" configuration2 f8 c' H4 j& Q
  178. # directive below) it is possible to tell the slave to authenticate before1 z  ]' d; ?" C9 @: P: e
  179. # starting the replication synchronization process, otherwise the master will# J! G" x% z# P/ N4 n! w7 i
  180. # refuse the slave request.
    # v4 e1 w2 T8 s2 |6 n! g( ~0 Z" ^
  181. #
    % @+ Y1 I( g: e5 S5 g
  182. # masterauth <master-password>" T) G! n8 j* }4 L& c- E2 G% j6 C
  183. + @$ n; d1 P2 L4 Y: b/ X+ O% {
  184. # When a slave loses its connection with the master, or when the replication! B( x& t  X* V2 P' }( G7 z4 O
  185. # is still in progress, the slave can act in two different ways:1 P5 T: o* x  u3 J" k: R7 J
  186. #
    $ b; ]6 R- a9 O9 \0 \# g
  187. # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will+ x) Q% y& ^2 k' |! S
  188. #    still reply to client requests, possibly with out of date data, or the: H1 k, T" Q7 x' k' y; A
  189. #    data set may just be empty if this is the first synchronization.) G/ e& E5 m$ l- [4 q# R- e# f
  190. #
    $ J) W$ Y) A* R1 i$ q: A+ E
  191. # 2) if slave-serve-stale data is set to 'no' the slave will reply with
    / B0 H3 n- f2 `5 C8 z- r* n
  192. #    an error "SYNC with master in progress" to all the kind of commands
    - ~( P5 o0 m. D6 A
  193. #    but to INFO and SLAVEOF.
    0 }. G& p) J8 T: ~; y
  194. #
    3 d1 q5 z, `" F. t9 g6 _* M
  195. slave-serve-stale-data yes
    ' T; R' Y; U/ b1 P/ {/ F

  196. 3 v2 t2 Q$ Z/ T; x! O- T2 T/ q3 V
  197. # You can configure a slave instance to accept writes or not. Writing against
    5 i& X. r% {( b; ~
  198. # a slave instance may be useful to store some ephemeral data (because data& d* L7 w/ [; k0 Y! O
  199. # written on a slave will be easily deleted after resync with the master) but. I4 P, c- ?& x  Z# @# H, W
  200. # may also cause problems if clients are writing to it because of a
    , u+ W( O& H( w0 ~6 h7 Z& |9 A+ M6 |
  201. # misconfiguration.
    1 s5 M3 s$ q7 h6 ]# J
  202. #+ q- D+ n( M3 a# K# G
  203. # Since Redis 2.6 by default slaves are read-only.7 E- J/ ?  b( i$ d8 i
  204. #
    ( S1 m( ?  |# G) p4 P
  205. # Note: read only slaves are not designed to be exposed to untrusted clients7 |, v0 ]! f  m- `
  206. # on the internet. It's just a protection layer against misuse of the instance.  \0 Z2 E! b4 C- ?6 C# a
  207. # Still a read only slave exports by default all the administrative commands
    ; Y2 w! d0 x* Y) g% T7 X, T
  208. # such as CONFIG, DEBUG, and so forth. To a limited extend you can improve
    , d4 w7 y, k" I' O  p( Q
  209. # security of read only slaves using 'rename-command' to shadow all the
    4 X5 G4 H' Y. b6 C* j
  210. # administrative / dangerous commands.5 q/ s3 S* @# W  R
  211. slave-read-only yes
    / B  z* m' e! _; d4 f! @( _+ o
  212. 6 E7 c0 P( u+ O0 t2 b2 b
  213. # Slaves send PINGs to server in a predefined interval. It's possible to change; Q4 U* i) e9 i3 Z  ?  v
  214. # this interval with the repl_ping_slave_period option. The default value is 10
    9 P( {/ k! O; b( q6 `
  215. # seconds.
    3 F* q+ H4 Q% ]2 m
  216. #
    $ q- _4 k' M8 ^0 M) {/ q
  217. # repl-ping-slave-period 109 j" C- t" |1 |

  218. " ?: z. X" e& a7 L9 Z/ |) R  b& w
  219. # The following option sets a timeout for both Bulk transfer I/O timeout and
    2 @4 |6 R3 }3 ^: J
  220. # master data or ping response timeout. The default value is 60 seconds.0 _+ U. o+ n0 y5 s+ U, K0 K4 _' Y
  221. #) \* J% T" ^" w* W" g, j8 p
  222. # It is important to make sure that this value is greater than the value# c" N" n( v. w/ z$ }; Y8 f4 G
  223. # specified for repl-ping-slave-period otherwise a timeout will be detected6 ~; D0 t) A+ Y' Q6 Y& ]
  224. # every time there is low traffic between the master and the slave." u# n! ~& O) B& {; y/ Z$ _" D+ B
  225. #
    : K' g. `( r" i4 R& s6 d
  226. # repl-timeout 60' Y* s8 F: I9 z& ^9 s# S
  227. 5 h' _  O$ N8 w3 D2 w, o2 H2 G' V8 O
  228. # Disable TCP_NODELAY on the slave socket after SYNC?. Q. u; w  Q6 G' @! F
  229. #
    : j5 d" V* p2 Z9 g7 k! Y$ G
  230. # If you select "yes" Redis will use a smaller number of TCP packets and7 S( E+ P, C" w
  231. # less bandwidth to send data to slaves. But this can add a delay for; R2 x: d- d& H4 N
  232. # the data to appear on the slave side, up to 40 milliseconds with
    ; [0 ?$ j/ Q  `( n: M4 N
  233. # Linux kernels using a default configuration.# Q, i& a4 p/ ]- N
  234. #3 V4 c' d  d) U! N& G1 g$ t5 h
  235. # If you select "no" the delay for data to appear on the slave side will; G: O5 d8 ?7 s* B; V2 \. T7 g
  236. # be reduced but more bandwidth will be used for replication.
    , l2 @5 a1 }3 O4 T1 ?
  237. #" N) F2 w/ p# U
  238. # By default we optimize for low latency, but in very high traffic conditions, N- C& l+ ]" E4 O
  239. # or when the master and slaves are many hops away, turning this to "yes" may' A8 u+ |& R/ Y& |* J+ H7 k8 d# R
  240. # be a good idea.
      }( H3 g, f* a% u
  241. repl-disable-tcp-nodelay no
    3 l- Y. c. Z5 V' C
  242. / `' ]- w& w) Y
  243. # The slave priority is an integer number published by Redis in the INFO output./ ]/ f/ G/ S0 j# m( ~% N" `  g" z
  244. # It is used by Redis Sentinel in order to select a slave to promote into a" Z% [$ K) v$ J% k8 Z: v
  245. # master if the master is no longer working correctly.# u! m7 T, B$ @3 ^9 |+ q( s
  246. #
    & S: B, p0 e7 |) H& q1 E
  247. # A slave with a low priority number is considered better for promotion, so5 u6 p7 e; ^2 K. [3 G0 k
  248. # for instance if there are three slaves with priority 10, 100, 25 Sentinel will
    - W% H3 @% J) {+ R% s- }
  249. # pick the one wtih priority 10, that is the lowest.
    4 V, R& E# j9 p6 U2 \5 P$ H
  250. #& b$ w& E) ^+ }4 G8 J
  251. # However a special priority of 0 marks the slave as not able to perform the$ Z- O+ W$ l* Z  E
  252. # role of master, so a slave with priority of 0 will never be selected by* b( _' x7 n+ s2 T  u
  253. # Redis Sentinel for promotion.$ R: w. a! B% J: {. M. @) O
  254. #2 \9 f5 I4 R! j: A0 Y0 R+ }) ]( W
  255. # By default the priority is 100.
    - O6 J0 V5 ], r2 l
  256. slave-priority 100
    * n) g2 t& o% b* S

  257. & [6 x5 J. _) m, O  t' w: d3 T
  258. ################################## SECURITY ###################################' Z" L: V" O# j

  259. * o- I. F2 Z) G3 f4 t- a+ Q( x  ~
  260. # Require clients to issue AUTH <ASSWORD> before processing any other
    # K  F* Y( D* S7 }5 v5 }8 \; I
  261. # commands.  This might be useful in environments in which you do not trust
    7 T2 n5 _- z$ e2 ]8 w4 N3 c* x
  262. # others with access to the host running redis-server., a/ ~; J1 j' {: D) r8 d1 O; K
  263. #3 c9 e3 `$ X/ M
  264. # This should stay commented out for backward compatibility and because most
    8 h( i1 n7 {1 X# |" Z
  265. # people do not need auth (e.g. they run their own servers).
    2 X5 o+ X5 K; L7 _4 j
  266. #
    1 ~% y" x1 j( m: W! h
  267. # Warning: since Redis is pretty fast an outside user can try up to0 O9 G% n0 S( L, k; l3 ?% p
  268. # 150k passwords per second against a good box. This means that you should& e- o* \2 U  A7 S
  269. # use a very strong password otherwise it will be very easy to break.4 Q8 w: p1 G' c. Z; T
  270. #
    ( _4 g& g" _+ h. [+ @- j3 |) A
  271. # requirepass foobared
    0 v  r8 B+ G- E( H" ~
  272. - I& y* a8 Z8 U; H
  273. # Command renaming., y/ ~" }1 I4 v3 U. d
  274. #! C& T8 W! E' F! R" L2 a
  275. # It is possible to change the name of dangerous commands in a shared/ v8 N0 W# U* x7 _9 D+ X
  276. # environment. For instance the CONFIG command may be renamed into something7 D6 Z" C. q0 E+ {6 s  j
  277. # hard to guess so that it will still be available for internal-use tools3 M& R% l3 n6 j# G) J7 @
  278. # but not available for general clients.7 p4 u( T0 t) Y+ a' k
  279. #
      ^' z* k& _( j; n9 u! F: u6 u
  280. # Example:- Y( v% N( X$ _; f
  281. #
    ) _* s0 n- B& B0 q
  282. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
    ; a' ?# D& t, r1 x0 k* D! E
  283. #
    & a6 c( l7 u: k. u
  284. # It is also possible to completely kill a command by renaming it into( s' v( ?6 x- j& N' _# A
  285. # an empty string:
    9 a( I+ |/ O* ~2 I
  286. #
    * z( r/ p1 Y$ B, E1 B" h4 F
  287. # rename-command CONFIG ""' p1 P: ~0 m% g' ~/ h! S" a! M
  288. # `" r2 U+ a0 \- u
  289. ################################### LIMITS ####################################0 R; \3 e# a# T! F7 {
  290. # V) p' Q; e' ]: ^+ _
  291. # Set the max number of connected clients at the same time. By default# }/ S. V5 Y9 r2 `- H6 f
  292. # this limit is set to 10000 clients, however if the Redis server is not
    & }( m0 L* _6 T* W% Y
  293. # able to configure the process file limit to allow for the specified limit
    4 D; S7 I/ L) S, n# ]6 I
  294. # the max number of allowed clients is set to the current file limit
    ' i/ z0 e5 C9 Z# n0 F3 y7 ?
  295. # minus 32 (as Redis reserves a few file descriptors for internal uses).
    0 q' a' w/ a" L. O4 X
  296. #
    - E5 H  a- {* j5 H
  297. # Once the limit is reached Redis will close all the new connections sending: l5 T9 V3 C( @( b
  298. # an error 'max number of clients reached'.
      L; h) E& Z0 |5 A
  299. #
    1 g; v7 m9 J; s" g# Y6 e& I3 \
  300. maxclients 500
    5 p$ m+ j- t( Q6 `9 t4 e1 E
  301. $ E' o5 d5 ~: |6 A5 q, M( {) X2 p1 X
  302. # Don't use more memory than the specified amount of bytes.
    6 h$ ~( C; L+ k# v  ?
  303. # When the memory limit is reached Redis will try to remove keys
    , \3 Y7 m# i; b! J. a* p5 \1 A
  304. # accordingly to the eviction policy selected (see maxmemmory-policy)." Z) h& q6 R$ A1 A# t
  305. #3 |: S/ B5 e% S, i
  306. # If Redis can't remove keys according to the policy, or if the policy is
    : ]- s- p8 G3 B: i& q; n! V
  307. # set to 'noeviction', Redis will start to reply with errors to commands
    & o" W+ T- c! J* s( T5 M5 p
  308. # that would use more memory, like SET, LPUSH, and so on, and will continue
    - e  Q$ t# c% W1 q* t$ N
  309. # to reply to read-only commands like GET.8 u2 `3 M8 e- C2 v1 Q  _
  310. #( t, }) b2 o& [( X! y& h2 V& [% i) T
  311. # This option is usually useful when using Redis as an LRU cache, or to set5 L& R6 G/ ^5 H! A
  312. # an hard memory limit for an instance (using the 'noeviction' policy).9 O& i/ ]; {8 T+ _8 \
  313. #+ i+ _& y, @/ R. L+ _0 V
  314. # WARNING: If you have slaves attached to an instance with maxmemory on,; p  o9 t  Q% `5 [3 [8 E5 y
  315. # the size of the output buffers needed to feed the slaves are subtracted
    ! w! W3 y! F/ N! ?
  316. # from the used memory count, so that network problems / resyncs will% E2 ~  x/ F) W; l- }; M
  317. # not trigger a loop where keys are evicted, and in turn the output
    8 o+ ~3 M0 |7 M5 t3 f- Y* Z9 ~7 a' s
  318. # buffer of slaves is full with DELs of keys evicted triggering the deletion
    ' x3 z7 G9 t6 u, X
  319. # of more keys, and so forth until the database is completely emptied.1 r9 ~& u' D* B1 E3 G8 H1 L
  320. #. V! y/ n; j/ ?3 n
  321. # In short... if you have slaves attached it is suggested that you set a lower! d9 U- ^  F9 d
  322. # limit for maxmemory so that there is some free RAM on the system for slave3 f$ u% A! R6 h: S
  323. # output buffers (but this is not needed if the policy is 'noeviction').
    % P) \( w  c" T8 w" |# |
  324. #
    1 G$ S: ?/ U5 t' q' f; A, ]5 w
  325. maxmemory 128000000+ @3 _* H5 R& M) |% K% v

  326. 0 n( \  f% ]" W- |1 P! s* H
  327. # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory3 a& b! r: {0 b5 v6 B
  328. # is reached. You can select among five behaviors:
    + H/ ^" F& L9 j! A
  329. # / S9 O  c! I& E7 O% u
  330. # volatile-lru -> remove the key with an expire set using an LRU algorithm9 e$ N" q* @8 t. S+ O
  331. # allkeys-lru -> remove any key accordingly to the LRU algorithm! |) K+ g" q3 a6 w
  332. # volatile-random -> remove a random key with an expire set$ G9 e! c9 K5 s1 Q5 v; g
  333. # allkeys-random -> remove a random key, any key
    7 V# \/ d/ ~! Z  V, d
  334. # volatile-ttl -> remove the key with the nearest expire time (minor TTL)
    . N# u' Y: f: g8 }/ ]' O! d
  335. # noeviction -> don't expire at all, just return an error on write operations7 X( G# Q6 R6 d: P+ e
  336. #
    ) W8 A6 N0 z9 f, c: V  x
  337. # Note: with any of the above policies, Redis will return an error on write2 Z1 X( s, x% P% X/ f/ w# x
  338. #       operations, when there are not suitable keys for eviction.1 c$ y' ]# q% u; p( b4 v
  339. #
    * I) E2 P" d0 [8 W' d3 c
  340. #       At the date of writing this commands are: set setnx setex append# @( x; c6 v& @( e7 e4 ]
  341. #       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
    % y* V9 v8 _1 c' t* p
  342. #       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
    : ]6 o. b) a+ g9 x& N* ^
  343. #       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby
    4 S  i# s6 X& P: U, U
  344. #       getset mset msetnx exec sort
    4 m" V3 Z- L6 x+ W! [
  345. #; v) L, k0 p- J, y- h
  346. # The default is:
    - L( K+ [5 Y! t- {  `1 a# R
  347. #" n* E. Q( T' r) v0 m/ {# O" r
  348. # maxmemory-policy volatile-lru: O7 p# V; j" c' b3 R6 H
  349. ( b5 ^, {0 U- s. ?$ i
  350. # LRU and minimal TTL algorithms are not precise algorithms but approximated
    , _6 j* J; A- v9 c
  351. # algorithms (in order to save memory), so you can select as well the sample7 i, d4 q5 Z* V
  352. # size to check. For instance for default Redis will check three keys and8 {4 o" E9 [# `  ]/ }5 c
  353. # pick the one that was used less recently, you can change the sample size; j& c7 n  J* x( g8 h* g
  354. # using the following configuration directive.
    & ~0 N' L6 D0 C* p( Y" \" P, _
  355. #9 b, G9 Y* V. }5 V2 F' ?
  356. # maxmemory-samples 3. ?5 z% y7 }4 q

  357. 9 @. c$ j" @" Q" Q: h
  358. ############################## APPEND ONLY MODE ###############################  D1 ^3 Y; e* D1 s

  359. 7 R; Y: v9 L- p$ v; v1 S% r3 B7 o
  360. # By default Redis asynchronously dumps the dataset on disk. This mode is  m/ y8 u: C5 U( ~
  361. # good enough in many applications, but an issue with the Redis process or
    . u/ o9 m, y6 z, s4 J$ f
  362. # a power outage may result into a few minutes of writes lost (depending on
    7 c# ~" x! u* ~
  363. # the configured save points).4 a8 ^8 u& b) v" n3 S5 z5 }# n
  364. #
    4 a. U+ L3 s9 Z/ R3 E8 J/ P8 {4 b
  365. # The Append Only File is an alternative persistence mode that provides$ o$ p$ M0 H- h# u, N. p* P) S1 w
  366. # much better durability. For instance using the default data fsync policy
    9 g( O$ D& h/ p: z7 u3 k
  367. # (see later in the config file) Redis can lose just one second of writes in a
    % [& \" r- }# B; @* `. [
  368. # dramatic event like a server power outage, or a single write if something5 Z5 m- @; i% [' D' S" w  M+ w2 t
  369. # wrong with the Redis process itself happens, but the operating system is
    7 x1 m+ P# K+ [& ~* n: H1 Q
  370. # still running correctly.
    # j# y6 s; E* C  J& K  e: k* a
  371. #
    / [& z' g( `' k% Q7 b: }2 X" a2 z9 H
  372. # AOF and RDB persistence can be enabled at the same time without problems.
    8 d2 I3 B$ L! P" j# q
  373. # If the AOF is enabled on startup Redis will load the AOF, that is the file
    & k+ y6 @# A- |3 y
  374. # with the better durability guarantees.' j$ o0 C6 \: ^1 U8 j
  375. #2 X- A2 F6 i4 B. R' ~6 C
  376. # Please check http://redis.io/topics/persistence for more information.
    " b$ I# h! d% Z( f, s
  377. 1 r$ e0 E1 Z, k" p( t' Q1 N# Z
  378. appendonly no8 `# G3 x, M8 J0 [4 P; r
  379. 0 E  U, J: T- ~3 A% u/ k# C/ H
  380. # The name of the append only file (default: "appendonly.aof")
    ( E+ c0 \" ?  W) N( v! |
  381. # appendfilename appendonly.aof
    2 ^6 i( K, @4 M, \+ g

  382. + Z& V  l( b" i4 p# i* V
  383. # The fsync() call tells the Operating System to actually write data on disk0 Y; D" `! H8 B0 M; K
  384. # instead to wait for more data in the output buffer. Some OS will really flush $ c- Y$ h1 o3 X+ G0 M
  385. # data on disk, some other OS will just try to do it ASAP." A* ], G5 I& o5 Z; _% r- \* d& Q) L
  386. #* i# J( m. o. s: C& |9 J0 I" g
  387. # Redis supports three different modes:$ b5 Y8 C8 H8 l% r0 J9 v8 T
  388. #& G$ }0 g- p: q& e4 l; N+ j5 k5 m
  389. # no: don't fsync, just let the OS flush the data when it wants. Faster.
    , j9 b- W$ B) O1 I2 E0 M. {0 Q
  390. # always: fsync after every write to the append only log . Slow, Safest.
    / K* E; I% W( S3 z
  391. # everysec: fsync only one time every second. Compromise.2 a4 {% X4 ?/ P! k: b3 I
  392. #4 h3 N% M5 r9 ?. W2 I
  393. # The default is "everysec", as that's usually the right compromise between; g& A% B1 @! C4 o
  394. # speed and data safety. It's up to you to understand if you can relax this to# A0 o0 k5 S8 I: c- Q
  395. # "no" that will let the operating system flush the output buffer when
    ) n. B# @8 J# N7 A6 T
  396. # it wants, for better performances (but if you can live with the idea of
    , ?5 ?. u% {9 A8 `! L9 B
  397. # some data loss consider the default persistence mode that's snapshotting),; w* H& T1 ^7 p) B/ a& p
  398. # or on the contrary, use "always" that's very slow but a bit safer than
    $ f+ X$ h5 a9 Z3 e$ u
  399. # everysec.# ^: }* T# X/ v( T; x/ {* B4 E3 ^
  400. #: C6 j7 ^5 n( l. Z/ k
  401. # More details please check the following article:
    , e/ m* Y' l$ |. r" X; T& Q) K
  402. # http://antirez.com/post/redis-persistence-demystified.html
    ( e6 O, g$ K6 d. s; E$ q3 Z' Z
  403. #/ Y$ Q4 c) n0 T6 |1 A) c$ t
  404. # If unsure, use "everysec".
    6 _4 L; f) M3 c

  405. 4 @' @& X. }# i, G/ b& }( }
  406. # appendfsync always
    1 T( Z; L" [3 e+ g# h$ A& G
  407. appendfsync everysec
    * Q  Y/ o. B+ i. q% W' Y# w
  408. # appendfsync no
    * K; F. ]- e2 ?

  409. # X$ O) N4 V6 ~0 y
  410. # When the AOF fsync policy is set to always or everysec, and a background$ h" q: B0 L, I2 y$ T9 [
  411. # saving process (a background save or AOF log background rewriting) is+ H  f/ Z* x8 z' O. r: @. q
  412. # performing a lot of I/O against the disk, in some Linux configurations
    7 k& V, N5 v; U( s! t) L# n5 \
  413. # Redis may block too long on the fsync() call. Note that there is no fix for% I( z6 a0 c2 l# [6 J1 }
  414. # this currently, as even performing fsync in a different thread will block
    / D  H# }# t- j2 y0 x( T
  415. # our synchronous write(2) call.9 C0 @1 g0 p& F6 u
  416. #; c; ]1 n, a8 c% k! n
  417. # In order to mitigate this problem it's possible to use the following option
    , r) [2 G0 I) ?8 M) q" T* z
  418. # that will prevent fsync() from being called in the main process while a
    % u- U' K$ w' f' z9 ~
  419. # BGSAVE or BGREWRITEAOF is in progress.1 Y2 {# q/ B, ?( o, v# o
  420. #  F6 {. X7 o! y6 ]; }- O+ h
  421. # This means that while another child is saving, the durability of Redis is" k0 a7 \( ]* }& \: r( N) n- K
  422. # the same as "appendfsync none". In practical terms, this means that it is
    : I. c, _7 ?6 \7 G8 o) I7 H
  423. # possible to lose up to 30 seconds of log in the worst scenario (with the
    # ?: \5 i* ?8 O: W- S1 Z% }
  424. # default Linux settings).
    5 a6 L+ ?% ~9 F! y! @. d
  425. #
    5 u% V  O& H( R+ T) x, ]% Y) N
  426. # If you have latency problems turn this to "yes". Otherwise leave it as
    9 X2 T" o; z, n8 E3 ?/ Z
  427. # "no" that is the safest pick from the point of view of durability.6 }. c3 {- O$ K- J+ D
  428. no-appendfsync-on-rewrite no: S- y" n' ?: A* @+ I7 H5 c' Q1 }

  429. ! S; h7 ?* z2 h9 m
  430. # Automatic rewrite of the append only file.
    " k( b0 J) F! g% T+ {) U
  431. # Redis is able to automatically rewrite the log file implicitly calling% |5 y. g0 h9 y! r" }
  432. # BGREWRITEAOF when the AOF log size grows by the specified percentage.# ?, M: G% q' A3 a7 [- W
  433. # . D4 _9 D3 b% p7 S8 E
  434. # This is how it works: Redis remembers the size of the AOF file after the
    + L" b) ]7 H3 `, k: T3 s5 j& D
  435. # latest rewrite (if no rewrite has happened since the restart, the size of
    ( i6 V* c4 V4 U' j* q. N6 U" P
  436. # the AOF at startup is used).+ z8 F) H: h4 {- O: [5 }2 h  B$ o
  437. #8 N* V. j* y- m0 g
  438. # This base size is compared to the current size. If the current size is
    2 H( V, T: B( R
  439. # bigger than the specified percentage, the rewrite is triggered. Also
    7 s( U& o  {' c$ d( c! X
  440. # you need to specify a minimal size for the AOF file to be rewritten, this
    1 t- [( W. r6 G9 A
  441. # is useful to avoid rewriting the AOF file even if the percentage increase- l- M' d) i. Z7 l
  442. # is reached but it is still pretty small.
    6 S6 U9 c2 p8 W7 U
  443. ## {+ [/ e7 z+ t6 \! u1 D* F) ~
  444. # Specify a percentage of zero in order to disable the automatic AOF
    : S1 I) b4 _8 m: H: a+ s
  445. # rewrite feature.  @; T3 w$ u' T% y
  446. . s% k0 r3 t: F) B
  447. auto-aof-rewrite-percentage 100+ k) _. P8 L& u5 f* m
  448. auto-aof-rewrite-min-size 64mb
    ( a; m% N4 x9 G1 T6 E( L( s
  449. / y% J2 c" U) D
  450. ################################ LUA SCRIPTING  ###############################: m0 I. \/ U: \1 W5 s

  451. : K: C/ N# V+ X. c4 J- p: e$ ?9 B& V5 I
  452. # Max execution time of a Lua script in milliseconds.
    " ]$ `7 F& O) o$ \: `2 ^+ M  }" a
  453. #
    . M8 k8 B$ a# |: \* b! ^$ a
  454. # If the maximum execution time is reached Redis will log that a script is* J3 P3 s: v5 [" G1 U4 d$ q
  455. # still in execution after the maximum allowed time and will start to8 N% B+ K, a% o- a, r0 b' p4 }
  456. # reply to queries with an error.' a# M2 C8 Q+ w1 f0 Q* Y! A' H
  457. #2 b. M- }, V$ a) _$ A4 V( G0 K. J
  458. # When a long running script exceed the maximum execution time only the
    6 {0 E& N& `7 D; E3 [. S
  459. # SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be
    0 u$ N0 Q. |8 K& S; ]* e
  460. # used to stop a script that did not yet called write commands. The second/ |, d! S9 W& k. u
  461. # is the only way to shut down the server in the case a write commands was
    4 e. Z2 f+ ~# C; l
  462. # already issue by the script but the user don't want to wait for the natural
    : c4 Z" v" K' N1 h3 o
  463. # termination of the script.6 z0 H. V5 |1 j( M/ R
  464. #0 V1 c) Q: U/ ~' h; u
  465. # Set it to 0 or a negative value for unlimited execution without warnings.
    / H1 e2 C- Y! G$ M6 ]
  466. lua-time-limit 50004 e2 x; Q% }2 G1 M# w) A
  467. $ x' Q2 q* t9 d: C0 {
  468. ################################## SLOW LOG ###################################5 O9 |+ e% \: K! |2 H* b$ `5 ]8 R

  469. 8 `) k4 {5 D3 H) `
  470. # The Redis Slow Log is a system to log queries that exceeded a specified: g: t: {. o# H4 k# i
  471. # execution time. The execution time does not include the I/O operations
    + b" ]; Y7 I# g/ V; ^0 G
  472. # like talking with the client, sending the reply and so forth,, Q% u! B+ p; ?4 P1 s3 I5 D
  473. # but just the time needed to actually execute the command (this is the only$ L( p0 X* x- x0 h
  474. # stage of command execution where the thread is blocked and can not serve
    ( h0 L. K3 i* i" e
  475. # other requests in the meantime).
    # O0 h+ t& [0 W4 N' l  u) S; K
  476. #
    " N* b8 T2 C# h8 R% C/ q
  477. # You can configure the slow log with two parameters: one tells Redis# g/ g2 {7 N. f. b
  478. # what is the execution time, in microseconds, to exceed in order for the
    5 j. C. D7 }9 y6 Y! ~
  479. # command to get logged, and the other parameter is the length of the
    % |. c3 ~- H* V% A- i# w
  480. # slow log. When a new command is logged the oldest one is removed from the3 R; t8 u* n2 v# L
  481. # queue of logged commands.* G' x0 t8 B2 z

  482. 3 x8 X/ V" n. z  i  l
  483. # The following time is expressed in microseconds, so 1000000 is equivalent3 u! f3 z' _0 F% a- {: n6 @
  484. # to one second. Note that a negative number disables the slow log, while
      d  E  D0 ~# f
  485. # a value of zero forces the logging of every command.
    / Z! g/ ]* K' u4 Z2 ^) w% i
  486. slowlog-log-slower-than 10000
    5 z6 G$ Q# t1 _7 P* f

  487. ! [7 \3 k. ~6 L8 E
  488. # There is no limit to this length. Just be aware that it will consume memory.' {4 O* v3 I) L7 l: X& R2 R
  489. # You can reclaim memory used by the slow log with SLOWLOG RESET.7 z* E0 Q' l- A3 t3 h
  490. slowlog-max-len 128# a, X0 O! Q" a$ s! }2 u* Y8 R

  491. * {0 h4 M  n9 V& T; i
  492. ############################### ADVANCED CONFIG ###############################
    1 Q8 p% u1 Z$ l1 M

  493. % b6 C2 b1 F8 C" q" j. W/ i9 t
  494. # Hashes are encoded using a memory efficient data structure when they have a8 a+ N# v& M9 m2 D+ V2 J
  495. # small number of entries, and the biggest entry does not exceed a given/ M, P7 g: g- w& s1 G1 S4 ?/ W
  496. # threshold. These thresholds can be configured using the following directives.8 W6 q' B) g# c$ x
  497. hash-max-ziplist-entries 512
    0 S, N! f  D1 ?! Z
  498. hash-max-ziplist-value 64
    ! \7 h+ `; M2 z6 u/ U

  499. : Y$ F8 w( Y8 X. R1 R
  500. # Similarly to hashes, small lists are also encoded in a special way in order
      E* [- p; V8 p+ a, K' W& |
  501. # to save a lot of space. The special representation is only used when0 Z( T  v0 @  s7 V2 b
  502. # you are under the following limits:* g% A$ \3 Y5 B0 F
  503. list-max-ziplist-entries 512& m: R2 o- T8 x8 {8 R
  504. list-max-ziplist-value 646 q  o9 \( Q6 f4 V! A; B

  505. 8 w' [/ Y7 A, I! G- f8 K
  506. # Sets have a special encoding in just one case: when a set is composed
    * p/ R4 \. a: {9 D+ R- V
  507. # of just strings that happens to be integers in radix 10 in the range+ U& E* }1 i6 z! u8 l" e
  508. # of 64 bit signed integers.
    * M5 Y" q4 N3 R5 D; x+ L6 u4 ^
  509. # The following configuration setting sets the limit in the size of the
    2 N! e' d9 I% R* t& ]
  510. # set in order to use this special memory saving encoding.
    7 J8 c2 X! N* X2 B: ~& B
  511. set-max-intset-entries 5129 g5 ]4 ]# `7 T- g8 ~# P# m  H
  512. ; K: l1 A" J; }0 U- b+ f) c' I' C
  513. # Similarly to hashes and lists, sorted sets are also specially encoded in* F5 L( R! n* f1 v3 O; _& a
  514. # order to save a lot of space. This encoding is only used when the length and
    7 b: @8 m2 G+ k! g, q2 z
  515. # elements of a sorted set are below the following limits:; q, S! P  T% W- r$ |. K5 c4 a4 G
  516. zset-max-ziplist-entries 128
    , S# F* R; b5 _- I( P
  517. zset-max-ziplist-value 64
    ! f% W7 S! y  ?* ]9 p$ m: i1 O2 f
  518. 8 U) h- A  a$ }% I
  519. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in# l: H4 s& B# }: Z
  520. # order to help rehashing the main Redis hash table (the one mapping top-level$ Z+ ~% h1 B9 G* f/ {0 Y3 o
  521. # keys to values). The hash table implementation Redis uses (see dict.c)
    2 b& @" F* y$ M
  522. # performs a lazy rehashing: the more operation you run into an hash table! u' z1 ]5 _" o/ L
  523. # that is rehashing, the more rehashing "steps" are performed, so if the
    ( p; s- n; v0 l) L* @
  524. # server is idle the rehashing is never complete and some more memory is used' f) e" [5 s- {4 M9 Z) s. m, D: d6 e
  525. # by the hash table." R5 S- b$ g0 N5 ^# u
  526. #
    6 Y# ~7 c# M; N4 Q& z, k
  527. # The default is to use this millisecond 10 times every second in order to
    * ^4 F- U) M. C4 V& M$ z6 Z
  528. # active rehashing the main dictionaries, freeing memory when possible." b9 h5 Q7 L& Z) y( B
  529. #8 i% a$ o- E. ~! [
  530. # If unsure:4 s( \0 Q* Z4 l& j# S
  531. # use "activerehashing no" if you have hard latency requirements and it is
    5 W. R* k% J6 U! ^
  532. # not a good thing in your environment that Redis can reply form time to time
    * A. A) g9 R1 f- F6 P4 s
  533. # to queries with 2 milliseconds delay.
    : i. {: `! Y/ \: V( e
  534. #
    3 H4 f" V9 H" r1 t' _
  535. # use "activerehashing yes" if you don't have such hard requirements but3 ^: N, l" x; N$ M, y4 Y/ c
  536. # want to free memory asap when possible.
    % n5 S3 }. Y( P3 `7 d
  537. activerehashing yes' B  [! p. ]; ^( `) C* \, X$ k
  538. 4 ~" [1 t' O! Q+ |$ L
  539. # The client output buffer limits can be used to force disconnection of clients
    0 o4 H1 Z% j7 |  r& X) x
  540. # that are not reading data from the server fast enough for some reason (a1 i( ?1 g8 J( ~' v) u% ]3 W
  541. # common reason is that a Pub/Sub client can't consume messages as fast as the- O* V4 G2 Q+ |* ~8 L; p, q
  542. # publisher can produce them).
    , i/ s: y4 ^* ?% z/ z0 J8 p! K
  543. #
    + T- k/ K  m5 |
  544. # The limit can be set differently for the three different classes of clients:
    " W; h' S! F$ B5 ^  ?) H0 c
  545. #) f" y4 Z' o0 k4 X" W
  546. # normal -> normal clients
    9 H+ L8 U) P3 l( n8 _' H
  547. # slave  -> slave clients and MONITOR clients
    - ?5 E( U5 F; a6 I# M" E0 q
  548. # pubsub -> clients subcribed to at least one pubsub channel or pattern
    + \0 D" o; X+ i* M$ X
  549. #* {7 B# c: `4 C+ ~
  550. # The syntax of every client-output-buffer-limit directive is the following:
    2 k4 [/ W4 {* I$ x3 K3 K0 [0 t
  551. #
    7 @. `; Q" R/ w6 G
  552. # client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>
    ' |' ?7 s+ w4 j
  553. #
    9 i) H: _6 H: H+ E
  554. # A client is immediately disconnected once the hard limit is reached, or if4 t* \: y" q1 i& g
  555. # the soft limit is reached and remains reached for the specified number of
    " {" ~( x$ k; \. d" z
  556. # seconds (continuously).1 q0 |7 ^; h$ ?2 {, T4 U/ d
  557. # So for instance if the hard limit is 32 megabytes and the soft limit is$ v8 \) j& l$ I0 h1 Y- m  b* \
  558. # 16 megabytes / 10 seconds, the client will get disconnected immediately
    ( Y2 g4 f) R: T2 O" Z' ^2 O$ S1 N
  559. # if the size of the output buffers reach 32 megabytes, but will also get1 n" Z+ l& z, J* X) z* e' Q$ X: ?3 r
  560. # disconnected if the client reaches 16 megabytes and continuously overcomes
    3 G8 z- E; X6 X- ^
  561. # the limit for 10 seconds.( d7 x- K( N+ [$ @# Y' ~. R
  562. #- o& e2 v; a1 F/ }
  563. # By default normal clients are not limited because they don't receive data# c( k4 n$ f! r- Z
  564. # without asking (in a push way), but just after a request, so only  O' l+ S7 Q& P0 T
  565. # asynchronous clients may create a scenario where data is requested faster
      P% a4 F8 o1 e5 ~: L6 T) Z
  566. # than it can read.$ g3 f* b3 ^# r5 ~) ?5 m
  567. #1 p( z4 ]7 ~3 e
  568. # Instead there is a default limit for pubsub and slave clients, since( \' m' a: k5 D1 o
  569. # subscribers and slaves receive data in a push fashion.: J) k5 t7 M+ H* g6 ]
  570. #
    % H9 i4 j6 l: }- [
  571. # Both the hard or the soft limit can be disabled by setting them to zero.& `" {; G3 X/ \4 k
  572. client-output-buffer-limit normal 0 0 0: a' g3 M1 t7 \1 k1 ?* z  U
  573. client-output-buffer-limit slave 256mb 64mb 60& P# C7 I8 \4 Q/ p3 U
  574. client-output-buffer-limit pubsub 32mb 8mb 60
    9 \) l$ e0 I0 Y, V9 ]7 w* m

  575. # B8 E; ]7 c  U3 u  f8 Q
  576. ################################## INCLUDES ###################################7 R% m! M, A! |6 g9 }2 g/ C+ [

  577. - a7 D) T. h& g: S! ]4 S
  578. # Include one or more other config files here.  This is useful if you
    + A5 \2 F- l' u8 g8 L
  579. # have a standard template that goes to all Redis server but also need
    : f2 I+ G5 Q) `  h5 L6 n
  580. # to customize a few per-server settings.  Include files can include; ~  z, M3 H& E3 g. ]
  581. # other files, so use this wisely.
    ( m: J# b5 Z4 A' s4 T. j# r
  582. #
    ) @/ I0 S2 X1 o! s* ]1 X5 O+ t
  583. # include /path/to/local.conf
    ) X4 e% h* A: r9 H( m
  584. # include /path/to/other.conf        
    . F9 ~1 X- d' H
  585. ##########################配置文件结束################################
    ! v( m: L: g- P- k
  586. 第三步:启动进程$ s# T$ A4 z9 a9 U8 }0 x" ?
  587. #redis-server /etc/redis.conf
    6 G- I$ m1 ~6 R2 J9 Q2 j1 x
  588. 查看进程有没有成功启动
    / n, t% A3 m/ R8 Z# b. g
  589. #ps -ef | grep redis
    + g4 m( y, X9 _- \3 {
  590. 测试输入一个键值- B7 Y- K/ q* W$ L. T
  591. #redis-cli set test "testredis": Z" {+ m4 R3 A1 K$ |/ ]' f
  592. 获取键值
    8 \5 t0 w, Q5 A" T# F
  593. #redis-cli get test6 T( }3 L& c0 s3 a* N* A$ T6 D: V
  594. * f$ N1 y" O, Z/ [5 S# t  m/ l
  595.   a- P, Q/ Y0 v3 e1 [+ s
  596. 第四步:关闭redis  (这个是更改配置文件后 正常的重启方式  不重新加载redis配置跳过)- b( L7 ?' t! S1 k6 r0 B0 ~
  597. # redis-cli shutdown      //关闭所有    8 q) `* z2 i( O, r/ n& J
  598. 关闭某个端口上的redis    9 v+ A) ]1 `% `8 Z
  599. # redis-cli -p 6397 shutdown  //关闭6397端口的redis  
    3 y% S- G  K. c. i& Q: F
  600. 说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename  dump.rdb  - q2 Z. y( O0 z( v9 J2 P4 _
  601. % }% }9 ], q( R! I0 M) i+ `

  602. 1 l. t% V0 e. S  S1 V+ w! |
  603. 第5步:php扩展安装
    ! b8 f9 l7 P& A/ F' U# {5 p
  604. phpredis PHP扩展下载地址 ; G) H6 g* n, W* e* L( q  h
  605. https://github.com/nicolasff/phpredis/tree/2.2.2
    . w6 s* x( v, S+ t
  606. 选择最新版本下载zip - j) _' }9 C7 Y2 x
  607. + x7 P, E8 |- Q; \2 J
  608. 然后自己上传zip  用unzip解压到当前目录 unzip 文件名- A) u" l7 k( Y7 D; o
  609. : d) Q8 U! m9 q( N) l
  610. # cd owlient-phpredis-90ecd17/   #打开解压后的文件夹里面  这个解压后的目录 要是不知道 可以输入 "dir" 查看
    ' w4 Y5 u$ g( {! x. B% t
  611. # /www/nginx_php-5.2.17/bin
    5 g$ l: E; V) N4 F$ {
  612. # ./configure --with-php-config=/www/nginx_php-5.2.17/bin/php-config- q* F1 d' L% ]- n1 W' j1 d- a9 [
  613. #make; w5 G& D% e- O2 ~! e5 F% r# s
  614. #make install   #记录产生的redis.so路径8 G9 F/ D9 N" V

  615. # Z! }" R2 b0 E2 z/ a# t
  616. 修改php.ini文件
    ; A. `, X' ?6 X0 y
  617. 在php.ini中添加如下一行:. D1 ?3 Y6 m( X! G- v8 k
  618. extension=/?/redis.so  #是刚刚记录的产生redis.so的路 写在 ?那  L( ~& C9 f" Q
  619. 重启 使之生效:% y/ h, f$ L1 @6 s. V, N) N
  620. /usr/local/php/sbin/php-fpm reload
    : g1 M* T% @4 M# u& S
  621. /usr/local/nginx/sbin/nginx -s reload , I) Q0 U; Q7 E4 D2 C

  622. & q1 o0 P7 \; |, _
  623. 将 Redis 作为 Linux 服务随机启动
    / ~! B1 E* h& K4 J4 ~; a+ v0 ]  P& V
  624. vi /etc/rc.local, 加入代码:- H+ l5 c' H3 T# W  m. L1 N
  625. /root/redis-2.6.10/src/redis-serve  #路径看情况修改 ' D# [; X# Y( D5 [7 n
  626. + d' S( ?/ T; q- e* U
  627. redis-cli -h localhost -p 6379 info  #命令要在redis目录下面执行7 @# N9 t* f% |; I* b3 j
  628. 提供host为localhost,端口为6379,redis服务的统计信息8 r+ f! D* S4 v5 ?4 A2 G

  629. 8 V5 t8 P  j6 Z8 H, c) t; t
  630. ( D/ Z6 D% f+ Z+ X) Y
  631. 就这样你的web服务器就支持redis了 记得要在 给dz 的配置文件 加上12.0.0.1哦
    ' x6 ~: _3 i0 ]
  632. dz配置文件在 config目录下面的 config_global.php
    2 |  M/ g0 H4 q$ G, C8 H
  633. $_config['memory']['redis']['server'] = '127.0.0.1';
    : ^7 u2 A4 Y' _1 `  y! m
  634. $_config['memory']['redis']['port'] = 6379;7 I4 h  ~2 z( f" l; M
  635. $_config['memory']['redis']['pconnect'] = 1;
    . U! \$ S; _* c. `% X% {+ `
  636. $_config['memory']['redis']['timeout'] = '0';1 {: i3 Q$ J- n5 Z- \+ J; B
  637. $_config['memory']['redis']['serializer'] = 1;; q6 V) s' q: p3 n) o. z% D' L
复制代码
关注微信公众号《神采飞扬网》,即可获取最新回复通知!

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

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

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

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