分享到:
发表于 2018-11-16 12:42:28 | 显示全部楼层 |阅读模式
环境配置
4 F( X1 {) }( ^& `6 S
4 ^+ S! }' y* g2 G3 g8 L9 p. y/ o* ^7 n) z: Q
http://www.discuz.net/forum.php? ... amp;highlight=REDIS
关注微信公众号《神采飞扬网》,即可获取最新回复通知!
 楼主| 发表于 2018-11-16 12:43:33 | 显示全部楼层
http://www.discuz.net/forum.php? ... 648&highlight=REDIS- a- r, J/ S4 X5 I3 |
无意间测试 单机状态 redis相当给力 测试1000请求/s  单纯的 get 和set 居然只用了 0.01秒 当时我惊呆了3 |( `7 \/ k* v% c- U6 {
8 r, }6 q. G( [9 f6 V
http://www.discuz.net/forum.php? ... 731&highlight=REDIS4 [! M7 c9 J; @$ S4 k- g( e+ n

, ^9 c- ]) J/ k; {; Ahttps://wenku.baidu.com/view/265a5ce176a20029bc642d0b.html* @9 h' ^8 g& S1 U( j0 x6 ]
2 p& I; ?0 c$ e; u8 L. d' `4 R
=======================================
7 |3 C) Y; t! @$ ^
  1. 连接上 ssh" Z5 [, u. L2 ^

  2. ; _) A- }/ [$ B, C( @% R% j

  3. 7 \( s2 B0 n. G* m. w/ l
  4. 第一步:下载redis2 I% U3 K/ c2 [' T
  5. # wget http://redis.googlecode.com/files/redis-2.6.10.tar.gz
    / \+ \+ |1 c: I% \* u# l2 K# G
  6. # tar zxvf redis-2.6.10.tar.gz
    & _/ p, N- Z6 P* A# k
  7. # cd redis-2.6.10$ u3 S9 b: K- D) e: h7 J
  8. # make ( a0 V; @* g0 X- w) k$ X% q
  9. # make install  
    0 K3 f" @4 G6 m2 P& G3 U
  10. #cp redis.conf  /etc/ #复制配置文件到etc目录下面: \% B# c; m8 d+ m5 [6 s: W% {  X8 W
  11. 第二步:修改配置( Z, }+ b7 k- z: ?
  12. #vi /etc/redis.conf
    & Q! `+ U7 n: o
  13. ######################下面是无措的配置文件 复制过去就成#########1 k; u: P$ M2 c
  14. # Redis configuration file example* q+ ?, z( U# C" r% V
  15. & @: X2 b% G# A. `) T
  16. # Note on units: when memory size is needed, it is possible to specify
    4 ?1 ^- y6 t, J
  17. # it in the usual form of 1k 5GB 4M and so forth:; w" j/ F% _8 c. d
  18. #* G" t/ U4 p6 {* A( q1 r
  19. # 1k => 1000 bytes! `  t: m7 Q( ]2 ?/ v+ o9 T
  20. # 1kb => 1024 bytes  k$ d8 w* s3 B6 T% Y
  21. # 1m => 1000000 bytes* k) g0 y% l  M+ ?( `. t) |
  22. # 1mb => 1024*1024 bytes/ k$ q# b3 T( A1 S+ n& p
  23. # 1g => 1000000000 bytes
    2 \7 m, [2 b8 V$ A. Y
  24. # 1gb => 1024*1024*1024 bytes3 K8 `* M% Y: m7 q
  25. #- h" s# T, J/ c( O" K5 w
  26. # units are case insensitive so 1GB 1Gb 1gB are all the same.' }8 B; x( \, i4 T$ H% `& O
  27. $ S# Y' `3 E2 W) w4 m: A% x
  28. # By default Redis does not run as a daemon. Use 'yes' if you need it.( P- R# h- y  e' x+ X
  29. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
    % M% i( J: j5 P" j: `
  30. daemonize yes
    4 Q& p- h2 h! k( c! D0 |/ m

  31. 0 W( b) ~0 Q; W/ n% p
  32. # When running daemonized, Redis writes a pid file in /var/run/redis.pid by6 v, F* i# S1 B; B- W
  33. # default. You can specify a custom pid file location here.
    1 w5 D0 \  o% C4 _
  34. pidfile /var/run/redis.pid+ k$ i( M  X7 ?# ], S
  35. 3 u6 q+ k3 D* v7 I$ z* {
  36. # Accept connections on the specified port, default is 6379.0 c' K+ }* t2 l" P- a3 k4 t
  37. # If port 0 is specified Redis will not listen on a TCP socket./ L# U0 s7 x: U
  38. port 63794 [$ ?- C% W7 O: g' s

  39. # S% `) L0 X1 e1 y7 |* x7 T& V
  40. # If you want you can bind a single interface, if the bind option is not, L% h  L+ X- W
  41. # specified all the interfaces will listen for incoming connections.
    7 s2 c% f, Y& c+ s8 D6 h
  42. #
    1 f; }4 h# Y5 V  e1 I' I% h0 U
  43. # bind 127.0.0.10 ~% ~7 l% }7 R; }  S8 T5 T8 A
  44. - d  o) Z* U+ x- M8 n8 d
  45. # Specify the path for the unix socket that will be used to listen for
    2 V$ V+ L# ?, D2 ^8 F  _
  46. # incoming connections. There is no default, so Redis will not listen6 |7 R) U" d! _0 b9 U0 I
  47. # on a unix socket when not specified.) F4 d& {* {* f0 I7 `, E* M
  48. #
    ; q3 J6 n% o7 b( c/ ~: |$ }
  49. # unixsocket /tmp/redis.sock
    3 U" ]2 O0 o4 L8 l
  50. # unixsocketperm 755
    ' K( i! T& I" |- Q
  51. 9 v& t+ O$ w# b( ]& y
  52. # Close the connection after a client is idle for N seconds (0 to disable)8 N7 R$ _( L$ I
  53. timeout 300
    - h7 d* F' o- j8 _2 l; c
  54. " o  N3 S" F! T+ [  h( Q; a7 ~
  55. # TCP keepalive.
    # e2 j6 p" y" Y# h) q) B" Y. }$ _
  56. #
    4 i) `. S+ u  z$ q' E- |
  57. # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence, n$ @& m, v- `
  58. # of communication. This is useful for two reasons:* \- M, Y  i' R) E( A% w4 c
  59. #
    3 g9 I4 |$ A: Y9 [) w8 X1 A
  60. # 1) Detect dead peers.
    3 _3 W9 l( e4 `  `
  61. # 2) Take the connection alive from the point of view of network- d$ P! {6 x: f; r1 X" z8 `& a" |. S
  62. #    equipment in the middle.$ x" M$ J1 N) l+ c6 [
  63. #
    ; ~* N* d1 v! v/ Z% x
  64. # On Linux, the specified value (in seconds) is the period used to send ACKs.
    ' d" a! H4 y, f% y( c3 ~
  65. # Note that to close the connection the double of the time is needed.
    + N- c/ J( j' r; h5 p3 E
  66. # On other kernels the period depends on the kernel configuration.* K3 [$ \- M8 z
  67. #
    . p# ^% |6 @" ~. K; M0 ~
  68. # A reasonable value for this option is 60 seconds.
    / W0 p" F( p: J
  69. tcp-keepalive 0
      C. s! K8 l: s  s

  70. ; Z& y) f) o; n
  71. # Specify the server verbosity level.
    - G, g& B# w5 u3 R, A6 T# H1 l
  72. # This can be one of:
    ' k6 j5 e  q. |1 F$ Y4 l4 c& [/ j, H
  73. # debug (a lot of information, useful for development/testing)& e) a8 ^, s. p; w+ v: p; A3 u
  74. # verbose (many rarely useful info, but not a mess like the debug level)( N  I1 q: v+ T# u
  75. # notice (moderately verbose, what you want in production probably)+ \5 U$ R' t( M' x" h. w# v8 D
  76. # warning (only very important / critical messages are logged)
    ! U* h4 g1 r# b5 d4 E3 T! I
  77. loglevel warning; e, I) G+ ]4 A

  78. # R$ b1 k1 R4 W- D5 s  U
  79. # Specify the log file name. Also 'stdout' can be used to force4 ^0 Z5 y# i4 }( T
  80. # Redis to log on the standard output. Note that if you use standard
    # m9 o. C* ], v& j
  81. # output for logging but daemonize, logs will be sent to /dev/null+ X" M1 @9 }2 ]- N
  82. logfile /var/log/redis.log* K6 l9 f% k8 F$ h4 T; v
  83. + }% [+ j1 _: x
  84. # To enable logging to the system logger, just set 'syslog-enabled' to yes,
    0 b/ K0 [% @; v4 M7 O; l5 i8 M+ i- E
  85. # and optionally update the other syslog parameters to suit your needs.
    ! _% H4 Q) i/ U  x
  86. syslog-enabled yes0 u+ ]- j( X9 a9 j$ O, _7 S$ v

  87. / n$ a- t7 m  W  `) U0 [
  88. # Specify the syslog identity.
    6 q. n) t5 [/ }! {
  89. # syslog-ident redis
    " c2 O% V. B; e) G7 D" B" r- _
  90. 5 K$ m- M8 V. L6 n3 j, j5 M' y4 z
  91. # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.6 ]4 }/ z( N, k! m# J* B; d
  92. syslog-facility local0
    9 F: t* f) L3 P! [4 x) B9 N0 n) m

  93. $ U" M* e: L& Z/ _% g* }. `1 M. ]
  94. # Set the number of databases. The default database is DB 0, you can select5 z" d' e' ?% b- S% {
  95. # a different one on a per-connection basis using SELECT <dbid> where6 E2 H6 c/ Y( U' O& t
  96. # dbid is a number between 0 and 'databases'-1
    , q8 m% u# Z6 F; S0 v0 b
  97. databases 16  p9 V6 d: ~3 S" x% X; v

  98. ) n7 L5 ?/ P% g
  99. ################################ SNAPSHOTTING  #################################( d: h. y) n2 k0 w6 A
  100. #
    0 ?5 `8 q* f2 d) W
  101. # Save the DB on disk:2 n4 W$ u9 z9 }5 u1 A" K* b0 {( Y
  102. #
    ( H" O* t3 I- }) r. m
  103. #   save <seconds> <changes>0 o3 z; s! Q/ N3 ]
  104. #
    3 K* h. }5 S  q/ q  S
  105. #   Will save the DB if both the given number of seconds and the given
    % u# T% R9 }, n( v5 c1 _
  106. #   number of write operations against the DB occurred.
    ' E# M# c9 Y6 [& R
  107. #
    7 l1 c. ^% h2 w) |9 W- j2 V
  108. #   In the example below the behaviour will be to save:. Z( Y6 E6 P5 G* {
  109. #   after 900 sec (15 min) if at least 1 key changed  I' V) F3 V4 W* E2 r" x
  110. #   after 300 sec (5 min) if at least 10 keys changed6 Y8 Z* a6 B, g! @. |9 v8 c
  111. #   after 60 sec if at least 10000 keys changed( ~7 F, u2 c1 r1 Z% Q
  112. #/ n" @) J0 ]$ U; y
  113. #   Note: you can disable saving at all commenting all the "save" lines.
    6 X+ `' M/ W. D0 U6 }8 p: ^- q
  114. #* ^; X$ R- _/ }; m0 M
  115. #   It is also possible to remove all the previously configured save' N+ I8 Y3 C/ t# L: y
  116. #   points by adding a save directive with a single empty string argument: `2 B# h  q$ r+ a. A5 ?
  117. #   like in the following example:- E  }2 n+ O  ^8 k2 e
  118. #6 A' X% t5 [/ k5 O& ?- S5 v! W
  119. #   save ""% r3 l6 F5 Y& D' q+ f: J" _  m

  120. - `8 n) f. O" Z0 a
  121. save 900 1# m0 u- F" m) B
  122. save 300 10
    ! B! }0 W" j! u& ~* t
  123. save 60 10000, i9 k2 @/ R7 h

  124.   |4 P" B* K, U0 R; `
  125. # By default Redis will stop accepting writes if RDB snapshots are enabled
    - I" J# u! \3 X" Z. \
  126. # (at least one save point) and the latest background save failed.* A4 z& k) L6 b; q) O$ ]
  127. # This will make the user aware (in an hard way) that data is not persisting! S% G$ L' j2 Z. x
  128. # on disk properly, otherwise chances are that no one will notice and some
    9 i  t* f7 \. v6 U) Q9 H$ z2 `
  129. # distater will happen.3 e3 n3 S, c" s
  130. #
    ) b$ D& Q6 f3 y: l
  131. # If the background saving process will start working again Redis will
    + `1 X9 C" u8 C6 R
  132. # automatically allow writes again.
    + d6 p8 h+ x6 [4 D" K
  133. #
    7 p( L9 j- S! l+ f# I
  134. # However if you have setup your proper monitoring of the Redis server
    ( f' E! \0 P4 K
  135. # and persistence, you may want to disable this feature so that Redis will  n3 ^; |3 v, C% g/ _' V
  136. # continue to work as usually even if there are problems with disk,
    3 q3 @( p! B# n' U- B
  137. # permissions, and so forth.- A1 o+ @9 q0 t# {
  138. stop-writes-on-bgsave-error yes5 p8 S) v1 ~/ r; \! `
  139. . m/ W& y) ^$ F, q/ v( Q8 Q$ I% }$ }
  140. # Compress string objects using LZF when dump .rdb databases?
    3 a. q0 W7 |, w8 H2 _2 t1 ^
  141. # For default that's set to 'yes' as it's almost always a win.- B& V( f9 j( f# K( s
  142. # If you want to save some CPU in the saving child set it to 'no' but
    3 A  y5 J! W4 r1 d
  143. # the dataset will likely be bigger if you have compressible values or keys./ {. |- `$ V4 g1 [5 q9 A3 d- k# ^
  144. rdbcompression yes
    $ l. _2 O8 l5 n+ R

  145. 5 S1 o2 @& `2 E7 X
  146. # Since version 5 of RDB a CRC64 checksum is placed at the end of the file.
    ' j( W* M7 `* n9 Y5 b6 _( V4 E
  147. # This makes the format more resistant to corruption but there is a performance$ @" d8 w, V, L2 O$ X3 ]: V8 e. V
  148. # hit to pay (around 10%) when saving and loading RDB files, so you can disable it7 k" [5 c3 J0 T9 F
  149. # for maximum performances./ n$ D( G( j' I( A. Q0 I; N
  150. #
    ' v2 c0 y: A. O+ v$ p/ d
  151. # RDB files created with checksum disabled have a checksum of zero that will
    ! G" e; Z; _& h7 H0 c7 l# {
  152. # tell the loading code to skip the check.- p; D* x$ X; f, m7 {; p- w
  153. rdbchecksum yes  C4 O6 x$ g2 o9 [3 ~0 w2 I- e: \& E

  154. / O3 z) y8 O0 i* `
  155. # The filename where to dump the DB3 k8 y6 v7 v: Z# q' F) n' K" ]: O
  156. dbfilename dump.rdb, K0 C" K- s9 ~5 o

  157. 5 B2 z" N9 M$ Z# ?8 z* F
  158. # The working directory.
    $ M/ U8 D- M9 F2 ]5 B* G
  159. #2 e/ k3 v0 b) t# M1 n
  160. # The DB will be written inside this directory, with the filename specified
    6 a5 y6 W1 q6 ~0 |4 Q0 B* O
  161. # above using the 'dbfilename' configuration directive.. }- x  L5 a, U9 |, i
  162. # 7 _" P+ c8 y. N7 X& d
  163. # The Append Only File will also be created inside this directory.4 t- n- n4 [, Q3 h: }$ f2 P
  164. # 9 R4 }7 `/ Q4 E& U% T
  165. # Note that you must specify a directory here, not a file name., r. i6 \* h3 s5 x
  166. dir /var/db/redis0 I# a0 {. a/ g: a9 s3 s8 n" O

  167. $ @7 g. w6 Q( p2 D
  168. ################################# REPLICATION #################################
    : }, g9 w. I: I
  169. 7 `) D2 S* e, `
  170. # Master-Slave replication. Use slaveof to make a Redis instance a copy of
    4 {1 A. G, D- |! y$ F, J. w
  171. # another Redis server. Note that the configuration is local to the slave( R% k* C6 ?% Z
  172. # so for example it is possible to configure the slave to save the DB with a
    - y9 B; |2 N1 }; l) I' v
  173. # different interval, or to listen to another port, and so on.
    . {4 t1 o% m1 [: ]& `
  174. #8 z9 R  u, a( X% K6 p  M" v9 e; l- b. d
  175. # slaveof <masterip> <masterport>
    ; q) _1 v! @4 M! I1 C: |- @

  176. ; l/ T( E5 m8 M: a/ H  W* B
  177. # If the master is password protected (using the "requirepass" configuration
    " Y- l; b& r8 Q. A; ]& \
  178. # directive below) it is possible to tell the slave to authenticate before
    3 C8 `; I, q8 }0 R7 `+ u
  179. # starting the replication synchronization process, otherwise the master will4 K7 ]' J9 g# ?5 i* D' C( M
  180. # refuse the slave request.
    3 O( P) G- o% G' T  b7 a
  181. #6 ?( u6 H/ k9 n' B1 Q) I- R
  182. # masterauth <master-password>* n5 G0 T- v9 w$ R; A
  183. 7 H( R1 I! x% P. `# S' r# j0 g
  184. # When a slave loses its connection with the master, or when the replication
    , Y  S" m* Y& J, \, p# t
  185. # is still in progress, the slave can act in two different ways:% W: d8 L' U2 _
  186. #' r7 ~2 B8 f  V, \7 O8 |* P- ]
  187. # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will4 H3 E2 M, ~) o& r
  188. #    still reply to client requests, possibly with out of date data, or the/ o8 h4 K* V2 N5 y( B. Q
  189. #    data set may just be empty if this is the first synchronization.
    , O* V& a. z: u8 ^5 i
  190. #
    * v4 w! x( m" E) i
  191. # 2) if slave-serve-stale data is set to 'no' the slave will reply with
    $ l& e; D5 ?7 E
  192. #    an error "SYNC with master in progress" to all the kind of commands) T. S: Y( |& O5 B4 s
  193. #    but to INFO and SLAVEOF.: }# R) V1 _8 Q" t5 s2 N7 X
  194. #9 x# g# b7 t/ x" q
  195. slave-serve-stale-data yes0 g! O$ W  d6 h

  196. 4 [. D& a4 v5 y. r! I  a0 K" B
  197. # You can configure a slave instance to accept writes or not. Writing against
    4 Y0 a4 h, |* `" G6 M& q
  198. # a slave instance may be useful to store some ephemeral data (because data* e( \5 K  [; m
  199. # written on a slave will be easily deleted after resync with the master) but
    $ S' Y# M6 i: d6 @% h
  200. # may also cause problems if clients are writing to it because of a7 j) t2 b0 J/ N
  201. # misconfiguration.1 e; v: f3 r+ H  f( m% w6 i, |
  202. #8 d* k( m2 G8 k. C' `
  203. # Since Redis 2.6 by default slaves are read-only.
    6 V& P: P0 |: D" K+ p6 R3 ~
  204. #
    - g0 w1 u6 H; q5 Q! k6 l- |# k" h
  205. # Note: read only slaves are not designed to be exposed to untrusted clients
    7 {6 Z0 P( W' L' h
  206. # on the internet. It's just a protection layer against misuse of the instance.+ x  {' Z  E4 j# y2 U9 B' T" _1 @
  207. # Still a read only slave exports by default all the administrative commands0 j# [# {2 r4 ^7 V  g& f% I' [
  208. # such as CONFIG, DEBUG, and so forth. To a limited extend you can improve* [' W) e* V7 O3 r8 \: i. {
  209. # security of read only slaves using 'rename-command' to shadow all the
    6 V. R# u  I7 K+ m4 w* @
  210. # administrative / dangerous commands.  o8 x; U7 ~  j8 T# f8 }
  211. slave-read-only yes+ \3 O8 W2 ~; [0 d* Z

  212. 8 w8 F  h, k8 T2 b
  213. # Slaves send PINGs to server in a predefined interval. It's possible to change
    ) `5 D2 V3 T( n/ m+ V* r' \5 A
  214. # this interval with the repl_ping_slave_period option. The default value is 10
    ' _. O' I; c, P0 |; J; G0 F
  215. # seconds.9 T3 Z+ i" U* f. K
  216. #
    # [- B1 [5 {( Y  `' V  |
  217. # repl-ping-slave-period 10
    ) G* }: W2 _5 K( G
  218. 8 x) [8 f2 @# I1 |" ~* s
  219. # The following option sets a timeout for both Bulk transfer I/O timeout and8 @$ O) x. b' S8 d7 A- A, ]
  220. # master data or ping response timeout. The default value is 60 seconds.
    : z( F) x3 F$ A) l
  221. #
    5 Z! N5 p# ~( |( ]0 ^" o5 V' D3 ?
  222. # It is important to make sure that this value is greater than the value5 i, ^& F6 y9 P  w% o, M
  223. # specified for repl-ping-slave-period otherwise a timeout will be detected
    9 j0 J9 w, @5 m! Z' s% u  ?' T
  224. # every time there is low traffic between the master and the slave.
    2 q  W3 C$ W( F: ~4 q, d/ t
  225. #
    7 T' l8 k" _( G
  226. # repl-timeout 60
    1 Z! J( o% j4 G# {

  227. 1 u$ X3 T& h5 @7 v# O- z5 v
  228. # Disable TCP_NODELAY on the slave socket after SYNC?0 V) G, l( b& I# B6 _
  229. #
    4 }0 n  n2 F& K- }$ w( o+ m
  230. # If you select "yes" Redis will use a smaller number of TCP packets and+ {% o7 z6 L' C& ~1 s, P, f, U0 x
  231. # less bandwidth to send data to slaves. But this can add a delay for; f* t* e% G! f3 _0 R
  232. # the data to appear on the slave side, up to 40 milliseconds with
    + S" a* R/ }/ f# O- \
  233. # Linux kernels using a default configuration.7 r2 Y4 r2 M* N- B
  234. #$ _% q* Z3 ], v
  235. # If you select "no" the delay for data to appear on the slave side will
    - j( G( O  }0 |9 t& {+ D
  236. # be reduced but more bandwidth will be used for replication.( ^9 ~0 `8 k- k5 S) r. q" i
  237. #
    ; f* T- Z0 Q! {5 c  ~; Q- r  N
  238. # By default we optimize for low latency, but in very high traffic conditions( D3 A1 {: r0 N7 v5 b+ L4 A8 ]
  239. # or when the master and slaves are many hops away, turning this to "yes" may# g! T" C1 h5 }0 @( w2 H
  240. # be a good idea.1 F. y& }& @6 l" \' ^: |
  241. repl-disable-tcp-nodelay no& k8 x- V& Q- b- n  Y5 X

  242. , _3 N3 `% E: t6 W8 P$ ?& X
  243. # The slave priority is an integer number published by Redis in the INFO output.
    / ]& ?7 S. H. b2 N! S" L1 x: p) [
  244. # It is used by Redis Sentinel in order to select a slave to promote into a6 V; ^+ i8 }  `0 k4 \! Q
  245. # master if the master is no longer working correctly.& I, h) ?. F( Q/ F$ }9 d7 o
  246. #' O7 n! Q' f, d; a
  247. # A slave with a low priority number is considered better for promotion, so
      j7 k- W, l, Y1 [0 g
  248. # for instance if there are three slaves with priority 10, 100, 25 Sentinel will
    , p3 v% a  x* y3 B1 ^
  249. # pick the one wtih priority 10, that is the lowest.- [$ Q% }  c1 {/ k6 U9 s
  250. #2 C" w8 S1 C( B2 n% `2 R
  251. # However a special priority of 0 marks the slave as not able to perform the' p) S5 ?7 [% a# y& p& N
  252. # role of master, so a slave with priority of 0 will never be selected by' v/ ~# M5 E2 L- P; i
  253. # Redis Sentinel for promotion.
    5 V4 \7 L5 t- i0 Z" h
  254. #) T/ V9 }  s" Z4 E& t
  255. # By default the priority is 100.: ~; |$ s! j& _, s2 W+ H8 y
  256. slave-priority 100
    & F% g* y) ~4 T; W; ?4 d! Y) L

  257. ( z7 q5 m8 s! R) T, I. W
  258. ################################## SECURITY ###################################
    2 R! x0 N+ t0 f7 w

  259. - {* I' z) M9 F
  260. # Require clients to issue AUTH <ASSWORD> before processing any other
    4 Z9 q5 W( S5 _7 E, R) \
  261. # commands.  This might be useful in environments in which you do not trust1 s7 O# q" f) |9 Q, E
  262. # others with access to the host running redis-server.
    : g( q, N7 d( R; G2 a2 ]0 E
  263. #3 a8 f* ~- k: C/ a0 g3 Z0 p" ?
  264. # This should stay commented out for backward compatibility and because most) N3 f# L5 g$ C, S# q' A% K
  265. # people do not need auth (e.g. they run their own servers).( M' R3 V7 T1 F0 e
  266. #
    3 h/ x! O& T% a; `% b# n1 m
  267. # Warning: since Redis is pretty fast an outside user can try up to
    8 S& {1 j7 p/ d3 o4 t
  268. # 150k passwords per second against a good box. This means that you should9 ]4 {, C" l4 {- V3 ^8 y' Y8 v
  269. # use a very strong password otherwise it will be very easy to break.& l& ~  r- `- F9 A* s% `
  270. #/ A' y) H% F/ {" W
  271. # requirepass foobared
    ; q: l; L8 \( c7 @9 R) G
  272. 3 |, E# V9 i7 _+ |# P9 g7 E/ m$ W
  273. # Command renaming.; k+ c7 X3 A9 r7 O' O; F9 @8 j
  274. #: _7 q6 B& ^/ S
  275. # It is possible to change the name of dangerous commands in a shared1 z/ f+ F: }7 x8 l
  276. # environment. For instance the CONFIG command may be renamed into something
      T; B, o* {) l, z7 w
  277. # hard to guess so that it will still be available for internal-use tools
    5 Z& Y, t7 A& p8 B3 \- X. I
  278. # but not available for general clients.
    : w+ M) H- y1 K* a
  279. #
    ! W2 o. v' v; z$ X
  280. # Example:
    # L% m$ b, q: U
  281. #
    # ?( i/ z0 i9 z" C
  282. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
    * O6 H* ]4 S! r4 y9 F& V1 I% Y6 W
  283. #
    1 F" X( h1 I1 A! `: Z* L" t
  284. # It is also possible to completely kill a command by renaming it into
    " w: S/ H$ `1 s
  285. # an empty string:
    # c/ U$ u. u- U. U  S: o$ n3 _
  286. #
    " k/ e5 B+ C2 g/ s4 h
  287. # rename-command CONFIG ""
    : Y& D$ {: D4 J1 a" ]4 c

  288. % `9 {9 n/ F+ j
  289. ################################### LIMITS ####################################2 |2 {9 V7 S) e; O

  290. ( @$ l& M' @. l& C/ @: z8 i
  291. # Set the max number of connected clients at the same time. By default7 {; F. {) l2 a- I# d0 G5 o
  292. # this limit is set to 10000 clients, however if the Redis server is not
    1 O1 e* b% W, l. @! B# U& s
  293. # able to configure the process file limit to allow for the specified limit. f5 R; o& @- O! f+ i) J
  294. # the max number of allowed clients is set to the current file limit8 u  H, ]3 Y1 H+ e% }2 r; _  Z
  295. # minus 32 (as Redis reserves a few file descriptors for internal uses).
    ; P8 F0 A5 S# H5 l8 D# f2 g: a, S' r2 x9 t
  296. #* M  H/ B3 W1 p
  297. # Once the limit is reached Redis will close all the new connections sending
    + t$ ?2 y9 }% {$ r: p& _
  298. # an error 'max number of clients reached'.
    , I# [+ q  A; `6 J, r. I
  299. #
    6 e& G" l! _* V- ~0 g1 C
  300. maxclients 500  Y( Q$ I( m2 H% h+ ^2 X

  301. 6 R& G" @/ r; _+ B
  302. # Don't use more memory than the specified amount of bytes./ O5 e! X" Y, c8 X5 D
  303. # When the memory limit is reached Redis will try to remove keys
    + U$ _" e* `" F- T: @; i* V# Z
  304. # accordingly to the eviction policy selected (see maxmemmory-policy).. T5 r+ X: D1 c0 _, `9 K
  305. #% G2 V, R! E, F8 j% t, D
  306. # If Redis can't remove keys according to the policy, or if the policy is" {2 u, t; P+ V" a* x2 q& |
  307. # set to 'noeviction', Redis will start to reply with errors to commands. `# G1 q* X7 q- ^+ p
  308. # that would use more memory, like SET, LPUSH, and so on, and will continue
    ' y9 r1 H" Y( ]
  309. # to reply to read-only commands like GET.
    3 U  \$ C1 `8 J" X% S- ]4 {
  310. #
    % v; R/ B+ t) D6 h7 h6 f
  311. # This option is usually useful when using Redis as an LRU cache, or to set
    # h0 B, @& T$ R% T/ D) b& M3 p
  312. # an hard memory limit for an instance (using the 'noeviction' policy).- b; ~/ I: [, t* r0 @& ]* c' B
  313. #
    3 v+ B: i) D, i* i# l4 e
  314. # WARNING: If you have slaves attached to an instance with maxmemory on,/ ]! f. E; w( F. o
  315. # the size of the output buffers needed to feed the slaves are subtracted2 T' a& S6 }5 Z3 ?
  316. # from the used memory count, so that network problems / resyncs will
    7 ]/ x: n% t5 M! I8 S; ^0 K" @5 X3 [
  317. # not trigger a loop where keys are evicted, and in turn the output
    8 J- r: W6 D+ U0 o! K
  318. # buffer of slaves is full with DELs of keys evicted triggering the deletion: x; P$ T5 R6 f* i  v7 C
  319. # of more keys, and so forth until the database is completely emptied.5 _: e5 v7 P; t* w8 t& Y
  320. #2 ?% d6 l( X  h( b' B* P6 g4 W
  321. # In short... if you have slaves attached it is suggested that you set a lower$ d, D; i9 I$ A, X# E! U+ \
  322. # limit for maxmemory so that there is some free RAM on the system for slave3 Y9 k* Z" e* `+ r
  323. # output buffers (but this is not needed if the policy is 'noeviction')., l, _5 H( v- `! X
  324. #
    5 i2 ]% u; M: H1 g
  325. maxmemory 128000000
    6 d9 r" Y- R+ ]- x& k% R) s" A
  326. : q  o/ \4 C; M" A0 a
  327. # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
    7 B4 `, J) G# Z$ [5 |
  328. # is reached. You can select among five behaviors:
    + a/ t. t4 F, `* Q1 n( B( u
  329. # + x2 \# g  `" l3 ]7 _1 V
  330. # volatile-lru -> remove the key with an expire set using an LRU algorithm
    7 ]0 `" z( C( G: j+ t6 v
  331. # allkeys-lru -> remove any key accordingly to the LRU algorithm" V. K" O& `6 {* B! ?5 p2 t- i. z" Q
  332. # volatile-random -> remove a random key with an expire set
    . H0 H* F& X% H4 {3 I" n( J
  333. # allkeys-random -> remove a random key, any key  G! H+ I) B: h; b9 b1 {
  334. # volatile-ttl -> remove the key with the nearest expire time (minor TTL)
    # W" D' |9 k& Y  W4 B" G0 H
  335. # noeviction -> don't expire at all, just return an error on write operations
    $ V2 d6 H( q) J% w3 V7 ^
  336. # % o" b0 y1 G- e1 @
  337. # Note: with any of the above policies, Redis will return an error on write
      b5 U/ I; ^+ ?- d
  338. #       operations, when there are not suitable keys for eviction.* A* g- l+ R5 {/ I$ t* K' A. A: g
  339. #
    ; w0 Y  V0 y# [5 x
  340. #       At the date of writing this commands are: set setnx setex append
    9 Y# w! E+ X0 T
  341. #       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
    1 A; s$ f* {6 b: ~! _+ h' i. a# @
  342. #       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
    : e9 D) H% N" ^% h3 G8 Q
  343. #       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby! U8 u- u, Y4 g8 ~1 [
  344. #       getset mset msetnx exec sort1 I! ~/ ^- H" M! ~& H2 S& A
  345. #5 ^; p+ J, C* t4 _, N& j
  346. # The default is:
    , F8 g  }" R7 V1 H
  347. #
    8 W2 k$ @8 C/ s4 \9 N4 T
  348. # maxmemory-policy volatile-lru1 u* g/ d9 u9 d
  349. / P/ F, c+ @1 U% {# b$ O& z( m
  350. # LRU and minimal TTL algorithms are not precise algorithms but approximated
    % t7 ?3 S- H3 r; ?1 }
  351. # algorithms (in order to save memory), so you can select as well the sample
    7 s3 f2 B/ t' u+ A
  352. # size to check. For instance for default Redis will check three keys and5 L; u" k  a9 I# L, B: ~
  353. # pick the one that was used less recently, you can change the sample size
    # M1 m6 b9 a1 a3 Z
  354. # using the following configuration directive.- {* J$ F" n1 n& l. H
  355. #( C6 O/ W5 j( H( r& w
  356. # maxmemory-samples 39 \. S6 ~% a  ^$ w
  357. - O+ `3 N. J( G
  358. ############################## APPEND ONLY MODE ###############################
    ! [1 ]+ @  p0 y: u3 C1 [
  359. * m* U5 U8 |: x( Z% f: I
  360. # By default Redis asynchronously dumps the dataset on disk. This mode is# p) p7 t) }9 T2 ^$ c1 i
  361. # good enough in many applications, but an issue with the Redis process or
    ( R) H% U, U6 _0 `  ]2 x
  362. # a power outage may result into a few minutes of writes lost (depending on, D$ f6 ^, E8 k. b5 Z& _+ j' b
  363. # the configured save points).9 w" l8 _) G- ?0 f3 l* ]
  364. #
    $ J% y% v' v  Q7 J- W1 z
  365. # The Append Only File is an alternative persistence mode that provides
      Z5 K) C9 A, T" g" u6 k) x
  366. # much better durability. For instance using the default data fsync policy( a2 U. L1 r0 T# S# L8 h6 w% L
  367. # (see later in the config file) Redis can lose just one second of writes in a
    ) a8 G# V* a3 u: A
  368. # dramatic event like a server power outage, or a single write if something
    4 m* j' K. W* ^5 x8 G$ o
  369. # wrong with the Redis process itself happens, but the operating system is2 {! L8 T3 B! {6 f8 g
  370. # still running correctly.
    : D9 r& c, {% a! s, ~+ _5 ~$ {6 w
  371. #6 L4 s! X& p4 {% \
  372. # AOF and RDB persistence can be enabled at the same time without problems.
    $ B( B" v9 `- V5 }
  373. # If the AOF is enabled on startup Redis will load the AOF, that is the file
    " y6 r* H2 G% _$ `
  374. # with the better durability guarantees.
    % C+ f  i4 [3 R) X  y4 k- m
  375. #
    % R- S/ Y' ~. Z% ]4 {: D) B
  376. # Please check http://redis.io/topics/persistence for more information.
    8 D, O. [8 \1 S7 k2 z
  377. 1 |8 X5 d. i6 U* H6 ]' W; n9 _) l
  378. appendonly no
    ' w# M) |! A8 `9 e5 m  e; B
  379. 8 B  X  w6 k8 D% b) ]
  380. # The name of the append only file (default: "appendonly.aof")- t6 b9 P( Y" h  u( Y" I6 c, K
  381. # appendfilename appendonly.aof
    % s) \! ^9 w$ {% a  w8 j

  382. 2 {7 D- s9 I+ W
  383. # The fsync() call tells the Operating System to actually write data on disk
    / n# g8 a# ^6 X/ |! F1 B6 A( P
  384. # instead to wait for more data in the output buffer. Some OS will really flush
    , ~, o6 L) o4 M( h; U
  385. # data on disk, some other OS will just try to do it ASAP.2 K+ x: M- r( U% i* T
  386. #7 m9 O: u  w8 ~% s9 p
  387. # Redis supports three different modes:$ M3 q( v& w- p0 Y' k0 i
  388. #
      Z$ C9 n! ?- w! F
  389. # no: don't fsync, just let the OS flush the data when it wants. Faster., G) V& o  k( Y* j4 B" _
  390. # always: fsync after every write to the append only log . Slow, Safest.- C% K0 |( l& b6 m$ q' c; V- J
  391. # everysec: fsync only one time every second. Compromise.7 W1 T- x2 [5 Q% L, g$ o
  392. #
    $ ?* R% M" h8 i# L  s
  393. # The default is "everysec", as that's usually the right compromise between
    & x* z* i# t) S$ g* M! x
  394. # speed and data safety. It's up to you to understand if you can relax this to
    9 D- O. X1 @/ v4 _7 q' }
  395. # "no" that will let the operating system flush the output buffer when0 f- v* }! B0 A  e
  396. # it wants, for better performances (but if you can live with the idea of' {6 P/ T, s1 h8 w% V
  397. # some data loss consider the default persistence mode that's snapshotting),  k6 P2 u# J  n3 W" h; \
  398. # or on the contrary, use "always" that's very slow but a bit safer than' d: S5 i7 D7 ^
  399. # everysec., T4 m: \; b" P2 O. F8 `, s
  400. #6 ]  v/ H5 ~4 y' ~
  401. # More details please check the following article:7 I1 ?& b; N6 B  ]" _2 y. M
  402. # http://antirez.com/post/redis-persistence-demystified.html
    - k, j3 D8 z, G
  403. #. U' \/ `. _, t3 ]9 D
  404. # If unsure, use "everysec".' D9 ~; q- B% Z  ]) F+ C' k0 z3 V: R
  405. 2 S4 ?+ p. P6 e" `! s: b
  406. # appendfsync always
    0 U0 d0 j' A5 k0 o& w1 S3 `6 n
  407. appendfsync everysec7 ]7 C: z9 B6 a. V
  408. # appendfsync no' |3 E0 B- @" Z2 a' \4 T
  409. 1 i; z& E' E2 @- |+ X9 L  G
  410. # When the AOF fsync policy is set to always or everysec, and a background
    & H! a7 U! q) u' n
  411. # saving process (a background save or AOF log background rewriting) is% o" Z; ]8 l3 W* \0 Q
  412. # performing a lot of I/O against the disk, in some Linux configurations
    9 @9 j6 z5 Y' o* M7 r! g: N5 [
  413. # Redis may block too long on the fsync() call. Note that there is no fix for+ W1 a# n7 x( r: _
  414. # this currently, as even performing fsync in a different thread will block
    . t' z4 c! f6 ^$ m" Y
  415. # our synchronous write(2) call.
    + Q" \4 |" b8 e5 A' n) H7 q
  416. #
    & {: H6 M! s  e, L/ b
  417. # In order to mitigate this problem it's possible to use the following option
    1 E6 B/ O$ `5 Q1 x- z
  418. # that will prevent fsync() from being called in the main process while a" I/ p/ b+ ?! Y# n- A
  419. # BGSAVE or BGREWRITEAOF is in progress.
    ; d' B9 i6 m# O6 B( m: K" v
  420. #6 r  M! Q' {% I. B% ^5 l
  421. # This means that while another child is saving, the durability of Redis is" T; p; o0 Y8 G3 f
  422. # the same as "appendfsync none". In practical terms, this means that it is
    * E( x+ o9 Z* E) J& r
  423. # possible to lose up to 30 seconds of log in the worst scenario (with the  B4 k( |; t" b( M
  424. # default Linux settings).( [8 s- I: b" k! j
  425. # , V( p6 U7 r  t) t8 |; s* P
  426. # If you have latency problems turn this to "yes". Otherwise leave it as
    . S; `, `: Z7 H7 k0 u( x4 g+ y, w9 w
  427. # "no" that is the safest pick from the point of view of durability., w# ?0 Y% e  K. Z3 l& U' E* s6 l
  428. no-appendfsync-on-rewrite no0 `, F! H/ a& i- [/ ^; Y7 u

  429. ( w0 Q" a0 o6 z. C( X- K( _' L( j5 }
  430. # Automatic rewrite of the append only file.
      s% e% I+ F. D
  431. # Redis is able to automatically rewrite the log file implicitly calling4 a' K! ]& P4 i5 G9 {% c
  432. # BGREWRITEAOF when the AOF log size grows by the specified percentage.4 d3 I. G3 B- m& P
  433. #
    2 w; d# A2 X! h$ w
  434. # This is how it works: Redis remembers the size of the AOF file after the. B' D8 P! v+ J; I% L
  435. # latest rewrite (if no rewrite has happened since the restart, the size of2 q0 n1 X; L0 T  c4 J/ L9 `, |
  436. # the AOF at startup is used).
    : ]4 w/ G; U! D- r6 D' W- m- O% D
  437. #5 |2 Q# A6 L1 A# S% o/ k
  438. # This base size is compared to the current size. If the current size is- i$ V2 x/ F' n
  439. # bigger than the specified percentage, the rewrite is triggered. Also
    2 e+ h* z; Q! \/ ^+ r/ M
  440. # you need to specify a minimal size for the AOF file to be rewritten, this0 J5 G9 W1 j( o$ u/ E; @% y
  441. # is useful to avoid rewriting the AOF file even if the percentage increase& e* u8 T! F& Y0 P
  442. # is reached but it is still pretty small.
    $ x7 M& G, \+ h  @2 Y
  443. #
    " x- z4 g8 A5 V# M/ s
  444. # Specify a percentage of zero in order to disable the automatic AOF
    * ?6 [5 s2 z% J. e3 i* K$ |- z
  445. # rewrite feature.; t6 B5 H/ Q5 u
  446. ' `- h! y7 o, q. @" _
  447. auto-aof-rewrite-percentage 100$ L4 u- [! c, m0 `% n
  448. auto-aof-rewrite-min-size 64mb
    6 G9 A: T( y; h

  449. 1 e" ^# ~& ]( [! K, [
  450. ################################ LUA SCRIPTING  ###############################% ^- H. H1 A3 C( u# j* ^; G

  451. ( O' f# y! ?" p/ W. ^) K1 G
  452. # Max execution time of a Lua script in milliseconds.
    . a5 M9 a% }# E4 d' C0 X  o
  453. #
    ( G. @* _* D, [8 B- Y3 B6 H
  454. # If the maximum execution time is reached Redis will log that a script is# K3 n$ i" q; m/ Z8 d3 S; u. H
  455. # still in execution after the maximum allowed time and will start to* K6 S3 w( f* Q
  456. # reply to queries with an error.3 D5 j/ K1 ~+ h/ K0 Q$ K
  457. #
    ) ~! N. u7 @& ~% X3 T& `( N( o
  458. # When a long running script exceed the maximum execution time only the! O- k- G: `# ?( l; {
  459. # SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be
    ( p  ?3 Z! H5 G) g: R0 Y2 L; \
  460. # used to stop a script that did not yet called write commands. The second. A" ?. W, ^  Z. u
  461. # is the only way to shut down the server in the case a write commands was
    - ?4 J# u* f2 J3 q
  462. # already issue by the script but the user don't want to wait for the natural
    : u; i) b! [' g& h; [4 I* `5 o+ c
  463. # termination of the script.
    ; z" @4 C& K* U( A) O1 W
  464. ## w9 U; D  O/ R: \4 R: T* ]
  465. # Set it to 0 or a negative value for unlimited execution without warnings.$ ^5 e9 O5 f0 \. L
  466. lua-time-limit 5000
    $ c$ G6 d* Z% k$ }8 N! `. n

  467. " o: x. ]. Z  ]2 b
  468. ################################## SLOW LOG ###################################
      h! d' d; R7 S( f% n0 C
  469. ( g3 V. q3 ~9 S9 I
  470. # The Redis Slow Log is a system to log queries that exceeded a specified/ V2 X+ k" S2 X% _* f
  471. # execution time. The execution time does not include the I/O operations* i+ ]" {. {9 L( w
  472. # like talking with the client, sending the reply and so forth,
    ; V. C4 d2 M3 E
  473. # but just the time needed to actually execute the command (this is the only4 z8 N. {9 U, U. h* C5 P: G5 Y
  474. # stage of command execution where the thread is blocked and can not serve3 x2 k8 A% R3 |; k' W2 N: p
  475. # other requests in the meantime).& d. D+ K' e8 X5 f4 a3 ?
  476. # ! J$ L& L. a# s$ m7 m% Q. ^! m& ~+ ^( F
  477. # You can configure the slow log with two parameters: one tells Redis8 W$ q7 ?8 d; b( D
  478. # what is the execution time, in microseconds, to exceed in order for the
    ! Z* Y3 d8 v5 V. m( R
  479. # command to get logged, and the other parameter is the length of the
    / z3 r9 T$ `$ Q0 S: ?6 t% [
  480. # slow log. When a new command is logged the oldest one is removed from the6 Y  q2 F) z* }* Z+ k! j
  481. # queue of logged commands.
    ; ]9 ~  Q& t6 t% @0 C! Q
  482. 5 w  S8 i- ^' I( ~. X' j  c( F+ N: |$ u
  483. # The following time is expressed in microseconds, so 1000000 is equivalent
    6 j  Z) P) ]) W9 ]
  484. # to one second. Note that a negative number disables the slow log, while
    5 g: U4 O8 U; J5 n7 y
  485. # a value of zero forces the logging of every command.# W* a& Q8 j; a, l3 s4 X& W0 s5 {
  486. slowlog-log-slower-than 10000
    ' U6 G( p' l; i1 I

  487. , l/ X( b% U* T3 c6 T/ f+ T2 x
  488. # There is no limit to this length. Just be aware that it will consume memory.
    - [1 R1 m2 c$ V5 l1 Z7 E5 Q1 ]& m
  489. # You can reclaim memory used by the slow log with SLOWLOG RESET.% {$ Y- i" C$ T3 l" A2 E3 h
  490. slowlog-max-len 128
    " Y4 z) a  M) _) E8 Q

  491. ) L1 s* B1 y  j: m3 W, ^
  492. ############################### ADVANCED CONFIG ###############################( }, }$ v/ G1 r  T& S

  493. % m5 H4 n9 W$ V7 b5 t, G
  494. # Hashes are encoded using a memory efficient data structure when they have a
    , X. @4 n  k, w( W( g, w9 q
  495. # small number of entries, and the biggest entry does not exceed a given9 z7 q3 T2 U& T
  496. # threshold. These thresholds can be configured using the following directives.
    ! H% j+ C3 h6 ]  |7 A' W! ~
  497. hash-max-ziplist-entries 512
    / B& z- |0 @* k  P$ P# T
  498. hash-max-ziplist-value 64: [! q% s, I7 j- W: G: N2 [1 |( q
  499. 0 b% r! y; e& q- ]
  500. # Similarly to hashes, small lists are also encoded in a special way in order5 g9 J! w0 k; u: ^  w- q2 n
  501. # to save a lot of space. The special representation is only used when5 R- Z; Y8 r0 J1 l3 F
  502. # you are under the following limits:
    + e( x# G! n$ i2 a, n
  503. list-max-ziplist-entries 512
    , b0 L$ t& ]/ l
  504. list-max-ziplist-value 64
    . Y; T* o. b; z2 K
  505. 1 _0 Z2 h7 S. x8 @6 X# G1 {4 S
  506. # Sets have a special encoding in just one case: when a set is composed7 d5 ~. ~, {' P! t: T- F' j1 M/ V8 u
  507. # of just strings that happens to be integers in radix 10 in the range
    , z5 D) B# Z$ V: U7 x- l8 b
  508. # of 64 bit signed integers.6 b- A4 \( @/ o; p  \
  509. # The following configuration setting sets the limit in the size of the  _+ ^+ F- I% I+ r! t
  510. # set in order to use this special memory saving encoding.
    ! f: s, {* ?2 k) g
  511. set-max-intset-entries 512/ h2 Y  T/ Y& k0 p

  512. % a3 M9 L9 m7 V5 H
  513. # Similarly to hashes and lists, sorted sets are also specially encoded in
    1 h# E( b3 y; |6 J
  514. # order to save a lot of space. This encoding is only used when the length and
    / L1 i, P: W$ e' V: k# K
  515. # elements of a sorted set are below the following limits:  g" o* V( z6 ]' i
  516. zset-max-ziplist-entries 1289 P, D& P8 P" ~2 v/ c7 a
  517. zset-max-ziplist-value 64
    5 s& V0 W$ r) i+ y! b8 G  L: Q

  518. 0 d% m* y" A: v
  519. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
    / ]" O2 ?. s7 x' |3 M9 B1 @( U
  520. # order to help rehashing the main Redis hash table (the one mapping top-level
    - i* }; f6 |# n" x
  521. # keys to values). The hash table implementation Redis uses (see dict.c)
    % ?2 A  a, v# a# C
  522. # performs a lazy rehashing: the more operation you run into an hash table
    * |' u) {3 p; x# g
  523. # that is rehashing, the more rehashing "steps" are performed, so if the
    + j# ]: @. b6 U; e, ?* @: o" l: W; m
  524. # server is idle the rehashing is never complete and some more memory is used) e- q- u& r1 ]+ R+ T
  525. # by the hash table.
    % `. r4 K7 b6 U. ^) A
  526. # " E( M* p' d( V& y
  527. # The default is to use this millisecond 10 times every second in order to) q9 Y* }- P$ B% e
  528. # active rehashing the main dictionaries, freeing memory when possible.
    ) V% \9 s8 z, ~
  529. #. d+ k, c( D: j7 t8 q- h
  530. # If unsure:6 G4 Y5 T( z; t: J4 e
  531. # use "activerehashing no" if you have hard latency requirements and it is6 r' G5 A' P( U7 f. ^% o; V
  532. # not a good thing in your environment that Redis can reply form time to time  k2 c% o: L2 X; S& q$ g
  533. # to queries with 2 milliseconds delay.
    5 \6 z) C7 f9 S' A- _
  534. #
      M: f( {& u! V" a
  535. # use "activerehashing yes" if you don't have such hard requirements but; e6 W" r: h' s& b! I( E8 `
  536. # want to free memory asap when possible.+ D: N" u* e5 W( w
  537. activerehashing yes5 L* s; m4 _; U
  538. ) K% X- h- L( ~1 s3 P
  539. # The client output buffer limits can be used to force disconnection of clients% Q: K9 ^  m4 z8 Y6 e5 \9 o
  540. # that are not reading data from the server fast enough for some reason (a
    $ m( O; ~4 J: A, l4 J- m( B" N
  541. # common reason is that a Pub/Sub client can't consume messages as fast as the# X0 i# ^  w3 E
  542. # publisher can produce them).' f0 Y- Y8 Q6 B8 {$ u
  543. #' m. S- W% ]9 Z: o  o2 \
  544. # The limit can be set differently for the three different classes of clients:/ w7 v: ?* x( J* \. K  ~
  545. #
    1 b# L& l& E# Q5 Z# V: J
  546. # normal -> normal clients( W& K( t) E' f: N* h
  547. # slave  -> slave clients and MONITOR clients0 }* h- l0 m" d* z0 o
  548. # pubsub -> clients subcribed to at least one pubsub channel or pattern$ k2 _7 v0 @+ h
  549. #
    ( s( c7 i3 |2 o
  550. # The syntax of every client-output-buffer-limit directive is the following:
    ) v$ h2 y* N( ~$ U0 @/ }+ d! X
  551. #
    & O: [5 u6 n7 [3 r
  552. # client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>' B3 u; Q# Q/ N& d7 G) ~8 g
  553. #
    . Q4 @5 V# r" X" v- Y+ o
  554. # A client is immediately disconnected once the hard limit is reached, or if
    9 m; |) C6 n( h! _+ H
  555. # the soft limit is reached and remains reached for the specified number of
    5 w- q2 S/ Z3 _* g% v) S/ ]
  556. # seconds (continuously).& x5 C1 z( [# Q: Q/ Y- q
  557. # So for instance if the hard limit is 32 megabytes and the soft limit is: X$ M: ?  k0 b4 V( k3 p  r; M
  558. # 16 megabytes / 10 seconds, the client will get disconnected immediately
    : g% @& l2 K2 _+ ?
  559. # if the size of the output buffers reach 32 megabytes, but will also get
    ! R7 U1 Q" U2 S
  560. # disconnected if the client reaches 16 megabytes and continuously overcomes
    . `. b+ A' b8 m4 ]: V' `8 w/ r
  561. # the limit for 10 seconds.; y  G7 \$ m, ~5 A! A3 d
  562. #
    ) \) K) P, m4 R# X
  563. # By default normal clients are not limited because they don't receive data! Y: j6 G5 T( R# c& B
  564. # without asking (in a push way), but just after a request, so only
    6 z  }/ s7 ^0 e% K
  565. # asynchronous clients may create a scenario where data is requested faster! v: {! B6 e; v* d' v5 H3 y4 z
  566. # than it can read./ k4 L* a9 e7 F( Q5 }
  567. #
      u7 Y0 F" ]8 s7 _. ^& R# T3 N
  568. # Instead there is a default limit for pubsub and slave clients, since$ \$ c) N* q* f5 u: L2 G/ R
  569. # subscribers and slaves receive data in a push fashion.# S" }/ ~; [4 Q/ c0 m; m
  570. #4 g8 a9 k) P8 A/ F# `$ L: G
  571. # Both the hard or the soft limit can be disabled by setting them to zero.
    ) F7 \4 e- ^! X0 L+ h- q7 ~9 y
  572. client-output-buffer-limit normal 0 0 06 l1 R& r# O2 X" ^% l. u7 S! Y
  573. client-output-buffer-limit slave 256mb 64mb 60
    ) Q+ r! N" y7 N. y
  574. client-output-buffer-limit pubsub 32mb 8mb 608 I6 D+ O! ?( \4 U7 A8 H

  575. & ~+ l6 c* `% A) C' `* z/ X
  576. ################################## INCLUDES ###################################
    9 n+ ?3 n5 L6 H3 V- l& ?4 p
  577. 0 e& \+ u" `. h% d) z* @! Q
  578. # Include one or more other config files here.  This is useful if you
    / T$ @5 J/ M1 \$ V5 E
  579. # have a standard template that goes to all Redis server but also need
      y9 A3 D& [$ r! L. ?* l6 o) M
  580. # to customize a few per-server settings.  Include files can include
    0 S, a. p' f2 L* T# ~- E
  581. # other files, so use this wisely.
    ; a' ^* f  a6 m% q
  582. #
    " c: v9 T2 p: }0 \9 o, o2 d
  583. # include /path/to/local.conf) k2 M+ D! N6 q  A' X% O8 H  X! k
  584. # include /path/to/other.conf        , {$ J$ W+ e- X; }+ N
  585. ##########################配置文件结束################################ 0 b$ c; v! |- ?4 a: P/ \
  586. 第三步:启动进程
    # H3 v$ q: n: [2 l, p
  587. #redis-server /etc/redis.conf$ |& o$ c2 o* n
  588. 查看进程有没有成功启动+ C( m) m# f9 w) k- H0 Y' s, B
  589. #ps -ef | grep redis
    8 ~- m" J6 k% {
  590. 测试输入一个键值& D& I$ S+ o% I) r' q- Y% r2 l
  591. #redis-cli set test "testredis"
    : L; A6 Y& y3 p- J: I3 t
  592. 获取键值7 T' w, s: {0 u3 ^5 n% G
  593. #redis-cli get test
    & y3 O1 @% |9 Z2 a
  594. 7 s$ r0 T' F* y, k0 M

  595. " V; I6 \: X+ l; T$ }( H
  596. 第四步:关闭redis  (这个是更改配置文件后 正常的重启方式  不重新加载redis配置跳过)4 ~7 c: M4 i2 K5 r# b9 J
  597. # redis-cli shutdown      //关闭所有    8 Q" g, q/ u# ]9 ~& X
  598. 关闭某个端口上的redis    2 @2 r* V& I( N' n. B* @
  599. # redis-cli -p 6397 shutdown  //关闭6397端口的redis  
    : T& o4 F/ I, N; E8 V
  600. 说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename  dump.rdb  5 p- o: m/ T0 i# Z. Y9 N4 n

  601. 4 p/ w% t4 U2 E4 ]

  602. % a- z; W. R0 z& }! I* W& s2 @
  603. 第5步:php扩展安装+ l( a% a9 w) O$ L4 L* [
  604. phpredis PHP扩展下载地址
    + _7 `& {+ L- K8 i3 Q5 l
  605. https://github.com/nicolasff/phpredis/tree/2.2.2 , _# g5 b9 ~& l" p
  606. 选择最新版本下载zip
    7 Y! S; W# e6 f" C# C& T

  607. 1 T* d) g: d6 f. E
  608. 然后自己上传zip  用unzip解压到当前目录 unzip 文件名5 z  u" q" R+ H5 ]

  609. 6 I! E4 M& k. F( F( n8 }
  610. # cd owlient-phpredis-90ecd17/   #打开解压后的文件夹里面  这个解压后的目录 要是不知道 可以输入 "dir" 查看* r0 ?1 x; T; c/ R
  611. # /www/nginx_php-5.2.17/bin
    + i2 T- L. b9 S; j
  612. # ./configure --with-php-config=/www/nginx_php-5.2.17/bin/php-config
    # ^8 C2 V2 d2 D/ c3 T% S% ?0 J0 ^
  613. #make
    % {: C0 ]6 o& u( u7 F8 w) L# [6 _( }
  614. #make install   #记录产生的redis.so路径; I: @! B( T* T7 `! b$ J, @3 f

  615. ; S9 a& i- n" M4 K' }
  616. 修改php.ini文件
    ! d( [$ D) P7 q  H
  617. 在php.ini中添加如下一行:' h5 Y4 ~: y) D! }/ B
  618. extension=/?/redis.so  #是刚刚记录的产生redis.so的路 写在 ?那; h% N' F2 W. L. D# @( _) j, F
  619. 重启 使之生效:) z, n+ w, I: e9 U- v3 ^% M6 \
  620. /usr/local/php/sbin/php-fpm reload
    6 C9 F( X! z( g+ d
  621. /usr/local/nginx/sbin/nginx -s reload
    : Z, r9 _5 y0 {' c9 O0 j

  622. 8 d. m3 {' X' l; {3 p
  623. 将 Redis 作为 Linux 服务随机启动
    - I6 l8 a6 F$ Y1 \; L, K
  624. vi /etc/rc.local, 加入代码:
    ' }7 H$ X  D1 k# j& I1 o
  625. /root/redis-2.6.10/src/redis-serve  #路径看情况修改 0 e* ?5 p3 D: U) S- @8 u

  626. 5 W4 s( r- F0 q% n. {+ Q/ p6 _
  627. redis-cli -h localhost -p 6379 info  #命令要在redis目录下面执行
    " r6 a4 ~+ l# I3 m
  628. 提供host为localhost,端口为6379,redis服务的统计信息( u$ T5 v: ?/ m) g3 b* n7 I# |
  629. 8 D, X" S9 s$ z

  630. 5 A5 r7 G- Q; B% V4 P* M
  631. 就这样你的web服务器就支持redis了 记得要在 给dz 的配置文件 加上12.0.0.1哦
    6 r9 a% \' _. m( I' B" b: N
  632. dz配置文件在 config目录下面的 config_global.php
    9 ?" |! f4 ?4 C& J$ ^5 O
  633. $_config['memory']['redis']['server'] = '127.0.0.1';
    4 j& \4 Z- x' O' ?' X
  634. $_config['memory']['redis']['port'] = 6379;
    4 k7 C' n7 M# [$ @+ T6 M
  635. $_config['memory']['redis']['pconnect'] = 1;/ i; q- |; d! M  h. D6 J5 k! o: F
  636. $_config['memory']['redis']['timeout'] = '0';
    & I( ~! V9 q$ q7 A8 l5 ~
  637. $_config['memory']['redis']['serializer'] = 1;
    # e  }; ~- k0 P8 J, u6 r( m/ E
复制代码
关注微信公众号《神采飞扬网》,即可获取最新回复通知!

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

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

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

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