分享到:
发表于 2018-11-16 12:42:28 | 显示全部楼层 |阅读模式
环境配置/ h: N' F$ e7 ]( f, H3 j) w4 L  T  M

+ S' D* t  p/ R6 B  X8 r# X  g0 B+ Q- k5 f4 `1 n- m
http://www.discuz.net/forum.php? ... amp;highlight=REDIS
关注微信公众号《神采飞扬网》,即可获取最新回复通知!
 楼主| 发表于 2018-11-16 12:43:33 | 显示全部楼层
http://www.discuz.net/forum.php? ... 648&highlight=REDIS
4 W) d. A# A, a' T5 n" w无意间测试 单机状态 redis相当给力 测试1000请求/s  单纯的 get 和set 居然只用了 0.01秒 当时我惊呆了. o3 G& ~. u6 y( T; g3 {

' t+ l8 R2 K0 [3 V: N9 v7 phttp://www.discuz.net/forum.php? ... 731&highlight=REDIS
! b* \  ^# i+ h+ ~3 K6 _0 Z- A% \, M' N8 {
https://wenku.baidu.com/view/265a5ce176a20029bc642d0b.html9 J9 @" Y4 x/ t, D) @( Y: ?

. b& c0 f$ {* W=======================================
& A3 u0 V% |* \' g/ e
  1. 连接上 ssh7 N0 u* m* ?1 R0 N: f+ G1 E6 Y
  2. " }2 R7 o) b; x9 `5 o
  3. 4 f3 L; T- Q1 `& g1 W
  4. 第一步:下载redis- l3 @; d0 D" N! V7 B
  5. # wget http://redis.googlecode.com/files/redis-2.6.10.tar.gz6 K7 z3 a! y) X& X% Q+ @
  6. # tar zxvf redis-2.6.10.tar.gz , d  w$ m# e& L+ s( x
  7. # cd redis-2.6.107 U/ N2 ?# i7 A+ D8 ]# R& a; Q# o9 P9 h
  8. # make 1 E- z. K$ r, V/ U' Z
  9. # make install  
    5 G/ w. `+ o  o# B& S# P
  10. #cp redis.conf  /etc/ #复制配置文件到etc目录下面
    . k/ o; r  ]. X8 ]' k
  11. 第二步:修改配置' g2 ?6 L* B/ x. S& j
  12. #vi /etc/redis.conf
    # O0 X3 V% P4 v1 ^% X
  13. ######################下面是无措的配置文件 复制过去就成#########
    0 N4 I7 S8 `8 F/ N7 d
  14. # Redis configuration file example4 O1 j$ r) n) S( @, }

  15. ; S# @/ V+ u7 w- \4 [+ X1 G( v: A6 h  \
  16. # Note on units: when memory size is needed, it is possible to specify, O+ X+ u: c/ W# J- r& J& P
  17. # it in the usual form of 1k 5GB 4M and so forth:. F) |' ?9 B9 y
  18. #+ m% z; u6 K$ p& s0 O" X9 Y7 f% R5 [
  19. # 1k => 1000 bytes3 |) y0 `# Q2 ~, m, i
  20. # 1kb => 1024 bytes
    ! f9 X. y- R7 I$ K6 v
  21. # 1m => 1000000 bytes& U& Q3 _$ [$ e0 d* q  k4 \! E% ^
  22. # 1mb => 1024*1024 bytes1 d6 j! f/ ^3 d* k
  23. # 1g => 1000000000 bytes- |( B) g9 [4 J: X" e/ ?7 v
  24. # 1gb => 1024*1024*1024 bytes
    , A5 q" |9 l' f6 B. v- [1 k6 Q7 }
  25. #! U" Y6 l5 Z* R5 X* t
  26. # units are case insensitive so 1GB 1Gb 1gB are all the same.+ x8 x& a( o0 J6 \

  27.   j+ k3 Y; z: h; _
  28. # By default Redis does not run as a daemon. Use 'yes' if you need it.
    . e8 e& z5 l8 s" I
  29. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
    ' j4 }  x  F& ]+ N+ c' K5 ^8 E
  30. daemonize yes
      L$ P3 H3 j4 \+ w$ u4 F) V

  31. , r3 \( R6 O6 L
  32. # When running daemonized, Redis writes a pid file in /var/run/redis.pid by3 l' n  u4 v  ?0 X
  33. # default. You can specify a custom pid file location here.
    1 `0 d7 X: y, U* [6 M5 v6 A/ e
  34. pidfile /var/run/redis.pid! v6 I7 W, t2 g; Q, F5 }0 G, m
  35. 0 [; s1 X( e  E
  36. # Accept connections on the specified port, default is 6379.& o- p; u0 A8 W) R9 d7 i4 |" a
  37. # If port 0 is specified Redis will not listen on a TCP socket.$ f1 f/ L. W0 c- J
  38. port 63798 w) R5 `  \+ y8 [7 i/ c

  39. 5 k: d% H, H5 T" d
  40. # If you want you can bind a single interface, if the bind option is not
    * G5 P8 s) H  }" g
  41. # specified all the interfaces will listen for incoming connections.. G3 n+ e1 Q  C6 m
  42. #
    - P- l+ D5 P) c  I
  43. # bind 127.0.0.16 y$ I; M- K4 ~0 M* s
  44. , ^8 y0 s6 g4 `6 f3 u! z- f
  45. # Specify the path for the unix socket that will be used to listen for! w8 O( X! r4 N; r4 v  s
  46. # incoming connections. There is no default, so Redis will not listen
    & L0 {& r& _3 ], C6 x, N0 U
  47. # on a unix socket when not specified.
    5 ]' ^! H6 q1 b3 v: K( i, l. O4 j
  48. #
    " r" @  S( m( B+ }6 g, f
  49. # unixsocket /tmp/redis.sock  {7 F( k5 D0 Y8 O1 j- p
  50. # unixsocketperm 755
    * z& q  m& @: A
  51.   @2 f/ W: p% c- |( f
  52. # Close the connection after a client is idle for N seconds (0 to disable)
    ' M$ C2 q1 C( [& S; @  `; Z9 v- E
  53. timeout 3001 K8 H+ x1 r: ?  J8 s2 K# J

  54. ' o1 ^" X) t/ P* M3 P2 C3 [. B
  55. # TCP keepalive.
    / j( t+ D' E4 {( C( c
  56. #  N! [9 q; M' c" H8 H3 q5 {$ F
  57. # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
    2 ^& l( i' c  Z# F' M
  58. # of communication. This is useful for two reasons:# `- Q5 q+ F0 ~1 C
  59. #. p* K) u  j0 [$ }" }6 Q: f
  60. # 1) Detect dead peers.
    3 X( ~  B% a1 U- X
  61. # 2) Take the connection alive from the point of view of network
    2 m% E/ J% u  C1 m
  62. #    equipment in the middle.
    2 L; R4 T* d% H% o$ j3 H7 n2 {
  63. #- n8 ~! p8 t! G
  64. # On Linux, the specified value (in seconds) is the period used to send ACKs.! ^  e/ E$ P, L. g. M
  65. # Note that to close the connection the double of the time is needed.
    , N$ D9 ?8 Y  t: b" |8 Y9 t$ I
  66. # On other kernels the period depends on the kernel configuration.; [5 C4 K) S9 x- ^3 D4 w7 }+ [
  67. #
    1 I) {" i: _; l
  68. # A reasonable value for this option is 60 seconds.: X# k! z! Q$ t3 O9 u7 m
  69. tcp-keepalive 07 o, E: w/ {$ n* K

  70. 5 r, U% U& [3 M; c/ r5 s
  71. # Specify the server verbosity level.
    + g6 o* b2 X, z% M  u8 e" {* n' A
  72. # This can be one of:, F' _6 e: d1 I) Y- j3 l
  73. # debug (a lot of information, useful for development/testing)
    * f$ j* L; `5 \- a- v
  74. # verbose (many rarely useful info, but not a mess like the debug level)
      F4 l+ x- A' u9 J4 G
  75. # notice (moderately verbose, what you want in production probably)1 L# ^5 c8 ?6 N; n9 i
  76. # warning (only very important / critical messages are logged)
    ( [/ g8 o3 s( O) n! X4 Y0 F
  77. loglevel warning9 t6 R4 m' X, R( h  O. o) O1 i) i
  78. 8 j# J$ T, u2 l- C2 S
  79. # Specify the log file name. Also 'stdout' can be used to force
    # |, F$ w4 e+ F! T7 K& ^2 f
  80. # Redis to log on the standard output. Note that if you use standard& t  j, V# ^- D1 C" P
  81. # output for logging but daemonize, logs will be sent to /dev/null  Q# ]/ Y" V2 H" i. M- b3 a& o
  82. logfile /var/log/redis.log2 D1 I' S: e; z' _
  83. / }3 l6 @4 z* t( c/ r$ d, U
  84. # To enable logging to the system logger, just set 'syslog-enabled' to yes,( V8 i  F7 o4 U; U
  85. # and optionally update the other syslog parameters to suit your needs.6 }: L5 |2 |: }* V, V4 F% o5 k
  86. syslog-enabled yes+ J& I, v/ R. t5 c( f
  87. ) @) T/ |8 y& H2 K7 M" f1 m
  88. # Specify the syslog identity.
    . E* Z9 |9 P( p- W; X, h
  89. # syslog-ident redis
    * U: P, R5 X9 \! H; A

  90. 6 D6 G0 _0 a' i, g7 X
  91. # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
    ( ~% w, x- x2 L6 z1 j5 Y8 J
  92. syslog-facility local0
    1 w& B9 L0 G8 M, U7 [6 x* v
  93. 4 r1 @  b: n+ ?$ V
  94. # Set the number of databases. The default database is DB 0, you can select
    2 e6 u9 N! o7 L- u, k# ?$ a' T5 I
  95. # a different one on a per-connection basis using SELECT <dbid> where5 ]8 E% V# a* p  m6 I8 {* C. D
  96. # dbid is a number between 0 and 'databases'-1$ f7 Q$ C. ~$ W# B
  97. databases 16) W5 y( `/ w" D! w  o/ y% i7 m6 h5 B

  98. ' n% z# k; e7 V2 J* }$ I
  99. ################################ SNAPSHOTTING  #################################. \0 h8 g' f0 v$ k8 @
  100. #
    + O1 ~2 p- r% N( L: C
  101. # Save the DB on disk:5 }# E, I" `% Q. h5 t
  102. #
    ; O  Q$ a* {( ^6 z3 Q) B
  103. #   save <seconds> <changes>/ T4 p8 N9 Q/ `0 ^6 d
  104. #( f! D' _5 o' ~: \9 q
  105. #   Will save the DB if both the given number of seconds and the given
    0 Z1 e6 c/ E6 P. k. G; T" L9 ]4 G
  106. #   number of write operations against the DB occurred.8 V$ H( Z# m7 k, m# w, @" ?. i
  107. #
    1 ?* C, P% S9 E/ o0 K/ j
  108. #   In the example below the behaviour will be to save:5 g0 K. q) `) b2 q1 h" M6 q3 |
  109. #   after 900 sec (15 min) if at least 1 key changed8 F) B7 n1 A' Z/ R
  110. #   after 300 sec (5 min) if at least 10 keys changed6 H: t1 V8 F6 [0 H
  111. #   after 60 sec if at least 10000 keys changed
    ' Z8 v" o- m' e
  112. #
    . |1 [7 l5 H' E
  113. #   Note: you can disable saving at all commenting all the "save" lines.
    5 g" J/ k8 k& R9 @
  114. #1 x: B* f4 k0 o/ V/ |
  115. #   It is also possible to remove all the previously configured save5 S2 c7 Z. m0 a& M+ @. ~! T6 ]! W6 r
  116. #   points by adding a save directive with a single empty string argument5 Y+ m9 g7 j! |7 R+ N- |
  117. #   like in the following example:& W4 r6 u- P: _) R
  118. #4 A5 H9 b" j" H% D
  119. #   save ""
    2 ?# K: @9 a; h6 N- K: `5 \

  120. + ]" D8 ^' B3 |0 Y- J: o, r* p  w
  121. save 900 1
    $ r! h9 d+ m0 k0 l8 {
  122. save 300 10
    % V$ a- B5 n: Y9 [- K$ {7 l
  123. save 60 10000
    5 d1 E/ q+ ]% H% d
  124. ! z( [' y3 f0 a8 l: v
  125. # By default Redis will stop accepting writes if RDB snapshots are enabled3 b. h' |0 B1 B2 L, D
  126. # (at least one save point) and the latest background save failed.7 e5 `, y0 o" ?. p% u7 k
  127. # This will make the user aware (in an hard way) that data is not persisting# N$ F  q4 I8 ]1 P2 l* ~
  128. # on disk properly, otherwise chances are that no one will notice and some  }. c4 A8 _* ^4 I
  129. # distater will happen.9 ?: p: l8 x/ t
  130. #
    # D# A1 b3 D7 o8 _
  131. # If the background saving process will start working again Redis will: y/ g" k6 S/ c3 S3 x
  132. # automatically allow writes again.' q5 B2 I0 s* n& @
  133. #0 Y0 Q' E  u( x5 Y6 ^
  134. # However if you have setup your proper monitoring of the Redis server* p2 R, y& Y* c3 L9 C4 P
  135. # and persistence, you may want to disable this feature so that Redis will3 ]* \) V; Y9 F3 i
  136. # continue to work as usually even if there are problems with disk,, I+ h9 P* ~" i. ?
  137. # permissions, and so forth.6 {8 {" q5 c, w' n) a* c" ~
  138. stop-writes-on-bgsave-error yes
    ) j: N% V! Q2 q9 W1 H: ]
  139. # t7 N% e; `7 O! X& Y5 |
  140. # Compress string objects using LZF when dump .rdb databases?
    & a& K" R% p) k2 Q6 r2 s
  141. # For default that's set to 'yes' as it's almost always a win.) y( C  t& W, w  _' x- I
  142. # If you want to save some CPU in the saving child set it to 'no' but
    : o: @; t6 `9 z- w2 p0 q3 X
  143. # the dataset will likely be bigger if you have compressible values or keys.+ B# v5 |) G: y& N4 U% n1 L% G
  144. rdbcompression yes
    / j; X9 }2 f7 B- q/ T7 @+ l/ u; _
  145. ' u2 U- Q. q8 X' w
  146. # Since version 5 of RDB a CRC64 checksum is placed at the end of the file.
    3 b: g( u1 u2 K  j+ _* |
  147. # This makes the format more resistant to corruption but there is a performance
    ! x9 ^, \" n) u
  148. # hit to pay (around 10%) when saving and loading RDB files, so you can disable it* g9 p0 m! B* _) ]
  149. # for maximum performances.# ]/ L# I. `4 ^* K( x* Y  b- j
  150. #( i3 y% |- v: |* j9 {( ~5 E
  151. # RDB files created with checksum disabled have a checksum of zero that will1 u. S) U% m' V, g8 z1 V" c
  152. # tell the loading code to skip the check.7 m1 Y: w4 q. g* R7 _: C
  153. rdbchecksum yes5 ]+ x  A+ x' {! N0 y$ f
  154. - c; u* I$ _8 ?2 ?+ }, U
  155. # The filename where to dump the DB. C. H! e! ~3 N0 ^& e# c) N
  156. dbfilename dump.rdb
    3 M* C3 d; y) C  y) ]

  157. & Z; ?, q8 Z* k% R
  158. # The working directory.* \& f, N4 T9 m: B
  159. #
    8 G# Q! w* o. d/ h6 l( m! t  E
  160. # The DB will be written inside this directory, with the filename specified+ G2 ?7 q9 k  m& `
  161. # above using the 'dbfilename' configuration directive.
    , j6 v; Q9 \) e+ M8 r6 j5 P; Y
  162. #
    ( r7 e1 p) ?9 I+ n* l
  163. # The Append Only File will also be created inside this directory.; V( F) h: n& d8 d4 N% z
  164. # 7 f  H$ Q3 {; i. s# N6 }: S! f
  165. # Note that you must specify a directory here, not a file name.7 t7 y  z' c5 T" `0 }$ V
  166. dir /var/db/redis& I/ q3 r- o4 t9 m5 r9 l$ X
  167. 5 I# i- {8 V. R* v/ E1 w9 O
  168. ################################# REPLICATION #################################/ r" f  F% x4 e) D- c4 {2 c7 M

  169. ) X+ p! p7 u+ ]' ?  ?
  170. # Master-Slave replication. Use slaveof to make a Redis instance a copy of% X5 b2 ~8 t1 b) W' W% D/ [
  171. # another Redis server. Note that the configuration is local to the slave
    ) q7 |) t: z" c. s
  172. # so for example it is possible to configure the slave to save the DB with a6 m9 K! d! U( W; a' _% Z
  173. # different interval, or to listen to another port, and so on.
    + e% F  O& {2 A0 @
  174. #
      E5 |5 `; f1 E1 Q. N
  175. # slaveof <masterip> <masterport>1 D+ `& f  \5 `  q

  176. # e0 {4 s8 {, |' E5 g; h2 j: x) j
  177. # If the master is password protected (using the "requirepass" configuration8 @) ?$ a* D* {4 ~6 [) E
  178. # directive below) it is possible to tell the slave to authenticate before4 w% W& l5 x) |* m; g
  179. # starting the replication synchronization process, otherwise the master will( U7 ?2 F% c, {+ m1 U# N4 }
  180. # refuse the slave request.$ z5 v, Z. N$ \% X
  181. #
    - z5 b3 N( O$ r( o% @
  182. # masterauth <master-password>
    7 @3 p, X, m! j1 ?, q
  183. $ w- `* L* K* z/ O2 N
  184. # When a slave loses its connection with the master, or when the replication8 I( f% y, c* _8 g  J; y
  185. # is still in progress, the slave can act in two different ways:6 I2 \  W: \/ C$ K6 B
  186. #
    ! @& D( v+ ?) q4 @" J* U; b( _
  187. # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will( [6 Z2 u  ?! Y' l& h
  188. #    still reply to client requests, possibly with out of date data, or the3 N4 ~2 j/ \* {- i1 \
  189. #    data set may just be empty if this is the first synchronization.  @/ ]3 `) s/ c; p8 M; @6 o( z
  190. #
    & D% b- B! p8 f
  191. # 2) if slave-serve-stale data is set to 'no' the slave will reply with0 B, v  O: q/ C% x( I; U: q
  192. #    an error "SYNC with master in progress" to all the kind of commands
    ' V" H8 A& D# h! x- S
  193. #    but to INFO and SLAVEOF.* p: P# r, y( q7 Z- W! c
  194. #
    ' \% {' a/ }) x; P" G5 [7 _
  195. slave-serve-stale-data yes
    9 u8 F2 U4 ]1 k' t3 D  A

  196. $ H$ @- [, s: |& b7 O# }
  197. # You can configure a slave instance to accept writes or not. Writing against
    5 d; r: c4 \4 q+ {
  198. # a slave instance may be useful to store some ephemeral data (because data
    ( c2 J# O& T* r/ |* o
  199. # written on a slave will be easily deleted after resync with the master) but
    3 |/ ^6 e1 G: S" |0 {1 P1 Q9 V
  200. # may also cause problems if clients are writing to it because of a" b9 l( C1 |" P- Y" ]
  201. # misconfiguration.
    # r( d# i+ ~5 o7 m9 x4 {! @: @
  202. #- o* [% f# ]% {+ o6 _% s. S; Y- U6 c
  203. # Since Redis 2.6 by default slaves are read-only.$ p2 I9 x, L  `% U4 e4 T
  204. #
    5 H5 h4 Y& {  ]6 n. P) R
  205. # Note: read only slaves are not designed to be exposed to untrusted clients
    6 ]' p6 B& Y# U- k: a( L
  206. # on the internet. It's just a protection layer against misuse of the instance.& J8 j5 I, d0 b. j, R& r# {
  207. # Still a read only slave exports by default all the administrative commands
    / I* d4 p: H& y
  208. # such as CONFIG, DEBUG, and so forth. To a limited extend you can improve
    % B* u1 ?* G7 a0 w- u; L
  209. # security of read only slaves using 'rename-command' to shadow all the
    ( H; J9 ]; L9 x, M3 B$ ?. |4 s* Y
  210. # administrative / dangerous commands.2 G4 l: E! O+ e' j* C
  211. slave-read-only yes
    ; }% |* T0 g. o! `

  212. 5 t; x9 v; k9 ?1 e
  213. # Slaves send PINGs to server in a predefined interval. It's possible to change9 D+ ?7 u" j, s( \, D$ x& Q) ^
  214. # this interval with the repl_ping_slave_period option. The default value is 10! U0 s3 f/ G1 @, `  a
  215. # seconds.
    4 ~! J. c$ ]4 _; y# U( k6 l
  216. #: M; `  S. X# _5 p% v8 a. d; c
  217. # repl-ping-slave-period 10
    ! K2 {& @+ V- B( J  O! N+ g) J, v( \

  218. ! Y- y8 ?% O1 w$ \6 Y( T- f
  219. # The following option sets a timeout for both Bulk transfer I/O timeout and
    / r: K- |7 m% k) z+ g2 ~' i
  220. # master data or ping response timeout. The default value is 60 seconds.! n2 t- i# U0 D; |- \( H3 P
  221. #& N( E  q: {* Y, `+ ?/ E; o
  222. # It is important to make sure that this value is greater than the value
    : X; R2 |  z& [
  223. # specified for repl-ping-slave-period otherwise a timeout will be detected. e, }% x4 y! x) ?+ ~& C. Y) f
  224. # every time there is low traffic between the master and the slave.3 g4 g0 p6 r& |5 O; s
  225. #
    # A) p+ H3 i: s9 J
  226. # repl-timeout 60
    0 u9 k) }1 K2 Y7 {( m! ?4 v5 A+ |! i, v

  227. - v) [+ S7 c/ S* U2 e2 K* \
  228. # Disable TCP_NODELAY on the slave socket after SYNC?0 i, A; f3 p# @7 o+ e6 n7 R$ T$ L, u
  229. #
    . t' F$ ~* T) n" o9 v9 g
  230. # If you select "yes" Redis will use a smaller number of TCP packets and; _: w( w9 }8 `* K* K: y/ b! o
  231. # less bandwidth to send data to slaves. But this can add a delay for
    7 ^+ H  l- B9 N9 H0 @
  232. # the data to appear on the slave side, up to 40 milliseconds with& `: e. F6 Z1 K' ]
  233. # Linux kernels using a default configuration.
    6 Z: e1 _. m: x4 v% K
  234. #
      Z) I* [5 j) z+ Z9 J. ?
  235. # If you select "no" the delay for data to appear on the slave side will# l. @) e, b8 c. i4 C
  236. # be reduced but more bandwidth will be used for replication.
    # G( F  h8 C9 k! _# f
  237. #
    2 `$ X9 ]3 z+ B% O7 x
  238. # By default we optimize for low latency, but in very high traffic conditions+ n5 i% ~. P6 g1 m6 p
  239. # or when the master and slaves are many hops away, turning this to "yes" may% g# G! N" R; X5 n, k
  240. # be a good idea.- l0 U% ]* |' J: }& n, H" }" d
  241. repl-disable-tcp-nodelay no% ~. @" ~6 l! s( A& y1 C

  242. & n, Y% @% W4 ^8 W: n3 y
  243. # The slave priority is an integer number published by Redis in the INFO output.' I0 f" G* Z. V, ~5 L
  244. # It is used by Redis Sentinel in order to select a slave to promote into a
      u% L+ k2 H' M: O, G& U0 A
  245. # master if the master is no longer working correctly.' m1 R$ U# x. k& j
  246. #5 b% R9 d6 |  n% F4 V6 \
  247. # A slave with a low priority number is considered better for promotion, so
    ( o9 {5 B0 l; c3 U" n( C$ d# B% D7 W/ G; x
  248. # for instance if there are three slaves with priority 10, 100, 25 Sentinel will
    4 d/ e. h* L3 @0 D$ x7 F6 _
  249. # pick the one wtih priority 10, that is the lowest.
    * P# P( }2 L9 [" B
  250. #
    # {* O- T; f& T9 _
  251. # However a special priority of 0 marks the slave as not able to perform the% W  ~1 `3 k* k* w, m+ c
  252. # role of master, so a slave with priority of 0 will never be selected by
    * P0 L0 U( A- c7 h
  253. # Redis Sentinel for promotion.
    ( \: D1 R& H* s% |" E
  254. #
    - m( L- x, [: g
  255. # By default the priority is 100.
    3 I5 w" @* {, n2 h
  256. slave-priority 100
    . _- U3 R! L& q1 j2 x0 I

  257. , S3 Q8 A. U# D% o6 B. i6 |! s
  258. ################################## SECURITY ###################################
    ! l  i9 r. ~: e
  259. 3 V: Q! m' p# w# x
  260. # Require clients to issue AUTH <ASSWORD> before processing any other9 f( B0 D5 F% w' b
  261. # commands.  This might be useful in environments in which you do not trust
    1 p/ j  V) w$ P1 P
  262. # others with access to the host running redis-server.
    0 |4 Q. K; U# h$ }/ F% \
  263. #
    , \% Y6 h/ j: E2 ^3 }8 J& D
  264. # This should stay commented out for backward compatibility and because most
    . S2 G  t+ n7 \* r" U* O4 O' ~
  265. # people do not need auth (e.g. they run their own servers).% h4 S  g4 O' T& G7 o
  266. #
    0 `  T) R8 L: y0 u  m4 e5 g
  267. # Warning: since Redis is pretty fast an outside user can try up to
    ; g9 L2 _( O+ ]& j" x0 C( c
  268. # 150k passwords per second against a good box. This means that you should
      \6 m/ s' ]: r7 J! b
  269. # use a very strong password otherwise it will be very easy to break.
    6 v; Y" o( a. J4 p* K
  270. #
    , j/ I' ~' }, c9 i  S! ]# o: o
  271. # requirepass foobared
    ) n& A; h: D2 c) x+ Z+ p
  272. , q" e+ F; w0 C3 `1 L5 U
  273. # Command renaming.
    ( a/ t7 l7 H+ K, K6 f) I
  274. #4 f; M2 \3 M) o; p7 ^
  275. # It is possible to change the name of dangerous commands in a shared
      T) {# e# z6 \9 H7 b* g
  276. # environment. For instance the CONFIG command may be renamed into something6 m- J% E$ ^, n. `: L* F
  277. # hard to guess so that it will still be available for internal-use tools0 I/ Z  L4 Q+ K3 p; V! h1 @7 S
  278. # but not available for general clients.2 G- c6 H2 q) s3 \4 s: T
  279. #
    9 C5 u( g+ z' h$ M  X
  280. # Example:
    / b, V9 q$ q7 w+ ~; e( D9 Z
  281. #
    - @* i7 m7 p3 M# j5 X  ~
  282. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52) k- y5 E" l5 o+ x, y0 s( q
  283. #' f3 s: ?) w: r# Q: L
  284. # It is also possible to completely kill a command by renaming it into
    / K, m4 }1 \: y, ~5 U$ r" R3 K/ s7 O( q; Z
  285. # an empty string:) o3 }: c0 s( g- }# o% f
  286. #9 t' Z& A; r5 {9 K, ?3 c
  287. # rename-command CONFIG ""
    4 M5 {$ I- t  f3 k  ~

  288. + B- e+ r/ K6 k" n- \) V
  289. ################################### LIMITS ####################################
    ; B3 P8 H; c3 r  o1 U1 T; Z/ J
  290. 0 t% `# J- m: x/ P& }
  291. # Set the max number of connected clients at the same time. By default
    3 o1 T: h, c7 r4 c; g
  292. # this limit is set to 10000 clients, however if the Redis server is not4 E2 m7 y! i- ~- q0 @# Z& K
  293. # able to configure the process file limit to allow for the specified limit- a" P2 s) D& }" E  `* U+ @
  294. # the max number of allowed clients is set to the current file limit
    3 z- o" y4 ?( I2 r, a) k
  295. # minus 32 (as Redis reserves a few file descriptors for internal uses).
    8 A% ]* M- C  h5 v4 q0 X  [5 u1 a
  296. ## @& ?: K) z- R: @) L8 G3 L$ m
  297. # Once the limit is reached Redis will close all the new connections sending, y/ o( L- w* ^  T! s
  298. # an error 'max number of clients reached'.
    1 C/ h9 x/ k4 y7 j" e
  299. #
    / }7 f5 b3 Y/ F: o( r$ e
  300. maxclients 500: O# o# v$ G! h$ ?, ?
  301. 1 ]; I. E) B5 h9 a) \* M- E
  302. # Don't use more memory than the specified amount of bytes.
    0 e6 r. _+ @8 @2 ^! N$ J
  303. # When the memory limit is reached Redis will try to remove keys
    8 u- u5 O+ |# f% _+ [" |3 j- i2 |
  304. # accordingly to the eviction policy selected (see maxmemmory-policy).7 F) [) D. Y: d, R7 n1 f
  305. #& C2 g7 U- o# _4 g
  306. # If Redis can't remove keys according to the policy, or if the policy is- `" O$ |* u! p$ w7 ^; V- t( y
  307. # set to 'noeviction', Redis will start to reply with errors to commands
    8 v1 L, b/ w  S1 P3 K- P* m7 g
  308. # that would use more memory, like SET, LPUSH, and so on, and will continue+ w* R6 X" k, u* f7 c- m7 e9 H/ _
  309. # to reply to read-only commands like GET.8 Z. E% m7 \4 D+ ]0 V4 h- r
  310. #
    0 s$ @: @. G* e& S# A' n4 K. H) M! c
  311. # This option is usually useful when using Redis as an LRU cache, or to set& K1 \* @4 D1 `) ?1 s$ o. L
  312. # an hard memory limit for an instance (using the 'noeviction' policy).
    " s9 h8 n- k3 ?  [& N; ~* X
  313. #4 a) p0 \6 D5 u' P  e
  314. # WARNING: If you have slaves attached to an instance with maxmemory on,' X+ E: p. g. n* Y! p. e+ G; D
  315. # the size of the output buffers needed to feed the slaves are subtracted; P. n. M0 W1 s, q
  316. # from the used memory count, so that network problems / resyncs will
    : _9 _$ O/ x; h1 ^: T' x! k  e
  317. # not trigger a loop where keys are evicted, and in turn the output, F  [# M6 i; E
  318. # buffer of slaves is full with DELs of keys evicted triggering the deletion
      P) r5 d1 w" S4 t3 R' N2 A. N
  319. # of more keys, and so forth until the database is completely emptied.
    ! D3 M8 k( z0 p3 d
  320. #2 V) [! X9 Z( u9 G' Y, e' B0 q
  321. # In short... if you have slaves attached it is suggested that you set a lower
    & ?/ o. j  N  l! U, g- F
  322. # limit for maxmemory so that there is some free RAM on the system for slave
    % H+ E4 K8 ]( T
  323. # output buffers (but this is not needed if the policy is 'noeviction').  O0 U* H8 d7 _/ s$ o+ N% Z
  324. #* R9 o! B" `- Y; ?: {
  325. maxmemory 1280000007 }. Z/ s7 e% Q" D! a1 e
  326. # i( b! l9 Y4 \5 d) l+ u
  327. # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory! U- C) K! p, U1 V! V& b* I9 \
  328. # is reached. You can select among five behaviors:$ D9 g, M  L5 U" G: K
  329. #
    # U7 d* ?7 b0 f" r7 d% j; B# A) ]
  330. # volatile-lru -> remove the key with an expire set using an LRU algorithm* ^; z8 y1 D1 Y. {* W) Y  r
  331. # allkeys-lru -> remove any key accordingly to the LRU algorithm8 C6 \" j2 A8 T# Q. Y+ b
  332. # volatile-random -> remove a random key with an expire set
    - y" a2 a4 P% u1 U! C) V
  333. # allkeys-random -> remove a random key, any key! d* D( }8 v* g- _
  334. # volatile-ttl -> remove the key with the nearest expire time (minor TTL)3 |; l1 i# U, C( g. {" D, I- Z
  335. # noeviction -> don't expire at all, just return an error on write operations
    . F  R( u4 Q% `3 K1 {! D' q
  336. #
    8 L( y) B  k. T9 u) d3 j( I
  337. # Note: with any of the above policies, Redis will return an error on write
    ( C6 \+ m3 h/ |' n% }% z2 G
  338. #       operations, when there are not suitable keys for eviction.3 W+ f+ t' p# R6 H5 L, N
  339. #
    0 L3 o8 v% U" |6 u% ^$ x; D
  340. #       At the date of writing this commands are: set setnx setex append
    6 V* r- z" F3 j; g
  341. #       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
    7 G0 b6 u' r" {8 |+ m9 z3 {
  342. #       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby/ L& J+ y' {4 ^/ V+ G/ Y' w
  343. #       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby0 A( y& d! E* J  G6 E6 ?
  344. #       getset mset msetnx exec sort
    $ \# q7 X! h9 Z6 B" L' m
  345. #
    8 c* Z' n, l" a3 S! M0 x" {/ K
  346. # The default is:; l$ E- Z7 ^; J
  347. #; s" M; |  `% z/ b1 S) [
  348. # maxmemory-policy volatile-lru
    1 ^* P" t: H2 |5 h- i

  349. % A* w$ E) m' G1 O( v
  350. # LRU and minimal TTL algorithms are not precise algorithms but approximated
    9 Q7 U* N" ~  C* ?  F; V3 M
  351. # algorithms (in order to save memory), so you can select as well the sample
    / }3 S2 X) S: ^5 T0 C7 O4 o
  352. # size to check. For instance for default Redis will check three keys and
    - Z, M8 ]; o- d/ r. ?. |
  353. # pick the one that was used less recently, you can change the sample size
    / X! Y- g0 m" f, F1 U% u5 p7 y
  354. # using the following configuration directive.
    $ C6 z- B3 `- q6 u) a8 a* v# M* j
  355. #7 {8 a! q5 d: e, @) _
  356. # maxmemory-samples 3( ^1 s/ G. v& T9 H
  357. % {# ^1 j- Z' C. W; Z/ u
  358. ############################## APPEND ONLY MODE ###############################
    $ [3 W: o$ C! u5 O7 P
  359. 2 m; J' X! T" s" h' O
  360. # By default Redis asynchronously dumps the dataset on disk. This mode is
    5 O1 w% |& M* E4 r" c
  361. # good enough in many applications, but an issue with the Redis process or+ b$ e4 w4 O: y! O+ U/ t- F
  362. # a power outage may result into a few minutes of writes lost (depending on( V. x8 V6 S7 I+ i. x! c
  363. # the configured save points).: f9 B0 }: j* J. u9 X! ^
  364. #
    ( J9 X* T1 ]& q% U: S& ]
  365. # The Append Only File is an alternative persistence mode that provides
    ; v8 f: x% @; L9 N; |8 v
  366. # much better durability. For instance using the default data fsync policy+ b) N$ T3 c, W( }" w
  367. # (see later in the config file) Redis can lose just one second of writes in a6 t. m9 \) O4 |" o' t& s: n0 p
  368. # dramatic event like a server power outage, or a single write if something
    " a8 a% V5 r3 Q2 c' X% o7 \3 p
  369. # wrong with the Redis process itself happens, but the operating system is4 a( U. {! E4 f; v  a  Z. j
  370. # still running correctly.
    , L: ^1 W1 v* S% c
  371. #
    - \% U& C1 U" g
  372. # AOF and RDB persistence can be enabled at the same time without problems." B' `% [! C1 v: Y/ J
  373. # If the AOF is enabled on startup Redis will load the AOF, that is the file. l  p3 X! w' i2 {' V. r6 g. t
  374. # with the better durability guarantees.
    4 K9 x' A  t7 M( a
  375. #, Z3 e% u1 q' Y8 @( a: I
  376. # Please check http://redis.io/topics/persistence for more information.5 O, q( \# p+ w& ^( F+ y, `

  377. / T3 M' ]  z: P3 B$ f$ m) U2 ]% {
  378. appendonly no; {/ H# R& W  a
  379. 0 y! e& k4 d6 s8 C& A: W
  380. # The name of the append only file (default: "appendonly.aof"), t. H, ?( K$ E! i; G
  381. # appendfilename appendonly.aof
    5 b7 `7 h+ |+ @( k3 u, K/ Y

  382. ! U: b# U5 ^+ P$ L
  383. # The fsync() call tells the Operating System to actually write data on disk7 D- z; l$ y+ l
  384. # instead to wait for more data in the output buffer. Some OS will really flush : `  ~- b0 r: ^+ y, u8 u. m
  385. # data on disk, some other OS will just try to do it ASAP.
    * Z. z- P0 V- h) U' I7 R# X. r# D
  386. #  C# \9 p: ]3 y! }* p) Z+ P9 w( Q' V
  387. # Redis supports three different modes:
    ' N, h- K2 ]: Q( P% O. ^
  388. #
    + o! ]9 G; |0 K& U* Q) T
  389. # no: don't fsync, just let the OS flush the data when it wants. Faster.
    8 M  l" c4 k3 D' E* `
  390. # always: fsync after every write to the append only log . Slow, Safest.! a. E5 f- k: k  ?/ U
  391. # everysec: fsync only one time every second. Compromise.; C+ X: p' l* a* {7 K1 {3 Q6 @
  392. #) A: e3 ?+ p  L# a4 `" v# _( k* t% x
  393. # The default is "everysec", as that's usually the right compromise between8 a7 ^, @2 i- J" H. U
  394. # speed and data safety. It's up to you to understand if you can relax this to
    " X7 K5 n; U& T8 J1 @# m$ b: C7 w4 |
  395. # "no" that will let the operating system flush the output buffer when
    - M$ b  d& K6 G" J; H" O1 t
  396. # it wants, for better performances (but if you can live with the idea of9 e, g- ~+ o& z/ [& ?+ Q6 O4 m7 L
  397. # some data loss consider the default persistence mode that's snapshotting),' a/ C$ U: I/ l4 [; @1 k# M
  398. # or on the contrary, use "always" that's very slow but a bit safer than& z2 I1 C9 `' y( ~
  399. # everysec." N; a7 I5 N" }1 l1 _
  400. #
    ( N) x3 o, d- s* E: B3 @6 s
  401. # More details please check the following article:4 l# C1 M; t% j6 G4 n+ _
  402. # http://antirez.com/post/redis-persistence-demystified.html0 a; w+ e+ I, {3 p# A$ C7 m6 U, w
  403. #
    7 m9 J* _2 ?  H, i' Q
  404. # If unsure, use "everysec"., S9 @$ B& ?& N3 L
  405. 7 x  H! m( _1 ^
  406. # appendfsync always
    % X4 f! D+ [, v) ]: b9 ~  V% e3 X
  407. appendfsync everysec( d8 k5 o, u. H+ f
  408. # appendfsync no) X" E$ V- D+ S% ~4 I6 C
  409. / D: _' j+ C( |* v
  410. # When the AOF fsync policy is set to always or everysec, and a background
    & `% _$ f( T) l# k6 e
  411. # saving process (a background save or AOF log background rewriting) is
    * m' D! |; l: L+ f" j* q1 _
  412. # performing a lot of I/O against the disk, in some Linux configurations
    ) g- ?" z$ L* [% N9 t
  413. # Redis may block too long on the fsync() call. Note that there is no fix for7 s5 z# z$ s# p' L, Y
  414. # this currently, as even performing fsync in a different thread will block- m* ^( O. G- {! ^: y
  415. # our synchronous write(2) call.( @+ D' i! a1 F5 O& x/ u
  416. #. o2 H+ l) `# W- H" S
  417. # In order to mitigate this problem it's possible to use the following option" L* ^5 O  q, h( o
  418. # that will prevent fsync() from being called in the main process while a) c1 a5 v5 u6 |5 o& o0 y
  419. # BGSAVE or BGREWRITEAOF is in progress.9 {/ R# c2 l* x
  420. #
    ; H" a& B7 N* u1 i
  421. # This means that while another child is saving, the durability of Redis is
    ( d6 ^  y) U8 @. W* {$ {' ~/ T
  422. # the same as "appendfsync none". In practical terms, this means that it is% b3 f6 V1 ]! K" v) _! G* y/ e. [
  423. # possible to lose up to 30 seconds of log in the worst scenario (with the- H& I) O6 a7 c5 h; `( T
  424. # default Linux settings).! s7 G5 S2 c* Q  c0 E
  425. #
    . [2 O9 Q9 c1 f2 X/ M
  426. # If you have latency problems turn this to "yes". Otherwise leave it as
    - C' M- H% r( k7 l1 z! H; N# v
  427. # "no" that is the safest pick from the point of view of durability.
    " o% b1 j/ p- `$ G: y; H
  428. no-appendfsync-on-rewrite no+ `" r4 g( x, y# \$ |3 g5 M9 I& M

  429. # ~1 Q5 u! K/ p- s& F$ P
  430. # Automatic rewrite of the append only file.
    " z4 Z# N$ p" Q5 l
  431. # Redis is able to automatically rewrite the log file implicitly calling3 p3 t/ x( L* K! v- X# n( _
  432. # BGREWRITEAOF when the AOF log size grows by the specified percentage.1 T, }" n1 P! Z" G9 Y
  433. #   L# ]3 l" J" W& R& W
  434. # This is how it works: Redis remembers the size of the AOF file after the8 a' f+ B- o- ^/ Y2 Y6 M" w
  435. # latest rewrite (if no rewrite has happened since the restart, the size of# \' @- r- u9 k( M
  436. # the AOF at startup is used).
    ( b1 t- x6 O: [0 i/ D" Y
  437. #
      `( v3 f" N6 Q  q: o
  438. # This base size is compared to the current size. If the current size is# B8 F5 j9 g* J& o
  439. # bigger than the specified percentage, the rewrite is triggered. Also$ s  n* B# K" e" I. B0 t: F
  440. # you need to specify a minimal size for the AOF file to be rewritten, this
    * K: `5 h3 E4 i$ t" P) o
  441. # is useful to avoid rewriting the AOF file even if the percentage increase* s+ h9 T% \2 v$ H
  442. # is reached but it is still pretty small.
    * \; O; y3 p4 X+ @* k! D
  443. #4 f- e, T" T: M
  444. # Specify a percentage of zero in order to disable the automatic AOF0 G8 |* W$ E, H3 H
  445. # rewrite feature.
    7 f  Z3 T. J0 m% X- }4 q& d
  446. " t! T! J  g2 ]+ a' f
  447. auto-aof-rewrite-percentage 100( W& a  ]! Q$ U# ?" [( \1 b3 J
  448. auto-aof-rewrite-min-size 64mb
    " v- H% ]- }0 H7 P. F; [/ |
  449. # k/ T  }- [" b! H5 l
  450. ################################ LUA SCRIPTING  ###############################
    2 \3 @( e8 w3 m6 m8 k! W8 D
  451.   p5 t2 d% [9 {
  452. # Max execution time of a Lua script in milliseconds.
    3 S1 t1 k/ U( O! s9 w* F1 Y
  453. #0 w( u3 d. t7 C) |0 [
  454. # If the maximum execution time is reached Redis will log that a script is
    5 O' f% J$ L5 a
  455. # still in execution after the maximum allowed time and will start to/ S: a7 k7 ]0 s+ Z( y
  456. # reply to queries with an error.
    ( L* ^: v9 l5 R  S$ [! x  C# n
  457. #
    ; o3 b$ w" G; _% s; S8 F* w/ Y
  458. # When a long running script exceed the maximum execution time only the+ `0 l: ?9 z$ [" J3 Z9 G" N
  459. # SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be8 f- {& Y, B; T' l) n9 y! E
  460. # used to stop a script that did not yet called write commands. The second$ q7 \2 Q6 E1 n+ r' }# s3 z
  461. # is the only way to shut down the server in the case a write commands was0 S/ j0 A0 H7 S. Q8 \( `7 |
  462. # already issue by the script but the user don't want to wait for the natural
    1 y5 ?3 a5 F- y) T  z$ b
  463. # termination of the script.8 b# d$ j: r0 T8 y5 S$ B1 V  @  ^0 w
  464. #
    0 b4 F' S# Y7 j. E) t$ Y
  465. # Set it to 0 or a negative value for unlimited execution without warnings.
    ) l4 a- K1 l2 M5 l2 H; B
  466. lua-time-limit 5000
    , u+ n0 q9 M+ z" n' v8 q' G& f
  467. / T$ q7 y0 Q. V5 R
  468. ################################## SLOW LOG ###################################* @( d, s4 A4 m) y: Z. Z  v" N
  469. : T( i- _0 h% b
  470. # The Redis Slow Log is a system to log queries that exceeded a specified( _% t2 r( o/ b
  471. # execution time. The execution time does not include the I/O operations2 h  ~6 f5 D2 j0 n: m8 f
  472. # like talking with the client, sending the reply and so forth,
    & H1 Y8 q1 g' ~$ e
  473. # but just the time needed to actually execute the command (this is the only( Q' J% Q! D& p' N! j* @
  474. # stage of command execution where the thread is blocked and can not serve0 O5 V" w4 P% O3 ?3 ^
  475. # other requests in the meantime).
    ! w% s7 Y& s( J0 @
  476. # 5 Q* ^, R$ S! Q0 o1 c" B% B9 h
  477. # You can configure the slow log with two parameters: one tells Redis
    6 c$ p1 r8 ^6 }3 Y, v
  478. # what is the execution time, in microseconds, to exceed in order for the1 Y; X, {: j4 ~$ ~) c
  479. # command to get logged, and the other parameter is the length of the
    9 A- J6 i; u  X+ j
  480. # slow log. When a new command is logged the oldest one is removed from the* @; S) l! H' {% Z. f+ y" I0 i, p
  481. # queue of logged commands.
    1 }# O! S5 b  X! e4 }. s

  482. 9 T8 a' j& i+ w% p, @7 `
  483. # The following time is expressed in microseconds, so 1000000 is equivalent
    6 s" M, s2 s- l  O3 L
  484. # to one second. Note that a negative number disables the slow log, while2 T8 {7 v, L7 p( H5 y
  485. # a value of zero forces the logging of every command.9 g) ]2 H3 T. C8 S# k3 |  y1 B
  486. slowlog-log-slower-than 10000
    5 ^/ u( ^5 J" \8 w

  487. 0 w! H; ]6 ~, O* ?% d
  488. # There is no limit to this length. Just be aware that it will consume memory.3 u9 B9 r4 E7 k# a% c2 j
  489. # You can reclaim memory used by the slow log with SLOWLOG RESET.
    & Y$ ?) W0 m& {4 I& [
  490. slowlog-max-len 128
    6 q9 R8 I" J% W' a
  491. % E9 i: j. n* E3 o$ d7 B. Y
  492. ############################### ADVANCED CONFIG ###############################7 @7 C( ~, g% |

  493. % v: Y  g% d7 n- k, [, j
  494. # Hashes are encoded using a memory efficient data structure when they have a
    & [5 |  ?. l( x
  495. # small number of entries, and the biggest entry does not exceed a given7 n7 t4 q" L# r  `. Q9 {
  496. # threshold. These thresholds can be configured using the following directives.
    + ^" V# _- Q; Y9 a
  497. hash-max-ziplist-entries 512
    $ X! H* v" x: u2 _  X
  498. hash-max-ziplist-value 64
    7 U6 F3 j# V8 q# W9 N& O
  499. 0 P- U* y, W/ _! H
  500. # Similarly to hashes, small lists are also encoded in a special way in order# C. o" m# R9 d: W+ ?# b8 M. h
  501. # to save a lot of space. The special representation is only used when
    , g5 g) m4 V% `# L0 f
  502. # you are under the following limits:
    " `% Y, W0 Y$ j0 v
  503. list-max-ziplist-entries 512( a7 f7 C8 W" g/ ^* C0 K/ H' o6 \$ ]
  504. list-max-ziplist-value 644 ?3 V% `, Z2 q, F0 X% K# X& [) l; n( V9 G
  505. 6 x5 S: c" f& t. c
  506. # Sets have a special encoding in just one case: when a set is composed
    9 ?" ?( l% g; }7 |
  507. # of just strings that happens to be integers in radix 10 in the range  C/ B" V. \8 c
  508. # of 64 bit signed integers.* d- j" g) m: X4 G
  509. # The following configuration setting sets the limit in the size of the! T$ X% C+ k7 J( U0 w# d
  510. # set in order to use this special memory saving encoding." Z$ A; D& j; v4 c9 i3 p8 d* _! Y
  511. set-max-intset-entries 512
    8 ?7 ^* ]: h* q$ W% k/ x  v
  512. 8 U& [) D) I3 l1 u/ B8 V- J% i+ k& d
  513. # Similarly to hashes and lists, sorted sets are also specially encoded in
    9 {8 c: f% I3 v! k+ z# o  q7 ~" r
  514. # order to save a lot of space. This encoding is only used when the length and
    ; T5 i; E/ w5 j; V
  515. # elements of a sorted set are below the following limits:$ C2 R$ N- T! x* _. c
  516. zset-max-ziplist-entries 128
    ) \9 Y! f* j6 R; Y
  517. zset-max-ziplist-value 64
    % z3 ?2 S  v1 P2 \

  518. + H1 y' ^! Y" V  o' w5 A+ N( }+ U( [
  519. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in' v/ x0 W5 f! q# b( p8 f$ y$ A% X6 [
  520. # order to help rehashing the main Redis hash table (the one mapping top-level
    5 N' Y" Z5 G- ]& ~/ Z/ \3 X$ U
  521. # keys to values). The hash table implementation Redis uses (see dict.c)
    4 S( O6 P# H* Z/ N( k8 ?* t
  522. # performs a lazy rehashing: the more operation you run into an hash table
    & s$ U* S4 ?/ B! j/ G. h
  523. # that is rehashing, the more rehashing "steps" are performed, so if the( f2 P& Q. N9 M4 b" L
  524. # server is idle the rehashing is never complete and some more memory is used8 I6 F: e: @* i0 g8 Q
  525. # by the hash table.
    ' M) J' n" \. X0 y! f8 \/ ~
  526. # . r. ~6 p9 [) Q& S( F
  527. # The default is to use this millisecond 10 times every second in order to
    * J3 m8 v+ U% v$ m2 ^$ m
  528. # active rehashing the main dictionaries, freeing memory when possible.
    + ]+ C+ g9 u2 A! W/ _* f( b
  529. #
    0 c8 x- l+ c- [0 a" _1 E* f
  530. # If unsure:( ~( m. z) z: G: F0 N
  531. # use "activerehashing no" if you have hard latency requirements and it is
    ! ?0 V9 _6 j' q, J
  532. # not a good thing in your environment that Redis can reply form time to time
    0 q& b5 x9 U3 K
  533. # to queries with 2 milliseconds delay.6 n5 Y  L  }; Y0 K, \$ z
  534. #2 r, Z; z6 M* \% \
  535. # use "activerehashing yes" if you don't have such hard requirements but
    , }3 }( ?9 ^; x2 D* ]- F
  536. # want to free memory asap when possible.7 |1 o3 \. q6 Z4 }$ |0 H& R
  537. activerehashing yes
    5 y0 d  ]4 V) j: Q6 Q
  538. 2 _& [% N* z1 V( S+ f2 W* m
  539. # The client output buffer limits can be used to force disconnection of clients, [6 I8 \7 `0 m7 y2 Q/ Z# w
  540. # that are not reading data from the server fast enough for some reason (a" \. `  c0 L  T8 @% h9 ~
  541. # common reason is that a Pub/Sub client can't consume messages as fast as the
    1 U5 D& z' L+ `/ X! P* V
  542. # publisher can produce them).
    5 k, o" p9 H' p( }% N; T& q
  543. #3 V# A! V& p2 e$ `' q. Z
  544. # The limit can be set differently for the three different classes of clients:5 p7 m; q2 r! g2 S) ^
  545. ## b% `9 U7 d( A5 s9 Z# O, N
  546. # normal -> normal clients
    0 Z; s* I. N6 c+ U# w# j* X# O
  547. # slave  -> slave clients and MONITOR clients& _( n4 [5 a' R& u$ U
  548. # pubsub -> clients subcribed to at least one pubsub channel or pattern- a) e7 [) ~+ T( A$ W, v/ f$ \
  549. #! d$ l7 x& U" Q( C- B5 q
  550. # The syntax of every client-output-buffer-limit directive is the following:
    1 A, i0 n; j- K$ h3 \) R1 i# r; `6 M0 R
  551. #
    $ s- u$ ]3 Y0 i/ J4 D; E- I( W
  552. # client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>
    : w) h$ r7 _1 f, s8 X' Y- R
  553. #3 x; Y3 [9 o# P3 x, ?% }1 J( R+ M: s
  554. # A client is immediately disconnected once the hard limit is reached, or if
    . Q( g4 ]4 Y' P% x
  555. # the soft limit is reached and remains reached for the specified number of! j& o8 F% U* Y6 i( v* Z$ ^
  556. # seconds (continuously).8 z' q3 Q, M3 O! G: O8 N
  557. # So for instance if the hard limit is 32 megabytes and the soft limit is5 e! A* J- {+ f
  558. # 16 megabytes / 10 seconds, the client will get disconnected immediately3 A" g) L, q% b
  559. # if the size of the output buffers reach 32 megabytes, but will also get. t. ^  ?* Z& C
  560. # disconnected if the client reaches 16 megabytes and continuously overcomes
    , G: `  Q& g- f& d: c# n
  561. # the limit for 10 seconds.% t/ ^% z8 U8 f& j4 }
  562. #
    1 y6 @! U, T; N# w
  563. # By default normal clients are not limited because they don't receive data
    % W+ N% n/ e8 P4 ]1 k
  564. # without asking (in a push way), but just after a request, so only- i/ i9 B# @* d7 C# j3 J. z
  565. # asynchronous clients may create a scenario where data is requested faster3 i* l3 L) R( H. j3 @
  566. # than it can read.
    2 b9 `* `- [) t( Y
  567. #
    - H- u( A8 h0 n9 D* I" a# n
  568. # Instead there is a default limit for pubsub and slave clients, since: C/ z' K' o0 {5 H: z' W* ?) u
  569. # subscribers and slaves receive data in a push fashion.+ |: Q, L% i' F. m
  570. #
    4 l# C& S# `; S* L  U
  571. # Both the hard or the soft limit can be disabled by setting them to zero.5 d3 |/ y3 t% r, F( c( F) x9 ?
  572. client-output-buffer-limit normal 0 0 0
    & x) {4 K9 ?  A
  573. client-output-buffer-limit slave 256mb 64mb 607 h8 Y. w. x) V: U6 ?2 T' p% c) h) z
  574. client-output-buffer-limit pubsub 32mb 8mb 60
    3 D3 e# M5 p: ]0 R/ Z! l! m: S- K* s

  575. ) W" V: _: v2 \$ ]
  576. ################################## INCLUDES ###################################
    3 X, k3 _8 j% z" {/ ~

  577. . c* u9 O! ]' q; \/ ~) {7 i
  578. # Include one or more other config files here.  This is useful if you1 l" F  o) o3 B3 O2 p! C
  579. # have a standard template that goes to all Redis server but also need
    9 R' x: X6 k7 G! k; Q$ H
  580. # to customize a few per-server settings.  Include files can include8 u3 ^( ^7 l# r& _
  581. # other files, so use this wisely.
    & |3 P3 q& S- S7 S9 q8 c) E6 m  R/ U
  582. #
    6 x! M2 a8 P# N, A# e& t" d5 P
  583. # include /path/to/local.conf9 ~* g1 B5 e( O% ^2 T, \6 e: A
  584. # include /path/to/other.conf        ( F8 G* h; j; v
  585. ##########################配置文件结束################################ * ^) k& A& N( X- R5 J0 k9 |
  586. 第三步:启动进程# r8 ^) L; c- G7 K# @' p* `* c
  587. #redis-server /etc/redis.conf( w& @) U  e1 T" |* |$ x. M
  588. 查看进程有没有成功启动4 x9 w$ n. c. B) ?  B% I
  589. #ps -ef | grep redis
    4 g& h% N0 ?5 c4 ?) _: P
  590. 测试输入一个键值
    3 T: n. \) R3 j( s% ^4 B! r1 L% [, F
  591. #redis-cli set test "testredis"( I( t) Y: G6 Y
  592. 获取键值: N4 ^4 o% o% I, }) U  G
  593. #redis-cli get test+ V% h( L4 k! |3 ~% g1 L$ [

  594. + f4 C4 b+ x  w2 ~2 M* l6 `
  595. . g% }0 r4 V8 r! n7 Z
  596. 第四步:关闭redis  (这个是更改配置文件后 正常的重启方式  不重新加载redis配置跳过)$ ?1 j7 x8 x8 i
  597. # redis-cli shutdown      //关闭所有   
    # [4 Q+ h! ^) T' S
  598. 关闭某个端口上的redis    - D. ~+ Z( o9 b/ i8 M9 ~
  599. # redis-cli -p 6397 shutdown  //关闭6397端口的redis  # N7 ]& E$ D) |! `2 U0 ]3 f3 d  I
  600. 说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename  dump.rdb  ) |+ i# L) S  B$ Z3 l& k) ~

  601. 8 K/ w1 `' ^+ ]- R8 |
  602. & M0 s  T3 Q( u9 H& z
  603. 第5步:php扩展安装
    1 @2 D4 U# d6 n
  604. phpredis PHP扩展下载地址
    9 [- A) t, D: z$ f7 F
  605. https://github.com/nicolasff/phpredis/tree/2.2.2 ! g& x2 `/ N$ h" H$ k
  606. 选择最新版本下载zip ) j4 L4 V/ i  D  q
  607. + H) s! M6 \& n  ?, ~. a. E/ \
  608. 然后自己上传zip  用unzip解压到当前目录 unzip 文件名( q0 f* G5 z& X# |/ v

  609. / V9 x/ E/ K6 R9 r9 s* C4 A' u4 R( i
  610. # cd owlient-phpredis-90ecd17/   #打开解压后的文件夹里面  这个解压后的目录 要是不知道 可以输入 "dir" 查看
    ' W4 E  v; }9 t- P2 C6 n8 G4 W8 I+ ~8 }
  611. # /www/nginx_php-5.2.17/bin 2 {0 U& U5 t& `0 t8 K% K
  612. # ./configure --with-php-config=/www/nginx_php-5.2.17/bin/php-config
    1 o8 A9 \! A& D1 f2 R
  613. #make% V4 {/ O- z; ^5 a
  614. #make install   #记录产生的redis.so路径
    - X, c/ @( R5 v( ^- b& x9 @7 N
  615. $ s- I- D6 C. h, K8 e
  616. 修改php.ini文件
    % X( I: V7 H& _
  617. 在php.ini中添加如下一行:
    * g4 z, q+ H. _" E# U! N
  618. extension=/?/redis.so  #是刚刚记录的产生redis.so的路 写在 ?那
    * {0 _* N  i2 g; B. X! e% d
  619. 重启 使之生效:
    6 r3 K! g/ X3 s5 @) Q
  620. /usr/local/php/sbin/php-fpm reload+ G' G) C, `0 k
  621. /usr/local/nginx/sbin/nginx -s reload
      x: O/ x9 H! }- }0 y, g  m7 O

  622. ; Q8 s" l2 T  b
  623. 将 Redis 作为 Linux 服务随机启动# a7 e$ F9 D" n; ?
  624. vi /etc/rc.local, 加入代码:0 }0 {$ a+ s: j% A+ }. i
  625. /root/redis-2.6.10/src/redis-serve  #路径看情况修改 % H) @. z. C* N, {( s

  626. ' q! ?* u/ Q9 h: K2 \& u9 O
  627. redis-cli -h localhost -p 6379 info  #命令要在redis目录下面执行
    ) f( r! G3 J( r
  628. 提供host为localhost,端口为6379,redis服务的统计信息
    9 f9 ~! b( x0 K# }7 O: D- m3 Z
  629. " k3 n$ Y; W6 ]9 x+ X3 p

  630. ; L0 }2 Y5 a! _. ~
  631. 就这样你的web服务器就支持redis了 记得要在 给dz 的配置文件 加上12.0.0.1哦
    6 k0 V  u3 ^- b; x5 V# ~) ^5 y$ ~+ q5 s
  632. dz配置文件在 config目录下面的 config_global.php
    % w6 K! C$ V' d
  633. $_config['memory']['redis']['server'] = '127.0.0.1';( _1 K7 S% h, N) S
  634. $_config['memory']['redis']['port'] = 6379;) w3 ?- n# t3 X
  635. $_config['memory']['redis']['pconnect'] = 1;
    7 O& G3 @3 N3 t9 M
  636. $_config['memory']['redis']['timeout'] = '0';
    ! |, w9 q2 r) u& O( N! P, C  H) [
  637. $_config['memory']['redis']['serializer'] = 1;- O) c: `& w% N8 V& j! @
复制代码
关注微信公众号《神采飞扬网》,即可获取最新回复通知!

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

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

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

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

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