分享到:
发表于 2018-11-16 12:42:28 | 显示全部楼层 |阅读模式
环境配置9 B0 j* q$ h! b; i4 c
: M, ~; F* b4 b* j( o
; R0 d7 @# G# p
http://www.discuz.net/forum.php? ... amp;highlight=REDIS
关注微信公众号《神采飞扬网》,即可获取最新回复通知!
 楼主| 发表于 2018-11-16 12:43:33 | 显示全部楼层
http://www.discuz.net/forum.php? ... 648&highlight=REDIS  r% m  P3 m/ D) `* p
无意间测试 单机状态 redis相当给力 测试1000请求/s  单纯的 get 和set 居然只用了 0.01秒 当时我惊呆了
6 i& m$ E) x3 N$ f* c, U7 S# L, P" o' G# _. u) m& {
http://www.discuz.net/forum.php? ... 731&highlight=REDIS
3 L/ G5 k( _- |! f# H/ `) u/ s% t
! }! c9 U+ k6 [; u3 thttps://wenku.baidu.com/view/265a5ce176a20029bc642d0b.html& C- F4 s2 w# f, I+ `2 `( _8 |1 |
0 w( u9 p5 c5 A* C+ @
=======================================& ^' d1 ^0 D/ o( ~: M% {7 t
  1. 连接上 ssh
    % V$ q6 U% N' U$ e: c

  2. 8 l! o5 i" k$ q
  3. $ ~' K3 N0 g2 `4 s
  4. 第一步:下载redis
    " X2 F" o& l( S: b* d: X' l
  5. # wget http://redis.googlecode.com/files/redis-2.6.10.tar.gz7 Y1 K# I  ?) J5 C1 x2 b2 V
  6. # tar zxvf redis-2.6.10.tar.gz
    . ^; l, s7 B' B: @1 x3 x
  7. # cd redis-2.6.10
    ; e/ K2 J% C/ k8 N
  8. # make & g* r! ~9 Z9 |
  9. # make install  2 r4 f; f; F- t7 A
  10. #cp redis.conf  /etc/ #复制配置文件到etc目录下面3 J/ N' A* S1 B0 h, s1 w4 L
  11. 第二步:修改配置
    / f$ h; Z( f, `2 o! G$ J' h8 \2 g
  12. #vi /etc/redis.conf
    3 C. H, k' i7 z; g! O3 p& A
  13. ######################下面是无措的配置文件 复制过去就成#########
    % F/ b) _, R0 E$ X+ I+ D3 d
  14. # Redis configuration file example
    3 k" A& k3 f% R  p" H  ?0 ^
  15. ) C* q5 q& x  K7 k( P; M/ [
  16. # Note on units: when memory size is needed, it is possible to specify# U4 v6 x8 U) y6 G' E- W: B% L
  17. # it in the usual form of 1k 5GB 4M and so forth:
    : F2 K. H9 M% l% u; K4 l
  18. #8 a1 f2 |7 g9 ]7 J2 @
  19. # 1k => 1000 bytes
    # M# a9 m* \1 B0 @& o4 F* U& Q% s
  20. # 1kb => 1024 bytes' d! Y$ J+ `/ Z
  21. # 1m => 1000000 bytes
    1 D% \/ _$ W3 P
  22. # 1mb => 1024*1024 bytes8 L2 Z! r- d# K4 I
  23. # 1g => 1000000000 bytes4 W6 W5 [+ G. T9 o3 }* C9 g1 U
  24. # 1gb => 1024*1024*1024 bytes
    9 @' U7 {) n# ?/ y# N- W0 l% D
  25. #
    2 M4 q+ ]" c  w+ f7 p2 n) l
  26. # units are case insensitive so 1GB 1Gb 1gB are all the same.) A& u3 |1 @3 f3 B. q
  27. ) E, f0 F' V: r
  28. # By default Redis does not run as a daemon. Use 'yes' if you need it.
    / _7 y: Y9 Z. R$ d! W2 J& n, i
  29. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
    : d. h$ |. a$ V0 w( Y
  30. daemonize yes
    8 z# Q  |: C% v/ a
  31. 6 E: ^. C7 R$ {2 D: p* V' j
  32. # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
    ! Q6 B% x+ c% p9 [! T
  33. # default. You can specify a custom pid file location here.
    $ o( B1 S2 i& H; v# K
  34. pidfile /var/run/redis.pid
    ; ~, G1 V' Y  Q% i

  35. 9 ?4 ]3 P3 O3 _: \. }: f
  36. # Accept connections on the specified port, default is 6379." j4 {9 u2 \8 Y. }+ B" G
  37. # If port 0 is specified Redis will not listen on a TCP socket." f  y/ y1 U6 Q  F$ L/ ]6 X# G6 P: w
  38. port 6379
    $ a. _" [& ~6 f- ~2 Q" J9 I6 t
  39. 1 R6 w+ Z' T3 ?8 e/ R: W( k
  40. # If you want you can bind a single interface, if the bind option is not6 g: O. W7 g( {# o9 U0 |* t
  41. # specified all the interfaces will listen for incoming connections.
    2 d5 I) h; T: W0 o7 y( W2 a
  42. #
    3 W& ~  _0 o7 C# ?9 h
  43. # bind 127.0.0.1
    ! j% X* {) T: Z1 @; K& T  |6 p
  44. % c- v/ d' I$ H9 t; f2 ]! V/ ?2 v
  45. # Specify the path for the unix socket that will be used to listen for
    ) h8 b' A5 T5 X2 [
  46. # incoming connections. There is no default, so Redis will not listen
    ' C. U- G4 `* S$ @. j1 I
  47. # on a unix socket when not specified.. q3 W) _$ T/ T" K$ V* y+ j
  48. #
    # K5 O' ^. o9 Z* g
  49. # unixsocket /tmp/redis.sock( X* d7 |- K! B/ ^3 y2 b2 P
  50. # unixsocketperm 755
    9 s  K- o$ P$ x0 ~3 p/ A3 |! ?9 [6 D' a
  51. ; @9 ~3 E+ c4 E) R$ h
  52. # Close the connection after a client is idle for N seconds (0 to disable)
    * Q9 X' N3 X# x* s: k; ?
  53. timeout 300
    : @, s$ M, O$ k. K0 T8 C8 X
  54. 1 F# m! g" P7 F- z
  55. # TCP keepalive.. E! W1 ]  Y5 L3 ?/ C: T
  56. #
    1 F0 k) K/ J9 a+ f* l
  57. # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
    ; @# a$ ^3 c( `) H! S* u
  58. # of communication. This is useful for two reasons:
    9 X$ K2 P* p4 X* W- x. e
  59. #
    ( M7 i- ~) w4 y1 t: x
  60. # 1) Detect dead peers.
    9 r- ^. H# }2 F0 u
  61. # 2) Take the connection alive from the point of view of network2 Z1 o' R% F% n
  62. #    equipment in the middle.
    1 G+ i" E+ i6 q
  63. #
    0 N1 ?4 Y$ I& p) {3 o
  64. # On Linux, the specified value (in seconds) is the period used to send ACKs.
    / V; Q' J% L4 E  E- f+ q/ p4 A6 r. m
  65. # Note that to close the connection the double of the time is needed.$ z  K: N# u5 Z
  66. # On other kernels the period depends on the kernel configuration.
    + ^! Z# b0 M: p& P" S! k: O& p8 e4 _
  67. #3 u0 J' P. ]3 J* ^
  68. # A reasonable value for this option is 60 seconds.: y8 H* I4 h2 `' ~
  69. tcp-keepalive 0) F& ?- w4 q2 M  w# W

  70. . {, ^' V; f' \0 _+ \3 K! h: k  {
  71. # Specify the server verbosity level.7 ]/ S- U: }/ c) @" K" z
  72. # This can be one of:
    / \1 y+ I: O# C; H+ u
  73. # debug (a lot of information, useful for development/testing)9 E/ M) @! p  K
  74. # verbose (many rarely useful info, but not a mess like the debug level)
      E, b8 w% f& n* U; Z! E
  75. # notice (moderately verbose, what you want in production probably)' \% e( `, [  o2 P( g% Z# _  D5 o
  76. # warning (only very important / critical messages are logged)% \7 C+ Q. V1 e9 @& X; P2 v% k$ d
  77. loglevel warning
    " S+ [" W! `: U+ U( a! i/ R
  78. 6 J+ j* m4 N" K! f4 ?' |& h
  79. # Specify the log file name. Also 'stdout' can be used to force
    0 f" c/ W: i) U* I; R9 F0 U
  80. # Redis to log on the standard output. Note that if you use standard- N2 a8 j2 D: }- f3 ~
  81. # output for logging but daemonize, logs will be sent to /dev/null
    " T, p1 f' H/ ]0 S
  82. logfile /var/log/redis.log* A& l/ ?! P, L& A8 ~

  83. 8 F( A6 z, |- K( o; @
  84. # To enable logging to the system logger, just set 'syslog-enabled' to yes,
    " |' A' d, y9 `  f* p. t/ H, z
  85. # and optionally update the other syslog parameters to suit your needs.# e( d  Q/ b3 C0 ^! A
  86. syslog-enabled yes( [% U% E/ t: _% W/ H- X6 p
  87. & ]' M* e; _5 q8 X( E' t
  88. # Specify the syslog identity." q7 p7 S: N0 u5 }1 G+ E  u
  89. # syslog-ident redis
    4 ]8 f; A; D# f) u6 E) K
  90. 7 r# \2 h& I" c( Z
  91. # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
    ; i: Y& i8 o) H
  92. syslog-facility local0+ u3 f# K* {6 [8 J/ _0 }

  93. ' K" `) e0 @& y8 P# A1 D5 s  S  m
  94. # Set the number of databases. The default database is DB 0, you can select2 t! s9 v4 l" ?+ f
  95. # a different one on a per-connection basis using SELECT <dbid> where. V7 V8 o+ K8 r* J
  96. # dbid is a number between 0 and 'databases'-1
    % u4 `. H1 M( Q, E. D/ @! g1 W
  97. databases 16+ S# H/ \! Q# d4 s. e
  98. , h2 ]. A% G* k, J0 K
  99. ################################ SNAPSHOTTING  #################################
    ' q% h6 j- D% n; K
  100. #3 r( ]' G- O6 M, {7 R% W; {- \) ^  H
  101. # Save the DB on disk:
    5 x2 O" [! Y( k/ c( U6 q/ ~+ {7 R
  102. #7 f9 e+ m) k( j' r' Q( l1 ]9 d
  103. #   save <seconds> <changes>
    - u/ L9 e' x/ \& \) N; ?5 m
  104. #
    0 l  q$ N: p4 a' ]0 j
  105. #   Will save the DB if both the given number of seconds and the given5 y4 o" u2 [0 F$ x; F. r8 G) \
  106. #   number of write operations against the DB occurred.6 x7 {- O/ O9 T
  107. #5 |- q+ n: r% e/ S$ Y2 W! C# m
  108. #   In the example below the behaviour will be to save:0 E+ v" R9 k$ W
  109. #   after 900 sec (15 min) if at least 1 key changed0 U3 l2 k% B+ `4 K
  110. #   after 300 sec (5 min) if at least 10 keys changed% c$ A, @# u: I+ T! W6 c2 _: }/ e
  111. #   after 60 sec if at least 10000 keys changed6 q" ?9 q. [3 J9 X4 U9 u7 Z
  112. #: i4 g, q' ~/ D2 Z- m+ H
  113. #   Note: you can disable saving at all commenting all the "save" lines.. E: t8 Q  l# J0 N
  114. #/ F' b, y( m6 I5 d- T
  115. #   It is also possible to remove all the previously configured save. @. U  O8 B0 ], O1 i
  116. #   points by adding a save directive with a single empty string argument& g  U- C4 X6 M9 w. k: F1 [4 p
  117. #   like in the following example:
    4 ]7 L3 l9 |2 q0 Z; _# T0 [
  118. #
    / r& C! L  c2 W
  119. #   save ""( {9 H6 M+ j( m

  120. ) Z% a/ X$ |3 m( A# ?) C
  121. save 900 1
    ( _6 ~2 r1 R- R' y* H& ^
  122. save 300 10
    ; {" p8 o. F$ W* U
  123. save 60 100003 D# W* V/ @0 j- y# A3 W5 @
  124. 0 W% h5 A+ u0 Z4 `: {4 c/ f
  125. # By default Redis will stop accepting writes if RDB snapshots are enabled
    8 e7 M9 \8 \' [; G* N8 b! E& ^
  126. # (at least one save point) and the latest background save failed.
    # S5 V% v! H9 {( D' x" R
  127. # This will make the user aware (in an hard way) that data is not persisting7 P6 Y* n" n# t0 W7 d' k% N! O
  128. # on disk properly, otherwise chances are that no one will notice and some
    1 I0 M* s" l5 Z$ J
  129. # distater will happen.- q. S- S7 C& j/ }! k+ |
  130. #
    / U3 k6 S! t+ Q/ @* V0 e* W
  131. # If the background saving process will start working again Redis will; z0 ?5 e9 u  p
  132. # automatically allow writes again.* P8 t2 I6 Q/ e5 p$ X# l3 r( r
  133. #: N% M2 x( D2 N! s
  134. # However if you have setup your proper monitoring of the Redis server0 C4 B- \7 S% }! B: Z* m3 z+ }
  135. # and persistence, you may want to disable this feature so that Redis will0 c  ^: C6 A+ a, d6 {/ \
  136. # continue to work as usually even if there are problems with disk,
    , K. \( l) E  _1 M
  137. # permissions, and so forth.. g" |9 e3 ~) R
  138. stop-writes-on-bgsave-error yes
    - s2 @" r3 b  @* y
  139. ) i& S6 ], z  H7 b; n
  140. # Compress string objects using LZF when dump .rdb databases?
      P2 C! S+ {2 b" Q: L4 E2 o( i7 H& F
  141. # For default that's set to 'yes' as it's almost always a win.
    2 O; K, ^% m- ^" c8 ^
  142. # If you want to save some CPU in the saving child set it to 'no' but/ Z. V( {( y! [" f6 L
  143. # the dataset will likely be bigger if you have compressible values or keys.
    3 e! `6 J. N& v4 d  W
  144. rdbcompression yes
    7 m; S) e1 m- T  B; w" G$ I0 M
  145.   n; D6 C: O. N  i# v) i5 q
  146. # Since version 5 of RDB a CRC64 checksum is placed at the end of the file.
    3 e* m& j& Q' g' k4 l" n
  147. # This makes the format more resistant to corruption but there is a performance7 _% Q& a7 M- D; S
  148. # hit to pay (around 10%) when saving and loading RDB files, so you can disable it# E9 B+ K# i6 x* w! R" w
  149. # for maximum performances.
    ( S# ?+ F( W1 }3 D
  150. #
    . p" `0 ~/ b! |4 A
  151. # RDB files created with checksum disabled have a checksum of zero that will
    0 E" F2 n6 Y2 }5 [$ z0 r. o& d  K. ~
  152. # tell the loading code to skip the check.
    + G, F! j( [6 A; B2 Q1 m
  153. rdbchecksum yes0 ?) p4 p9 }" w6 x& m

  154. 8 E) u$ Y; P3 q8 C& o
  155. # The filename where to dump the DB
    " d* o. [% A) _" @
  156. dbfilename dump.rdb
      P& O) q8 u4 D# e* l, _
  157.   K  `& v  f: n' k0 q$ M9 H
  158. # The working directory.
    ' o' T; R, O* f  k" j& u
  159. #
    ! ?9 l& o# v. R* Y) y; r# y
  160. # The DB will be written inside this directory, with the filename specified" n" x2 i) `$ J
  161. # above using the 'dbfilename' configuration directive.
    7 u- O& A% p# n  o
  162. # 7 C* ~& I, b& r6 k  t9 F
  163. # The Append Only File will also be created inside this directory.
    , e, H( D3 J1 T
  164. #
    ' t: ~$ c$ G. J" z
  165. # Note that you must specify a directory here, not a file name.
    ! x% ~& o( ?0 V* F  F
  166. dir /var/db/redis' A: C- B4 `- A5 @/ y
  167. ! K6 Q: h  E- q- @* q5 Q
  168. ################################# REPLICATION #################################$ o$ T; V( }1 ^. _- _

  169. 3 M- v, }- P& G, P) B. G
  170. # Master-Slave replication. Use slaveof to make a Redis instance a copy of
    : L# B& M9 j# E$ J0 z3 R; {
  171. # another Redis server. Note that the configuration is local to the slave* h+ f- V" F3 V6 y9 u. B/ m- c
  172. # so for example it is possible to configure the slave to save the DB with a/ ~1 X8 A$ D3 @3 s9 i# W
  173. # different interval, or to listen to another port, and so on.
    . V6 \4 N; J( ]
  174. #
    " c4 K) _8 g/ ]( U' B2 O, D
  175. # slaveof <masterip> <masterport>/ ?; \2 T( w9 z' q& I% [
  176. . H9 J- q+ ], o$ R6 U9 v' z# P
  177. # If the master is password protected (using the "requirepass" configuration
    ; M, b6 E' S3 r
  178. # directive below) it is possible to tell the slave to authenticate before
    4 @. l# i9 T7 l6 R; ^" w
  179. # starting the replication synchronization process, otherwise the master will
    3 x; ^8 ?0 y% Y9 y& t( x
  180. # refuse the slave request.8 P! g/ T8 M- T2 T5 E$ _0 ~
  181. #8 q5 }* w, `" ~0 N+ C
  182. # masterauth <master-password>
    9 C6 B1 f" z. {: |$ s  g8 V
  183. / r$ ]2 C9 C, I
  184. # When a slave loses its connection with the master, or when the replication
    $ o! q7 L5 p9 u. L( x7 T0 Z6 x
  185. # is still in progress, the slave can act in two different ways:* ]( R* w; V0 k/ D* R) }
  186. #
    3 k4 h+ A2 V' s" o% [# E
  187. # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will, J% a; i6 G7 A
  188. #    still reply to client requests, possibly with out of date data, or the3 D. i2 J+ v4 M. r" |
  189. #    data set may just be empty if this is the first synchronization.  u9 j' A+ j: c6 _4 e
  190. #
    " T2 U, D4 [7 ^- v9 B
  191. # 2) if slave-serve-stale data is set to 'no' the slave will reply with
    % Z0 S' O3 R8 L7 e/ e! I1 Z
  192. #    an error "SYNC with master in progress" to all the kind of commands
    * q* E' m5 E" x" ]. g2 P2 i5 x+ G
  193. #    but to INFO and SLAVEOF.
    6 O1 s3 b; \3 f7 d8 [" {
  194. #
    2 \9 n) M$ s: v/ {6 B' v' S
  195. slave-serve-stale-data yes
    * Q& j8 N" s% G! {' [2 f

  196. * N: j8 f0 T; r. g$ h: ^/ G3 x
  197. # You can configure a slave instance to accept writes or not. Writing against* p' k8 i, v; o! Z! F! P- G+ e
  198. # a slave instance may be useful to store some ephemeral data (because data
    4 s1 v5 m: ^. g0 ~) O9 V
  199. # written on a slave will be easily deleted after resync with the master) but
      x( F. Q# @$ D. i
  200. # may also cause problems if clients are writing to it because of a& I* i  y6 m& ^& O. B
  201. # misconfiguration.& t2 t3 e' \. f# ]( T7 M
  202. #
    & w8 K+ R1 C# \4 |4 w6 o0 j
  203. # Since Redis 2.6 by default slaves are read-only.$ v7 D3 i7 }5 o
  204. #' }% q/ S' ~  e5 J* f' W" U  e
  205. # Note: read only slaves are not designed to be exposed to untrusted clients
    9 f$ G1 R6 p. M1 A5 q) E
  206. # on the internet. It's just a protection layer against misuse of the instance.# p  w2 t2 W  ]1 M# u! Z, h; o
  207. # Still a read only slave exports by default all the administrative commands
    . S: n' u3 R8 e1 P  J
  208. # such as CONFIG, DEBUG, and so forth. To a limited extend you can improve7 F; g8 \+ T1 u- ]6 y
  209. # security of read only slaves using 'rename-command' to shadow all the
    6 K' V% Q" y6 W! L" c6 ]7 c
  210. # administrative / dangerous commands.$ G8 D1 V0 s! @" y9 ?1 b+ I
  211. slave-read-only yes/ }1 S  D1 p% D( x' E' e
  212. 4 y$ o- Y# g. G# {# g! P/ T
  213. # Slaves send PINGs to server in a predefined interval. It's possible to change
    3 W2 m* r8 m1 j! s( y9 l6 k/ Q4 y, W
  214. # this interval with the repl_ping_slave_period option. The default value is 101 M+ [9 |' h" L% n# Q- [: k
  215. # seconds.  }) \; {9 O2 y3 s0 u) }1 B) e
  216. #4 b. O: s# H4 g, X1 g( X* m4 s% `
  217. # repl-ping-slave-period 10, ?& _* N0 p8 N1 n

  218. + s% f! h: p6 b" u
  219. # The following option sets a timeout for both Bulk transfer I/O timeout and; `  l9 l1 y  o4 r7 J) f7 Q6 ?
  220. # master data or ping response timeout. The default value is 60 seconds.
    0 Y! P6 Q7 f( c" m2 J. Y5 ?
  221. #* ]" b2 Q* h4 p- Q' W
  222. # It is important to make sure that this value is greater than the value7 q% v0 C- w* V% W$ r+ F# F
  223. # specified for repl-ping-slave-period otherwise a timeout will be detected( ^+ d, S$ P( W3 s  L
  224. # every time there is low traffic between the master and the slave.
    : j; y! q2 {  D. `; f; a
  225. #' Q7 y& L# s, O4 Z$ \9 O! T: e
  226. # repl-timeout 608 z6 w, ]- t2 k% I
  227. 8 x- J3 G  y% g% x( I
  228. # Disable TCP_NODELAY on the slave socket after SYNC?
    2 V& s' t' B+ B5 `. x& \
  229. #4 n$ f* t1 d, p  k
  230. # If you select "yes" Redis will use a smaller number of TCP packets and4 [1 q3 A3 |- a3 q1 b  L& R& @
  231. # less bandwidth to send data to slaves. But this can add a delay for& R7 D  [) v4 ~9 g, R
  232. # the data to appear on the slave side, up to 40 milliseconds with8 z" u$ n# Z9 a/ l2 @; v9 s
  233. # Linux kernels using a default configuration.
    ; j4 G3 G. a8 W# d* {
  234. #
    0 c! k% i" i0 \
  235. # If you select "no" the delay for data to appear on the slave side will
    1 W; k& L0 {( Y/ o6 S; S
  236. # be reduced but more bandwidth will be used for replication.3 a5 p1 D8 F8 K( D& H
  237. #9 D4 @# O$ m& j! G- ]4 V
  238. # By default we optimize for low latency, but in very high traffic conditions
    8 f# _4 Y6 |. \" I9 Q: v9 \
  239. # or when the master and slaves are many hops away, turning this to "yes" may
    & C- @# G+ k% h, L9 R$ D, @
  240. # be a good idea.
    ! q1 p5 ]# P. W0 f8 |
  241. repl-disable-tcp-nodelay no# t2 c" v' J- @3 A9 W3 S& I
  242. 3 {# w) {: I2 e+ n2 r% |' z5 A
  243. # The slave priority is an integer number published by Redis in the INFO output.
    ! e% `. h' m! d
  244. # It is used by Redis Sentinel in order to select a slave to promote into a' [1 M$ z5 G; v- H* I& l0 u
  245. # master if the master is no longer working correctly.
    . W0 x# @+ M. z0 R
  246. #$ F5 l9 C: A/ J$ W- `% J6 i: s
  247. # A slave with a low priority number is considered better for promotion, so2 b/ ?, `  G0 |
  248. # for instance if there are three slaves with priority 10, 100, 25 Sentinel will3 e, [- ^% ^6 _/ T; ^& @
  249. # pick the one wtih priority 10, that is the lowest.) W7 A7 R0 ]. R+ `* W8 {; B
  250. #$ k! T3 h+ D% V' L. @' {) _
  251. # However a special priority of 0 marks the slave as not able to perform the
    6 }& n/ `6 I, j  O- C, J
  252. # role of master, so a slave with priority of 0 will never be selected by
    $ U! U# E: y* {# p5 h
  253. # Redis Sentinel for promotion.
    ! [* G  x: u( Q! s
  254. #
    ) D" \- r4 |5 g7 ]1 `3 K
  255. # By default the priority is 100.& {6 n3 B# U3 g( K5 P7 l
  256. slave-priority 1004 q( s" K6 F3 R3 w& f

  257. 2 l- \+ ?9 ?/ V( X1 x
  258. ################################## SECURITY ###################################
    0 S$ k' j- M( N: I3 c% H: s
  259. * w  W6 r6 m& K2 W5 ^
  260. # Require clients to issue AUTH <ASSWORD> before processing any other' S% w+ L, c  A$ d+ k
  261. # commands.  This might be useful in environments in which you do not trust% \" ]# I& d( M* b% g! w3 l
  262. # others with access to the host running redis-server.1 p( m2 s  _5 }) n
  263. #" Q, x4 B8 _  \7 @% I
  264. # This should stay commented out for backward compatibility and because most
    - z2 P. n% ~; r4 a, C: U( c
  265. # people do not need auth (e.g. they run their own servers)." }( J, f! Q1 K
  266. #
    1 ~: j8 i5 t2 I- [
  267. # Warning: since Redis is pretty fast an outside user can try up to8 P) K# q( R0 Z, I' f) [" d! `
  268. # 150k passwords per second against a good box. This means that you should
    + W, v" S% q( D  ~# f
  269. # use a very strong password otherwise it will be very easy to break.
    2 u6 q9 J6 D, e
  270. #& J/ G" q4 p8 V2 q* C4 G' Z
  271. # requirepass foobared
    - l7 _* t% p! R4 W& ~% a
  272. 3 g9 @/ l/ O0 S8 t4 s
  273. # Command renaming.
    - W7 k- W8 V0 ?0 J: J
  274. #
    & `0 Q9 |% e- S7 d
  275. # It is possible to change the name of dangerous commands in a shared
    3 M+ X/ Y, d% @( g1 J
  276. # environment. For instance the CONFIG command may be renamed into something" U- w6 P* j2 L7 B
  277. # hard to guess so that it will still be available for internal-use tools
    ' U/ c+ Z& V4 ]- a8 \2 E7 R0 A
  278. # but not available for general clients.
    8 B  ^/ n: O1 R" W5 m* S, ]
  279. #
    2 j: G) f1 i: K" r: @
  280. # Example:
    ' E( E9 s9 E2 h
  281. #& Y$ S$ B6 D; z8 w  w
  282. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52. O( q2 ?% @: M% ]
  283. #
    ( C6 E1 D8 X9 p- [6 \; w9 b
  284. # It is also possible to completely kill a command by renaming it into
    " L. }' @( ~3 X  @
  285. # an empty string:
    9 V' s$ e# j  {$ C% Z
  286. #
    6 Y1 [2 A  s7 m* N: h3 T2 a
  287. # rename-command CONFIG ""
    4 [4 V6 L7 D$ n

  288. ! d5 J) J0 H2 x
  289. ################################### LIMITS ####################################
    * ]! N2 H2 {: g
  290. $ A, D7 P$ K) I2 Q( s- M
  291. # Set the max number of connected clients at the same time. By default. }0 s3 w5 C) |1 p2 H
  292. # this limit is set to 10000 clients, however if the Redis server is not
    8 ]8 Y( ], j+ K! W  H3 r
  293. # able to configure the process file limit to allow for the specified limit+ i; K* U$ \! q* ~2 J1 C- z' l
  294. # the max number of allowed clients is set to the current file limit; C$ K7 h  |; K( b9 ^$ z! h
  295. # minus 32 (as Redis reserves a few file descriptors for internal uses).
    : ]3 i3 n6 Q6 [0 c. {0 W% m) X7 B
  296. #8 a# C7 S, N7 x7 P$ B  z  M: K
  297. # Once the limit is reached Redis will close all the new connections sending
    ! ?% v4 ]/ |5 h+ {; n# M$ Q+ S+ ]
  298. # an error 'max number of clients reached'.$ W" O: ^# b4 I$ [4 H1 I
  299. #
    $ R9 |, S2 ~' j7 O* S0 I
  300. maxclients 500
    ' @! E( p. v3 F/ r
  301. ) H' V- N2 C7 H/ {* J$ j: ~. [
  302. # Don't use more memory than the specified amount of bytes.
    6 w" K' P" l4 Y1 |
  303. # When the memory limit is reached Redis will try to remove keys2 M' [% X, @) h3 V
  304. # accordingly to the eviction policy selected (see maxmemmory-policy).6 o% V0 l* C* P0 W+ R) @) ^
  305. #" x7 ~  z, R; S6 A& g% |  o- }; q* _
  306. # If Redis can't remove keys according to the policy, or if the policy is9 I$ Z% X0 u4 c$ O, k3 v
  307. # set to 'noeviction', Redis will start to reply with errors to commands
    ( R  }$ \. O1 f8 f- B
  308. # that would use more memory, like SET, LPUSH, and so on, and will continue
    ! N3 B* u/ |4 t. r. Z* w
  309. # to reply to read-only commands like GET.( B7 L6 D7 V7 _1 K0 {$ A; ?/ U
  310. #
    ( d/ ^  p( S; ^- ^! x# [: F
  311. # This option is usually useful when using Redis as an LRU cache, or to set
    ' D2 t8 g. p, ?
  312. # an hard memory limit for an instance (using the 'noeviction' policy).
    - U7 a: b: f8 X
  313. #7 H; K5 c6 c7 v" J& J! E4 {; w
  314. # WARNING: If you have slaves attached to an instance with maxmemory on,
    7 Q; |3 @+ K$ ]7 Y6 {  @
  315. # the size of the output buffers needed to feed the slaves are subtracted
    9 w2 U- Z- _0 N1 m; H3 F$ B
  316. # from the used memory count, so that network problems / resyncs will5 j3 F7 \) O5 r' E1 @8 V6 d
  317. # not trigger a loop where keys are evicted, and in turn the output
    2 t- I/ e( u% z' l" H; W1 k
  318. # buffer of slaves is full with DELs of keys evicted triggering the deletion" Y# N/ a& j) X3 g+ r: ?" L# ?
  319. # of more keys, and so forth until the database is completely emptied.4 b5 B3 G, d1 d- i3 s' Z# H
  320. #
      z/ I6 \6 U* Z5 W' \- _
  321. # In short... if you have slaves attached it is suggested that you set a lower. i* F( W$ L" c* q2 d
  322. # limit for maxmemory so that there is some free RAM on the system for slave. ]3 i2 Q, P5 \9 [- l
  323. # output buffers (but this is not needed if the policy is 'noeviction').6 M1 U. q3 l9 N8 N- V: Z
  324. #" f" L# [5 r7 J4 Z: F3 v
  325. maxmemory 128000000( ?, T# }( {& c0 K3 O$ v
  326. & i4 u( F2 R0 T# Y  X  I+ D0 S
  327. # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory7 P- D% @+ L8 E8 N3 h& `
  328. # is reached. You can select among five behaviors:( q3 @" d% ^! R% O  x' U  W# c
  329. # ( S! [7 j: X1 r6 A3 s
  330. # volatile-lru -> remove the key with an expire set using an LRU algorithm; g# i" E" ^6 B. x* t
  331. # allkeys-lru -> remove any key accordingly to the LRU algorithm
    ! E8 C. N/ d% t8 d1 T
  332. # volatile-random -> remove a random key with an expire set; H7 J4 B: `" {7 R4 L0 s* [
  333. # allkeys-random -> remove a random key, any key# q. Z* \3 a( d1 C7 h
  334. # volatile-ttl -> remove the key with the nearest expire time (minor TTL)$ h" P/ A& @/ O* j5 j
  335. # noeviction -> don't expire at all, just return an error on write operations
    0 d- d6 f7 A" d) {1 P( G+ T1 G0 Z  J
  336. # 3 i# A+ Z- ~5 T) Y) L6 g
  337. # Note: with any of the above policies, Redis will return an error on write$ o% I; g- j5 T% B& u0 ?
  338. #       operations, when there are not suitable keys for eviction.
    3 l) U: Q- P- I4 u! u- B
  339. #
    2 q  d* b/ n6 Z2 x) M8 W
  340. #       At the date of writing this commands are: set setnx setex append5 C! y# _8 u  a: c" u
  341. #       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
    ; W' G$ t+ k& @$ ?: }, O
  342. #       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
    " W1 p4 {8 X9 M, C) B7 {2 O- Y
  343. #       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby5 C5 D+ f0 N. y/ {' l/ [
  344. #       getset mset msetnx exec sort* K$ \" C: B" R, _
  345. #
    $ ]! u# a7 B& h/ e
  346. # The default is:
    # ~/ D# }& E: @" o% d! \+ Q# _
  347. #
    3 E& ?+ R! Z# {" S* U1 N) C
  348. # maxmemory-policy volatile-lru) F  N; e' a# q9 D3 n
  349. 1 g! W9 M$ |6 W
  350. # LRU and minimal TTL algorithms are not precise algorithms but approximated% q9 ]/ e; L+ ]$ M. J; z. _
  351. # algorithms (in order to save memory), so you can select as well the sample0 m$ v7 r; n+ |/ \  l* I
  352. # size to check. For instance for default Redis will check three keys and7 V) W) ?( A1 s: P9 H0 N5 o% w& V
  353. # pick the one that was used less recently, you can change the sample size( B% ]; W- y" m& n  S
  354. # using the following configuration directive.
    1 ?# y. `6 ~3 E& M: g
  355. #* ]& G$ A1 b. A3 s" E5 r( m
  356. # maxmemory-samples 3) O- A+ p1 d( R9 `, L# A; w
  357. ; T. ?! g( w7 q( u4 U& V% W; a+ T
  358. ############################## APPEND ONLY MODE ###############################. Q$ I2 G1 e2 ]& R! f5 v* C! }
  359. ! ~% a( B5 c2 H. O) }# o8 k. p
  360. # By default Redis asynchronously dumps the dataset on disk. This mode is
    ' ^6 @$ P" P) P0 Q2 m
  361. # good enough in many applications, but an issue with the Redis process or
    ; @8 ^0 X% f  i
  362. # a power outage may result into a few minutes of writes lost (depending on
    ; z# V1 |2 n4 Q& U1 `. [
  363. # the configured save points).5 @  Y, q2 W, ^
  364. #5 x: Z6 S! U- H7 M& ^) i" a
  365. # The Append Only File is an alternative persistence mode that provides
    6 D' \) w5 p& r8 m7 f
  366. # much better durability. For instance using the default data fsync policy
    ' B* i. f3 o" W* ]% Y. [0 |8 B4 p
  367. # (see later in the config file) Redis can lose just one second of writes in a9 r# u. S) y- y+ ~: B; u7 e
  368. # dramatic event like a server power outage, or a single write if something$ t; C% m5 b, N4 A
  369. # wrong with the Redis process itself happens, but the operating system is! E6 @# c( I* t  r& N: e
  370. # still running correctly.( [% c; W4 `8 V; I/ m! V& o
  371. #1 g# o6 w  n( w9 Q7 a8 P
  372. # AOF and RDB persistence can be enabled at the same time without problems.2 ?5 Q9 ^* U( z* Q8 n% V' V( S
  373. # If the AOF is enabled on startup Redis will load the AOF, that is the file* ]. W9 @# [# ^) K' e2 a9 H
  374. # with the better durability guarantees.
    # d6 ~5 P( g" m# q& \* \
  375. #; B) P, z6 M0 I& r5 [. k; f
  376. # Please check http://redis.io/topics/persistence for more information.
    , A9 o& t. o, n. h

  377. 1 p1 m: K# C4 ?1 a
  378. appendonly no
    . i! z6 z, b0 H1 l( K8 V

  379.   Y: p3 f1 {  L: I( ]
  380. # The name of the append only file (default: "appendonly.aof")! a% I+ T3 S* o' k3 R
  381. # appendfilename appendonly.aof3 h0 T0 V( B) f3 |5 `
  382. ; s: _+ p0 K* c% s% G7 C6 v7 a
  383. # The fsync() call tells the Operating System to actually write data on disk; s  C) u) b* I1 Y. j) _; P# h- m
  384. # instead to wait for more data in the output buffer. Some OS will really flush " a! ]3 G" L2 V6 X  y
  385. # data on disk, some other OS will just try to do it ASAP.
    ; ]2 O$ ^9 M. b+ ?  e- s7 y5 T! ?
  386. #
    ) f7 u8 U' \2 W" R" ]$ V/ w
  387. # Redis supports three different modes:' j) m4 J6 a: m0 I! a: J  d
  388. #0 c- F7 B: a% T) U2 L
  389. # no: don't fsync, just let the OS flush the data when it wants. Faster.* z3 L1 c2 C2 B% B# e: u8 H
  390. # always: fsync after every write to the append only log . Slow, Safest.# e; U& F% r  h; S# X
  391. # everysec: fsync only one time every second. Compromise.* R7 R0 {' V. j' M
  392. #
    & E% b. m/ v, H6 G
  393. # The default is "everysec", as that's usually the right compromise between
    1 D- r0 s8 `' |! e# i
  394. # speed and data safety. It's up to you to understand if you can relax this to
    . O% |9 j5 [; O" n6 P, d0 E. D8 h
  395. # "no" that will let the operating system flush the output buffer when7 y: F/ D/ C* [1 `+ s
  396. # it wants, for better performances (but if you can live with the idea of0 z% t- h3 |8 Q6 K2 L0 M
  397. # some data loss consider the default persistence mode that's snapshotting),
    * }( ~7 m7 ]9 c% U
  398. # or on the contrary, use "always" that's very slow but a bit safer than
    / G0 E3 P6 g8 u2 s  j
  399. # everysec.
    8 C7 d& l. S( `4 l4 J
  400. #/ N; O# d9 B. D8 j/ [9 s
  401. # More details please check the following article:
    4 P# w$ W, k4 N5 O; v
  402. # http://antirez.com/post/redis-persistence-demystified.html
    2 g; e9 y4 D$ w
  403. #
    2 Z+ g+ O: o2 _- X8 ?  J9 t( p
  404. # If unsure, use "everysec".6 q, M9 \# O( |; X

  405. ; y1 n( Z: q& z" c. K; P8 e4 `
  406. # appendfsync always
    " m+ I  l' j* l0 I- S
  407. appendfsync everysec# j3 J  t+ D! N; g# d: F
  408. # appendfsync no9 y  }8 w. k0 {1 k; t0 a) Q" F, {' ~
  409. 9 N- `! L6 n* x0 Q5 V
  410. # When the AOF fsync policy is set to always or everysec, and a background; c  S1 G9 v. e" W
  411. # saving process (a background save or AOF log background rewriting) is
    . h5 ^* z1 t! w3 i
  412. # performing a lot of I/O against the disk, in some Linux configurations; E: {& i; i5 ]2 q
  413. # Redis may block too long on the fsync() call. Note that there is no fix for
    % P" ?! }. E" V: d. I
  414. # this currently, as even performing fsync in a different thread will block2 q" z* O1 V* V2 t( S/ R: Y
  415. # our synchronous write(2) call.4 z; O, c8 ]9 Y8 y
  416. #
    % W6 p, B& Q* K/ d7 q
  417. # In order to mitigate this problem it's possible to use the following option
    % W3 V$ }4 C8 P. K) F9 Z  s
  418. # that will prevent fsync() from being called in the main process while a# X( f$ b" [4 `0 Z" E# J, X
  419. # BGSAVE or BGREWRITEAOF is in progress.
    # \5 H' d7 M1 X! v
  420. #$ z2 U4 b& p2 a: a9 X2 A
  421. # This means that while another child is saving, the durability of Redis is% a# O1 q2 B; d1 V" i( [
  422. # the same as "appendfsync none". In practical terms, this means that it is
    , h' P( H) E! s  d+ h4 o
  423. # possible to lose up to 30 seconds of log in the worst scenario (with the
    ( I1 X3 q4 Z- B2 w$ X! ~
  424. # default Linux settings).- y* @) K: n# M/ y0 r  d
  425. #
    1 E8 U# o7 y7 Z5 Y5 G& u
  426. # If you have latency problems turn this to "yes". Otherwise leave it as
    - X+ A* I( C3 G, E
  427. # "no" that is the safest pick from the point of view of durability.
    ; a, @* P- a2 w& Q. Y
  428. no-appendfsync-on-rewrite no, w% Z! U5 S5 Z

  429. 0 F8 S& p; w& v1 n* h* Q5 Z: e
  430. # Automatic rewrite of the append only file.
    ) [1 Q1 ~) E8 }* W! \' n
  431. # Redis is able to automatically rewrite the log file implicitly calling' [9 c# m, F* W3 Q) L  E
  432. # BGREWRITEAOF when the AOF log size grows by the specified percentage.- Q8 n( q9 V# E5 w5 t: m& A
  433. #
    . F7 G3 z3 x, v! }
  434. # This is how it works: Redis remembers the size of the AOF file after the
    & e. g: `: g" d/ M, E2 J% b
  435. # latest rewrite (if no rewrite has happened since the restart, the size of" E) Z. K8 Y# n9 ^! y" V2 d  L$ t
  436. # the AOF at startup is used).
    , s5 o) P1 V3 w+ c3 W
  437. #
    ; E" W- E5 K0 e+ t& D
  438. # This base size is compared to the current size. If the current size is9 K: P. l& K0 d: H6 J6 [& A* I
  439. # bigger than the specified percentage, the rewrite is triggered. Also
      o: T- ]" l* x) Q
  440. # you need to specify a minimal size for the AOF file to be rewritten, this
    4 I; L  c) E+ M, x/ X7 T% o
  441. # is useful to avoid rewriting the AOF file even if the percentage increase
    ( M, D* D" c0 c1 A2 g! u7 B( `
  442. # is reached but it is still pretty small.! V; N9 ^2 ~# k: K- V$ l
  443. #
    7 P% ?  j% m' x4 S) P& j( E2 B5 c
  444. # Specify a percentage of zero in order to disable the automatic AOF0 `2 ?8 X% g1 S0 y! d
  445. # rewrite feature., W7 z2 B+ n* T' }8 Y
  446. " s, d8 k8 u) s" ~/ g
  447. auto-aof-rewrite-percentage 100# O& V" ~/ N* R0 E- Y
  448. auto-aof-rewrite-min-size 64mb
    5 q. \8 b5 C& Z/ I* O) {

  449. 1 A, P. j* D* E4 I, Z/ X9 N
  450. ################################ LUA SCRIPTING  ###############################
    " e6 y3 i; h& G. Z( ^( c% U2 E

  451. % `: X& }" f/ `) \
  452. # Max execution time of a Lua script in milliseconds.
    & x0 Y7 l' g6 e5 C" G" a+ C) `
  453. #
    % ^" W$ K! ]* }$ [/ ]7 P( n  ~  c
  454. # If the maximum execution time is reached Redis will log that a script is
    ( M: e2 n  C6 N- u2 F  x
  455. # still in execution after the maximum allowed time and will start to) h( e  h/ U0 `) r1 s6 ~
  456. # reply to queries with an error.
    ! f7 k& ?% Y3 |
  457. #
    1 t9 D- r1 V: p3 Z  X
  458. # When a long running script exceed the maximum execution time only the
    , f! v1 S: t" E+ M: d
  459. # SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be
    , k5 F% U. O, p. ^: d. k$ }3 c1 D
  460. # used to stop a script that did not yet called write commands. The second
    # l' D! ]# F, ~9 a  \4 k$ |1 B) j
  461. # is the only way to shut down the server in the case a write commands was
    * _$ K0 E/ R1 U7 O
  462. # already issue by the script but the user don't want to wait for the natural% O: W/ h5 p( f. D* n7 R
  463. # termination of the script.7 w. x) s0 G5 ~% f& Z$ |
  464. #- ?; a! ^6 R3 Z4 c" {9 g# c& L7 A0 O
  465. # Set it to 0 or a negative value for unlimited execution without warnings.$ B$ ?+ i% [1 P" i6 @
  466. lua-time-limit 5000) {$ ~) q, |) U, {$ W8 @
  467. : X- k# K2 n. v5 J
  468. ################################## SLOW LOG ###################################
    # Z9 f+ l5 _% H
  469. : D1 v( t# n5 m+ L; Z
  470. # The Redis Slow Log is a system to log queries that exceeded a specified
    1 r% R9 M% J! y  N. i) R. v- k
  471. # execution time. The execution time does not include the I/O operations; i  [: L# A1 z% x4 n1 y  \
  472. # like talking with the client, sending the reply and so forth,) I1 I. O! @0 J5 h: H1 {
  473. # but just the time needed to actually execute the command (this is the only
    ( h- q4 q# L! b7 q, b/ k
  474. # stage of command execution where the thread is blocked and can not serve( w; p' F  }5 T* E' S) M! w
  475. # other requests in the meantime).
    8 J2 O& J. r: [+ y+ L' X
  476. #
    ( B7 L: w  C  B4 J9 H, j! Z8 h8 n
  477. # You can configure the slow log with two parameters: one tells Redis3 v+ N; ]1 E3 g0 g% ^6 S+ e
  478. # what is the execution time, in microseconds, to exceed in order for the- Y3 _% k, I$ G* g
  479. # command to get logged, and the other parameter is the length of the
    ; I( s2 K3 O# E) Q
  480. # slow log. When a new command is logged the oldest one is removed from the
    / I5 u1 C; G2 V1 p
  481. # queue of logged commands.
    - N) ~. n  i% B7 i3 l/ R* d8 j
  482. ' U& R" N% m* `+ m9 [$ p
  483. # The following time is expressed in microseconds, so 1000000 is equivalent
    1 c3 \- ^8 x4 G( a# l! x+ Z2 H
  484. # to one second. Note that a negative number disables the slow log, while* k% C1 r# Z9 Q+ z  h+ p
  485. # a value of zero forces the logging of every command.: u! ?1 O3 N$ F2 v, A- X4 A7 E+ {
  486. slowlog-log-slower-than 10000
    & H. R; ^( o6 T; V* m- ~% X) t

  487. / V2 T5 s* ]3 X
  488. # There is no limit to this length. Just be aware that it will consume memory.
    ' n' N% ?+ z3 t
  489. # You can reclaim memory used by the slow log with SLOWLOG RESET.
    ' {7 G: a5 T0 d; h4 D1 ^' q
  490. slowlog-max-len 128
    * v$ {8 T7 N9 z6 Q5 {6 y4 a% ^
  491. " l. A' Y8 k! E+ m! w* a
  492. ############################### ADVANCED CONFIG ###############################$ M/ q2 h/ Q( C0 ^
  493. . j! X5 ^3 R/ ]& P  \  F
  494. # Hashes are encoded using a memory efficient data structure when they have a; L$ `" ^- L( N. {  W. N
  495. # small number of entries, and the biggest entry does not exceed a given" A' r' [8 a% @- z9 V" D$ Y
  496. # threshold. These thresholds can be configured using the following directives.
    , Z2 s* b5 e% `* k9 H3 ?( x* x
  497. hash-max-ziplist-entries 512' A" d, i' V5 e' C1 r5 }
  498. hash-max-ziplist-value 646 L/ ]2 t  h/ {( q) E% X

  499. " q5 e6 F  D) `, x
  500. # Similarly to hashes, small lists are also encoded in a special way in order
    - v) t! @" y3 h
  501. # to save a lot of space. The special representation is only used when
    ! n& H# q7 |3 j
  502. # you are under the following limits:
    " S6 P( {( t$ Q4 U9 h+ Q
  503. list-max-ziplist-entries 512
    ! z- e7 I1 g3 v0 e3 Y) q) B6 E
  504. list-max-ziplist-value 64
    8 U/ D# a* o0 o& `& I

  505. 2 j  \$ z- |- t+ L) D0 F* B
  506. # Sets have a special encoding in just one case: when a set is composed
    1 j" f4 ~- _& G' a+ }  E
  507. # of just strings that happens to be integers in radix 10 in the range
    * A4 b: U) r  w9 m
  508. # of 64 bit signed integers.
    . X: X! M9 W4 B% p, w
  509. # The following configuration setting sets the limit in the size of the
    * ]/ h% o# y7 Z, T) N& E
  510. # set in order to use this special memory saving encoding.
    1 ]% o) _9 Q% d5 _3 P! v0 b- E5 A$ g
  511. set-max-intset-entries 512: ]' i- V' x: I% \
  512. 1 X$ e2 |9 z2 U0 ?
  513. # Similarly to hashes and lists, sorted sets are also specially encoded in, b7 U5 e6 j" g. h" v6 T7 u; E! `
  514. # order to save a lot of space. This encoding is only used when the length and9 ^3 ?. p: e) [! x! Q0 A8 m
  515. # elements of a sorted set are below the following limits:5 }# O3 J7 _+ D  C' s+ P
  516. zset-max-ziplist-entries 1281 {# I! h5 Z0 V& ]# z9 O9 |! i
  517. zset-max-ziplist-value 64
    0 g+ U6 p. V1 d  Q' T

  518. 8 ]; H1 N# F% g) q! ~6 e4 I# e
  519. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
    . s5 p; R/ _, ^) P( q6 E3 ]
  520. # order to help rehashing the main Redis hash table (the one mapping top-level
    ! r: F; ?  G# y, J3 M7 V0 B( M  R0 Q
  521. # keys to values). The hash table implementation Redis uses (see dict.c)
    2 w" r, \- X0 Z# o' d6 Z! G4 h& \
  522. # performs a lazy rehashing: the more operation you run into an hash table+ \( g5 t+ ?7 q/ \8 ^3 e  z9 }
  523. # that is rehashing, the more rehashing "steps" are performed, so if the  G1 G( J% M' N+ k
  524. # server is idle the rehashing is never complete and some more memory is used
    ; T* n6 u4 m5 e! F# m
  525. # by the hash table.
    " j8 b) o+ s6 ~3 ]! S$ Z0 d8 e6 b
  526. #
    ' }; f6 V" Y) h# d% A8 j8 D2 O
  527. # The default is to use this millisecond 10 times every second in order to: C' S2 I2 n" R/ Q+ f
  528. # active rehashing the main dictionaries, freeing memory when possible.
    3 H2 K, o' p" t
  529. #
    3 `* J, t$ m* O! |
  530. # If unsure:$ K  ?0 E# R3 q+ q- m
  531. # use "activerehashing no" if you have hard latency requirements and it is6 I/ ]1 A% r" S5 d# t: J. a
  532. # not a good thing in your environment that Redis can reply form time to time( k: I! `  f) e& K
  533. # to queries with 2 milliseconds delay.) {( E% E( U% [  ]" z
  534. #" q- Z1 U  l: s
  535. # use "activerehashing yes" if you don't have such hard requirements but4 p) Y( L; C* M3 Q  ?
  536. # want to free memory asap when possible.
    5 v# X0 W9 c( a  q$ p" _
  537. activerehashing yes+ I. j4 T6 P4 [" o: {2 Z
  538. & g2 D5 X( Y! W2 \! \; Z# Z6 f
  539. # The client output buffer limits can be used to force disconnection of clients
    ) d; M7 ]2 N8 _/ m2 o( g
  540. # that are not reading data from the server fast enough for some reason (a7 m% t5 S$ ^6 F+ d$ g) w& G
  541. # common reason is that a Pub/Sub client can't consume messages as fast as the. [5 F# _' |  w
  542. # publisher can produce them).
    , V/ U1 q+ n1 H1 ^! x& O9 d& ~
  543. #9 g1 ]' z  m5 i7 ^/ B) L& A
  544. # The limit can be set differently for the three different classes of clients:
    * z7 x, Z  d1 o) \7 v( J
  545. #
    , P8 B# V( n1 s- Y9 C. l9 D. E1 ^
  546. # normal -> normal clients
    . [: ?- p$ |) v+ w. _( e# P' V
  547. # slave  -> slave clients and MONITOR clients9 }5 {* I/ Y/ s
  548. # pubsub -> clients subcribed to at least one pubsub channel or pattern3 c0 Q9 t* \% O3 C  L
  549. #/ K* A9 k  M/ {, [) W2 A* E
  550. # The syntax of every client-output-buffer-limit directive is the following:
    . v' U& ?: O% P7 _0 Z* A1 u
  551. #
    ) h$ U/ H* L# U2 {% v
  552. # client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>
    4 q2 L: U* j! J
  553. #
    ) u! |; _9 l" I# R! D& h+ L2 H
  554. # A client is immediately disconnected once the hard limit is reached, or if
    9 T/ H- W6 g) W. G
  555. # the soft limit is reached and remains reached for the specified number of
    % x3 w4 H2 w; x5 x1 C+ G
  556. # seconds (continuously).
    0 D8 j) v1 p1 V- ]; P' o! D
  557. # So for instance if the hard limit is 32 megabytes and the soft limit is& @& H  S/ N5 X# s6 D
  558. # 16 megabytes / 10 seconds, the client will get disconnected immediately
    3 p* u& P) `5 \* ]% y* u
  559. # if the size of the output buffers reach 32 megabytes, but will also get8 d2 I# e- D" I  @2 ?2 C
  560. # disconnected if the client reaches 16 megabytes and continuously overcomes7 f9 I* {. d) x1 l0 u7 |
  561. # the limit for 10 seconds.6 U! ~- C* w& @! I1 y
  562. #6 O1 }1 l4 d: N8 G# [4 k8 O
  563. # By default normal clients are not limited because they don't receive data
    / v  |2 \8 _' h  y
  564. # without asking (in a push way), but just after a request, so only
    ( H8 [  K2 r7 Y+ j& {/ [4 H
  565. # asynchronous clients may create a scenario where data is requested faster
    5 u, a2 m* M! i+ T+ P0 N
  566. # than it can read.
    , j" N/ p7 [9 V- R( l
  567. #" l# C7 q' e7 o" e
  568. # Instead there is a default limit for pubsub and slave clients, since+ e$ S; m8 t4 z/ e& m
  569. # subscribers and slaves receive data in a push fashion.
    6 X9 g1 d) r& r3 c
  570. #
    ; Z* V9 V* V) G
  571. # Both the hard or the soft limit can be disabled by setting them to zero.$ ^8 G5 w2 K/ `) |6 A* P
  572. client-output-buffer-limit normal 0 0 0
    . \4 m* T9 {% b& Z
  573. client-output-buffer-limit slave 256mb 64mb 60* W& ?: l7 u% G3 C& r! G# }4 K/ h
  574. client-output-buffer-limit pubsub 32mb 8mb 60
    % K, J/ T7 A! B9 S" X: _* a* F

  575. ; a8 j# L- P* e
  576. ################################## INCLUDES ###################################
    , o- x7 B/ N& J; o
  577.   G; `* w/ B/ ?, Z7 ]
  578. # Include one or more other config files here.  This is useful if you
    & w1 z* l: {8 i: S( y. l
  579. # have a standard template that goes to all Redis server but also need
      L6 |, V! Y2 J: N5 ^" P" G0 M
  580. # to customize a few per-server settings.  Include files can include$ z; E1 w) G! Z8 O( G1 ~$ n
  581. # other files, so use this wisely.+ K9 c' q! y' n* [
  582. #
    $ Y( P: ~; V- c. H' H! W- d- \" B
  583. # include /path/to/local.conf# T0 X3 Q5 Y" j
  584. # include /path/to/other.conf        8 ?! i. L1 b1 t, q2 n
  585. ##########################配置文件结束################################ # a3 S: Y2 C! y: e5 m9 }
  586. 第三步:启动进程
    9 M1 S9 C" d8 N
  587. #redis-server /etc/redis.conf+ y' e  v* L8 Q- j/ F  g
  588. 查看进程有没有成功启动* ~8 ~' L9 r5 l1 K* H8 P3 W! Q4 J
  589. #ps -ef | grep redis
    ( O" x" ?( ~& I0 v
  590. 测试输入一个键值7 B/ Q9 f: t+ \2 k1 d
  591. #redis-cli set test "testredis"
    8 X. x4 T3 L4 n& n3 `; d! S
  592. 获取键值
    % c9 e+ Q3 I! k, L& X2 g! q
  593. #redis-cli get test
      D& c: ]* m/ V) R8 d" B% v. s
  594. - L  B! A8 h, a8 h+ \/ Q$ }2 O% @

  595. : U' o' `; k$ Q8 x
  596. 第四步:关闭redis  (这个是更改配置文件后 正常的重启方式  不重新加载redis配置跳过)' _# b8 B7 w: A* d+ y
  597. # redis-cli shutdown      //关闭所有   
    / R7 |" Z: v5 [: }  ^
  598. 关闭某个端口上的redis   
    7 |. e# \9 ?8 R2 N. c. q
  599. # redis-cli -p 6397 shutdown  //关闭6397端口的redis  
    5 O9 n! G% r7 F+ Z" b
  600. 说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename  dump.rdb  ; v: H+ N+ e, Z3 n, ]  M5 e: D
  601. + P8 [2 e  ^8 c+ C9 f5 B$ @$ V* R2 v

  602. 3 y1 z4 _/ M0 m9 X. q. C
  603. 第5步:php扩展安装) D- @7 D2 p* j
  604. phpredis PHP扩展下载地址
    0 S, }0 J/ {4 e' g
  605. https://github.com/nicolasff/phpredis/tree/2.2.2 . E6 E3 b4 @$ u7 i' E: z# ]: t* ?
  606. 选择最新版本下载zip
    1 e! f0 Y$ A7 p8 }: X! o! d* K

  607. & L. I3 ~8 F: }0 r( X1 h
  608. 然后自己上传zip  用unzip解压到当前目录 unzip 文件名; A5 L. B/ _4 w! v8 e
  609. 6 N2 |: Z) {! b  E6 w5 H
  610. # cd owlient-phpredis-90ecd17/   #打开解压后的文件夹里面  这个解压后的目录 要是不知道 可以输入 "dir" 查看* p) H. P$ m$ B# |3 b
  611. # /www/nginx_php-5.2.17/bin 4 N" }# j0 F8 ~2 y
  612. # ./configure --with-php-config=/www/nginx_php-5.2.17/bin/php-config
    : ]- U" z) Z: c/ r/ ?& N5 Q
  613. #make
    ' [; R) ~2 j4 y# R7 P
  614. #make install   #记录产生的redis.so路径8 |  x# U  k. S

  615. ) }: P8 P$ g5 ^* i- |: E; b. S, B
  616. 修改php.ini文件
    , V( q6 D3 u4 O) c' I9 s  E
  617. 在php.ini中添加如下一行:
      z9 T2 s. b" b' r+ ~
  618. extension=/?/redis.so  #是刚刚记录的产生redis.so的路 写在 ?那
    % n5 X) E6 R+ R
  619. 重启 使之生效:+ b1 y6 o2 D' L  D! l
  620. /usr/local/php/sbin/php-fpm reload
    , }2 ]. S* t6 m  i; q% Z% J7 _0 K) R
  621. /usr/local/nginx/sbin/nginx -s reload 0 S* J+ o" L1 ]+ e. ^$ }" ~  H

  622.   B$ z/ G! U  s, {0 y
  623. 将 Redis 作为 Linux 服务随机启动
    , [* o) y3 v/ ?/ f( I, C5 N# A( t
  624. vi /etc/rc.local, 加入代码:
    0 Z' O( \; n( v. q  g# Y7 g
  625. /root/redis-2.6.10/src/redis-serve  #路径看情况修改
    - K- P* t3 i+ _1 g2 i2 |
  626. % S1 v6 {5 k% r- h7 I
  627. redis-cli -h localhost -p 6379 info  #命令要在redis目录下面执行' W; E( w" f# F6 f2 s
  628. 提供host为localhost,端口为6379,redis服务的统计信息
    ' W/ v) [/ y3 d" I& f% R7 m
  629. # l% X  H$ R' _$ Z, l" q% I; P

  630. / C! A' X7 S  a  O
  631. 就这样你的web服务器就支持redis了 记得要在 给dz 的配置文件 加上12.0.0.1哦
    . R) o/ e* \, x! |2 E& y0 ]$ ?
  632. dz配置文件在 config目录下面的 config_global.php/ d  v" W% l6 |3 e
  633. $_config['memory']['redis']['server'] = '127.0.0.1';
    / p6 c- G& d- f9 k
  634. $_config['memory']['redis']['port'] = 6379;. V; [! |5 \% W3 D, f
  635. $_config['memory']['redis']['pconnect'] = 1;
    9 Y6 ^1 f& Y2 Q8 A
  636. $_config['memory']['redis']['timeout'] = '0';1 A6 Y7 U1 Q2 m$ N3 j; q9 h( L
  637. $_config['memory']['redis']['serializer'] = 1;
    1 f1 |# w! h% e4 q2 T
复制代码
关注微信公众号《神采飞扬网》,即可获取最新回复通知!

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

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

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

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