分享到:
发表于 2018-11-16 12:42:28 | 显示全部楼层 |阅读模式
环境配置
- q3 g( b: U* G7 A( B- i1 j4 J5 P6 u2 m" ^2 [2 V7 |$ J
# T8 M: A, \/ X4 v/ B
http://www.discuz.net/forum.php? ... amp;highlight=REDIS
关注微信公众号《神采飞扬网》,即可获取最新回复通知!
 楼主| 发表于 2018-11-16 12:43:33 | 显示全部楼层
http://www.discuz.net/forum.php? ... 648&highlight=REDIS
& p0 W' @$ Q+ T: z无意间测试 单机状态 redis相当给力 测试1000请求/s  单纯的 get 和set 居然只用了 0.01秒 当时我惊呆了: d& L: j8 v% G" e

7 C$ U6 X0 o& v$ J! E: U) Yhttp://www.discuz.net/forum.php? ... 731&highlight=REDIS! i' M: i$ @6 Y

9 ?) `" b- e. |$ d) Ghttps://wenku.baidu.com/view/265a5ce176a20029bc642d0b.html
) `6 F$ }# z7 O% T
1 I# A: O: H1 \6 }+ i& J=======================================+ J" h" I( d- R+ `3 `8 f
  1. 连接上 ssh
    % Q! R" _  Q5 T! X# L

  2. 4 h0 _$ v. r' p% v# [8 q2 K

  3. % `" |/ r' ^" H& D8 M0 p9 N' b1 N
  4. 第一步:下载redis
    + X; k) D" T& E- B' g6 \
  5. # wget http://redis.googlecode.com/files/redis-2.6.10.tar.gz
    " k; P/ G, f1 @( U
  6. # tar zxvf redis-2.6.10.tar.gz
    9 D4 ]3 q: Q9 i0 Z9 \
  7. # cd redis-2.6.10& Q1 c: v) k" x9 m
  8. # make / k  O; V6 y. Z$ @: A' l2 p
  9. # make install  
    2 Y( L* c) Z/ n' a$ T/ l
  10. #cp redis.conf  /etc/ #复制配置文件到etc目录下面) _+ ^  H/ V* C6 W: x2 z1 U
  11. 第二步:修改配置+ h8 c2 b$ J! S9 E2 l, ]; b$ K7 j, o
  12. #vi /etc/redis.conf) [3 k8 |- K/ M) W* ^# s
  13. ######################下面是无措的配置文件 复制过去就成#########1 {) I9 L: q! d2 i% O! ^- I
  14. # Redis configuration file example
    $ i1 j/ r) {; R. M( W, e8 \
  15. 1 g' S! H" B3 R( ~( _9 |
  16. # Note on units: when memory size is needed, it is possible to specify* l% M! @. D3 t0 g  G6 M
  17. # it in the usual form of 1k 5GB 4M and so forth:: t( c0 o# V! n' A
  18. #
    3 E/ k! |; Q; X2 B
  19. # 1k => 1000 bytes. z6 j* @* w+ s8 b- Y8 F
  20. # 1kb => 1024 bytes" k; \4 K# Y, l
  21. # 1m => 1000000 bytes9 A, O0 h% B1 u( S7 B! B' |2 t
  22. # 1mb => 1024*1024 bytes4 y6 U" P$ ~8 l" r
  23. # 1g => 1000000000 bytes. G) n' o  \- G5 z$ W9 C
  24. # 1gb => 1024*1024*1024 bytes
    % f& ]; ?! y$ k" ?5 _
  25. #' V% m: r$ |( w* j
  26. # units are case insensitive so 1GB 1Gb 1gB are all the same.
    & f# ~2 {3 V0 w* N

  27. $ x* W1 k, `3 e6 l( }- T
  28. # By default Redis does not run as a daemon. Use 'yes' if you need it.5 A& p0 s1 Y* y2 H
  29. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.! f1 t2 @2 s: D! P
  30. daemonize yes; |7 y4 U# \0 X

  31. 4 Y8 O9 ~# F: u/ c7 z6 `) u
  32. # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
    " W$ U1 l) B4 ?" c0 H$ y
  33. # default. You can specify a custom pid file location here.
    6 N) V& O, b0 o6 j6 J
  34. pidfile /var/run/redis.pid
    ) U4 N3 q% j/ I1 j% M4 e

  35. % h1 M$ g$ f6 H; W
  36. # Accept connections on the specified port, default is 6379.
    / U/ T' q  m$ B
  37. # If port 0 is specified Redis will not listen on a TCP socket., k$ d( g+ ]0 K7 u- y& v8 o
  38. port 6379
    8 E4 h, ~' V9 D. G2 x# C$ {
  39. 4 s" X" m/ x+ U0 k
  40. # If you want you can bind a single interface, if the bind option is not5 ~0 J& E- B( q- v% W
  41. # specified all the interfaces will listen for incoming connections.4 Q7 F; Y2 @0 W' L- b( l* Z, }
  42. #
    : h0 S5 ^# ~" o& p
  43. # bind 127.0.0.1& b! V. J+ Z/ q6 x5 h

  44. & d( K+ a4 b0 y( Z& H
  45. # Specify the path for the unix socket that will be used to listen for- ~" ^4 t5 j7 B+ A+ s% Y" O
  46. # incoming connections. There is no default, so Redis will not listen
    ' i2 o: X% |2 [2 U
  47. # on a unix socket when not specified.
    & p9 v+ z6 u2 i: N/ Y& R
  48. #
    6 S9 \1 M- D2 W
  49. # unixsocket /tmp/redis.sock
    . m5 r5 C1 @( {$ l( O# t3 z0 K
  50. # unixsocketperm 755# h+ i% i7 Y- U; ^8 t

  51. 5 ^5 ~9 p, H- K9 \
  52. # Close the connection after a client is idle for N seconds (0 to disable)7 c9 F1 l/ m* _8 n6 w% Q- C) r- d
  53. timeout 300% z6 X# B& z- f3 f/ G! K
  54. & O. c: }2 n' x/ i. Q( j
  55. # TCP keepalive.
    : `/ G: U2 K! U5 V5 D+ V
  56. #& z# r. l, T9 k* V" Z* q+ D
  57. # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
    " R4 Z+ D; U# Y4 W. r: n
  58. # of communication. This is useful for two reasons:. Y; U) C/ }4 Z" ~/ G& B5 U( l
  59. #
    ; ^/ r' o* B" s# d* Y# e6 C* o5 n
  60. # 1) Detect dead peers.7 A/ ~5 G% k+ [' ]5 ~) B+ U% M
  61. # 2) Take the connection alive from the point of view of network
    - N; r' J6 W1 i/ m" E2 d! D& B
  62. #    equipment in the middle.
    & S) U# p7 }+ x+ ]  v" h, E
  63. #: b4 |) w! K# d; |; U# p
  64. # On Linux, the specified value (in seconds) is the period used to send ACKs.
    ; c, P" r: T5 ]* @7 F! }, m4 @; z
  65. # Note that to close the connection the double of the time is needed.
    - q( q5 x) U- K) [; w
  66. # On other kernels the period depends on the kernel configuration.
    ) _- i8 D: P4 @
  67. #8 n4 e3 z& P/ s/ k, q0 |$ {; l. o
  68. # A reasonable value for this option is 60 seconds.
      ?. V0 v; j" G1 o; }4 o8 B+ D
  69. tcp-keepalive 0
    6 U9 p$ F1 o" v1 v% C4 Q
  70. 4 ?: X/ [  d5 ?( `
  71. # Specify the server verbosity level.
    + B3 ]2 ~9 y/ }; _
  72. # This can be one of:
    2 D7 [9 y3 s$ h1 t7 O
  73. # debug (a lot of information, useful for development/testing)  \8 k$ t! W( b1 q1 F7 ~
  74. # verbose (many rarely useful info, but not a mess like the debug level)
    ! z9 W* x+ C) J: M3 {( [
  75. # notice (moderately verbose, what you want in production probably)
    6 k1 T/ F$ M: G. b  L
  76. # warning (only very important / critical messages are logged)4 y2 t, E$ m1 Y* P
  77. loglevel warning! ?) q) E8 ~( D: H6 G8 w2 t
  78. ) [1 w8 i! K6 ~6 x  X4 c# C! Q" p
  79. # Specify the log file name. Also 'stdout' can be used to force
    + M# Y' n' i$ X! F( z
  80. # Redis to log on the standard output. Note that if you use standard. Y, Z, }5 A2 T( {; V$ ]" T
  81. # output for logging but daemonize, logs will be sent to /dev/null2 d8 x9 k" c* c( i) I# U1 ^
  82. logfile /var/log/redis.log2 ^1 s- A2 |8 |  `
  83. 3 l& S, J' n% G/ a
  84. # To enable logging to the system logger, just set 'syslog-enabled' to yes,
    5 t0 g% h& r* a% W
  85. # and optionally update the other syslog parameters to suit your needs.0 n( n& F/ Z9 o+ R5 w6 p
  86. syslog-enabled yes1 B) H! \& z, T
  87. ) S/ z4 j) ^' A' F
  88. # Specify the syslog identity.
    ' @' _8 p- |3 j% {: p0 ^
  89. # syslog-ident redis* }/ e7 q( V" f5 o" ~; x+ o6 v* ^* Z

  90. 7 r4 @' R% @, ]0 d( Z
  91. # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
    3 u" `) D2 b/ l/ c
  92. syslog-facility local01 u: x; r1 m+ U' W  F  y- _
  93. & J7 J9 @0 ^. _1 ^& }" a/ F( f
  94. # Set the number of databases. The default database is DB 0, you can select, O+ I8 r. S- t! J0 K5 U) j
  95. # a different one on a per-connection basis using SELECT <dbid> where0 [) Q% V, I4 t: A9 M( Y
  96. # dbid is a number between 0 and 'databases'-1
    6 ^/ X9 }# M  c7 j; k
  97. databases 16
    * a" ?; I" x. q4 k1 X" \$ T  s

  98. . v4 k3 {& ]/ C$ e
  99. ################################ SNAPSHOTTING  #################################; Y7 ]2 R0 s7 D- ~8 Y
  100. #
    $ G6 n( v8 w4 d: c
  101. # Save the DB on disk:
    6 [2 l" `5 I' P1 T
  102. #
    7 s- f6 Z# T$ W  v8 V' T6 @4 H3 S
  103. #   save <seconds> <changes>
    & e! P2 L. h" e( y3 q4 @
  104. #
    1 L+ _5 O1 d& S% C
  105. #   Will save the DB if both the given number of seconds and the given& |5 ]3 K% b* Y$ C. z8 K- ?
  106. #   number of write operations against the DB occurred.% b) I* `% N3 }! G, L8 V# k
  107. #
    5 ^! w6 m% s+ X6 u- B2 Z) F
  108. #   In the example below the behaviour will be to save:5 F0 v: p; |- Y) {0 n0 S/ }1 `
  109. #   after 900 sec (15 min) if at least 1 key changed
    ) L  u- Q; l% }, g
  110. #   after 300 sec (5 min) if at least 10 keys changed
    " _/ f' |9 y+ p$ z; F
  111. #   after 60 sec if at least 10000 keys changed
    1 L" D6 b: b1 D4 O8 g" U( _
  112. #/ H, _4 ^% t/ I- q: j. m0 g' g
  113. #   Note: you can disable saving at all commenting all the "save" lines.9 O  p0 l# O7 O' T. i4 f/ j
  114. #
    + a0 R# T% ^! d  I# ^2 ?8 S
  115. #   It is also possible to remove all the previously configured save2 {  W, \  c5 ^: O8 ^$ b) g. p- f
  116. #   points by adding a save directive with a single empty string argument* ^) ^7 f- A6 H; I; M
  117. #   like in the following example:
    5 z( `: B6 h4 O- M2 [8 u
  118. #
    4 S0 ~$ F3 [3 \
  119. #   save ""
    8 J6 u9 L) e4 U4 m- E  o

  120. 3 n0 f7 A$ y( ?0 `
  121. save 900 1
    + i0 F  {3 t: _. x+ d
  122. save 300 10  O( s- g: r8 d3 y; ?0 s8 Q5 R& u
  123. save 60 10000
    0 c( Z2 F! S# f: ~. P6 l+ ^- a
  124. 2 ]% \6 W9 u' u/ r
  125. # By default Redis will stop accepting writes if RDB snapshots are enabled! S! ^7 G5 y/ |; R* Y( Y4 R
  126. # (at least one save point) and the latest background save failed.
    ! T; x1 O2 h" y9 ~
  127. # This will make the user aware (in an hard way) that data is not persisting
    " z& B5 Y6 G1 o( O& C! }# f
  128. # on disk properly, otherwise chances are that no one will notice and some
    + m) |; d; t) A$ L
  129. # distater will happen.: l6 C9 g  r5 a  D& b
  130. #
    - k, Y8 r7 O' V% R
  131. # If the background saving process will start working again Redis will
    & Q4 ^& Z* i& n# u9 T$ F
  132. # automatically allow writes again.  V3 m. o7 q6 e$ c& Q
  133. #% V- ~$ g; L+ }1 y6 c
  134. # However if you have setup your proper monitoring of the Redis server1 l1 M* [3 q6 @. F) `& N3 ~$ _& o
  135. # and persistence, you may want to disable this feature so that Redis will6 W. v6 r% y) ~" Q
  136. # continue to work as usually even if there are problems with disk,8 C& }9 Q/ Q3 y8 t
  137. # permissions, and so forth.( d0 R5 d" T# h% {6 {: N/ l8 @' \
  138. stop-writes-on-bgsave-error yes
    $ C8 ]/ s# ~8 m( Y) Y7 ]

  139. . j( v! N, W  [) }, M
  140. # Compress string objects using LZF when dump .rdb databases?
    $ ~+ U. E' T- I' T, T
  141. # For default that's set to 'yes' as it's almost always a win.7 G% H$ O( A# a5 g
  142. # If you want to save some CPU in the saving child set it to 'no' but
    4 r" a. j1 J: n" {
  143. # the dataset will likely be bigger if you have compressible values or keys.
    2 }- Y+ y. [5 L! s
  144. rdbcompression yes
    0 W- `9 }( a2 I7 s

  145. 2 I2 |. p$ l5 l+ w8 a
  146. # Since version 5 of RDB a CRC64 checksum is placed at the end of the file.* O: J  _( |1 L
  147. # This makes the format more resistant to corruption but there is a performance4 Y0 T9 ?. T9 l* l; A& C# p3 h4 C/ [
  148. # hit to pay (around 10%) when saving and loading RDB files, so you can disable it
    ! w% y1 _) t$ w# P- e; u
  149. # for maximum performances.
    2 E% X3 r5 f, l7 c
  150. #
    ( s: C& }$ o- E2 Q/ c% s$ g
  151. # RDB files created with checksum disabled have a checksum of zero that will( C. g, Q. {7 H' b4 c0 o  Y
  152. # tell the loading code to skip the check.
    # `) r/ {" x0 Z# @; ~2 Q+ x! M4 q7 |
  153. rdbchecksum yes
    5 ^: S4 }" U8 C2 x

  154. : {) h7 R& i  q+ j
  155. # The filename where to dump the DB
    " S. O& [+ \; v6 ^
  156. dbfilename dump.rdb$ G! f& e, o' p2 @$ y% e& i
  157. + o, P( M, z7 ?
  158. # The working directory.0 W- `5 c  d  @; a7 F9 s
  159. #& n' b/ o% {* _6 Z: h
  160. # The DB will be written inside this directory, with the filename specified
    2 [  N+ O6 }, B; a8 K( {/ N
  161. # above using the 'dbfilename' configuration directive.6 F8 N3 w7 \) `- H
  162. #
    1 Q$ p6 U7 u3 e" C3 G2 h
  163. # The Append Only File will also be created inside this directory.5 w' L: k$ h% i1 V# F2 l2 u7 m
  164. # % F* ]) c& [( C% t! T, a
  165. # Note that you must specify a directory here, not a file name.% ~% {5 ^( D* ~& C/ G
  166. dir /var/db/redis
    7 T0 z5 ^- s; b" A  Q2 @, r
  167. & _6 u+ a; p0 W1 C% A& S
  168. ################################# REPLICATION #################################5 ^5 E; z- e( x' `

  169. / z+ Q- e  U* A/ A! S
  170. # Master-Slave replication. Use slaveof to make a Redis instance a copy of0 q# L7 e8 R) n
  171. # another Redis server. Note that the configuration is local to the slave
    ( L5 B8 _( L, w0 _4 ?
  172. # so for example it is possible to configure the slave to save the DB with a
    9 E! B1 P3 ^! ~+ e1 M' H& V& a
  173. # different interval, or to listen to another port, and so on.: a* H* G% N; {. F  H0 N1 ?- S2 ]/ o
  174. #
    + F/ {5 H8 N; `2 ~' c+ {
  175. # slaveof <masterip> <masterport>) p; i4 L/ l" h7 e, B; x0 z; t6 n

  176. ' Q1 Y& O& h& O: ]0 ]  Q/ m  E
  177. # If the master is password protected (using the "requirepass" configuration
    " j5 P) x; i7 c: U) m+ X4 y
  178. # directive below) it is possible to tell the slave to authenticate before  k' U) _' M; B8 m4 o; V
  179. # starting the replication synchronization process, otherwise the master will. h  X/ y9 N6 L* q: s4 o& T
  180. # refuse the slave request.
    ( E% F! P; u( v# u
  181. #
    0 N. w1 t3 j1 `! A6 n7 ~) M  Y
  182. # masterauth <master-password>& d/ ^7 @' E1 _+ T; @0 l+ s" G. Z

  183. * y1 Y; V3 W8 Y( M' T  u
  184. # When a slave loses its connection with the master, or when the replication
    6 z! D# T2 A8 [4 l( s% K9 C
  185. # is still in progress, the slave can act in two different ways:
    ' B; ~% B, u8 K  K$ Z& O" X6 q
  186. #
    : q$ y) U  d5 f# `6 H
  187. # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will
    0 V1 [( q: q  }/ Q
  188. #    still reply to client requests, possibly with out of date data, or the0 }1 X+ I9 r- A0 g4 [! F: O
  189. #    data set may just be empty if this is the first synchronization.
    ! w& l( s/ l" P+ `& [
  190. #
    / _9 G7 U' F. t! V# _8 ^9 s
  191. # 2) if slave-serve-stale data is set to 'no' the slave will reply with! K  b/ x; Q: n4 B
  192. #    an error "SYNC with master in progress" to all the kind of commands
    4 }8 J5 B; q$ m
  193. #    but to INFO and SLAVEOF.
    ! L9 @7 I* u6 p/ q5 Y9 k& \
  194. #9 Q) }: a1 N1 g
  195. slave-serve-stale-data yes
    5 F+ ]. L5 i, s2 f+ C
  196. % y6 ~6 ?* L- {- h- C1 d
  197. # You can configure a slave instance to accept writes or not. Writing against
    0 W" ?  s  y* R  @, s$ d  B
  198. # a slave instance may be useful to store some ephemeral data (because data
      y- C: T% x! h( A; x9 l
  199. # written on a slave will be easily deleted after resync with the master) but
    # ~' h" T+ ~& q  V
  200. # may also cause problems if clients are writing to it because of a0 K& n  K* {2 ^% W1 ^# t
  201. # misconfiguration.
    * D; S' i; x6 ]
  202. #
    , b, \' W8 ?7 d- I' N
  203. # Since Redis 2.6 by default slaves are read-only.
    3 r9 m; E. A5 v7 m' _3 t
  204. #3 Q- Y: y2 r7 c% X2 g
  205. # Note: read only slaves are not designed to be exposed to untrusted clients0 P; w" ^8 E( e0 d6 {: d# J+ l
  206. # on the internet. It's just a protection layer against misuse of the instance.# ]" Q5 i  h- X! v
  207. # Still a read only slave exports by default all the administrative commands  ^$ k9 Z, z; L7 Z7 b& e: h) B
  208. # such as CONFIG, DEBUG, and so forth. To a limited extend you can improve7 Z( o0 J4 s( O- a
  209. # security of read only slaves using 'rename-command' to shadow all the
    ' V# l* a& c; B+ g1 p
  210. # administrative / dangerous commands.
    ) l/ \. a; X5 V( S! V$ z
  211. slave-read-only yes6 x0 b% I  g* S

  212. / t8 M# k& |% R; E
  213. # Slaves send PINGs to server in a predefined interval. It's possible to change
    9 f8 V; v  `. B9 p  u$ h/ m: {1 d
  214. # this interval with the repl_ping_slave_period option. The default value is 10
    8 {0 }) ^; g5 ?( I# Z$ W
  215. # seconds.
    / B8 ~) p0 O, @& b# k2 B
  216. #
    ( m) @5 |  }1 X, X* U4 f
  217. # repl-ping-slave-period 10( ^* o2 m% G, `9 B/ @: ]

  218. , ^  t+ w, z* T( Q; a! l
  219. # The following option sets a timeout for both Bulk transfer I/O timeout and' E# E% v+ f* n$ e$ H
  220. # master data or ping response timeout. The default value is 60 seconds.
    2 a  _* S+ C5 x. v+ U: V
  221. #
    ( C' ~( L; c( J7 X; C
  222. # It is important to make sure that this value is greater than the value9 Y' b- a4 F( K* E% ?9 _
  223. # specified for repl-ping-slave-period otherwise a timeout will be detected. m3 d9 e5 j0 G7 }  H* d9 a" @1 J
  224. # every time there is low traffic between the master and the slave.( P5 ]; H3 R: Y+ i! \2 `
  225. #0 m1 F9 \4 b% n
  226. # repl-timeout 60
    & v2 f; X5 x' L1 J) w* U
  227. " u1 `/ X2 v/ Z$ X) c6 b
  228. # Disable TCP_NODELAY on the slave socket after SYNC?
    ' W( p: L7 D2 B
  229. #8 O- O& j" L- z5 X6 |" g  x
  230. # If you select "yes" Redis will use a smaller number of TCP packets and
    $ C# N( y' `7 S6 P2 J% q
  231. # less bandwidth to send data to slaves. But this can add a delay for
    9 A4 p; r/ S8 P5 M! N
  232. # the data to appear on the slave side, up to 40 milliseconds with
    ( j8 Z! }  a1 E: z# m
  233. # Linux kernels using a default configuration.  q: C  E2 v4 H9 l5 \& L  Q
  234. #
    / l5 H$ L3 X$ ?1 r$ }2 F1 Y
  235. # If you select "no" the delay for data to appear on the slave side will9 \3 J. \  t! V# `- y/ d; T& c
  236. # be reduced but more bandwidth will be used for replication.
    - W2 O  B; a- u: v* d* V4 [1 X
  237. #
    0 Z' B( ?: A0 s! s
  238. # By default we optimize for low latency, but in very high traffic conditions
    . w! e% v. t/ u' w
  239. # or when the master and slaves are many hops away, turning this to "yes" may; p: ~6 K; H6 U: O+ ^
  240. # be a good idea.
    . s/ L- }2 P. u( P1 p( k
  241. repl-disable-tcp-nodelay no
    . F. ^' G2 A9 @1 W
  242. 0 c0 t1 N% d+ w  v8 I& A
  243. # The slave priority is an integer number published by Redis in the INFO output.7 D& E: Q: K& c* c3 n4 x$ G
  244. # It is used by Redis Sentinel in order to select a slave to promote into a
    : k0 S/ A: n- A8 ]+ U3 N6 }; M2 ?* Q
  245. # master if the master is no longer working correctly.6 j4 ~3 ?; ?: q
  246. ## h8 x& N# F: h3 P( p
  247. # A slave with a low priority number is considered better for promotion, so
    2 i; Y! N6 g5 `
  248. # for instance if there are three slaves with priority 10, 100, 25 Sentinel will. v* _. u5 w; ^6 H1 F5 F* b( D
  249. # pick the one wtih priority 10, that is the lowest.5 K  L& g2 K' S
  250. #) f! q1 p. u) K6 e; ~
  251. # However a special priority of 0 marks the slave as not able to perform the% S; @. e2 z5 H' }2 c2 {
  252. # role of master, so a slave with priority of 0 will never be selected by
    . w# X: g; m1 P: ]
  253. # Redis Sentinel for promotion.# J2 }' _% k5 ~3 F
  254. #
    " ]8 A/ A2 h3 I+ S" }6 i$ I; T
  255. # By default the priority is 100.
    + [  m) a9 S6 I" V1 ]  |* n
  256. slave-priority 100
    - d6 I4 |- M/ R: |4 o. C7 z
  257. " O0 u4 ?5 y/ P! Z
  258. ################################## SECURITY ###################################
    $ u3 L( u2 n0 V0 v; }
  259. * {! o. @' [) G
  260. # Require clients to issue AUTH <ASSWORD> before processing any other
    ; u* Q+ `  Z& t! |3 {5 L/ M
  261. # commands.  This might be useful in environments in which you do not trust
    6 B  ?: K& Z+ E) W- V/ P0 e5 R
  262. # others with access to the host running redis-server.+ |& V5 h" C9 X3 D9 W
  263. #
    4 e" z! w) P6 M3 ~! r; K7 W
  264. # This should stay commented out for backward compatibility and because most5 V% F- _, w! ?& r& A) z+ W
  265. # people do not need auth (e.g. they run their own servers).  o' C9 j' T0 r) ]  D/ u
  266. # 5 i" Q& `1 t) C$ Q6 s5 M* e
  267. # Warning: since Redis is pretty fast an outside user can try up to) }4 b9 `% b; J9 {; Y- c/ Z+ H3 a
  268. # 150k passwords per second against a good box. This means that you should
    . P) V) [  m1 U; _
  269. # use a very strong password otherwise it will be very easy to break./ q" E; {( {% h
  270. #3 O7 k0 |. I0 _/ T" R$ T) n
  271. # requirepass foobared
    - C8 \, B8 {6 p6 d1 Y1 X7 X* Y$ z4 A/ F

  272. 9 H- W4 }" \% n4 B  Z1 m+ X) [
  273. # Command renaming.* L6 p* ]6 J! P' I3 B/ n( H
  274. #) ]4 c4 A" g" b1 i1 o
  275. # It is possible to change the name of dangerous commands in a shared
    * A! T7 M" d1 h& x9 ^
  276. # environment. For instance the CONFIG command may be renamed into something% V7 e9 T* C* o1 I, p: z: n8 V' ~# _
  277. # hard to guess so that it will still be available for internal-use tools
    ' A: k4 G! J/ ~
  278. # but not available for general clients.
    5 s% h5 E& R3 t3 U' G; J
  279. #
    2 f6 C0 F. k6 R$ d
  280. # Example:8 F( E6 O; R- |0 l3 B! {( J/ }
  281. #! m4 f5 {" T0 _# D  l0 v) n3 n
  282. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
    2 ], R+ C4 Y! z+ f' }* R
  283. #
    $ G2 {: }# T. U$ S+ v1 Y
  284. # It is also possible to completely kill a command by renaming it into7 @) ?. c" c$ s+ B  E2 [3 O) c6 S
  285. # an empty string:7 i* D$ o  @# K) q- @! E3 q. E
  286. #$ P. }2 q) P* x+ y& x  ^9 @
  287. # rename-command CONFIG ""2 g4 w2 [! M) }5 l" }* p
  288. $ V2 J$ T+ w; P" `# L
  289. ################################### LIMITS ####################################7 B* ^7 A- |4 s! d

  290. - w4 y; V) `6 M+ v- c; h0 C6 i
  291. # Set the max number of connected clients at the same time. By default
    5 M0 f& a* X5 ?6 k( ?
  292. # this limit is set to 10000 clients, however if the Redis server is not& C9 s1 t: h( v8 V' l  Y- O! R" h
  293. # able to configure the process file limit to allow for the specified limit
    8 O7 O4 V) b" O- V6 Q
  294. # the max number of allowed clients is set to the current file limit% {4 h. G9 [! M0 m7 A2 ?
  295. # minus 32 (as Redis reserves a few file descriptors for internal uses).5 H7 t  P% }8 x6 t! b; P
  296. #
    2 p5 u& f/ [2 @* G- d
  297. # Once the limit is reached Redis will close all the new connections sending1 C, j8 q* L1 H2 k: F
  298. # an error 'max number of clients reached'.
    ' T, n6 b! ?0 D0 {- I, ?
  299. #: N7 G2 V, ?7 l1 q. T8 s' x
  300. maxclients 500
    ! W! p: h. L8 q" i9 ?' P2 N( ?/ o

  301. # X& ?% ]  f, Y. c
  302. # Don't use more memory than the specified amount of bytes.
    - |8 e0 U  k9 ?2 `
  303. # When the memory limit is reached Redis will try to remove keys
    . ?1 ]# s; w! I9 W; \
  304. # accordingly to the eviction policy selected (see maxmemmory-policy).- t- J0 Q8 u! }+ F7 d& m
  305. #  T7 H. @3 X" R7 O0 Q
  306. # If Redis can't remove keys according to the policy, or if the policy is* Q3 ~9 a& K' m
  307. # set to 'noeviction', Redis will start to reply with errors to commands
    ! e2 C4 B% `- r' a! X: I1 E
  308. # that would use more memory, like SET, LPUSH, and so on, and will continue
    : F0 X' j0 c  p" s3 Z4 A# s
  309. # to reply to read-only commands like GET.
    ' o5 l  _& `/ d( Q  [5 m- |
  310. #
    8 z: g9 A: [4 H; B) Z6 {% m2 ^7 K
  311. # This option is usually useful when using Redis as an LRU cache, or to set& |0 {2 E" `; I, ]) d/ }
  312. # an hard memory limit for an instance (using the 'noeviction' policy).' L3 h) ]& B6 f. h, N( G
  313. #
    1 j" E) B2 W  ~' ^' B- [
  314. # WARNING: If you have slaves attached to an instance with maxmemory on,
    % \0 X) r" @1 Z( b; x
  315. # the size of the output buffers needed to feed the slaves are subtracted, |$ a: w$ \" |* e4 ?, b
  316. # from the used memory count, so that network problems / resyncs will, X4 ]3 N" q# X
  317. # not trigger a loop where keys are evicted, and in turn the output
    & A6 d- O8 }! @# S5 O3 w
  318. # buffer of slaves is full with DELs of keys evicted triggering the deletion7 i  ]$ t3 c* g3 Z4 h6 C
  319. # of more keys, and so forth until the database is completely emptied.
    ' l% V1 h+ F& {. Z% H
  320. #+ u; ~" O* g4 u$ K
  321. # In short... if you have slaves attached it is suggested that you set a lower
    + z; N6 J1 l4 ~+ Z1 H
  322. # limit for maxmemory so that there is some free RAM on the system for slave
    9 e8 a0 a7 W! g& h% o
  323. # output buffers (but this is not needed if the policy is 'noeviction').
    . r5 S& X2 g& }  m2 ^; p& ?! i
  324. #; b' p* ?# a* m, D9 L0 }. s
  325. maxmemory 128000000
    6 e( s) i" u3 K% u1 W7 ?$ m% p9 P: V
  326. ' d0 X/ F5 o( G% K9 R
  327. # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory5 L( V5 I* N$ w0 u; u& S
  328. # is reached. You can select among five behaviors:2 x* F% W( x  P- k5 [& F' R
  329. #
    * I  h+ f) A5 n6 A( Y
  330. # volatile-lru -> remove the key with an expire set using an LRU algorithm% q1 C! A' j" ?! R# V5 y2 x6 i" A
  331. # allkeys-lru -> remove any key accordingly to the LRU algorithm$ F( h$ @: u5 N1 s
  332. # volatile-random -> remove a random key with an expire set) {5 g8 o, i9 H
  333. # allkeys-random -> remove a random key, any key6 {0 Z+ A2 j" v0 K( a9 e7 y+ Y( [
  334. # volatile-ttl -> remove the key with the nearest expire time (minor TTL)  D' a* J0 z' l
  335. # noeviction -> don't expire at all, just return an error on write operations
    - N/ m' w  H9 L0 T' V$ v' I
  336. #
    8 y# l4 @, z3 ^5 B
  337. # Note: with any of the above policies, Redis will return an error on write& \( y! {& E# _" }
  338. #       operations, when there are not suitable keys for eviction.
    1 a! o. s$ `, P9 ?) x
  339. #2 e  Q/ _" y% S! v: G8 R" F
  340. #       At the date of writing this commands are: set setnx setex append' R& M/ [9 r" R( X
  341. #       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
    / T3 m% v2 Q8 y6 j
  342. #       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
    ' u# z* [% M+ y" [$ w4 X, z% W
  343. #       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby/ |# V6 e. p* G/ t6 @
  344. #       getset mset msetnx exec sort
    & c. f& }: _/ q9 A
  345. #! ]6 V( w, ?# v; n, i7 i1 E
  346. # The default is:
    9 U/ M) t6 d, [. x
  347. #
      F4 q$ r( E) r% ~$ n$ b+ ?1 u
  348. # maxmemory-policy volatile-lru
    : }' b; ]: g) o; m: L
  349. ) Y, V9 u2 d# R
  350. # LRU and minimal TTL algorithms are not precise algorithms but approximated  x3 i7 h, O5 y6 C' W; X; H
  351. # algorithms (in order to save memory), so you can select as well the sample5 `2 K6 v9 I& G- N
  352. # size to check. For instance for default Redis will check three keys and$ I2 J! h) @" M0 k
  353. # pick the one that was used less recently, you can change the sample size7 }. O7 q* v$ {
  354. # using the following configuration directive.2 W# S1 _/ P9 q
  355. #- r% [2 \7 t' L' L: f
  356. # maxmemory-samples 3
    ! H: z4 j  p% L

  357. 3 y8 Q3 p, l1 Q: O- n2 h9 x; P
  358. ############################## APPEND ONLY MODE ###############################
    8 w3 C0 R7 J% J
  359. # }4 x$ m( _" V! |
  360. # By default Redis asynchronously dumps the dataset on disk. This mode is3 {5 a+ @) G+ z9 o" }1 @# k2 A
  361. # good enough in many applications, but an issue with the Redis process or( q2 k" c) q5 e& e% c
  362. # a power outage may result into a few minutes of writes lost (depending on# Y" c: ~1 ~: c- D
  363. # the configured save points).
    * }& ~3 u3 f+ |2 v9 f$ p4 O
  364. #% s2 p! I4 a* u! N  S" K
  365. # The Append Only File is an alternative persistence mode that provides: V# `% g# t3 e3 }
  366. # much better durability. For instance using the default data fsync policy
    ' m0 s$ O  ?; Q) n8 V" F6 G
  367. # (see later in the config file) Redis can lose just one second of writes in a
    # ^7 [- `5 v* i
  368. # dramatic event like a server power outage, or a single write if something9 }5 o9 T5 ]) w, A( @4 L- I
  369. # wrong with the Redis process itself happens, but the operating system is3 [. o7 \0 P7 u$ ]' U' n+ D
  370. # still running correctly.
    ( f6 W) `0 O, z) `% Z; H( t
  371. #1 d7 X  q" z5 T
  372. # AOF and RDB persistence can be enabled at the same time without problems.% }# l. J  ]' R$ @# P9 |$ D$ Z
  373. # If the AOF is enabled on startup Redis will load the AOF, that is the file
    3 J4 ^2 j' `" u
  374. # with the better durability guarantees.8 ?# q% D) B! A) y0 n
  375. #- W) ~1 x3 F9 m9 \$ c* K
  376. # Please check http://redis.io/topics/persistence for more information.
    + |6 k4 o7 v3 v- ?  r0 v& ^

  377. % q1 Q9 S2 `/ d9 G
  378. appendonly no* l$ `$ }* t+ @( p5 D- W) {
  379. . `5 u2 `- q( l* c* }/ ~* u: G+ @
  380. # The name of the append only file (default: "appendonly.aof")) `2 V" }) `, W1 l, R
  381. # appendfilename appendonly.aof
    5 h5 m) p4 R7 f

  382. + n! U0 H1 i+ w1 t, n1 u8 e
  383. # The fsync() call tells the Operating System to actually write data on disk7 K; X% w: M2 @6 q" t+ D0 @
  384. # instead to wait for more data in the output buffer. Some OS will really flush ( F; h) t+ x- O3 Y: N1 v9 I" ^
  385. # data on disk, some other OS will just try to do it ASAP.( G% _) G! k3 e4 J
  386. #- ^. r$ g* V# r' E- B1 R
  387. # Redis supports three different modes:: |( b# p: P: T8 _9 A4 R
  388. #% a9 v" V# s9 I6 |& e8 R( R
  389. # no: don't fsync, just let the OS flush the data when it wants. Faster.3 {! a1 t  q; j
  390. # always: fsync after every write to the append only log . Slow, Safest.
    , j$ Z+ x3 W4 k9 _
  391. # everysec: fsync only one time every second. Compromise.% k% h. f7 p& y3 R$ z3 E- G
  392. #
    7 f6 c4 x4 \$ n  L
  393. # The default is "everysec", as that's usually the right compromise between4 H1 E- x  `5 X1 i1 ~% z3 `
  394. # speed and data safety. It's up to you to understand if you can relax this to
    ) `) ^$ p" |) z
  395. # "no" that will let the operating system flush the output buffer when
    & E8 J% v6 q8 a/ i
  396. # it wants, for better performances (but if you can live with the idea of
    . J$ x1 @& T! K  O- a6 n
  397. # some data loss consider the default persistence mode that's snapshotting),
    $ l. g" N7 Q  v9 g
  398. # or on the contrary, use "always" that's very slow but a bit safer than
    , Q1 K: X9 Z- y" _
  399. # everysec.
    # b& l- B0 S( E4 A  f* v/ Y
  400. #/ a& a2 ]; e1 M, u' p
  401. # More details please check the following article:
    : N' j7 [4 M  n% b2 a
  402. # http://antirez.com/post/redis-persistence-demystified.html
    + S. n( ^- Z$ v  e+ |' j
  403. #
    $ G; {' X' B$ ^5 o
  404. # If unsure, use "everysec".
    2 i+ |$ L4 j& P; n$ ]9 q+ d) [

  405. 1 n/ |% r* z3 k1 k+ [8 W/ Z+ H5 A
  406. # appendfsync always
    + N) E2 _2 l6 O1 P! _) |
  407. appendfsync everysec
    6 }! Z; B! m$ ?: ]
  408. # appendfsync no) P; I+ N4 V3 @! D0 @7 @
  409. 0 e! w! \4 w7 X& f1 l0 D
  410. # When the AOF fsync policy is set to always or everysec, and a background
    / ]8 ~0 W& Q* V9 D. t% T
  411. # saving process (a background save or AOF log background rewriting) is6 X; B. q, c( j6 S
  412. # performing a lot of I/O against the disk, in some Linux configurations4 B& E7 r8 i2 T' `+ N+ d% U
  413. # Redis may block too long on the fsync() call. Note that there is no fix for1 C% p  ~% q3 }& j3 y7 K0 E5 W$ o
  414. # this currently, as even performing fsync in a different thread will block
    - f' d/ n- B+ b  D; t3 t
  415. # our synchronous write(2) call.1 d0 @; \* D$ A2 ]% m
  416. #
    . H' C) H' Z9 D; c9 s  f& m
  417. # In order to mitigate this problem it's possible to use the following option
    # ~% v$ e  m. F1 _3 B. u8 Y0 ~! r
  418. # that will prevent fsync() from being called in the main process while a
    6 G! X1 {6 u' k! n
  419. # BGSAVE or BGREWRITEAOF is in progress.% j7 D" k! d5 s2 z7 H7 b7 o+ p
  420. #
    7 I; i% t/ E9 _# p3 ]0 @
  421. # This means that while another child is saving, the durability of Redis is
    ( k3 ~; z6 J9 }- [& R$ q9 Q" L
  422. # the same as "appendfsync none". In practical terms, this means that it is0 W' ]* N& P$ F+ Q0 ]1 t
  423. # possible to lose up to 30 seconds of log in the worst scenario (with the. L& @3 r5 F- `( g3 R
  424. # default Linux settings).
    6 A/ z: d& }% N8 m# f
  425. # 0 @9 o% m6 G. [+ ?
  426. # If you have latency problems turn this to "yes". Otherwise leave it as/ W+ [, d% |% \% [. ]$ G& f
  427. # "no" that is the safest pick from the point of view of durability.
    7 g# Q$ V! t, C' V  ~
  428. no-appendfsync-on-rewrite no8 D- |  q. `% N
  429. - b: B0 T: R# M3 |2 a# N* x$ l
  430. # Automatic rewrite of the append only file.0 O6 y+ ~5 r7 B' ]( ]' O! i
  431. # Redis is able to automatically rewrite the log file implicitly calling/ A: Q" J& I1 p% V$ H- o
  432. # BGREWRITEAOF when the AOF log size grows by the specified percentage.
    ! Z  T9 |, V; d4 G4 n8 V
  433. # + a, y! M- q( c8 p+ ]6 m
  434. # This is how it works: Redis remembers the size of the AOF file after the
    1 i, P( J& U% O& V# ?
  435. # latest rewrite (if no rewrite has happened since the restart, the size of* x9 O: ^8 u; L  h+ @
  436. # the AOF at startup is used).
    5 s% R8 l! G6 z
  437. #/ |% W( G) |$ s7 X0 O
  438. # This base size is compared to the current size. If the current size is
    ' V- `$ r1 C9 A4 Y
  439. # bigger than the specified percentage, the rewrite is triggered. Also
      M# t9 A, H2 n, z, G
  440. # you need to specify a minimal size for the AOF file to be rewritten, this6 t9 \! D$ e( r( f6 z
  441. # is useful to avoid rewriting the AOF file even if the percentage increase, @7 k4 m* ]$ a1 j( L' Q8 d
  442. # is reached but it is still pretty small.
    ) H) Y. d6 a7 _; ^6 P. K
  443. #
    ' V2 K+ H3 W5 T3 h$ Y4 v7 Q
  444. # Specify a percentage of zero in order to disable the automatic AOF6 T, B8 X4 G7 _1 J
  445. # rewrite feature.* I* d% m0 \+ u, t. f

  446. / \# C$ \) p" L' {+ }4 f. G3 U
  447. auto-aof-rewrite-percentage 100
    - C. V7 w2 g9 x7 v" V6 M) r- ~* x
  448. auto-aof-rewrite-min-size 64mb  o2 f6 T* y& d/ n: c
  449. 8 L" H9 h& V8 W+ p1 p9 ^9 ?* ]
  450. ################################ LUA SCRIPTING  ###############################9 d& b7 h# B2 [$ z

  451. 4 i& U3 ^5 ^* d2 U: [3 q, }5 |
  452. # Max execution time of a Lua script in milliseconds.( J$ H5 }) t' D# l5 `
  453. #/ J5 C! ]; x" X" v
  454. # If the maximum execution time is reached Redis will log that a script is
    ; i& v4 `: u& m. x% N! h
  455. # still in execution after the maximum allowed time and will start to
    / s- M) S# \3 q0 z* W+ x/ o
  456. # reply to queries with an error.7 _% I6 ]5 x7 X# q
  457. #1 |3 D4 V5 |* L+ d$ l2 N0 L
  458. # When a long running script exceed the maximum execution time only the
    ; s2 ~" W$ |8 W0 d
  459. # SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be$ i8 J" V. o' G8 `
  460. # used to stop a script that did not yet called write commands. The second
    9 w4 X. Y  ]; _2 o( `% R$ r
  461. # is the only way to shut down the server in the case a write commands was
    7 g& _4 k0 e( F& a% i# v1 |6 ^
  462. # already issue by the script but the user don't want to wait for the natural
    ; t* l$ J; w. A* M4 J' x( M: [
  463. # termination of the script./ k; ?+ H# H" A8 H
  464. #
    1 }3 X4 w* Z. f9 ~; K! f
  465. # Set it to 0 or a negative value for unlimited execution without warnings.- Q9 E) Y, S+ c8 S  f
  466. lua-time-limit 5000( e# K0 n& n* _$ J6 P4 ~
  467. , j3 E1 q9 G8 ^+ U8 b5 f
  468. ################################## SLOW LOG ###################################
    ' D5 d& }  f3 X. \
  469. 5 N' F! f, @! l, k
  470. # The Redis Slow Log is a system to log queries that exceeded a specified8 J6 ~! n# D7 U/ @5 q  O. D5 u
  471. # execution time. The execution time does not include the I/O operations4 L! U" U! D, b- M/ l% O% f5 V8 Z
  472. # like talking with the client, sending the reply and so forth,% X/ j% q: ~/ s1 h
  473. # but just the time needed to actually execute the command (this is the only
    8 _8 \& l# z  v& Z
  474. # stage of command execution where the thread is blocked and can not serve  M  ^# I5 s- j0 c3 R
  475. # other requests in the meantime).
    + p6 O+ C1 k/ K, |% O
  476. #
    ! ~6 S- h" U3 U- C# u8 e$ S# {8 z
  477. # You can configure the slow log with two parameters: one tells Redis* e- f1 u$ R8 R  E
  478. # what is the execution time, in microseconds, to exceed in order for the
    ! y: {) i3 I( @# ^  s
  479. # command to get logged, and the other parameter is the length of the
    ! i3 B3 s- G) S1 Z) k% p0 R
  480. # slow log. When a new command is logged the oldest one is removed from the2 Z+ `8 O% G* \: N
  481. # queue of logged commands.$ G3 F6 N3 k4 y# i9 u; e$ q& q
  482. 9 {# ~% |9 H1 t) ?( L: i) E
  483. # The following time is expressed in microseconds, so 1000000 is equivalent0 {* [- d; q8 c- r$ j' {
  484. # to one second. Note that a negative number disables the slow log, while  d  R5 W: `" S$ W  v! i
  485. # a value of zero forces the logging of every command.. Q# y, B8 u2 R4 Z( y
  486. slowlog-log-slower-than 100009 _3 r/ e7 c) N' b$ m/ l: }

  487. - |2 P. F: @8 G1 T
  488. # There is no limit to this length. Just be aware that it will consume memory.
    5 s3 o) i& K. y& w: Z& E
  489. # You can reclaim memory used by the slow log with SLOWLOG RESET.! j# {' R: c. O9 B9 E
  490. slowlog-max-len 128- O+ |% V. }2 ?; Z; i+ \* T

  491. * \: p6 P& |0 x/ n" C& F; P% c9 v
  492. ############################### ADVANCED CONFIG ###############################* V6 q" ^2 j2 k& R) l" B* W

  493. : C5 |8 A8 Y8 C' I
  494. # Hashes are encoded using a memory efficient data structure when they have a  s- L  n" }! l! S# ~+ [$ D
  495. # small number of entries, and the biggest entry does not exceed a given
    6 {, A' d% u9 I/ m: X
  496. # threshold. These thresholds can be configured using the following directives.
    , q+ k0 b' a) u
  497. hash-max-ziplist-entries 5123 B% v; |  N8 n; n* q
  498. hash-max-ziplist-value 64
    ! K( }0 t* h( I! B8 ]

  499. ' a- b3 X0 P! q, |4 r9 y* w
  500. # Similarly to hashes, small lists are also encoded in a special way in order
    % [" l8 _* _' d! u7 l
  501. # to save a lot of space. The special representation is only used when' Z' y4 W5 q$ i( Z
  502. # you are under the following limits:: H/ U" V" B7 S
  503. list-max-ziplist-entries 5127 J, D: k) j9 F! F$ V  |$ E
  504. list-max-ziplist-value 64
    , ?0 h. `3 V' c% h; ]( s

  505. 2 W- i6 m7 z/ P$ \
  506. # Sets have a special encoding in just one case: when a set is composed8 c) i% D5 A, u! G7 v
  507. # of just strings that happens to be integers in radix 10 in the range* @3 d4 u1 q! L) U
  508. # of 64 bit signed integers./ x( P  g+ L. V$ o7 Z& y; K0 q' g5 x
  509. # The following configuration setting sets the limit in the size of the, z3 i- U3 F+ H" ^
  510. # set in order to use this special memory saving encoding.
    3 ^& C1 H6 |% c: U1 a
  511. set-max-intset-entries 512! W$ i: B6 j  G4 ^7 l1 R' b, X
  512. ( B+ ^$ F6 t) @
  513. # Similarly to hashes and lists, sorted sets are also specially encoded in$ ^, R; s0 W/ E1 _
  514. # order to save a lot of space. This encoding is only used when the length and7 o( w1 M, v# ~3 z* M( q/ H
  515. # elements of a sorted set are below the following limits:( G, r/ k0 q( ?+ r0 g, ?: A
  516. zset-max-ziplist-entries 128
    9 `( T# B4 U1 ?0 f
  517. zset-max-ziplist-value 64, ~& N! w  a9 ?, h
  518. 1 u: k1 f" n4 L) x% D
  519. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in: c# Q1 ]2 ^: O: R: C2 a; l' k% z0 o
  520. # order to help rehashing the main Redis hash table (the one mapping top-level$ \% S3 s& x4 H( P. O& K# @  T
  521. # keys to values). The hash table implementation Redis uses (see dict.c). M* C3 ]/ r' J' X' {- J$ v
  522. # performs a lazy rehashing: the more operation you run into an hash table
    2 [! Q- u; A) t' H7 `8 z
  523. # that is rehashing, the more rehashing "steps" are performed, so if the
    & O& w  I( k+ y6 f7 s. r# }* s; d! |+ B: V
  524. # server is idle the rehashing is never complete and some more memory is used- t- T( p5 }5 e
  525. # by the hash table.$ I/ K) u/ v; s) x. g. A/ m
  526. #
    ) T0 d& R% ]7 A% k! K0 m9 o
  527. # The default is to use this millisecond 10 times every second in order to
    ; H8 A3 L# l% }; D
  528. # active rehashing the main dictionaries, freeing memory when possible.  x" ~9 z6 \* b" M' ?* x
  529. #
      y: D/ U0 N$ Q* Q8 t3 u
  530. # If unsure:
    5 J+ E) U! a+ v# |8 m5 v( H
  531. # use "activerehashing no" if you have hard latency requirements and it is) Z0 v; U; r" `8 c; V9 R/ ~4 ~
  532. # not a good thing in your environment that Redis can reply form time to time
    7 V* A5 [1 E  g9 @: f2 j, I
  533. # to queries with 2 milliseconds delay.+ f+ ]/ D4 H  |: x% B3 O; s
  534. #$ }' f. J) @9 c7 ]) j0 l2 z# h
  535. # use "activerehashing yes" if you don't have such hard requirements but
    # ?/ c+ Q" ^8 p2 z% F" ^& n. T  p
  536. # want to free memory asap when possible.4 A, J7 C" x1 e( H1 z
  537. activerehashing yes
    $ A8 E- ~% G- W+ ?

  538. * ]5 A% N  j( C2 h  ]
  539. # The client output buffer limits can be used to force disconnection of clients
    9 [  |/ p, c$ C' Z  l- n' O
  540. # that are not reading data from the server fast enough for some reason (a! l% b0 Y8 |3 h1 t
  541. # common reason is that a Pub/Sub client can't consume messages as fast as the$ M5 f  c; `6 B7 @
  542. # publisher can produce them).
    - ~- ~$ N  S- x+ I8 r9 C& f2 M
  543. #6 r* y6 |( E# f6 m) e0 l
  544. # The limit can be set differently for the three different classes of clients:1 f% n" D2 n$ _
  545. #0 K! u" n* z& f) }
  546. # normal -> normal clients; l, {& G2 s8 J- J3 x- R
  547. # slave  -> slave clients and MONITOR clients6 [$ y" B2 r) [& C" |( Q8 t2 U
  548. # pubsub -> clients subcribed to at least one pubsub channel or pattern
    , O$ }0 |4 y0 ~$ g" ?. S
  549. #
    2 r$ O. h- r( o9 p* [/ V
  550. # The syntax of every client-output-buffer-limit directive is the following:, i7 G  L6 G% O( |  [' E
  551. #) f- W7 g& e  G0 |8 N0 f
  552. # client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>
    ( ~  I/ H% `+ N0 V9 o- J: y
  553. #9 b- |; P5 ~6 z, T1 ~6 v
  554. # A client is immediately disconnected once the hard limit is reached, or if
    ' r$ m. o6 B! I# R; G* [2 l: r8 Q
  555. # the soft limit is reached and remains reached for the specified number of' B2 Y- J4 J' Z6 M2 m2 E- M- n7 a* H
  556. # seconds (continuously).+ `; P1 Z+ f3 a& Q9 e* A4 q
  557. # So for instance if the hard limit is 32 megabytes and the soft limit is
    6 [/ F+ c6 h1 s7 e
  558. # 16 megabytes / 10 seconds, the client will get disconnected immediately
    ; e% ]4 w; C3 W/ i5 x
  559. # if the size of the output buffers reach 32 megabytes, but will also get" l+ j' `$ B( u* P! v
  560. # disconnected if the client reaches 16 megabytes and continuously overcomes
    / B2 O- n% D! i; _
  561. # the limit for 10 seconds.
    " P5 o3 ]( ~) z$ w, A5 X
  562. #
    - l( {# Q$ n+ _  K% D
  563. # By default normal clients are not limited because they don't receive data; I2 m4 @1 H: o1 u( z
  564. # without asking (in a push way), but just after a request, so only; s3 R- Q( _4 ^5 w  \" t" M0 i
  565. # asynchronous clients may create a scenario where data is requested faster
    & X5 {& R; a1 X( W# Y. U% D
  566. # than it can read.
    # S1 w3 N# ^" X6 N+ I3 J4 ^
  567. #
    . B+ z' _; ]8 e4 r% `  y
  568. # Instead there is a default limit for pubsub and slave clients, since
    7 A, V+ h' f# a6 V* T
  569. # subscribers and slaves receive data in a push fashion.
    - ^, w" w4 e! J5 @
  570. #
    8 @. c; m0 M* N0 j  ]( M
  571. # Both the hard or the soft limit can be disabled by setting them to zero.
    ( F: t& H  v: k) |4 b
  572. client-output-buffer-limit normal 0 0 0! S; t+ q9 o1 Z8 t7 S3 ^5 [
  573. client-output-buffer-limit slave 256mb 64mb 60
    9 \* k8 P2 a' G/ |
  574. client-output-buffer-limit pubsub 32mb 8mb 60
    2 l; I) A! g: o( T# i, R! [( ?$ z

  575. # H) z# o+ E+ v3 `( r) [; W
  576. ################################## INCLUDES ###################################' g$ M- K# K" Z8 P

  577. ) Q. \7 E4 O. n, E2 |) ]8 ~
  578. # Include one or more other config files here.  This is useful if you
    # U/ Z* m& ?9 S
  579. # have a standard template that goes to all Redis server but also need) W% w. ]; l# I1 u" G3 d; ]
  580. # to customize a few per-server settings.  Include files can include
    ) n: x( O$ I- w8 p  z0 a
  581. # other files, so use this wisely.& `, O- o% M* E& W
  582. #% O! [. b# [+ U
  583. # include /path/to/local.conf; H9 e5 g3 a# U5 `6 c4 r
  584. # include /path/to/other.conf        * T/ W% K6 I7 O0 L' \2 X( C
  585. ##########################配置文件结束################################
    4 v0 _6 N. p5 ~9 F, \( V
  586. 第三步:启动进程
    : {9 C6 {" U4 J& B" b6 N1 ?/ a
  587. #redis-server /etc/redis.conf
    . t) m+ v/ _: h
  588. 查看进程有没有成功启动/ S. X" |3 I4 D& Z
  589. #ps -ef | grep redis   E0 |0 i# `: [7 @& d+ J
  590. 测试输入一个键值
    - \% |) i6 G  B, j# O/ A! F
  591. #redis-cli set test "testredis"
    + g+ D- A7 z5 ]
  592. 获取键值
    . [! g; h6 k5 `' F
  593. #redis-cli get test7 H; p4 s$ z2 `1 Y* `: ^7 e) O

  594. . @; O3 j+ ]8 p- _
  595. 3 W/ I$ [1 F! d* {+ J
  596. 第四步:关闭redis  (这个是更改配置文件后 正常的重启方式  不重新加载redis配置跳过)8 G/ K+ L! q0 t: G- q' E* f+ v
  597. # redis-cli shutdown      //关闭所有    4 G1 a& j! k$ W. U- c: _. z
  598. 关闭某个端口上的redis   
    8 n2 s, W! I0 W* t8 u! h
  599. # redis-cli -p 6397 shutdown  //关闭6397端口的redis  7 d! u- k1 r* a3 h- W, D
  600. 说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename  dump.rdb  
    8 y/ Z! I. j3 ?1 y  m. i! z* h! N! d

  601. * |/ W* l; |7 I8 E* W$ O) t, q

  602. 8 C# U. m7 @2 G& {
  603. 第5步:php扩展安装5 g& P9 j! A6 I) L& @' y9 x
  604. phpredis PHP扩展下载地址 ; [' t: b0 t, c9 _* f/ P6 L/ @
  605. https://github.com/nicolasff/phpredis/tree/2.2.2
    5 G! C8 [6 T8 ~1 {5 t
  606. 选择最新版本下载zip 3 E" e: v  G" U* i+ T( S6 u. O
  607. 8 K8 m9 X9 A' K! f, ]& l1 h" b
  608. 然后自己上传zip  用unzip解压到当前目录 unzip 文件名9 J% h" L1 u$ G4 }1 {
  609. 0 J- h0 C: O5 k- U! g. A9 T
  610. # cd owlient-phpredis-90ecd17/   #打开解压后的文件夹里面  这个解压后的目录 要是不知道 可以输入 "dir" 查看" I1 l0 s2 V8 Z' [, N6 R; M7 W
  611. # /www/nginx_php-5.2.17/bin
    # K8 j7 u  q  e& i, z  K
  612. # ./configure --with-php-config=/www/nginx_php-5.2.17/bin/php-config& L! r' L* t/ _5 r6 F* F9 N6 F
  613. #make
    " q& ~5 O! A! ]9 Y
  614. #make install   #记录产生的redis.so路径6 N  P( [4 d& H' }' p3 `

  615. ; G6 E2 d. B0 L0 K
  616. 修改php.ini文件
    , h- L+ F, R/ ^
  617. 在php.ini中添加如下一行:
    . }5 t- {9 _. k7 ^! O
  618. extension=/?/redis.so  #是刚刚记录的产生redis.so的路 写在 ?那
    8 |' ~0 Y/ X/ Q8 ~9 C
  619. 重启 使之生效:, f; V/ F% @3 n: k1 Y! v
  620. /usr/local/php/sbin/php-fpm reload
    % ]+ N, p6 o- {0 G2 d6 K/ g
  621. /usr/local/nginx/sbin/nginx -s reload 6 i( u% j$ M" w" f* M" }1 P) _8 b
  622. , ^& A4 K) W4 {) S
  623. 将 Redis 作为 Linux 服务随机启动
    0 [! o8 N: S2 O1 T
  624. vi /etc/rc.local, 加入代码:
    , \! B- A; V. y% a
  625. /root/redis-2.6.10/src/redis-serve  #路径看情况修改
    $ m- G, F2 e8 j) J% S

  626. 5 |) i- Y* O  Q
  627. redis-cli -h localhost -p 6379 info  #命令要在redis目录下面执行
    4 g( U. z7 J% P% Y( y
  628. 提供host为localhost,端口为6379,redis服务的统计信息
    : Q. Z/ K" ~) S: j( S& _+ {

  629. 8 c' U  j5 {: w) {# @

  630. , G! p" e. T4 L# ?4 y$ j0 {
  631. 就这样你的web服务器就支持redis了 记得要在 给dz 的配置文件 加上12.0.0.1哦% d# P8 w" F4 L3 h
  632. dz配置文件在 config目录下面的 config_global.php- R. d+ s6 j- [# n. Z
  633. $_config['memory']['redis']['server'] = '127.0.0.1';& @8 q$ K; }" H+ g2 A+ N
  634. $_config['memory']['redis']['port'] = 6379;/ h) ]( c- t5 T2 B
  635. $_config['memory']['redis']['pconnect'] = 1;
    + U8 s2 i6 _7 `' d. S" F+ h7 m
  636. $_config['memory']['redis']['timeout'] = '0';
    . ~) M# e0 J/ @3 _1 U# o( Z
  637. $_config['memory']['redis']['serializer'] = 1;9 h  ]% q& z4 Y
复制代码
关注微信公众号《神采飞扬网》,即可获取最新回复通知!

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

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

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

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

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