分享到:
发表于 2018-11-16 12:42:28 | 显示全部楼层 |阅读模式
环境配置. r7 n- J' ?! |# V$ I
8 O5 Y4 N* U& X  m/ i# k

0 V* s! E' E3 {+ I- d2 E- Mhttp://www.discuz.net/forum.php? ... amp;highlight=REDIS
关注微信公众号《神采飞扬网》,即可获取最新回复通知!
 楼主| 发表于 2018-11-16 12:43:33 | 显示全部楼层
http://www.discuz.net/forum.php? ... 648&highlight=REDIS
' r3 V4 Q: D& T- N- V6 ?无意间测试 单机状态 redis相当给力 测试1000请求/s  单纯的 get 和set 居然只用了 0.01秒 当时我惊呆了
0 r; n2 O# |0 K) k: b
# t' H/ B# x% y. X# C+ ahttp://www.discuz.net/forum.php? ... 731&highlight=REDIS
5 ~# L9 Y7 z8 |# d- ?) _/ D
6 J5 P0 |6 u# l7 J! m4 ~6 ^0 bhttps://wenku.baidu.com/view/265a5ce176a20029bc642d0b.html8 h9 [% E- f, |' T

3 G( p9 T- [( v9 B0 P=======================================0 R. s7 H3 w/ H5 Z: b9 M& \
  1. 连接上 ssh1 k% O0 f2 P6 t& T8 `, r! P2 f

  2. 3 C5 n! ]6 u& A8 P* h
  3. - N  f! l/ i* ~0 \
  4. 第一步:下载redis+ _+ }8 u* ~+ I
  5. # wget http://redis.googlecode.com/files/redis-2.6.10.tar.gz
    8 t$ y0 J+ D+ t4 Y9 O  D
  6. # tar zxvf redis-2.6.10.tar.gz 7 W+ N# A: A+ d; d. o! P" y8 w: V% |
  7. # cd redis-2.6.10& K) T) c4 }0 K8 l3 w" N/ m
  8. # make ) Y  w1 ~& n: S4 P1 V$ g
  9. # make install  
    1 c! t* Y0 m. Q' M  |1 Y9 k
  10. #cp redis.conf  /etc/ #复制配置文件到etc目录下面: [# O  M+ ^. V) P4 r
  11. 第二步:修改配置8 ~3 h8 N, j8 m6 H
  12. #vi /etc/redis.conf( P5 g" p0 Q* t# s) r
  13. ######################下面是无措的配置文件 复制过去就成#########
    7 W! r' [: n; U4 U
  14. # Redis configuration file example8 ]7 y6 B) o, u

  15. $ F$ ^+ q7 y1 N4 h; O7 K) {
  16. # Note on units: when memory size is needed, it is possible to specify
    3 L2 o5 D8 Y$ L9 e5 ^
  17. # it in the usual form of 1k 5GB 4M and so forth:3 U2 R( h* {! b5 f/ z5 B
  18. #: r, x7 }9 ]# n+ R8 W
  19. # 1k => 1000 bytes
    3 ~( V3 ]6 S" W" C5 S& I
  20. # 1kb => 1024 bytes. z4 g* Z+ \1 ~. x- y
  21. # 1m => 1000000 bytes
    ) h: @1 D' q! t& }0 B' \
  22. # 1mb => 1024*1024 bytes
    * V; j4 r# q9 z
  23. # 1g => 1000000000 bytes4 V. W! w& t& R8 g
  24. # 1gb => 1024*1024*1024 bytes- L. n! k6 \3 K; q# l6 [3 ~
  25. ## R5 ^7 A: \7 n& x8 l
  26. # units are case insensitive so 1GB 1Gb 1gB are all the same.  D$ `/ r8 L  |8 k7 [4 i

  27. . `3 M0 h0 q" _9 |8 i
  28. # By default Redis does not run as a daemon. Use 'yes' if you need it.$ K0 T. q8 ^1 K/ n5 ?) Q9 Y6 e3 U$ y
  29. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
    5 ?3 F+ X/ n1 r. V# j
  30. daemonize yes
    ; X7 G' B* v% ?% @

  31. 9 f( S7 D  C! u) h
  32. # When running daemonized, Redis writes a pid file in /var/run/redis.pid by+ U  Y/ A# ?" g# E
  33. # default. You can specify a custom pid file location here.
    " E0 N; ]- U( D6 z* i2 W
  34. pidfile /var/run/redis.pid/ J1 j  z5 ?; H+ S

  35. / V1 {4 z: D0 M9 m5 `) q6 z# Q% q; M. g
  36. # Accept connections on the specified port, default is 6379.4 c7 h8 D) ]2 O$ _) u* s9 ]
  37. # If port 0 is specified Redis will not listen on a TCP socket.3 Z2 g- X6 X$ h- C
  38. port 6379/ l- _0 p6 Z$ w* }# c
  39. 7 q7 M. V' K# l' v5 |3 i; `; o
  40. # If you want you can bind a single interface, if the bind option is not
    1 ^) ]3 `; p9 `5 x: l
  41. # specified all the interfaces will listen for incoming connections.+ [0 P2 A" V- G) Z) f" I
  42. #
    + H( _" L6 }' i1 Z6 d
  43. # bind 127.0.0.1% F1 s9 ?' [0 d7 t

  44. ) j, {% t; ]$ A6 Y
  45. # Specify the path for the unix socket that will be used to listen for
    # W7 {( S5 F( w" N2 `
  46. # incoming connections. There is no default, so Redis will not listen, @2 V% n* A: f* ?& x
  47. # on a unix socket when not specified.+ u# p8 g6 e# \4 R
  48. #) M3 ?) n+ r$ S" r) U. m
  49. # unixsocket /tmp/redis.sock' [4 u: |  M5 @
  50. # unixsocketperm 755
    2 i/ t  Z# a2 q' U/ s3 T6 h- g
  51. & x- V$ G/ q# {9 w
  52. # Close the connection after a client is idle for N seconds (0 to disable)
    ; w4 D. U2 O5 z6 [4 r$ F  q
  53. timeout 300& \' a3 ^4 q( p5 O
  54. ; E" R" G/ L0 E" x' V. K7 L% T0 Z
  55. # TCP keepalive.9 b9 ?5 Q7 u6 u4 W! ^& t. o
  56. #. O0 M7 R' H6 l0 U* `5 r1 M: w9 V
  57. # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
    8 z& K4 L% J* w* ?' U
  58. # of communication. This is useful for two reasons:
    % \2 U7 ]/ r( }3 t% |% M
  59. #0 X& I8 }2 Y/ K9 x
  60. # 1) Detect dead peers.
    / @! R4 G2 [' f( k! Z
  61. # 2) Take the connection alive from the point of view of network
    " t: T! |5 X  H
  62. #    equipment in the middle.
    ( f) x. X9 `! F9 {
  63. #6 i* b7 i. h5 [7 ~; D, s. M% }. J
  64. # On Linux, the specified value (in seconds) is the period used to send ACKs.
    8 ^4 j/ a; C3 h: y
  65. # Note that to close the connection the double of the time is needed.
    " L) Q) f4 t$ O! Y2 f& Q1 Z
  66. # On other kernels the period depends on the kernel configuration.  P4 \4 w2 Y5 f. w7 h: O) n( z' y( n$ w
  67. #
    + U+ s! {5 z% c. j
  68. # A reasonable value for this option is 60 seconds.+ U1 f. J* T1 N9 z
  69. tcp-keepalive 05 s  q; h; r: E

  70. ! Q2 @; g  U1 \1 ^) F' ~0 v
  71. # Specify the server verbosity level.
    + |2 I9 l1 R- Y* A, T0 p7 i
  72. # This can be one of:
    1 B3 \; @& d" L6 L/ y( M- K
  73. # debug (a lot of information, useful for development/testing): A; g9 j, i" e
  74. # verbose (many rarely useful info, but not a mess like the debug level)
    + i. o" }- w- l
  75. # notice (moderately verbose, what you want in production probably)- V$ X# V* A1 s- J! h3 f; Q. v8 H6 F+ O
  76. # warning (only very important / critical messages are logged)
    4 `0 Q: r# m/ ~1 }5 e
  77. loglevel warning
    8 d) X- i( T4 F) l4 C$ w5 B
  78. ! i2 D+ ]2 Y% n- f$ F7 y9 z
  79. # Specify the log file name. Also 'stdout' can be used to force
    9 l& S; k) o3 W8 q" [# p
  80. # Redis to log on the standard output. Note that if you use standard& k1 X% g4 z" s/ V2 Z5 k
  81. # output for logging but daemonize, logs will be sent to /dev/null. s! H3 D. @1 X& y( ~1 v
  82. logfile /var/log/redis.log, j: L/ l+ T1 p0 c* k
  83. 5 ]: L! n4 C# r& w
  84. # To enable logging to the system logger, just set 'syslog-enabled' to yes,
    7 o( ]6 y( P* r
  85. # and optionally update the other syslog parameters to suit your needs.) ?. z' D3 q* X& M, c/ }' u
  86. syslog-enabled yes, }  I! a$ q. h
  87. 4 S. x. C+ r: U9 q/ z- n
  88. # Specify the syslog identity.
    1 v+ Q& U6 y, }2 p+ ~$ z$ N, A7 H
  89. # syslog-ident redis; V( k  {0 t( v2 j
  90. 6 O: {) z( M! p$ ?& j6 U  {
  91. # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.% v, `4 T# f, G/ f
  92. syslog-facility local0" a. @0 u2 H' ^1 Z4 M2 D

  93. 6 S- C2 x+ M, m
  94. # Set the number of databases. The default database is DB 0, you can select
    ; u/ J' O  ?0 v( x
  95. # a different one on a per-connection basis using SELECT <dbid> where5 o0 V6 H& P4 D! z
  96. # dbid is a number between 0 and 'databases'-1( x4 Z9 u! H7 ?& P' O' _/ `
  97. databases 16
    + z: d% c8 }$ s& }3 B
  98. ( E% D. N/ K+ i# B) x" c" H+ |5 }
  99. ################################ SNAPSHOTTING  #################################
    4 s7 v0 M  K7 W- `  q( [% ^8 p1 V
  100. #
    2 i# f$ X. [5 }1 g" X
  101. # Save the DB on disk:
    " V! W% u% W! a1 X; q
  102. #
    7 g0 I0 s& j5 S# t
  103. #   save <seconds> <changes>, ]. F7 n$ I5 y
  104. #6 V/ w& L+ d0 L" k# }$ R0 i
  105. #   Will save the DB if both the given number of seconds and the given
    - ?+ c  n8 `/ I) e
  106. #   number of write operations against the DB occurred.
      e( e- k0 c  e2 E$ J8 g
  107. #5 n. `* y) }) ]9 N7 u! ?
  108. #   In the example below the behaviour will be to save:
    $ a8 Y7 m9 h$ [2 H- T
  109. #   after 900 sec (15 min) if at least 1 key changed
    : Z2 ^5 W  J$ k9 X
  110. #   after 300 sec (5 min) if at least 10 keys changed$ T8 {- j1 q$ o% i0 M
  111. #   after 60 sec if at least 10000 keys changed
      ?9 J9 R, I$ y( b, p
  112. #+ g" T. X! A, |' a1 s
  113. #   Note: you can disable saving at all commenting all the "save" lines.+ [7 Y. l: K0 @9 ?# }: F- a  U
  114. #
    . m6 t" I; A6 Y( Z; x8 u* I* b
  115. #   It is also possible to remove all the previously configured save
    ; @3 g# u4 I, t4 C! ?: J
  116. #   points by adding a save directive with a single empty string argument
    ) w2 y1 E6 j2 E# \6 U# E
  117. #   like in the following example:
    9 O8 H( X/ Z8 Q
  118. #
    " y2 v9 k, N1 Z. R* B) Z
  119. #   save ""# t2 ~) U7 v1 M) |/ ]4 q! \0 ]

  120. 2 M) d4 g( X+ g
  121. save 900 1
    * r  e; x  d( ?% ^" z! ?
  122. save 300 109 Y9 a  M1 i+ z: J; I  _( p
  123. save 60 10000
    ! }4 r* G) v7 ^& ]; B' y  M( Q% ?) w% E
  124. 1 {7 n* v4 i0 Z6 U, {6 q
  125. # By default Redis will stop accepting writes if RDB snapshots are enabled
    $ f: q$ n: V+ S! S4 P
  126. # (at least one save point) and the latest background save failed.! P  n& t9 t7 O5 P' ?# Y4 o
  127. # This will make the user aware (in an hard way) that data is not persisting
    . y- v( B- K, v( [' d
  128. # on disk properly, otherwise chances are that no one will notice and some
    5 H, ?* q4 G9 [0 H# j3 T
  129. # distater will happen.
    & A* u* e. I( o) \
  130. #
    / G* w" C( X8 r6 k
  131. # If the background saving process will start working again Redis will
    ' c4 J( o5 W: U# u/ A) y
  132. # automatically allow writes again.7 x) I4 L( P2 ^: r
  133. #
    % m3 z+ u! r% {( p7 k* N
  134. # However if you have setup your proper monitoring of the Redis server
    ; I  V, ~0 N! W3 k- X. W0 r
  135. # and persistence, you may want to disable this feature so that Redis will- m* z' b: \2 K: C0 ?
  136. # continue to work as usually even if there are problems with disk,6 a9 E5 s) c9 I- y1 m& T' m
  137. # permissions, and so forth.* S. h' }- D2 T0 o4 c; _
  138. stop-writes-on-bgsave-error yes! E4 o2 N' k; `. n* c

  139. 9 [: Y. N) B3 h) K/ m* P
  140. # Compress string objects using LZF when dump .rdb databases?5 e4 O) [0 c7 v, \  H
  141. # For default that's set to 'yes' as it's almost always a win.
    / ], _+ W" Z$ J1 P4 D& M- Y+ C
  142. # If you want to save some CPU in the saving child set it to 'no' but
    1 M6 q2 t$ w2 V( ^' L7 v
  143. # the dataset will likely be bigger if you have compressible values or keys.
    7 D' G& o  a8 H$ V
  144. rdbcompression yes  C& {8 p7 ~& Z

  145. - p- N0 C: J& g
  146. # Since version 5 of RDB a CRC64 checksum is placed at the end of the file.
    " J+ U2 a% [$ h( P6 a
  147. # This makes the format more resistant to corruption but there is a performance& i1 p8 u% Q- g  |* K3 v; W6 K! i
  148. # hit to pay (around 10%) when saving and loading RDB files, so you can disable it
    ( Q6 K: A# X" _; X4 N$ }- A
  149. # for maximum performances.3 |3 P! `% m( I# x6 p& f  E  F1 |
  150. #
    1 a7 P9 _7 N; x( r
  151. # RDB files created with checksum disabled have a checksum of zero that will* k* I5 L4 l4 V* v/ {, Q6 t, @
  152. # tell the loading code to skip the check.+ _7 f! ^; q6 M) d0 a3 R& [, n% ~( v
  153. rdbchecksum yes- \5 o& u0 Z7 U$ m& d( \# a

  154. 3 }5 s, h' e$ t# @. Q
  155. # The filename where to dump the DB
    # S4 I7 L3 d& O
  156. dbfilename dump.rdb2 u4 U& e, C4 H/ l- q2 C( R
  157. ; ]) @8 W1 b# w+ C, d0 b) W6 e
  158. # The working directory.
    : k9 c3 F# C4 A2 s% i2 R
  159. #4 f& n# t, R3 K8 k
  160. # The DB will be written inside this directory, with the filename specified3 [, e/ _) Q" L+ Y( d8 [
  161. # above using the 'dbfilename' configuration directive.
    9 m1 }* u& K) a6 m# ~, y- [' U
  162. # 8 k" d) o$ X) |5 W
  163. # The Append Only File will also be created inside this directory.) x) @( b$ d! I6 K
  164. # 0 ~  I& d% d) C# h1 p2 g3 X8 k
  165. # Note that you must specify a directory here, not a file name.
    ; ^8 s9 B0 c& d" ~' H
  166. dir /var/db/redis
    " P5 @0 P9 Y* E
  167. , E3 Y' y3 L2 P3 R! {* N
  168. ################################# REPLICATION #################################/ K5 @4 `+ G! D6 m) T2 k3 b: q% ^$ X
  169. $ A: a$ _2 ^$ `) s/ `
  170. # Master-Slave replication. Use slaveof to make a Redis instance a copy of9 N/ a% k. O) g$ W  R; l8 ?' _
  171. # another Redis server. Note that the configuration is local to the slave
    4 f3 C6 k5 O/ S, y1 A9 x2 `6 Y1 s; f
  172. # so for example it is possible to configure the slave to save the DB with a
    3 ?4 ~' X2 W2 f- C& X+ t
  173. # different interval, or to listen to another port, and so on.
    & a, d: p8 |8 K& f9 L9 h* t0 `
  174. #
    * H7 l' N# q& Z  U% l: v
  175. # slaveof <masterip> <masterport>
    , a  C+ A: z/ s4 u
  176. * v, S; N8 e* [# Z0 R8 u) X. _
  177. # If the master is password protected (using the "requirepass" configuration
    ; \; {8 W7 I1 b, b+ s
  178. # directive below) it is possible to tell the slave to authenticate before8 p( R, d! I3 `% @: y$ o  e0 j
  179. # starting the replication synchronization process, otherwise the master will
    $ P# o. G6 ?1 {$ Z; d
  180. # refuse the slave request.
    ' {, F5 r. p& m% U1 v7 G2 }
  181. #
    4 I0 f, F: H* s8 v( p
  182. # masterauth <master-password>
    - S: I2 ^+ n$ I7 o$ Q
  183. 3 m' j1 N& Q8 y9 i  E$ p: m  E
  184. # When a slave loses its connection with the master, or when the replication
    7 _* E2 A5 v5 |; l+ w
  185. # is still in progress, the slave can act in two different ways:/ O( p. o7 o7 D$ U7 T5 ~8 `
  186. #
    ; `" x0 e+ D, s3 ^$ g
  187. # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will
    ) U+ X/ }9 [. [: v
  188. #    still reply to client requests, possibly with out of date data, or the, {; W' D6 ^8 P5 z; e- E5 W
  189. #    data set may just be empty if this is the first synchronization.
    6 m4 X% N. b5 h
  190. #" L& m: i3 u- u% `1 K
  191. # 2) if slave-serve-stale data is set to 'no' the slave will reply with) n9 V; J$ s# l' d9 ^) W
  192. #    an error "SYNC with master in progress" to all the kind of commands4 [* `3 b/ C/ i! l
  193. #    but to INFO and SLAVEOF.
    % |- ?1 @6 n5 w: f2 K. E7 A
  194. #
    * V' Y$ n0 L. U, m, V, k
  195. slave-serve-stale-data yes% Y* I7 U% M, P. {7 s

  196. + {3 {" Y- D& A8 b
  197. # You can configure a slave instance to accept writes or not. Writing against# B9 j* B! [; X6 C5 {) V
  198. # a slave instance may be useful to store some ephemeral data (because data
    ( h* G; w: F: J& `/ J
  199. # written on a slave will be easily deleted after resync with the master) but5 B4 E. I* v0 [6 u# ~
  200. # may also cause problems if clients are writing to it because of a! N4 D0 \! N; A9 e* a' v$ N
  201. # misconfiguration.
    7 F1 Y& u( X3 O5 d0 J9 @
  202. #
    ' K; s, S, Y# a" J
  203. # Since Redis 2.6 by default slaves are read-only./ |: Y4 I) _2 ?, D
  204. #/ S. p, f# }6 z0 e: x
  205. # Note: read only slaves are not designed to be exposed to untrusted clients$ D% B! R; U: Q  e2 c8 w" ^
  206. # on the internet. It's just a protection layer against misuse of the instance.6 S0 q. }- `$ w2 W3 J1 M4 n
  207. # Still a read only slave exports by default all the administrative commands
    + q. n! c8 S$ k; K/ L
  208. # such as CONFIG, DEBUG, and so forth. To a limited extend you can improve
    - U3 L8 x$ @! s& o& N6 _8 J5 c
  209. # security of read only slaves using 'rename-command' to shadow all the
    . o1 _* ~: Q6 h- K8 s5 P: v
  210. # administrative / dangerous commands.
    7 K* r& [& P9 U/ q5 S; i% c
  211. slave-read-only yes2 W: l9 k' M+ K+ ~, `
  212. 0 i1 I  ?* d( `* g' P& C
  213. # Slaves send PINGs to server in a predefined interval. It's possible to change( m$ R2 g6 A: C0 h
  214. # this interval with the repl_ping_slave_period option. The default value is 10, I6 R5 \0 t6 ~! h6 d
  215. # seconds.% z* \4 s% ^# w. r; |1 @
  216. #
    5 {. m! F  Y  ?/ S$ q
  217. # repl-ping-slave-period 10
    4 W4 P( ?  _$ m6 K

  218. 1 j5 ^; r/ }) p  G# i
  219. # The following option sets a timeout for both Bulk transfer I/O timeout and; R3 C; r; C" h) v  {
  220. # master data or ping response timeout. The default value is 60 seconds.) p* L4 ?0 M" M' ^; U8 b6 D' v
  221. #
    / D) J: m. E  a" J8 [
  222. # It is important to make sure that this value is greater than the value) d7 H* Q5 [( I1 }) Z( Y. |
  223. # specified for repl-ping-slave-period otherwise a timeout will be detected
    1 G6 ]* J' ^9 o) q! R
  224. # every time there is low traffic between the master and the slave.4 e! U7 ]; I; I5 v: n4 {( X+ d
  225. #
    & p: z. p5 @# A) H
  226. # repl-timeout 60
    ) X- Y- f2 ~- ]4 j$ k
  227. 3 F& `$ ], I4 B, j) {" l
  228. # Disable TCP_NODELAY on the slave socket after SYNC?9 t, d3 t, i2 G. U# \) d4 Q5 [
  229. #! r6 r( ]* A/ d# F/ _! H/ S) {
  230. # If you select "yes" Redis will use a smaller number of TCP packets and8 o9 _! J9 q8 }) v% r  a
  231. # less bandwidth to send data to slaves. But this can add a delay for
    ! Q8 e' o7 q4 }' q7 ^
  232. # the data to appear on the slave side, up to 40 milliseconds with
    " j- C) J- }8 R( E5 I2 I. w; b% B! h
  233. # Linux kernels using a default configuration./ y6 X+ g* Y# Y/ n2 h0 \, q$ }
  234. #
    3 e& K& w) d! d, B4 e. F- v; F
  235. # If you select "no" the delay for data to appear on the slave side will" A, F  H+ j" X
  236. # be reduced but more bandwidth will be used for replication.2 L4 C+ K, n' ~
  237. #7 y0 }* u3 v. n1 n
  238. # By default we optimize for low latency, but in very high traffic conditions' y2 E' G1 B6 V$ |& M7 G) D/ N" i
  239. # or when the master and slaves are many hops away, turning this to "yes" may, ~0 k7 W" d" i8 `+ L1 \
  240. # be a good idea.- G( P5 [) Z3 Z+ |/ z4 U" J
  241. repl-disable-tcp-nodelay no
    7 s) `* x8 c$ v$ x+ u
  242. 4 f& A8 l& d- M7 `
  243. # The slave priority is an integer number published by Redis in the INFO output.
    8 p% O- V5 y9 b. S
  244. # It is used by Redis Sentinel in order to select a slave to promote into a
    % O$ Z6 K  h5 U6 I4 g  Z
  245. # master if the master is no longer working correctly.4 k: O9 B( s) o- y4 c
  246. #2 y4 D* i% c7 W! G3 f2 z8 J
  247. # A slave with a low priority number is considered better for promotion, so
    ' @$ m8 X: d: }5 Q3 r# i3 W$ w5 t
  248. # for instance if there are three slaves with priority 10, 100, 25 Sentinel will% K0 a+ e- H+ E! l! [$ I% {
  249. # pick the one wtih priority 10, that is the lowest.
    . b. K, _* F* t0 t6 ?/ J
  250. #
    : m* p/ p4 r. F! n
  251. # However a special priority of 0 marks the slave as not able to perform the
    ( \! h: Q8 r, Z% Z8 N  j
  252. # role of master, so a slave with priority of 0 will never be selected by) i9 N$ n' B6 h& q5 s2 j
  253. # Redis Sentinel for promotion.
    + n; M# V# }; N9 `$ ^( s
  254. #
    , j, P6 |) x& z
  255. # By default the priority is 100.2 w4 i- T$ v( q' a/ w0 w
  256. slave-priority 100
    - o0 o2 K) b9 M0 J* h
  257. * c3 D( s! b4 r( l$ v
  258. ################################## SECURITY ###################################
    2 y) y$ I0 \0 q
  259. + |4 o  I5 H+ I* V& d$ e
  260. # Require clients to issue AUTH <ASSWORD> before processing any other
    6 w1 w" m- J+ r) g. K7 J4 ?5 a
  261. # commands.  This might be useful in environments in which you do not trust  a5 ^  h8 T: N3 _( a6 w
  262. # others with access to the host running redis-server.
    $ L% e( Z. }1 F8 y
  263. #) m* D3 Y: K$ u6 z" f2 Q
  264. # This should stay commented out for backward compatibility and because most* [) k; u. D3 G" _! A6 ?2 a
  265. # people do not need auth (e.g. they run their own servers).
    9 V6 G0 }* ~: |
  266. # / u( d* T0 [3 U) d
  267. # Warning: since Redis is pretty fast an outside user can try up to5 R1 [" @& {3 a6 i1 [% Y( A
  268. # 150k passwords per second against a good box. This means that you should
    ) L: ~0 c, x$ j$ x- N) ?  r/ m
  269. # use a very strong password otherwise it will be very easy to break.# r8 O" F5 l6 l$ E  T
  270. ## p6 m' |: I7 P& f: I- Q, _
  271. # requirepass foobared
    ! b6 R- r# M( A) Z1 L7 H% H
  272. % ~* j$ {% ?! D+ v, q
  273. # Command renaming." K$ A: S9 O2 e0 |% K! l
  274. #
    ! W& C- T' |6 K( B% ]" \: I$ l
  275. # It is possible to change the name of dangerous commands in a shared! g* e4 B3 Z# D% Z" e: i5 K1 P/ L
  276. # environment. For instance the CONFIG command may be renamed into something
    $ Q- `' Y+ N$ f
  277. # hard to guess so that it will still be available for internal-use tools
    . a+ S4 [! o# f% F& F; |
  278. # but not available for general clients.& f$ t! G9 m" |
  279. #
    $ G/ P. t1 p( C- Z# E; E2 y6 k
  280. # Example:
    % V) E  z9 t8 u( H4 A0 p
  281. #( o9 H3 G# R; C2 k6 D* X' }
  282. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52! w* d& c# p" A2 w) m6 `
  283. #' k* L% v" O; P  `
  284. # It is also possible to completely kill a command by renaming it into
    8 |7 y  _& c; X7 t& q2 ~
  285. # an empty string:
    4 {$ e( L8 ~( s! \5 n9 v
  286. #
      E" i. L& O  ]8 b) I! U5 S
  287. # rename-command CONFIG ""
    5 I& u$ `% J4 o
  288. , R; ~: M- d( m7 h& B
  289. ################################### LIMITS ####################################
    ) v8 s) b* \) l' x9 P0 U, n! v* G# U
  290. , E& g5 X2 G# P' w! O1 c
  291. # Set the max number of connected clients at the same time. By default
    ' [5 a/ z4 w5 H& @" T1 v
  292. # this limit is set to 10000 clients, however if the Redis server is not
    0 }% g$ j( Y, G- J+ G. C3 U
  293. # able to configure the process file limit to allow for the specified limit
    1 h' t5 u( n" R9 o3 A
  294. # the max number of allowed clients is set to the current file limit# [' H( `& O& N  W9 P( D
  295. # minus 32 (as Redis reserves a few file descriptors for internal uses).* }/ g& d- f8 V2 H
  296. #
    . h: p, Y: D- K! A  Q0 Y4 [9 O
  297. # Once the limit is reached Redis will close all the new connections sending
    ( ^& c5 U4 B" E1 N7 ^) O
  298. # an error 'max number of clients reached'.
    0 O; K2 {- E; j! Y9 v
  299. #
    1 y4 _  w4 y" n3 T5 |
  300. maxclients 500! H4 D; t0 |0 r9 \5 I
  301. # o! |/ a& e! D. p
  302. # Don't use more memory than the specified amount of bytes.
    , S; x7 R/ ]- h
  303. # When the memory limit is reached Redis will try to remove keys* k, Q4 v' T  s. N
  304. # accordingly to the eviction policy selected (see maxmemmory-policy).( d1 B" l( e, G& c2 ~
  305. #- O4 L$ p- `3 m+ u; r3 l' |  k2 g
  306. # If Redis can't remove keys according to the policy, or if the policy is
    & K7 W$ j7 C7 M. U) X  b5 s
  307. # set to 'noeviction', Redis will start to reply with errors to commands9 \# \3 e" m" t: H; V% P$ }4 }
  308. # that would use more memory, like SET, LPUSH, and so on, and will continue
    , Q" }$ [1 s) T. f* Q
  309. # to reply to read-only commands like GET.4 C1 \8 e2 ^; [, T
  310. ## i2 E+ d. [8 ?" |
  311. # This option is usually useful when using Redis as an LRU cache, or to set
    1 S  _& C. |, l& ^8 J3 i- q0 h
  312. # an hard memory limit for an instance (using the 'noeviction' policy)., z( O$ ~' p, |3 e
  313. #2 W$ Q) D3 Z0 d, m8 y2 {
  314. # WARNING: If you have slaves attached to an instance with maxmemory on,( S) _7 L  v1 G% Q- d  k
  315. # the size of the output buffers needed to feed the slaves are subtracted% E5 x) I7 n( ^1 J) a! s* F
  316. # from the used memory count, so that network problems / resyncs will  b3 k2 T7 N% k# l- q/ v
  317. # not trigger a loop where keys are evicted, and in turn the output9 E. h* I4 s9 n
  318. # buffer of slaves is full with DELs of keys evicted triggering the deletion3 U$ t6 X& ~% J$ e& l& w
  319. # of more keys, and so forth until the database is completely emptied.
    " ~( z# v: Z% k' d8 T1 k
  320. #
    . Z. i" c; _6 I* a
  321. # In short... if you have slaves attached it is suggested that you set a lower
    6 J* ~) j# _; q, b# |
  322. # limit for maxmemory so that there is some free RAM on the system for slave4 |4 ^0 G9 g$ ?1 U8 W5 e
  323. # output buffers (but this is not needed if the policy is 'noeviction').
    ; @6 r) Y, ~2 Z; x& J* t
  324. #
    : n; E$ x0 y+ d0 Q2 }7 Q) [
  325. maxmemory 1280000007 X) S1 l% b: r/ V7 R

  326. - Y9 k1 t7 E4 Q
  327. # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
    5 C: r1 w9 m0 K- s: v! k* s5 w
  328. # is reached. You can select among five behaviors:/ y$ N, ^: J( |3 N$ [
  329. #
    4 o2 `( L" _, A+ n/ k! V
  330. # volatile-lru -> remove the key with an expire set using an LRU algorithm) F( X3 E1 w" Q3 G; T) U
  331. # allkeys-lru -> remove any key accordingly to the LRU algorithm3 M" X# g3 z! h4 x
  332. # volatile-random -> remove a random key with an expire set
    ; R6 S6 L' g& S  `  n  n
  333. # allkeys-random -> remove a random key, any key6 w2 \- x5 [+ t8 N/ h! F
  334. # volatile-ttl -> remove the key with the nearest expire time (minor TTL)1 X+ I! a1 I6 [# p' A: |2 N
  335. # noeviction -> don't expire at all, just return an error on write operations
    " y) I0 v- @  Z' f  v
  336. # : X; T: C1 _4 U: k# C
  337. # Note: with any of the above policies, Redis will return an error on write- b; p/ G  o; a, \. ]8 s/ Y
  338. #       operations, when there are not suitable keys for eviction.
    # b5 A% F, D& O
  339. #
    / U  `! N1 _; }; P5 z
  340. #       At the date of writing this commands are: set setnx setex append
    4 |0 j; X1 O& g0 ^6 V+ [- }- s" _
  341. #       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
    & d4 ^, b1 B2 {( w! t
  342. #       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby. V4 I$ Q: N1 W; q
  343. #       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby
    : G' O. @% T/ `
  344. #       getset mset msetnx exec sort
    7 w& y& Q; c) E: k5 z; Z* p
  345. #
    1 s& i/ s8 U& m! Y( K9 a4 m
  346. # The default is:
    ) l& ?4 r; U% x+ H# Y9 X. A
  347. #7 G: |7 k7 T  {- J' I, i7 m
  348. # maxmemory-policy volatile-lru" z+ P( w' _3 F: [9 k2 I

  349. , r- t# e9 o2 {2 i8 m) {
  350. # LRU and minimal TTL algorithms are not precise algorithms but approximated# ~, Q- t2 `# P3 }/ H
  351. # algorithms (in order to save memory), so you can select as well the sample
    ; ^# V( {, m7 X7 I5 L( N9 m# i
  352. # size to check. For instance for default Redis will check three keys and/ A- O. ?: N% C0 E5 u( F- f
  353. # pick the one that was used less recently, you can change the sample size6 U0 t2 k0 O, O; l" U3 Q; S  e) I/ m
  354. # using the following configuration directive.1 j' B5 y0 N2 r
  355. #
    6 x) T: \8 A2 Y+ k; }# u; M$ q
  356. # maxmemory-samples 3
    . t- H+ i, k  b' l) ]6 a1 _

  357. ( L2 Z! P0 V! h& Q7 s: w
  358. ############################## APPEND ONLY MODE ###############################2 y% [$ v$ ?2 [8 Q4 {

  359. 3 \$ ]+ r  O3 Z' L- F# i
  360. # By default Redis asynchronously dumps the dataset on disk. This mode is- N8 s4 x8 `1 b2 f8 B+ O
  361. # good enough in many applications, but an issue with the Redis process or0 Y; E1 A6 q% W2 X% e
  362. # a power outage may result into a few minutes of writes lost (depending on" g5 A  X7 m/ X  m% t, Z+ D
  363. # the configured save points).
    - d. Q, v, W1 Y0 K# Y7 e+ v
  364. #
    4 M7 q) Z, D. E: F- N* c( h  H- B9 E
  365. # The Append Only File is an alternative persistence mode that provides
    6 e2 B* f9 g; Z* I" s% ]
  366. # much better durability. For instance using the default data fsync policy
    * F  h; C: |# o) L) }- L
  367. # (see later in the config file) Redis can lose just one second of writes in a
    5 k* n! Y0 I1 A5 ~0 L) ?
  368. # dramatic event like a server power outage, or a single write if something3 _! j- @9 v2 x; d, n
  369. # wrong with the Redis process itself happens, but the operating system is: x9 b, S5 [% a8 x2 c4 v# H% ?
  370. # still running correctly.6 N8 u. g8 d7 b& u$ V
  371. #
      E& Z0 l5 [+ {( `# ?. N
  372. # AOF and RDB persistence can be enabled at the same time without problems.
    ; i- N9 D$ n4 n, f0 M$ ~* `
  373. # If the AOF is enabled on startup Redis will load the AOF, that is the file
    2 L* t% {4 D% @# j/ z8 l
  374. # with the better durability guarantees.# |6 u# Z5 F6 M
  375. #4 Z* N+ X3 `3 y/ y! I
  376. # Please check http://redis.io/topics/persistence for more information.
    * e2 V0 f0 Q  H8 |

  377. ! g& C* R7 i4 U, z) P, d
  378. appendonly no
    9 i) R; p9 L6 |5 ]6 P+ _

  379. + B4 Q& C4 f# {; j
  380. # The name of the append only file (default: "appendonly.aof")
    0 D1 h# }3 Y% }( c0 U7 Z% W
  381. # appendfilename appendonly.aof: N: k6 C( |# F$ ~1 |8 J

  382. : o- x) z1 \0 G
  383. # The fsync() call tells the Operating System to actually write data on disk% u* O4 w" e' R1 p: O2 f7 g
  384. # instead to wait for more data in the output buffer. Some OS will really flush
    : r, M3 M& o) G2 |* F8 g
  385. # data on disk, some other OS will just try to do it ASAP.# F& m4 b, Q. @1 ]( v$ c
  386. #7 M  D" {: ^* U
  387. # Redis supports three different modes:
    " i! u. T& P' ]7 |9 y  W% T# G
  388. #, t6 }8 s+ p- {6 X- M0 K
  389. # no: don't fsync, just let the OS flush the data when it wants. Faster.
    9 Q5 X, u+ `6 v+ k+ P6 g0 ?. {
  390. # always: fsync after every write to the append only log . Slow, Safest.
    $ F) P) O+ p7 f/ b/ {6 v$ q5 l
  391. # everysec: fsync only one time every second. Compromise., q* a* p2 v7 j: w" \- a' \% a
  392. #) [1 ]8 ]7 b8 E% U! A1 F- R
  393. # The default is "everysec", as that's usually the right compromise between
    ; e7 v  ^0 q8 O4 g: C- G! v
  394. # speed and data safety. It's up to you to understand if you can relax this to* Q/ `0 o. _, Q8 G2 H0 v
  395. # "no" that will let the operating system flush the output buffer when. |' U6 q. L" B7 O( E) ?/ o& v2 G$ c
  396. # it wants, for better performances (but if you can live with the idea of
    7 t; q9 F! F8 D: w6 F
  397. # some data loss consider the default persistence mode that's snapshotting),4 u4 A  |5 q& a, d% I* L
  398. # or on the contrary, use "always" that's very slow but a bit safer than
    , r- q( h9 @8 i' @
  399. # everysec.* b/ j% U/ ^5 W& O8 N
  400. #( K9 c. P  d" Y7 ~5 p% w+ g
  401. # More details please check the following article:+ ^/ o& L4 @& P% r2 y' e& P/ h3 f
  402. # http://antirez.com/post/redis-persistence-demystified.html
    ; X) K6 B! r0 @( n
  403. #
    ( F. D( X) o* J$ S+ \+ ^1 b: I
  404. # If unsure, use "everysec".
    2 d! o& s% f0 Z" J" j

  405. ; d7 v1 Z* [. j& c& \
  406. # appendfsync always' X1 R. Q7 B1 z& }8 x  c" D
  407. appendfsync everysec' P8 }  b2 A7 X: J. Q; @
  408. # appendfsync no* H+ h2 j0 C/ `2 m
  409. * n: F  _% j9 U$ g
  410. # When the AOF fsync policy is set to always or everysec, and a background# l: Y8 d8 I3 b9 v  g/ ?4 y
  411. # saving process (a background save or AOF log background rewriting) is7 w0 V) k  o8 e1 w. D" l5 ~0 a5 I
  412. # performing a lot of I/O against the disk, in some Linux configurations
    # E0 c3 ?& S  I- ~" |9 v
  413. # Redis may block too long on the fsync() call. Note that there is no fix for
    . f8 R6 ?2 x, m" i  X
  414. # this currently, as even performing fsync in a different thread will block
    : n) `1 T1 c# W/ v( c" h
  415. # our synchronous write(2) call.) W( D/ f8 u/ I7 q" d- I
  416. #
      L; X; T% a. ^' ^6 I
  417. # In order to mitigate this problem it's possible to use the following option  P" I, Z5 F! W9 k$ Y# `; P
  418. # that will prevent fsync() from being called in the main process while a* ]4 Z" t6 D  W2 j9 ]
  419. # BGSAVE or BGREWRITEAOF is in progress.' G) c6 g8 b% s; L. R- H) K. G
  420. #
    , L/ z% u4 W9 U( n2 B
  421. # This means that while another child is saving, the durability of Redis is
    $ f% K8 ?0 P( \) N
  422. # the same as "appendfsync none". In practical terms, this means that it is: t! Q9 g1 @" D- s0 c
  423. # possible to lose up to 30 seconds of log in the worst scenario (with the3 z) f7 a: e/ A# \, }+ K
  424. # default Linux settings)./ ]9 z2 P6 O3 F2 P
  425. #
    ' h1 n! k, C; A9 o0 i
  426. # If you have latency problems turn this to "yes". Otherwise leave it as! _0 t1 j& ]% n' w
  427. # "no" that is the safest pick from the point of view of durability.
    ! S4 {7 G4 f$ v, @! b$ v
  428. no-appendfsync-on-rewrite no' A" [8 `8 }! N2 @- [# p2 y, A* }
  429. ' A# x5 c/ Q6 t
  430. # Automatic rewrite of the append only file.- w. |6 j7 I5 d; N% A
  431. # Redis is able to automatically rewrite the log file implicitly calling
    + R4 i% f& P; P' c: o: V4 y3 p
  432. # BGREWRITEAOF when the AOF log size grows by the specified percentage.$ J1 Y! }. a+ L" X4 P! q/ X& O8 z3 F
  433. #
    - D: w- `* m1 }
  434. # This is how it works: Redis remembers the size of the AOF file after the0 q8 W: H+ q( F* ]
  435. # latest rewrite (if no rewrite has happened since the restart, the size of
    7 f( a; {: D# w" B; ^, p
  436. # the AOF at startup is used).
      P6 R. z9 }" x) l) O) U: K
  437. #
    , D$ j% E9 W7 R! U- j
  438. # This base size is compared to the current size. If the current size is, y. H7 p  k2 C. e$ X8 V
  439. # bigger than the specified percentage, the rewrite is triggered. Also
      T& z1 H- |4 B4 A
  440. # you need to specify a minimal size for the AOF file to be rewritten, this$ E1 B: }! t1 {; ]- `; z! W5 Y& c8 o
  441. # is useful to avoid rewriting the AOF file even if the percentage increase! @/ C8 e$ K6 U+ E+ g/ U
  442. # is reached but it is still pretty small.- z6 U1 f. Q7 e3 L+ t4 r
  443. #1 ?) D: B: b; y. {
  444. # Specify a percentage of zero in order to disable the automatic AOF6 U+ |2 T( u' m8 e8 [6 W
  445. # rewrite feature.% ~4 b& j# ]& ]' o

  446. ( Z( }* Z, Y# e! N$ h
  447. auto-aof-rewrite-percentage 100
    0 `) }! {4 Q% L* P
  448. auto-aof-rewrite-min-size 64mb
    4 C, d& b3 J) P* w0 ^

  449. / Y; c& g* q; b4 [! I0 @
  450. ################################ LUA SCRIPTING  ###############################
      A4 x4 Z! H! @* ~3 A4 E; R' d. h
  451. 8 i/ ?" d( W7 h: U; B0 Q/ D6 f. Q0 _
  452. # Max execution time of a Lua script in milliseconds.! y9 c3 _8 ^! ^
  453. ## D: l8 X- j/ |
  454. # If the maximum execution time is reached Redis will log that a script is, P# c7 X" x1 t! ^0 V
  455. # still in execution after the maximum allowed time and will start to5 {' w& l6 O4 U2 J9 `
  456. # reply to queries with an error.' R: _' L0 C( f+ t" P
  457. #
    5 c* I: }1 W/ W
  458. # When a long running script exceed the maximum execution time only the
    8 Q0 R" o) W" V* x) T) P) h
  459. # SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be
    9 n" m4 D: w$ i
  460. # used to stop a script that did not yet called write commands. The second6 }7 B2 }* m- `
  461. # is the only way to shut down the server in the case a write commands was
    : _1 T* G5 p. p- C" T
  462. # already issue by the script but the user don't want to wait for the natural' @/ @$ D1 z$ ]" G& |
  463. # termination of the script.
    2 [1 Q- b" [+ V4 L
  464. #
    ( ^/ F- D1 S9 x2 {" r
  465. # Set it to 0 or a negative value for unlimited execution without warnings.; D- @4 c% y, @# n0 T. Y8 E
  466. lua-time-limit 50009 l, Z# ?2 y0 L# C: F
  467. " {' ~, _% r: M/ J, b9 L, @
  468. ################################## SLOW LOG ###################################- t% T$ C, s) s  |, X! l
  469. - ~4 ]! P( u2 u( I1 G( A. p
  470. # The Redis Slow Log is a system to log queries that exceeded a specified( Q7 A- w% P* z" E* I: T8 F
  471. # execution time. The execution time does not include the I/O operations
    $ K3 z  e7 Q% c; U/ ^8 R
  472. # like talking with the client, sending the reply and so forth,
    7 Q- H, j! W5 F9 B2 k
  473. # but just the time needed to actually execute the command (this is the only
    - H! U( |* X- J/ X0 ^" e
  474. # stage of command execution where the thread is blocked and can not serve- _* U' U# k" O3 k; @
  475. # other requests in the meantime).# [8 N9 Q  ?0 F' x2 M& n& k
  476. #
    * n, M3 b6 g# ]" b" o7 }
  477. # You can configure the slow log with two parameters: one tells Redis" v; O) t2 _8 c7 X6 q
  478. # what is the execution time, in microseconds, to exceed in order for the
    1 G7 y2 W. d$ W* U6 C
  479. # command to get logged, and the other parameter is the length of the
    , G' d0 }  e8 y8 {- L' b) f( Y- |! g
  480. # slow log. When a new command is logged the oldest one is removed from the2 O8 n1 A; K( f1 W
  481. # queue of logged commands.8 o  Q9 {% w6 ~* G

  482. + |0 [, V& X: u: p" j, p# F! K
  483. # The following time is expressed in microseconds, so 1000000 is equivalent
    " T6 z0 f) r( r. s7 `/ o5 Q* s
  484. # to one second. Note that a negative number disables the slow log, while2 @# D4 S8 a  t
  485. # a value of zero forces the logging of every command.1 `0 k; q# E0 R
  486. slowlog-log-slower-than 100006 @1 J! y1 p+ V4 I- Y# o: p
  487. + w" |4 o/ C7 R
  488. # There is no limit to this length. Just be aware that it will consume memory.9 ^3 j9 x) h( n& J6 ^  `! T8 {- H
  489. # You can reclaim memory used by the slow log with SLOWLOG RESET.. `$ N1 y) w5 t4 o2 F
  490. slowlog-max-len 128$ z1 e+ B" J, e' w2 R, a
  491. & l& I$ X$ j# |0 x% @0 f' [4 T
  492. ############################### ADVANCED CONFIG ###############################3 C# D0 `# d4 |" }7 n9 n
  493. & i$ ~. m5 l, f1 L% R+ D+ @5 C
  494. # Hashes are encoded using a memory efficient data structure when they have a
    % ]; L( k" C6 C9 r6 E6 k
  495. # small number of entries, and the biggest entry does not exceed a given$ _% e9 s6 p; @$ [
  496. # threshold. These thresholds can be configured using the following directives.
      z& M2 U4 M* O
  497. hash-max-ziplist-entries 512
    * C4 R# \: ?% Q0 l8 J" d! u# G; Y
  498. hash-max-ziplist-value 643 g; F, h7 u. j. o

  499. 3 K1 U! W5 n* @1 c
  500. # Similarly to hashes, small lists are also encoded in a special way in order
    8 I. H+ a, b* }
  501. # to save a lot of space. The special representation is only used when
    5 a) I: [9 y9 f5 X
  502. # you are under the following limits:: ?6 b/ \8 |0 J$ x; D2 N# D; E
  503. list-max-ziplist-entries 512( T8 H: ^6 N0 v
  504. list-max-ziplist-value 644 x$ C$ P2 S8 f
  505. ; t- S8 P! o* c" o' d
  506. # Sets have a special encoding in just one case: when a set is composed8 G5 K% w% |+ ~; y- r
  507. # of just strings that happens to be integers in radix 10 in the range
    6 l2 F( _' z& [
  508. # of 64 bit signed integers.
    3 y" o. W+ w4 A4 X, p
  509. # The following configuration setting sets the limit in the size of the
    ( a6 ^) @9 r7 t5 d/ q* j9 N
  510. # set in order to use this special memory saving encoding.
    , k( B& T9 q+ j1 P* ^6 g- t8 b
  511. set-max-intset-entries 512
    # w/ h' H$ f, f4 I" U1 V
  512. 4 C$ q0 B4 v9 c% E$ Y5 q' p
  513. # Similarly to hashes and lists, sorted sets are also specially encoded in
    ; W% H! ?, B/ I9 V' f* C5 b
  514. # order to save a lot of space. This encoding is only used when the length and
    ( \" X$ r; E: p5 _; p' r
  515. # elements of a sorted set are below the following limits:
    6 D. ]/ U  E) ^5 F. p+ N
  516. zset-max-ziplist-entries 1288 ~" Y# r& X/ n
  517. zset-max-ziplist-value 64) g' N( q5 q% P7 n- ?9 f5 M- h# ~
  518. 5 Z8 f1 e! Q, g
  519. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
    1 i2 e. [0 V. ?2 }8 _: t& M& V
  520. # order to help rehashing the main Redis hash table (the one mapping top-level% @; c1 P) O2 X# R$ h3 O9 y9 ?
  521. # keys to values). The hash table implementation Redis uses (see dict.c)6 `6 f/ F' r: M- }) C2 C
  522. # performs a lazy rehashing: the more operation you run into an hash table
    ) Y" ?7 ?. O% @) v$ J) D% r% U
  523. # that is rehashing, the more rehashing "steps" are performed, so if the
    4 L$ q9 f6 _- D
  524. # server is idle the rehashing is never complete and some more memory is used
    $ E  m4 k( g4 V( \
  525. # by the hash table.
    ! B9 i1 C$ z( j0 `5 A
  526. # 5 t$ @( Y* k' j) a. u; |
  527. # The default is to use this millisecond 10 times every second in order to
    / h* |+ M: D( l
  528. # active rehashing the main dictionaries, freeing memory when possible.
    . K% a+ [/ f- G" B( F0 _- n
  529. #- t: J& X4 \) |3 |% ?
  530. # If unsure:
    6 C! w# h% W2 ^( N/ h* M1 k
  531. # use "activerehashing no" if you have hard latency requirements and it is
    2 R0 r, |/ H/ [/ P/ c- S
  532. # not a good thing in your environment that Redis can reply form time to time
    8 B  K5 p5 }$ O
  533. # to queries with 2 milliseconds delay.5 \; x- g6 v' c. @
  534. #
    3 j# q- Z( D4 A" a
  535. # use "activerehashing yes" if you don't have such hard requirements but
    ) q2 E# b- L3 u; p9 w( X
  536. # want to free memory asap when possible.
    : ?' t8 F# d/ D0 y6 R7 M
  537. activerehashing yes
    / V# [3 a- I4 n8 K' `
  538. 4 D  _# E7 N9 X4 n7 R
  539. # The client output buffer limits can be used to force disconnection of clients
    : W4 `: W/ }, c
  540. # that are not reading data from the server fast enough for some reason (a+ x& i9 M4 n" z- U2 y! q
  541. # common reason is that a Pub/Sub client can't consume messages as fast as the, Y( {" m, R, d" w, E+ K
  542. # publisher can produce them).' Z- y& ]+ U5 f
  543. #
    % c  R" k# u$ o7 W  b
  544. # The limit can be set differently for the three different classes of clients:
    & r6 M3 v; C5 i
  545. #% e3 d& x$ K' K: }" a, G$ f
  546. # normal -> normal clients
    5 R: M# P8 |: F% C( a& `
  547. # slave  -> slave clients and MONITOR clients
    2 j. |& R# u% a6 g. r
  548. # pubsub -> clients subcribed to at least one pubsub channel or pattern7 r' D8 R: s0 F' X
  549. #- _: Z( Z$ F, t4 @( t
  550. # The syntax of every client-output-buffer-limit directive is the following:
    # g/ I- Q( X* N1 H; x& V! ]
  551. #6 x& P3 w; u1 u" e
  552. # client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>
    4 {) j! U0 J$ I' e
  553. #
    2 H/ e- z3 a) H: b& f
  554. # A client is immediately disconnected once the hard limit is reached, or if" P! }$ O; L) i1 {
  555. # the soft limit is reached and remains reached for the specified number of
    9 I2 `4 `( k) ]9 W5 u8 M2 Q
  556. # seconds (continuously).' G3 x8 c; q; [1 w  k
  557. # So for instance if the hard limit is 32 megabytes and the soft limit is' [. B5 F, L, m3 s2 ~* m( f
  558. # 16 megabytes / 10 seconds, the client will get disconnected immediately
    6 }, r9 V2 k- o. |# h( N
  559. # if the size of the output buffers reach 32 megabytes, but will also get
    9 {* w: J1 o7 s  N. S1 T* \6 {
  560. # disconnected if the client reaches 16 megabytes and continuously overcomes3 i& Q) B" x  x# H* W+ `
  561. # the limit for 10 seconds.
    7 C$ Y! H# Z4 Y% X8 j4 r
  562. #
    : t) l3 Y6 k* ?" B3 Z
  563. # By default normal clients are not limited because they don't receive data
    ; C9 `6 @' `$ U& a! T+ R
  564. # without asking (in a push way), but just after a request, so only5 d" B, x# o# [' X* y. S
  565. # asynchronous clients may create a scenario where data is requested faster, n0 [) |, V( B& `4 S
  566. # than it can read.. q$ o+ G" |6 m
  567. #
    8 ~6 k5 _6 e$ w8 d2 b/ z, O
  568. # Instead there is a default limit for pubsub and slave clients, since
    ; o; R9 R! w+ l* ~9 x+ L
  569. # subscribers and slaves receive data in a push fashion.$ S; p, X' T4 M6 f: b" V( @
  570. #+ V& Q: S7 s( U) w9 D2 n. e# u9 \
  571. # Both the hard or the soft limit can be disabled by setting them to zero.
    , k% D( @$ v* L) L
  572. client-output-buffer-limit normal 0 0 0
    . }2 `  i: X1 Y) q
  573. client-output-buffer-limit slave 256mb 64mb 60
    ' N* D/ T8 k( ]* r, @! n! M
  574. client-output-buffer-limit pubsub 32mb 8mb 60/ m4 V0 b1 p+ {+ M* \
  575. 5 L% y% N) k9 q2 D4 ]2 h
  576. ################################## INCLUDES #################################### [1 ?0 J. @$ M# v. M1 k; i5 Z

  577. * s6 x; n/ v4 x9 C, j2 U
  578. # Include one or more other config files here.  This is useful if you
    ' B6 `3 l0 s6 [$ q0 {
  579. # have a standard template that goes to all Redis server but also need
    . N' s/ v5 ]6 D! _4 w: l5 {8 K
  580. # to customize a few per-server settings.  Include files can include
    & |. q+ f. ?# f# Q. S" x
  581. # other files, so use this wisely.* Y0 l! v9 A% H+ c! a" W5 {
  582. #! w1 q# M1 C, {/ K/ D
  583. # include /path/to/local.conf2 m: v3 g( U& m$ M  Q
  584. # include /path/to/other.conf        
    / a! D! m* V. a, h  L4 a( _
  585. ##########################配置文件结束################################
    2 s  U+ u' L( D  N5 _: c, Z
  586. 第三步:启动进程
    6 x; T% G& }& t; t$ Y) l; B
  587. #redis-server /etc/redis.conf
    " R2 {" L8 e$ `  ~
  588. 查看进程有没有成功启动4 c: y. e# y3 q+ s$ r
  589. #ps -ef | grep redis 4 s) Y0 z2 _( M+ Q
  590. 测试输入一个键值
    ; h# q) K5 P; c. {3 r/ Y
  591. #redis-cli set test "testredis"
    $ Z3 ~! T1 j; A. `: @$ I
  592. 获取键值
    9 U# r, H9 W$ z3 I, I: l, N" L) S* q9 S( d
  593. #redis-cli get test
    0 r$ H  k" H* b: p5 z$ ]0 x( ~
  594. 7 d( M' |$ E! C. U+ K1 D
  595. " Y( m2 S# Z# G$ u3 h4 |
  596. 第四步:关闭redis  (这个是更改配置文件后 正常的重启方式  不重新加载redis配置跳过)3 ~! s, `8 Y7 N$ x- r5 }
  597. # redis-cli shutdown      //关闭所有    9 ^) r. T' F: P) a2 l6 W
  598. 关闭某个端口上的redis   
    , C) {8 I+ g! o* M+ d6 ?/ A
  599. # redis-cli -p 6397 shutdown  //关闭6397端口的redis  ( a+ w  e8 f+ V2 L; z. a
  600. 说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename  dump.rdb  0 M$ {, j, [$ z7 S. O
  601. ! e" }( d5 V- J4 s" z

  602. 1 q+ x  C: v7 T
  603. 第5步:php扩展安装( i& |2 t- G+ y' `
  604. phpredis PHP扩展下载地址
      E0 J/ e6 J% E  X, F3 w
  605. https://github.com/nicolasff/phpredis/tree/2.2.2 & s3 l7 U9 `7 U4 x4 ]4 `
  606. 选择最新版本下载zip 1 z2 v! M) l& X6 l, |6 N" {( j/ T, J

  607. 9 P0 O4 [: x& |) l, m& B& J
  608. 然后自己上传zip  用unzip解压到当前目录 unzip 文件名
    , X: ^6 i3 ?* S
  609. * I" M+ q& {* d' |) \& I
  610. # cd owlient-phpredis-90ecd17/   #打开解压后的文件夹里面  这个解压后的目录 要是不知道 可以输入 "dir" 查看
    , ?9 |" R" |- S2 S& c
  611. # /www/nginx_php-5.2.17/bin * }+ u0 x8 V7 H) w6 ~7 k5 K
  612. # ./configure --with-php-config=/www/nginx_php-5.2.17/bin/php-config5 T8 v8 U7 K7 d5 Q) M& W
  613. #make
    + w0 }7 g( R; j/ Q+ e
  614. #make install   #记录产生的redis.so路径  j5 X! A3 o  O) w6 @

  615. ; }0 ~( W# z) Y+ C, |- j# s
  616. 修改php.ini文件
    5 p0 m+ o% S+ V4 v+ f. [
  617. 在php.ini中添加如下一行:* U$ ?7 d1 \: T# V
  618. extension=/?/redis.so  #是刚刚记录的产生redis.so的路 写在 ?那
    ( m) U, R& r& m! V. u
  619. 重启 使之生效:
    - S5 U- k& i1 Q' ]
  620. /usr/local/php/sbin/php-fpm reload
    $ J+ m$ V2 g7 e% I+ O$ h; m2 ]$ b
  621. /usr/local/nginx/sbin/nginx -s reload * f# s& p4 K; N3 |( ^" ]

  622. / ?* _9 T/ K; m$ G  a& C+ y6 e
  623. 将 Redis 作为 Linux 服务随机启动
    5 ^6 ^2 Z& c' G( Y8 i
  624. vi /etc/rc.local, 加入代码:) P' h: u# @+ s3 T$ L% g0 n9 M3 r% ]# T
  625. /root/redis-2.6.10/src/redis-serve  #路径看情况修改 4 i8 X- l  t( G: Q* g
  626. 8 G6 G+ s6 C2 Q% M  K) Q5 b5 I
  627. redis-cli -h localhost -p 6379 info  #命令要在redis目录下面执行' X5 Y) _2 }) ^; T
  628. 提供host为localhost,端口为6379,redis服务的统计信息
    3 k1 ~! @  S+ m  P7 x  ~
  629. 5 _" ^8 z. U& a
  630. 0 V; }" Y1 Y3 ]( T) k/ t
  631. 就这样你的web服务器就支持redis了 记得要在 给dz 的配置文件 加上12.0.0.1哦
    ) g+ @& b0 Q& x4 c
  632. dz配置文件在 config目录下面的 config_global.php: C6 D. @, B1 f7 H; y% p  b
  633. $_config['memory']['redis']['server'] = '127.0.0.1';- l! }: M7 P5 B
  634. $_config['memory']['redis']['port'] = 6379;/ U; c# I+ @6 v; Q* u. Y* y3 M
  635. $_config['memory']['redis']['pconnect'] = 1;1 {: _- {$ v) S, }5 E  ?; D
  636. $_config['memory']['redis']['timeout'] = '0';
    " H  y: @. O% n0 \, a
  637. $_config['memory']['redis']['serializer'] = 1;
    6 g" T3 h! E2 n) i' z& V
复制代码
关注微信公众号《神采飞扬网》,即可获取最新回复通知!

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

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

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

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