分享到:
发表于 2018-11-16 12:42:28 | 显示全部楼层 |阅读模式
环境配置
$ S6 H* e$ K% |' Q9 v2 y6 {& f; C# K0 A, i# b( Q+ |4 B

1 g# b/ F6 Q4 o, H1 S8 Rhttp://www.discuz.net/forum.php? ... amp;highlight=REDIS
关注微信公众号《神采飞扬网》,即可获取最新回复通知!
 楼主| 发表于 2018-11-16 12:43:33 | 显示全部楼层
http://www.discuz.net/forum.php? ... 648&highlight=REDIS
& Y2 l5 l5 g& B  W0 j0 x无意间测试 单机状态 redis相当给力 测试1000请求/s  单纯的 get 和set 居然只用了 0.01秒 当时我惊呆了
8 k& e/ j/ ?; d! ^! J' d$ k5 h$ t% z+ x. v$ E1 [& V+ `
http://www.discuz.net/forum.php? ... 731&highlight=REDIS
* f. k3 F% b8 m# H# X& G
" O6 I5 l. ?( p0 B1 x6 S. a9 ehttps://wenku.baidu.com/view/265a5ce176a20029bc642d0b.html9 J5 y/ f4 S# ^1 ~, h

; \8 m. ~+ B/ {=======================================* f5 [2 s# U9 g# F2 Y
  1. 连接上 ssh9 z' L6 g# ^4 \% f" l

  2. : k, y5 E5 A8 z( e: L/ D) X

  3. 2 M0 o+ m. h" P- h! X, q' E
  4. 第一步:下载redis
    " V* K  J: A) I. z! j( ^1 G3 u
  5. # wget http://redis.googlecode.com/files/redis-2.6.10.tar.gz* \: k( F* g3 o9 T  a7 R6 ~2 ]
  6. # tar zxvf redis-2.6.10.tar.gz
    7 w: A# a7 \! q& ]+ T; w
  7. # cd redis-2.6.103 n  V; l  I9 k" q1 l- b3 W- x) B& H
  8. # make ! ~! p2 R8 F: Z9 U/ G6 Y  P( I
  9. # make install  
    / _7 K' L( U( K8 H
  10. #cp redis.conf  /etc/ #复制配置文件到etc目录下面
    ( d4 p8 k$ m4 k% L$ H
  11. 第二步:修改配置
    1 ^4 N3 X' O7 w$ O& n! U
  12. #vi /etc/redis.conf. J: ?# L( s9 h0 T8 `4 G1 c
  13. ######################下面是无措的配置文件 复制过去就成#########2 w# `+ k9 s5 W9 `7 {
  14. # Redis configuration file example  O( Z# [/ u# K" F8 k

  15. 3 x+ x4 u# M1 v
  16. # Note on units: when memory size is needed, it is possible to specify& m: {( i9 ]- i$ b% |' ~7 c. B
  17. # it in the usual form of 1k 5GB 4M and so forth:; y8 c1 O: `7 H; c) C
  18. #
    - |5 V7 z9 _) l
  19. # 1k => 1000 bytes
    2 X5 ^% E, m, Q% d: _
  20. # 1kb => 1024 bytes
    0 t2 @% |7 L* F! S! `0 ]1 _
  21. # 1m => 1000000 bytes
    ! \. R; V2 J* l' H6 M
  22. # 1mb => 1024*1024 bytes) p/ W% `) I9 H) W6 W5 o" E( c
  23. # 1g => 1000000000 bytes; u* _- D, R3 I: ^' O
  24. # 1gb => 1024*1024*1024 bytes0 D; W/ E( J4 r
  25. #0 }! m4 a+ ~& r: u4 l8 I
  26. # units are case insensitive so 1GB 1Gb 1gB are all the same." s3 b0 V+ R* J5 K) p: z* d9 Y
  27. 7 v2 W$ d3 l9 Z7 n# B- N0 C
  28. # By default Redis does not run as a daemon. Use 'yes' if you need it.4 z5 P  I, ?1 y7 v( w
  29. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.8 X- ^( i$ G: c4 s, n7 g
  30. daemonize yes
    + h0 Q4 ^- ^/ {! ]3 h
  31. ! @) V( A( E3 X: B. V
  32. # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
    4 ~; v( l- Q* `
  33. # default. You can specify a custom pid file location here.* ~) R  T7 D$ N9 l$ T; Y
  34. pidfile /var/run/redis.pid
    , e; s, B/ P6 w9 |* B

  35. $ U% N2 Q) g/ K2 h8 g: z. o
  36. # Accept connections on the specified port, default is 6379.7 ?  E! R3 L3 _. k( g
  37. # If port 0 is specified Redis will not listen on a TCP socket.
    $ B: |6 |. H) v' b6 y( Q
  38. port 6379$ M/ F9 B. L: X# A% ?: Z
  39. * |: T+ e6 [# A
  40. # If you want you can bind a single interface, if the bind option is not
    $ [, h0 |. |8 Y( |4 w9 T
  41. # specified all the interfaces will listen for incoming connections.0 d4 m3 M3 r  h& L% i, ]5 B8 ^
  42. #
    8 J; E. k/ Q; T. y
  43. # bind 127.0.0.1
    , q! _, m- H4 i4 q  A

  44. ( V$ r( G- c' ]: z1 x+ Z2 Y
  45. # Specify the path for the unix socket that will be used to listen for
    5 k5 t7 Y; L# E) }( z! w
  46. # incoming connections. There is no default, so Redis will not listen
    ) o( Q- J6 P/ M( O* E
  47. # on a unix socket when not specified.
    " i% C" G9 o) Z
  48. #4 \4 l" e5 N: ?% y, U
  49. # unixsocket /tmp/redis.sock5 f! L6 S( {8 l8 W/ E
  50. # unixsocketperm 755+ \$ ]+ ]0 C4 q
  51. . C7 M$ w6 t& X  R4 X* W
  52. # Close the connection after a client is idle for N seconds (0 to disable)- O0 [( P; ?4 L) }; E9 ~
  53. timeout 300  }, K! j  E" ~/ m/ _/ R! M

  54. ' G9 n0 z* g2 B/ z) x& ~& p% h: r
  55. # TCP keepalive.0 ]: }; t4 m; Y, @/ [9 X' y
  56. #
    * u+ N- j% X8 G' F- {7 _3 O' z
  57. # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
    2 c+ t  d; {, h  F7 i! S+ j9 k
  58. # of communication. This is useful for two reasons:
    ' K% W0 k( h4 F4 k
  59. #
    : L! j) w3 p# Y8 u1 H+ K
  60. # 1) Detect dead peers.
    ( V* X; Y9 j8 e) t, O
  61. # 2) Take the connection alive from the point of view of network( J/ S- S1 q) V! Z3 C
  62. #    equipment in the middle.' C3 i1 P( N; N2 E# g
  63. #
    2 @; l" h  e1 U( d" k
  64. # On Linux, the specified value (in seconds) is the period used to send ACKs." c. Q  A5 Y$ a6 `* I' h
  65. # Note that to close the connection the double of the time is needed.! v# @8 e+ {+ w2 m% T
  66. # On other kernels the period depends on the kernel configuration.
    0 q( w9 }) }% Z- J9 _+ c1 U
  67. #
    9 ^2 f3 q! `! i+ g* G7 P; P
  68. # A reasonable value for this option is 60 seconds.
    . @5 u; f' C) T1 q3 l* J9 ]8 s
  69. tcp-keepalive 0* D; o  u0 U( G' ]0 B2 i2 p/ U& x4 W8 F
  70. 0 `6 ^: r1 {8 A; s' ?8 d: Z
  71. # Specify the server verbosity level.
    / x7 i! j9 T% x& W; X7 P
  72. # This can be one of:
    # |/ f- w2 z# o- A, p9 E2 O
  73. # debug (a lot of information, useful for development/testing)$ j  X& R) ?# {; ?
  74. # verbose (many rarely useful info, but not a mess like the debug level)
    & H0 g5 ]0 b8 y$ I, T- ]6 s1 T
  75. # notice (moderately verbose, what you want in production probably)
    + ]8 v# ?0 d- k/ Q/ q, Q! t
  76. # warning (only very important / critical messages are logged)
    2 Y$ M; j5 q3 g+ `( f
  77. loglevel warning) r3 O1 S: x8 \9 Z% g) Z' X+ F" R
  78. $ d% T3 F6 D, }4 w
  79. # Specify the log file name. Also 'stdout' can be used to force
    , A) P: n/ l' ^. F& P) R1 \5 [
  80. # Redis to log on the standard output. Note that if you use standard
    - M# Q9 j4 p8 q: r+ c
  81. # output for logging but daemonize, logs will be sent to /dev/null4 m4 b# N* ~* o; W
  82. logfile /var/log/redis.log
    & q4 K3 h6 W: d3 }
  83.   C0 u; n$ s6 B  L& `
  84. # To enable logging to the system logger, just set 'syslog-enabled' to yes,
    ; ^3 {8 K5 ?7 {& b
  85. # and optionally update the other syslog parameters to suit your needs.; b0 u7 ~/ B0 d
  86. syslog-enabled yes
    7 X6 I7 r% I! d: T* Q3 a

  87. * i( X/ a  L# Q9 h, j  u: z
  88. # Specify the syslog identity.% l9 W5 P$ M$ Y) e0 Q
  89. # syslog-ident redis
    1 w8 R& B5 @& S* t3 C$ e8 I8 T# _- o5 }* ^
  90. 3 P- `: A" F" X" o) @) |* _* Q, K3 S- Z
  91. # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.. G3 [0 R" u8 F$ q
  92. syslog-facility local0
    1 ]' V/ B% n4 i1 h# x9 [2 L
  93. 6 R! r& H9 S) {$ C! {
  94. # Set the number of databases. The default database is DB 0, you can select) q& i2 h: o' }4 ?6 g* H: y
  95. # a different one on a per-connection basis using SELECT <dbid> where( \7 J3 i6 }5 Y
  96. # dbid is a number between 0 and 'databases'-1, _; _& N4 b1 L. T3 p* s
  97. databases 16
    3 a0 x4 j" {' f2 a$ p

  98. + E6 a& N' E$ i" G
  99. ################################ SNAPSHOTTING  #################################$ A# K* R5 M. t7 U% ]
  100. #
    * P6 C0 U, Y3 @2 _! k7 I4 t( H
  101. # Save the DB on disk:
    7 h) f# y' P% @! L! V5 D2 A1 v2 B" @
  102. #! P! R. C. e3 J8 _9 @
  103. #   save <seconds> <changes>
    ' C9 B: U! Q7 B5 `$ R* T* i
  104. #
    - T4 N0 H! z7 ?) @) @/ M
  105. #   Will save the DB if both the given number of seconds and the given- ?' a0 X; D# x. q& g9 N4 m4 z, {! \
  106. #   number of write operations against the DB occurred.
    2 b" |; J6 b0 m4 Q3 C' g
  107. #4 ?" x+ w- j1 y& U* G/ w) A
  108. #   In the example below the behaviour will be to save:2 e' z5 y  a- V2 q& O1 i5 `
  109. #   after 900 sec (15 min) if at least 1 key changed
    # J4 e! M% f0 p; x
  110. #   after 300 sec (5 min) if at least 10 keys changed
    ' c9 U. X; K4 Y2 l
  111. #   after 60 sec if at least 10000 keys changed
    & m) t8 M  H: J7 h) c  E
  112. #
    1 l4 @; E6 A9 p( T* r4 W+ z
  113. #   Note: you can disable saving at all commenting all the "save" lines.4 a: t) _( z9 u0 S( Q
  114. #
    , j" ?2 i" f( N8 E3 X( K
  115. #   It is also possible to remove all the previously configured save  m; @/ {8 {: ^+ q* f5 w
  116. #   points by adding a save directive with a single empty string argument, H- G  f: X, h1 o, W
  117. #   like in the following example:) y2 n: G5 @6 [( f1 z
  118. #: {2 T, ^! R$ S1 X8 |0 n/ j6 E
  119. #   save ""
    / K1 h+ n) _7 _

  120. . E5 Y0 `; M+ P
  121. save 900 10 M" Q! J7 S2 q/ @. B+ i
  122. save 300 10
    ! s" G6 s0 Q: F# F
  123. save 60 10000. o. L: T) u0 T

  124. 8 v, }. f* v: G2 J+ X
  125. # By default Redis will stop accepting writes if RDB snapshots are enabled$ T! X2 b* X1 ~) W6 H8 l
  126. # (at least one save point) and the latest background save failed.  _( Y0 X0 W/ ]' S3 ^6 g
  127. # This will make the user aware (in an hard way) that data is not persisting
    2 H4 T( x) m2 b) o$ `
  128. # on disk properly, otherwise chances are that no one will notice and some1 F, f4 I' ]$ ~2 x3 `& z* x
  129. # distater will happen.& M4 z2 U" B$ q
  130. #7 |1 t: ]' q6 k- Q- {5 S
  131. # If the background saving process will start working again Redis will
    % n9 V5 k: e. o( O
  132. # automatically allow writes again.' s4 b& t- F; ^3 s: k
  133. #
    ! ?! w+ h+ N) ]: t5 |. u
  134. # However if you have setup your proper monitoring of the Redis server
    1 u# R" t8 n  R4 p4 Z# ^8 I
  135. # and persistence, you may want to disable this feature so that Redis will* X/ g" e$ j& L. r+ u
  136. # continue to work as usually even if there are problems with disk,4 Y3 i% T) \/ q% K# J: U* h
  137. # permissions, and so forth.
    ! w% ?! G) L# }; `$ r2 v5 v  `. B
  138. stop-writes-on-bgsave-error yes2 I0 x% |! b; q- ~

  139. : G# t$ i! B8 _! l
  140. # Compress string objects using LZF when dump .rdb databases?
    5 y! x; R' m: R' z+ ]7 q
  141. # For default that's set to 'yes' as it's almost always a win.% X) u- D) m. D4 X
  142. # If you want to save some CPU in the saving child set it to 'no' but- r6 R' G- c& x6 q) S. N( d
  143. # the dataset will likely be bigger if you have compressible values or keys.' p( c( O: f# O, o
  144. rdbcompression yes
    ( O+ P/ [# {2 P4 z" z  }

  145. % @1 M) g- z, X) {* m# K% l8 \; P
  146. # Since version 5 of RDB a CRC64 checksum is placed at the end of the file." r. L0 W9 q! R
  147. # This makes the format more resistant to corruption but there is a performance
    + U3 W9 Y  d& Y/ W' x: A
  148. # hit to pay (around 10%) when saving and loading RDB files, so you can disable it
    " N6 {& L0 j: ?4 K9 i) l& m, _
  149. # for maximum performances.
    * x8 Y' L# M+ h) ^
  150. #7 x2 R+ m& F# t% a2 m
  151. # RDB files created with checksum disabled have a checksum of zero that will
    ) ~$ W9 D+ t+ U" ?2 A# }
  152. # tell the loading code to skip the check.
    8 ]0 V5 Q& J( ]+ _- u" y
  153. rdbchecksum yes: D! Y7 P2 J2 [8 D$ d- p0 J
  154. * H' R! ~( h' V# r+ l$ r
  155. # The filename where to dump the DB
    6 q" m5 S) S  @3 Z# s1 H
  156. dbfilename dump.rdb% E! d! b" b. u+ X) C

  157. - B: }( O" \! h3 d( f, c0 L8 i8 l# [
  158. # The working directory.
    . x* J) @4 v; K/ Q" N! F
  159. #
    % s! v: V& e2 O
  160. # The DB will be written inside this directory, with the filename specified/ Q; G/ ~" s8 M) O# h/ Q+ O
  161. # above using the 'dbfilename' configuration directive.
    " K* B$ K) K$ P9 o  L
  162. #   [; U, s4 ^7 Y* }; x) v4 c
  163. # The Append Only File will also be created inside this directory.
    % a  N8 n& l1 v
  164. # 7 _' f7 }9 d/ r  u1 E' Y7 G* Q& s( C
  165. # Note that you must specify a directory here, not a file name.4 e; N; `! J4 `7 ]3 [, i. g
  166. dir /var/db/redis
    7 v. w6 B; \: R# R' ^7 F2 Z8 f* |
  167. 7 a1 M- u5 d, o9 n: G
  168. ################################# REPLICATION #################################& B  V  ]8 v5 ~6 g# a% q3 p, i

  169. " V" }0 p$ L( P( E; M; W" w
  170. # Master-Slave replication. Use slaveof to make a Redis instance a copy of" E5 w3 t1 F! b0 l4 i
  171. # another Redis server. Note that the configuration is local to the slave
    + m/ |; P1 W" h9 `
  172. # so for example it is possible to configure the slave to save the DB with a
    . X0 f* d% d' q- A2 T+ h
  173. # different interval, or to listen to another port, and so on.
    , u  o; A" n7 W! ~
  174. #
    * ~8 ^, h( x, g9 v( L3 [5 w
  175. # slaveof <masterip> <masterport>6 j( I  j2 l: \0 O) {  h  c5 a
  176. / p& V' O( i) x+ x) e, b
  177. # If the master is password protected (using the "requirepass" configuration# s  Z' ?; U4 H! h
  178. # directive below) it is possible to tell the slave to authenticate before
    ! L3 A+ F6 ~! a" ]+ k+ W7 ?5 `
  179. # starting the replication synchronization process, otherwise the master will3 g3 v) q" H. X' ]
  180. # refuse the slave request.3 q; y& O0 D7 [; W6 P( K$ M) M6 _- c
  181. #
    6 H# }/ h+ K5 K$ z. d
  182. # masterauth <master-password>* F' E- D1 }/ b$ U# r( A0 k0 e0 Q' i& `

  183. / G; G  g+ P0 `9 g
  184. # When a slave loses its connection with the master, or when the replication: [6 Y! m3 f5 ^
  185. # is still in progress, the slave can act in two different ways:! M# U0 n9 @! J& Y0 ^
  186. #
    * j7 C4 B- Q/ Y5 B$ z
  187. # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will
    ! c1 Q4 C, D. _1 D
  188. #    still reply to client requests, possibly with out of date data, or the
    9 ?6 l6 T5 [& ?0 |4 X& c
  189. #    data set may just be empty if this is the first synchronization.: f, C7 z" g2 X9 }
  190. #- F" G# s% U4 N' E
  191. # 2) if slave-serve-stale data is set to 'no' the slave will reply with
    $ s  Z# W* P# i$ ~
  192. #    an error "SYNC with master in progress" to all the kind of commands1 _; ]7 {# X: d( I% H! X- G; ~  _
  193. #    but to INFO and SLAVEOF.* J5 {; X: `3 p# K4 w3 ?
  194. #
    , t3 s- v! n" C+ S, L! `$ ]0 t
  195. slave-serve-stale-data yes$ C( q9 A$ r4 }0 B
  196. 2 s" S, [- \' R2 y2 A
  197. # You can configure a slave instance to accept writes or not. Writing against
    6 P+ c. ~7 I4 X! c
  198. # a slave instance may be useful to store some ephemeral data (because data+ G: v9 Z, g* N8 Z
  199. # written on a slave will be easily deleted after resync with the master) but2 z9 E2 W% y( e" ?0 k- u' S
  200. # may also cause problems if clients are writing to it because of a
    * x& u& T& s) s  `5 F3 C, R
  201. # misconfiguration.7 i+ r7 R1 Q, ]6 L& ]
  202. #
    3 |: ], ]. t& Y4 b
  203. # Since Redis 2.6 by default slaves are read-only.9 j  T# _" O" `- h, F/ l) i
  204. #( w+ ~* @# v1 ]1 _. h- r  f
  205. # Note: read only slaves are not designed to be exposed to untrusted clients
    $ }6 @" Y# \, z3 B' A9 U* g
  206. # on the internet. It's just a protection layer against misuse of the instance.
    % E% P2 S) k7 d/ y5 t4 ^% `
  207. # Still a read only slave exports by default all the administrative commands
    + R3 b3 [" y9 E; J4 \6 ?0 @" k
  208. # such as CONFIG, DEBUG, and so forth. To a limited extend you can improve  p( B4 M% r' i0 _. o1 a5 W
  209. # security of read only slaves using 'rename-command' to shadow all the
    / a7 B2 J. }+ C# v3 @' i' `+ d
  210. # administrative / dangerous commands.$ J+ i3 o  l" f; t6 U3 c
  211. slave-read-only yes6 D( u. e- H/ X% }) w

  212. 0 B, [1 u; z2 R3 n  a: N8 S; O
  213. # Slaves send PINGs to server in a predefined interval. It's possible to change2 H; W, b( T! R5 r
  214. # this interval with the repl_ping_slave_period option. The default value is 10# x- n- ?8 K8 y4 v" y
  215. # seconds.. e$ X/ T7 U5 p% Y) o
  216. #
    4 X/ R2 e" x. O- b4 d( `4 R
  217. # repl-ping-slave-period 10
    ! E+ n# \8 ^8 j
  218. 4 u" l  U7 A* f1 @+ L0 W2 Y2 |
  219. # The following option sets a timeout for both Bulk transfer I/O timeout and# G; _) v; M7 y! M1 j2 r0 @
  220. # master data or ping response timeout. The default value is 60 seconds.1 R4 K  b# y$ b* ^8 {
  221. #% M; Y8 p* I+ p/ X# S* V3 @
  222. # It is important to make sure that this value is greater than the value
    9 f$ x6 s. t6 G  w" c& a
  223. # specified for repl-ping-slave-period otherwise a timeout will be detected  r  {" e5 Z! l% g  @
  224. # every time there is low traffic between the master and the slave.
    - M$ L, r( ~/ q2 I
  225. #
    - d1 y1 g( F) s
  226. # repl-timeout 60
    % P; l( p0 K! a; Q
  227. 8 G$ W8 M6 k: B  D
  228. # Disable TCP_NODELAY on the slave socket after SYNC?
    6 z! A* s% Q! i. X% [" v
  229. #
    - ]6 Y$ k9 |: l- F8 R4 w
  230. # If you select "yes" Redis will use a smaller number of TCP packets and
    ' `- ^- r. I/ g9 h+ {( o
  231. # less bandwidth to send data to slaves. But this can add a delay for. Q, R7 k8 {8 u
  232. # the data to appear on the slave side, up to 40 milliseconds with$ ^- x8 U% l# y) y4 E
  233. # Linux kernels using a default configuration.
    ! E* U" n) b+ l5 ~9 i# b
  234. #
    & K7 o+ |3 @/ A2 i; Z
  235. # If you select "no" the delay for data to appear on the slave side will/ @) z. V4 T+ i' n- z; V# {% y
  236. # be reduced but more bandwidth will be used for replication.
    1 G; @# `/ _/ K0 x4 c
  237. #  ~8 [, \2 U3 j
  238. # By default we optimize for low latency, but in very high traffic conditions9 A7 x4 I, |1 G9 F+ j2 |2 b
  239. # or when the master and slaves are many hops away, turning this to "yes" may
    $ q; |2 ^/ @) B
  240. # be a good idea." y7 N% l" a$ O1 H1 d3 t
  241. repl-disable-tcp-nodelay no
    5 \2 c9 ?( F" k7 E
  242. ( ]: v9 }9 T; G' D+ N8 A
  243. # The slave priority is an integer number published by Redis in the INFO output.
    6 `; r/ p7 m! l* {$ Q) A7 H1 F
  244. # It is used by Redis Sentinel in order to select a slave to promote into a
    % k2 P% G' T7 I- u" l% _! j
  245. # master if the master is no longer working correctly.7 ?0 m5 g+ W* n
  246. #7 z; }9 j8 V- x! O+ @8 L
  247. # A slave with a low priority number is considered better for promotion, so
    4 N- y( Y5 T( t1 H
  248. # for instance if there are three slaves with priority 10, 100, 25 Sentinel will6 k, \! U9 g5 S
  249. # pick the one wtih priority 10, that is the lowest.
    0 q; I9 S. I! p* r1 `
  250. #+ b+ M3 s9 e& E( \
  251. # However a special priority of 0 marks the slave as not able to perform the
    ! A) ~! G9 g" ]- X% H7 A
  252. # role of master, so a slave with priority of 0 will never be selected by
    6 I7 g) ]7 @/ `" M4 k
  253. # Redis Sentinel for promotion.& H# ^+ i  s. U
  254. #2 S+ h" J3 x( J9 ^4 a3 n
  255. # By default the priority is 100.
    : H( f" q( [0 j4 d# y
  256. slave-priority 100% r& j; E  A" E3 r5 H/ B" {6 R& T$ Y3 n

  257. 0 t3 U3 k9 [1 c; `5 K- y
  258. ################################## SECURITY ###################################% Y' y, ]3 w% \8 Z6 T+ F( y) z
  259. 5 r8 k: V# _: K" k0 v" a9 A
  260. # Require clients to issue AUTH <ASSWORD> before processing any other: [, u0 X! F( w. ~/ O
  261. # commands.  This might be useful in environments in which you do not trust& D6 _! z* @8 h3 j$ |1 s
  262. # others with access to the host running redis-server.0 r4 }3 p4 t1 G. Q& z- Z
  263. #
    ! {2 U: |, _' K* n& |9 [
  264. # This should stay commented out for backward compatibility and because most+ z+ W% E4 b1 t; o3 [! r( B
  265. # people do not need auth (e.g. they run their own servers).
    - ~$ k% p# B7 q/ v! V6 b/ |
  266. #
    0 ]- h1 K" `4 g" o5 q( J
  267. # Warning: since Redis is pretty fast an outside user can try up to
      U: Z# a& H* ]8 k8 V0 G& `) m
  268. # 150k passwords per second against a good box. This means that you should
    6 {& M3 z  r2 `$ e$ a3 m- E7 Q
  269. # use a very strong password otherwise it will be very easy to break./ v* ?6 j) s3 L: U& a8 _" W
  270. #  l/ J+ r( Z; D, b9 W5 x& s; X5 Q" J
  271. # requirepass foobared
    2 B2 l1 r7 f3 H! X  |( R5 Z5 k9 p

  272. ; T, Y2 h4 N& J
  273. # Command renaming.9 y5 _' f3 c7 A
  274. #& H% ]1 e6 D$ a( [/ e( A3 t% T; @1 n
  275. # It is possible to change the name of dangerous commands in a shared/ e) Q7 }6 b- ]6 Y7 v
  276. # environment. For instance the CONFIG command may be renamed into something
    ' ]7 R$ V7 A2 l% ^' x
  277. # hard to guess so that it will still be available for internal-use tools2 A: A' m. m6 D2 O3 T
  278. # but not available for general clients.
      e  O5 P5 `  J- c! x0 y/ W
  279. #
    * |# {5 L/ {0 s/ T% Y7 {/ M
  280. # Example:3 j0 I! |2 N$ n9 t0 P( |9 ~
  281. #
    % C9 l7 E% c( H0 I2 A: @
  282. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
    8 |% p0 x. V( \+ ^! |2 F
  283. #: h) K6 o% ^8 h1 v0 W* [4 ^5 B: X
  284. # It is also possible to completely kill a command by renaming it into7 {; c) [: |9 v, p
  285. # an empty string:" a) x9 _" R3 ?1 ?' C& y
  286. #
    ( g) j1 R, x7 q7 S5 Q5 e& Z% j) g
  287. # rename-command CONFIG ""  z- H  M% I: ^3 k/ p2 I
  288. 6 c% T/ M* e$ A0 S$ J
  289. ################################### LIMITS ####################################3 Q1 |2 n, l% N" x
  290. ( v9 O9 ~; k; W5 H) O; @
  291. # Set the max number of connected clients at the same time. By default. O) W0 Q, }* x. \% A5 p3 t
  292. # this limit is set to 10000 clients, however if the Redis server is not, t* g( e! l4 e4 t
  293. # able to configure the process file limit to allow for the specified limit, C, G, y) g5 |8 S# b6 b9 d- {
  294. # the max number of allowed clients is set to the current file limit
    4 l4 F2 y; u8 K: V+ k6 r1 t
  295. # minus 32 (as Redis reserves a few file descriptors for internal uses).
    # K" f& z4 y( Y: F
  296. #
    7 c4 Q! t, q' K
  297. # Once the limit is reached Redis will close all the new connections sending. n' j: V, N7 y4 _$ @9 h( u! K! D
  298. # an error 'max number of clients reached'.
    . Y" h6 D2 M1 W7 Y  \- `
  299. #, N( t  U6 z0 x6 [- s
  300. maxclients 5002 a" d! w  J0 D8 c6 \( `

  301. 9 G- S" K1 D4 e6 K0 G$ R# ]
  302. # Don't use more memory than the specified amount of bytes.
    % t( T1 q. Y( X! [* A
  303. # When the memory limit is reached Redis will try to remove keys
    & Q; F5 d- @0 l; |0 h2 p6 c
  304. # accordingly to the eviction policy selected (see maxmemmory-policy).4 F0 z1 H- m) D# N3 I
  305. #
    & z5 s! U2 v8 u, T; X
  306. # If Redis can't remove keys according to the policy, or if the policy is
    ; q$ ~' C/ D! s% b  w
  307. # set to 'noeviction', Redis will start to reply with errors to commands& d( U6 U( p& }4 O* D0 l
  308. # that would use more memory, like SET, LPUSH, and so on, and will continue0 }  {! R2 P1 C. h" S
  309. # to reply to read-only commands like GET.
    & e5 F" D4 H) [; C
  310. #
    ! [' m: }6 _7 w% v) a
  311. # This option is usually useful when using Redis as an LRU cache, or to set
    + S, l7 u! o! ~" U7 U" F0 ?7 C
  312. # an hard memory limit for an instance (using the 'noeviction' policy).- n( I* {/ _) i# u0 {7 U
  313. #
    $ d! X5 q. x0 D3 H
  314. # WARNING: If you have slaves attached to an instance with maxmemory on,
    # _  G$ X& m: @. |' D& i
  315. # the size of the output buffers needed to feed the slaves are subtracted
    ; o8 H6 d# x" m" a. c1 w( Q" H+ k
  316. # from the used memory count, so that network problems / resyncs will
    7 D, J2 s  G6 B5 m3 F7 @
  317. # not trigger a loop where keys are evicted, and in turn the output
    " H7 c, k+ V: f4 Q' g5 e
  318. # buffer of slaves is full with DELs of keys evicted triggering the deletion1 b9 n. X- c. S, d
  319. # of more keys, and so forth until the database is completely emptied.
    : V( C' P, ]+ z8 J- Z* C
  320. #! V! r% Q* u! l, |4 B# F4 J
  321. # In short... if you have slaves attached it is suggested that you set a lower+ F1 \' V3 A6 ~/ w
  322. # limit for maxmemory so that there is some free RAM on the system for slave
    ) ^1 s4 ?* H* m' p$ \; Q6 x
  323. # output buffers (but this is not needed if the policy is 'noeviction').
    " y* l) _3 [, V* [
  324. ## |( v5 Z* A8 n1 ]: H* c
  325. maxmemory 128000000
    * T$ i# O- k2 u/ r4 r; g# X
  326. 1 z& M. S3 t3 _' Z) G3 K; ?
  327. # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory( a7 n" ?+ ~. }) y/ A
  328. # is reached. You can select among five behaviors:: h0 g9 [% G# T' k5 }) b
  329. #
    ( h9 Z+ v/ H: R: u! F0 X5 l
  330. # volatile-lru -> remove the key with an expire set using an LRU algorithm9 y% p! t: n9 @0 h! r1 K6 Q0 S7 ^
  331. # allkeys-lru -> remove any key accordingly to the LRU algorithm
    9 B4 W- g- W0 r/ H0 q! ]
  332. # volatile-random -> remove a random key with an expire set) c& z) F1 I- E) O2 y
  333. # allkeys-random -> remove a random key, any key
      S& M  D( X9 |! M+ F* h
  334. # volatile-ttl -> remove the key with the nearest expire time (minor TTL)5 E" _6 y( q6 k' z
  335. # noeviction -> don't expire at all, just return an error on write operations9 J2 _2 \# y* T9 D: G/ h
  336. # ! K2 w7 S" K( a/ o# e- ~3 O* w* M
  337. # Note: with any of the above policies, Redis will return an error on write' C, s# z) S' w. h  ?* q8 K
  338. #       operations, when there are not suitable keys for eviction.
    5 }/ u$ f0 |5 Y- l2 P# t6 c
  339. #
    * m! u" k! W1 N2 {& N7 ]5 F
  340. #       At the date of writing this commands are: set setnx setex append5 ^* }4 ]- d8 n! M4 r( I
  341. #       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
    ; a, X7 s, D* a' }% M: c
  342. #       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
    - q% ?* m( |; K3 a/ ^
  343. #       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby6 M9 D  @0 \' z  t! p
  344. #       getset mset msetnx exec sort
    8 z0 A3 y2 C, z9 I' k  r. Y
  345. #
    ; d- y% D% X) R/ W$ r4 A! Z8 `
  346. # The default is:
    4 o" d* H! s* M3 F
  347. #3 Z& ]; v4 m3 h# R
  348. # maxmemory-policy volatile-lru
    0 w$ B1 a1 l& ]) m
  349. 3 R8 c+ p5 H7 V$ E. z) a
  350. # LRU and minimal TTL algorithms are not precise algorithms but approximated3 g) Y/ O( X/ ]. Z# M7 r9 L" R0 O
  351. # algorithms (in order to save memory), so you can select as well the sample" M2 a: K) D% G' x8 L2 [
  352. # size to check. For instance for default Redis will check three keys and
    " L3 D! u8 W7 Z, _0 V% Z( s' l  d
  353. # pick the one that was used less recently, you can change the sample size
    9 W' Q  l) k$ g4 x
  354. # using the following configuration directive.
      m0 l! {0 V$ K" v0 Y6 B& l
  355. #% W% {; `. _4 k, y1 r  A5 Q6 x* H
  356. # maxmemory-samples 3: H- M, B& }# y0 G( [, E

  357. 6 o& b" i/ ]# ]  c. W
  358. ############################## APPEND ONLY MODE ################################ o7 k- }5 }5 t3 c

  359. 7 ^' G# g5 u! ^! I" O, C' |
  360. # By default Redis asynchronously dumps the dataset on disk. This mode is5 s; G% L2 g: K0 E( M
  361. # good enough in many applications, but an issue with the Redis process or( k) A$ D/ G6 `' [: e0 O- i
  362. # a power outage may result into a few minutes of writes lost (depending on1 V# w* V9 i1 }4 F- r( M
  363. # the configured save points).
    2 x7 d2 J1 a# m9 E1 O) h% [! j
  364. #
    . m& H; C$ ~/ i
  365. # The Append Only File is an alternative persistence mode that provides
    ! j4 P- z( p+ a
  366. # much better durability. For instance using the default data fsync policy
    2 D8 c  g  P. J$ o  ~
  367. # (see later in the config file) Redis can lose just one second of writes in a1 `, {) ]" l! z- |- O
  368. # dramatic event like a server power outage, or a single write if something* o2 F3 M5 ^/ W
  369. # wrong with the Redis process itself happens, but the operating system is
    " S& g0 b2 n1 Q  p% N7 U- o
  370. # still running correctly.  e( L$ _- m( Y. k
  371. #
    8 ]3 g/ \7 U$ |' H9 S  D* ]
  372. # AOF and RDB persistence can be enabled at the same time without problems.
    # c- M2 F; }) B( h- C  \+ ?
  373. # If the AOF is enabled on startup Redis will load the AOF, that is the file# S4 Z& w$ R# q; Z4 c
  374. # with the better durability guarantees.
    - i. U+ S. k: `+ x$ h# a$ h5 L5 R
  375. #+ M5 Q; y2 G: T
  376. # Please check http://redis.io/topics/persistence for more information.
    % ^% w9 Z# P* `% l4 ^) C

  377. 9 h7 k9 w* L4 r' ^5 m; H
  378. appendonly no
    # S% f: ^, P( M+ d  i& h7 }

  379. $ D, g9 L6 k$ l2 M4 h" W1 N
  380. # The name of the append only file (default: "appendonly.aof")
    6 [1 h5 _5 Q" Y/ F* e5 N3 N* |! |! c( w
  381. # appendfilename appendonly.aof
    ) s. N' B8 a) x. F# T

  382. , [% y$ f8 {  N- c( u6 _" V8 o
  383. # The fsync() call tells the Operating System to actually write data on disk
    2 J4 m% N! y* F% z2 V
  384. # instead to wait for more data in the output buffer. Some OS will really flush
    ; X, A% _7 Q3 X* ]/ A2 O' M2 i; w
  385. # data on disk, some other OS will just try to do it ASAP.8 z% a* I; z- V: _4 I  B) O- u& F0 M
  386. #
    5 t0 D) ]  p4 s1 I' |
  387. # Redis supports three different modes:
    0 H) D' {! }4 @  E# R# D
  388. #5 M+ I5 U9 M7 w
  389. # no: don't fsync, just let the OS flush the data when it wants. Faster.; R4 S4 M: t" D( R" {7 ]
  390. # always: fsync after every write to the append only log . Slow, Safest.
    * K5 t/ z3 A5 v% U: U
  391. # everysec: fsync only one time every second. Compromise.
    & T& U/ ]. Q' B' d, E8 Z( p
  392. #2 z- H4 A3 q3 c& I0 x: T4 u% l
  393. # The default is "everysec", as that's usually the right compromise between  |. P) y* n  d7 ^: q
  394. # speed and data safety. It's up to you to understand if you can relax this to' M# L  j1 X0 e5 E/ P! I0 d
  395. # "no" that will let the operating system flush the output buffer when
    1 K* C2 ]5 n5 G( r( H5 u% Z
  396. # it wants, for better performances (but if you can live with the idea of
    2 g5 u  V6 |: x/ a
  397. # some data loss consider the default persistence mode that's snapshotting),& l! l, X6 f& _& q$ ?% s
  398. # or on the contrary, use "always" that's very slow but a bit safer than
    9 r- Z, k: X, E( S2 G; R/ B
  399. # everysec.& P# F  b9 Y1 ?; c
  400. #
    + U  @% |+ {, d3 Q. O4 O
  401. # More details please check the following article:
    4 u1 w% D8 V& o- |9 [8 X% o
  402. # http://antirez.com/post/redis-persistence-demystified.html
    2 ~+ \7 x5 j6 Q. X! [# l+ Y
  403. #* ]; f# M0 ^4 l3 J  ~0 s+ Z  h
  404. # If unsure, use "everysec".
    5 Z: P, }% J3 n' L- P5 j
  405. + [6 V& g7 x: \6 G4 l
  406. # appendfsync always
    6 a+ x3 i( r+ B6 N1 z% [
  407. appendfsync everysec" f. r( e: z! |1 X! i9 U; s
  408. # appendfsync no
    9 r* d3 p1 \1 w/ J$ Y+ V
  409. 3 @6 \) v: r& f- u3 ?7 x7 R2 |
  410. # When the AOF fsync policy is set to always or everysec, and a background; `. t  ]. F% F. N1 z
  411. # saving process (a background save or AOF log background rewriting) is8 `, ~: D" Y' q5 G6 v; R! h
  412. # performing a lot of I/O against the disk, in some Linux configurations
    6 c/ L/ A/ `/ l
  413. # Redis may block too long on the fsync() call. Note that there is no fix for9 |" C. B& D0 k8 W  Y
  414. # this currently, as even performing fsync in a different thread will block
    : n: L0 C. F! n1 h
  415. # our synchronous write(2) call.
    : u2 y0 ?: V. @' Y) B& T! _
  416. #
    5 C% b0 D: M$ x/ A% W! a) l; {1 Z
  417. # In order to mitigate this problem it's possible to use the following option& L+ o+ p3 V/ S. L" A. d
  418. # that will prevent fsync() from being called in the main process while a
    5 a! n8 f6 F, \5 {/ e/ r, ?8 Q
  419. # BGSAVE or BGREWRITEAOF is in progress.
    7 B: b) |: u4 l) O: Z3 f
  420. #% c, H+ B! x7 {; V; r
  421. # This means that while another child is saving, the durability of Redis is
    ! X0 z. T: x( x( u) N0 W: v
  422. # the same as "appendfsync none". In practical terms, this means that it is
    , `! V/ G; @7 H3 ^' _
  423. # possible to lose up to 30 seconds of log in the worst scenario (with the
    : u% Z4 x% x/ \
  424. # default Linux settings).
    ' _9 J7 ]! e3 ?0 t4 _
  425. #
    % W* g5 A& `2 L/ |6 v+ p/ @
  426. # If you have latency problems turn this to "yes". Otherwise leave it as
    ' e0 A/ H7 P( `+ E" q6 ?
  427. # "no" that is the safest pick from the point of view of durability.
    6 ^& g3 ^, e1 i# w
  428. no-appendfsync-on-rewrite no
    - o4 f" }4 M  b9 w  H! X

  429. 9 G5 J5 T1 v  M
  430. # Automatic rewrite of the append only file.& u0 i# \+ f$ h: N% ^# [1 E# j
  431. # Redis is able to automatically rewrite the log file implicitly calling
    & f5 H) R. ~2 {% `/ h; b
  432. # BGREWRITEAOF when the AOF log size grows by the specified percentage.3 X0 h7 D, x0 ^2 W  N# \  A6 y
  433. #
    0 k- Q. u7 ^& y: s
  434. # This is how it works: Redis remembers the size of the AOF file after the
    8 o& g, E- Q$ b4 S; p5 ?+ m
  435. # latest rewrite (if no rewrite has happened since the restart, the size of& e7 ]8 Z9 E7 A7 @  Y& g  c
  436. # the AOF at startup is used).
      X7 d- S0 I- Q( G
  437. #$ {! P) o: g; S' @) m7 s2 m% L
  438. # This base size is compared to the current size. If the current size is
    : r, Z  ?5 K. o
  439. # bigger than the specified percentage, the rewrite is triggered. Also
    2 {5 g4 A+ S( h2 z8 S& N
  440. # you need to specify a minimal size for the AOF file to be rewritten, this
    ; E- Y  ?5 g1 e2 H& J
  441. # is useful to avoid rewriting the AOF file even if the percentage increase
    * y9 q2 g( P5 e; |* M$ {
  442. # is reached but it is still pretty small.0 y+ y4 ~2 D  \2 H8 g( N! u
  443. #1 B; ~- ~. R" b
  444. # Specify a percentage of zero in order to disable the automatic AOF5 k" y  J4 Y- [. `. p3 C' X, |
  445. # rewrite feature./ H# P& U& G& M

  446. 2 }  i$ P2 h8 `1 k
  447. auto-aof-rewrite-percentage 100* G+ m! V& e1 Z4 J+ W/ |
  448. auto-aof-rewrite-min-size 64mb) A2 B3 y; u+ w0 a2 E  b" g0 h
  449.   ]) g% |/ G; W3 z
  450. ################################ LUA SCRIPTING  ###############################. h- l  S, G4 f' j9 B

  451. 2 g2 v  G  I4 x) a. Y
  452. # Max execution time of a Lua script in milliseconds.
    - C; U/ c4 i- {
  453. #
    8 f5 S7 z" Q6 ?9 v9 h; K: g' g
  454. # If the maximum execution time is reached Redis will log that a script is* j) E9 D7 p& }0 X  O
  455. # still in execution after the maximum allowed time and will start to. h- l) f5 C' N1 Y$ m3 C
  456. # reply to queries with an error.' M  w( K  T2 C1 t* r4 c# R4 i
  457. #& k  K6 K. z- E; u) v( d
  458. # When a long running script exceed the maximum execution time only the
    ; U, b) E5 j8 k; \! b2 g7 L" h
  459. # SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be/ u3 r; J& |6 Y  |( ?0 D, \
  460. # used to stop a script that did not yet called write commands. The second
    % t2 s+ v* _' C+ J2 L
  461. # is the only way to shut down the server in the case a write commands was
    2 T/ u7 h; m+ U+ D8 P
  462. # already issue by the script but the user don't want to wait for the natural; @# N8 Y6 t9 {7 E! W2 V
  463. # termination of the script.* a  B7 R' q* `; @, B/ c
  464. #
    , t' D- ~) B( Y7 |
  465. # Set it to 0 or a negative value for unlimited execution without warnings.! C& q( j0 ?/ U0 s  [  B
  466. lua-time-limit 5000
    $ _' g: A& w( a

  467. $ X6 y; ^8 _' N6 E( g+ S& S' d8 V
  468. ################################## SLOW LOG ###################################% M# c" }1 O6 T, l' O2 e  [. ]0 w0 A4 _

  469. ( R" w& M# @  `" l3 b( f
  470. # The Redis Slow Log is a system to log queries that exceeded a specified! U/ U1 I0 @5 K9 R3 O) }
  471. # execution time. The execution time does not include the I/O operations% z: N: L3 k6 ?! `$ a
  472. # like talking with the client, sending the reply and so forth," X/ i& e6 v  |: h
  473. # but just the time needed to actually execute the command (this is the only
    # _, C1 c5 |6 P" d) [& t3 H
  474. # stage of command execution where the thread is blocked and can not serve- D& Q. L% A, Q/ Y& B
  475. # other requests in the meantime).! n3 ~; N: D5 V- K3 Y
  476. # ! E" }5 Q3 B5 z' D- q3 n; f; i
  477. # You can configure the slow log with two parameters: one tells Redis
    3 h/ T. W0 z) V& |  n5 x
  478. # what is the execution time, in microseconds, to exceed in order for the
      W% z" f( N# T
  479. # command to get logged, and the other parameter is the length of the
    5 d( ^* ]5 }; P4 O# r
  480. # slow log. When a new command is logged the oldest one is removed from the
    ' w5 w' F+ Z* J4 v
  481. # queue of logged commands.
    * x6 d" [1 L. ?* p& v+ F1 ]5 F. ^

  482.   N% |+ @4 u# x' n
  483. # The following time is expressed in microseconds, so 1000000 is equivalent6 S) B, f$ x/ G8 D; T- a0 y
  484. # to one second. Note that a negative number disables the slow log, while1 L! `6 J2 V; b& \" l! C/ r
  485. # a value of zero forces the logging of every command.$ K* d1 r9 B& [9 Y6 L9 U5 b9 e
  486. slowlog-log-slower-than 10000
    7 t( o5 u" s3 ]
  487. * x; O  ^. ?( L% e# ~
  488. # There is no limit to this length. Just be aware that it will consume memory.& g0 z" `! [" ^- u+ k1 G0 h
  489. # You can reclaim memory used by the slow log with SLOWLOG RESET.
    0 N/ c5 b5 N* ~3 h6 d/ l1 A
  490. slowlog-max-len 1282 h( g; V# O( j; u

  491. ' b+ u% w% m# A+ g, J2 L; M) Y
  492. ############################### ADVANCED CONFIG ###############################+ F( r2 E! m/ G: T

  493. & F. `8 \* q7 o4 H& t3 A  r2 m
  494. # Hashes are encoded using a memory efficient data structure when they have a
    1 b; [+ A7 k9 y/ g" Q- x. |
  495. # small number of entries, and the biggest entry does not exceed a given
    : P2 u3 }( x. j. f
  496. # threshold. These thresholds can be configured using the following directives." R7 h. s( I. g2 P
  497. hash-max-ziplist-entries 512
    1 e. l. s# R% P1 @% J
  498. hash-max-ziplist-value 64
    # o4 s5 f  s+ k

  499. ' V4 Z' }6 Y1 M6 d$ M4 Z7 I
  500. # Similarly to hashes, small lists are also encoded in a special way in order, Y& Q& r' O6 M" E" _
  501. # to save a lot of space. The special representation is only used when
    $ Q$ I6 u5 J, H: x# b" m5 X
  502. # you are under the following limits:
    $ g* u7 e! v  P) ^
  503. list-max-ziplist-entries 512
    : X3 l& W$ n, M/ Q% X3 j2 ^9 {
  504. list-max-ziplist-value 64
    $ ]! i  F5 h, b: q

  505. * a! A) B0 W2 ?" q
  506. # Sets have a special encoding in just one case: when a set is composed/ v4 N1 s% ]. v
  507. # of just strings that happens to be integers in radix 10 in the range7 f& S% t( v! L+ C2 B/ P" I' n! g
  508. # of 64 bit signed integers.
    , U0 s0 `* @3 G' v( C* E; a: Y
  509. # The following configuration setting sets the limit in the size of the
    5 K* g1 q' W) a6 h. @0 R, b/ \
  510. # set in order to use this special memory saving encoding.
    / q. P! X6 \- w$ [6 V
  511. set-max-intset-entries 512
    8 b) h8 G. m! D: C( ?/ N: _

  512. / W" U: Y! |! H" [
  513. # Similarly to hashes and lists, sorted sets are also specially encoded in8 R4 [9 T- K. S, a  E+ B' k
  514. # order to save a lot of space. This encoding is only used when the length and% X+ a' D" |3 w+ _  O/ N
  515. # elements of a sorted set are below the following limits:
    " Y; }) A; Y/ J7 f% {
  516. zset-max-ziplist-entries 1285 W" x4 B7 X) c- U% G' d
  517. zset-max-ziplist-value 64# G: v4 T+ H% j5 l' ~1 e

  518. 3 e" b" v$ \: O" W
  519. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
    ! }' [# G6 ^+ }9 S* j1 C
  520. # order to help rehashing the main Redis hash table (the one mapping top-level# e) R8 d- X( N. A
  521. # keys to values). The hash table implementation Redis uses (see dict.c)
    & V* t  Y$ \! r" f3 _, x: R
  522. # performs a lazy rehashing: the more operation you run into an hash table8 b  `! }. v; D% O) u6 j% L9 ]
  523. # that is rehashing, the more rehashing "steps" are performed, so if the" V& F. b( e, D3 l
  524. # server is idle the rehashing is never complete and some more memory is used
      c8 g+ m6 [: b  D
  525. # by the hash table.
    ( F: v! q! ]8 A5 K& w* Y
  526. # $ `( P- B$ M7 a+ m2 v3 L
  527. # The default is to use this millisecond 10 times every second in order to
    0 a2 L$ K4 |  J9 j
  528. # active rehashing the main dictionaries, freeing memory when possible.7 Y! A3 b$ _, a" V7 y
  529. #8 @$ H; d! |, z) T) r+ i  s& r* h
  530. # If unsure:2 H2 w# P) M5 f4 ^# T8 ]9 I! ~
  531. # use "activerehashing no" if you have hard latency requirements and it is
    5 i; ?8 L  m3 i, T
  532. # not a good thing in your environment that Redis can reply form time to time
    / N1 W. v  }; ?3 n
  533. # to queries with 2 milliseconds delay.$ x0 M- N4 u1 F
  534. #
    , ?/ c- b% s4 I8 ?' W+ A
  535. # use "activerehashing yes" if you don't have such hard requirements but% @* r) p- M; k4 Q# W5 ?
  536. # want to free memory asap when possible.( w  W2 q, h6 t$ q3 t
  537. activerehashing yes% ]8 F! t  n8 w, }' G7 {

  538. : _& Z+ q: W9 j
  539. # The client output buffer limits can be used to force disconnection of clients
    * A. D( x: P7 |6 S2 q
  540. # that are not reading data from the server fast enough for some reason (a" R9 z7 U2 x, R
  541. # common reason is that a Pub/Sub client can't consume messages as fast as the
    4 n* H" m, O/ d3 {9 v* {
  542. # publisher can produce them).
    7 o# l! n4 p; G
  543. #8 t2 X/ @- m9 X/ d- T1 D2 a
  544. # The limit can be set differently for the three different classes of clients:
    ( C5 h, K8 C9 a. J5 z2 j: m& Z, R
  545. #; Y" K8 E) c5 A0 m$ E- v
  546. # normal -> normal clients
    1 p! U- p' W# ^3 Q  ~, F3 h
  547. # slave  -> slave clients and MONITOR clients* X* x8 w$ }- Y6 f2 z
  548. # pubsub -> clients subcribed to at least one pubsub channel or pattern% J5 A( y; u: M  f: q4 s
  549. #
    7 e& P) y  Y# q) G* u2 _
  550. # The syntax of every client-output-buffer-limit directive is the following:4 C2 J1 d$ y7 U* `, m
  551. #; D1 y3 y: C% v+ Y
  552. # client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>
    ) U, V, {( g* ~' N" j
  553. #8 A7 s5 L) `( j" A( _0 k  S  Q
  554. # A client is immediately disconnected once the hard limit is reached, or if2 [' e0 `+ O8 [. O  g
  555. # the soft limit is reached and remains reached for the specified number of
    ! U+ u" h  W# A) O9 b; c0 d# s
  556. # seconds (continuously).
    / l, a7 ^! B5 d( \
  557. # So for instance if the hard limit is 32 megabytes and the soft limit is6 \( `, x5 S6 b+ x8 i+ ^
  558. # 16 megabytes / 10 seconds, the client will get disconnected immediately8 H- P) n! k7 `3 f6 d
  559. # if the size of the output buffers reach 32 megabytes, but will also get
    * O' u0 M6 |$ X1 g: S: A
  560. # disconnected if the client reaches 16 megabytes and continuously overcomes, T; n* n! P9 g* A
  561. # the limit for 10 seconds.
    0 w# }7 E4 z- W/ d
  562. #) F9 G9 j5 q" i
  563. # By default normal clients are not limited because they don't receive data0 ?; o" Z" E" b5 S  g- ^
  564. # without asking (in a push way), but just after a request, so only
    4 c' o. h0 D4 ]1 B  w. Q
  565. # asynchronous clients may create a scenario where data is requested faster% {; F; S% `3 F
  566. # than it can read.% o: W! a# k0 Y0 M) z& q' m5 v
  567. #' h0 i# u4 D1 r% ?8 \5 @
  568. # Instead there is a default limit for pubsub and slave clients, since
    1 u1 ~3 N9 C7 Y  N" Q  b- e3 Q
  569. # subscribers and slaves receive data in a push fashion.
    3 A% l8 y5 h+ }; A) T7 l
  570. #
    & W$ z4 g  f0 {" G
  571. # Both the hard or the soft limit can be disabled by setting them to zero.) x. w5 D2 L  Z, u
  572. client-output-buffer-limit normal 0 0 05 A4 U- [1 Y$ F6 v
  573. client-output-buffer-limit slave 256mb 64mb 60
    ; d! z( f: q3 R$ o0 k
  574. client-output-buffer-limit pubsub 32mb 8mb 605 a. Z  i0 a% \2 i8 n3 S

  575. 1 U1 y" e4 R! Q
  576. ################################## INCLUDES ###################################. t- q% X7 l& `) a; D" n6 M; y) Y( M

  577. 7 |' C1 X' J$ d& Y0 q( G/ j0 G+ o
  578. # Include one or more other config files here.  This is useful if you3 I+ e) ~8 z" ]
  579. # have a standard template that goes to all Redis server but also need7 j, J& z+ ?8 X$ h; `
  580. # to customize a few per-server settings.  Include files can include6 O: ?9 `8 n( K; c5 V, _! Y, |0 a
  581. # other files, so use this wisely.
    , z* O' n) y0 x, Q, T8 Y6 C
  582. #
      ?# P/ E; c' Y! C7 T1 V+ H0 o2 n
  583. # include /path/to/local.conf$ z, L1 R, |- ]' Z4 H  m
  584. # include /path/to/other.conf        4 r( _! b9 {: d6 Z
  585. ##########################配置文件结束################################
    * p2 l, ~0 s8 T0 B7 n" K/ |" m
  586. 第三步:启动进程
    ( n9 F/ y& W1 X$ }' l' h% r
  587. #redis-server /etc/redis.conf
    0 z' n2 N; l5 {# M& G
  588. 查看进程有没有成功启动# W- \! u/ C: d: J
  589. #ps -ef | grep redis
    6 }6 q2 {6 ?4 R+ t' C1 [
  590. 测试输入一个键值
    ) `, o0 ]& j+ Y9 }1 Y# E& b
  591. #redis-cli set test "testredis"
    2 x" r& |8 w* `; H  k0 b5 O
  592. 获取键值( c4 C: y% R6 A$ Y
  593. #redis-cli get test5 g2 C) {* k3 N& i

  594. ( _$ K4 E. [. x# _
  595. 0 a- @; ^5 ~4 O& b
  596. 第四步:关闭redis  (这个是更改配置文件后 正常的重启方式  不重新加载redis配置跳过)
    ! A# J& m$ w; _7 n# K. o. F
  597. # redis-cli shutdown      //关闭所有    ( ^" d2 O% G  U, e
  598. 关闭某个端口上的redis   
    $ z/ E- u, r8 f4 L
  599. # redis-cli -p 6397 shutdown  //关闭6397端口的redis  
    # ?  o# q6 C: h% v! [5 n
  600. 说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename  dump.rdb  
    / [, Y( w; c2 r) z$ s4 V1 d
  601. 7 s. a' o" g9 Z
  602. # _& L- v6 P3 q
  603. 第5步:php扩展安装
    ' W7 f7 {$ J2 R  Z1 p2 K
  604. phpredis PHP扩展下载地址 % P/ ]( n  s# f/ k
  605. https://github.com/nicolasff/phpredis/tree/2.2.2 # ?9 M  l$ f  V6 {& M
  606. 选择最新版本下载zip
    8 e* ^2 O$ N1 C
  607. # t+ Y5 W+ s4 N; A
  608. 然后自己上传zip  用unzip解压到当前目录 unzip 文件名. Z8 o. Y- F3 H# m" }* b" }

  609.   @/ ]1 D/ x" Z; t! T0 Q8 x
  610. # cd owlient-phpredis-90ecd17/   #打开解压后的文件夹里面  这个解压后的目录 要是不知道 可以输入 "dir" 查看. P+ B& B: ]' H: t
  611. # /www/nginx_php-5.2.17/bin . q# o% Y  K: A# D
  612. # ./configure --with-php-config=/www/nginx_php-5.2.17/bin/php-config8 O; ?* Y2 Y( y/ M' o7 s7 e
  613. #make
    - a; @9 x& `" x( j9 @. p/ s8 j& P
  614. #make install   #记录产生的redis.so路径9 D( t8 `0 Z5 V9 X; N4 J
  615. 7 }  X3 S% J8 B/ V  _' G
  616. 修改php.ini文件3 ]0 @; b. D8 Q# ?4 K) L8 r, ?2 [
  617. 在php.ini中添加如下一行:
    4 Y4 E* e9 }/ H$ a, L
  618. extension=/?/redis.so  #是刚刚记录的产生redis.so的路 写在 ?那
    ) P) a' [. t& O2 E7 b3 l, t/ J4 H
  619. 重启 使之生效:
    . |1 \9 e" C5 Q; e. k+ v
  620. /usr/local/php/sbin/php-fpm reload# E2 C3 p$ i4 B& `2 s* o
  621. /usr/local/nginx/sbin/nginx -s reload 9 M6 h4 W; E9 q) B+ r( C# T* l

  622. ) C) U% s4 Z0 {* c/ }
  623. 将 Redis 作为 Linux 服务随机启动; |8 k" N' D6 Z9 ?
  624. vi /etc/rc.local, 加入代码:
    6 o  o# k& g* ]9 N: q: v
  625. /root/redis-2.6.10/src/redis-serve  #路径看情况修改 ' W% ]3 c( u4 Q0 g( v

  626. : ~- `) T+ g1 s
  627. redis-cli -h localhost -p 6379 info  #命令要在redis目录下面执行" ~: N9 O! y- p* ~3 k: s
  628. 提供host为localhost,端口为6379,redis服务的统计信息2 `( o. V" e1 \/ a0 G
  629. 6 J. [) E- I9 q
  630. : o2 V! B* {1 K
  631. 就这样你的web服务器就支持redis了 记得要在 给dz 的配置文件 加上12.0.0.1哦0 R, w+ Q( ]  T
  632. dz配置文件在 config目录下面的 config_global.php, t$ h0 B1 H6 ~" c3 g3 E& S6 [- j
  633. $_config['memory']['redis']['server'] = '127.0.0.1';
    . E) v2 L% o+ E( Z# |
  634. $_config['memory']['redis']['port'] = 6379;
    & d) }$ t: d* }
  635. $_config['memory']['redis']['pconnect'] = 1;. b% f) V7 q0 u# h: j5 M, k
  636. $_config['memory']['redis']['timeout'] = '0';
    0 X8 H8 Z3 E4 u9 H
  637. $_config['memory']['redis']['serializer'] = 1;
      _* F4 U9 W4 e% w! `& ~
复制代码
关注微信公众号《神采飞扬网》,即可获取最新回复通知!

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

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

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

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

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