分享到:
发表于 2018-11-16 12:42:28 | 显示全部楼层 |阅读模式
环境配置# Y$ U( d: {3 T( X9 a
& S9 o" D9 U4 C

8 f, {& m7 y, ~/ ?2 thttp://www.discuz.net/forum.php? ... amp;highlight=REDIS
关注微信公众号《神采飞扬网》,即可获取最新回复通知!
 楼主| 发表于 2018-11-16 12:43:33 | 显示全部楼层
http://www.discuz.net/forum.php? ... 648&highlight=REDIS
; w' v: Y3 `' h1 y5 B无意间测试 单机状态 redis相当给力 测试1000请求/s  单纯的 get 和set 居然只用了 0.01秒 当时我惊呆了
* O" x6 O$ w6 K+ b% O) Q% z* [* f- \4 n' J8 Z* r
http://www.discuz.net/forum.php? ... 731&highlight=REDIS* V& r6 L8 L2 S( }

9 s2 Q( u2 ]' }* }" whttps://wenku.baidu.com/view/265a5ce176a20029bc642d0b.html
3 V+ }% w& q1 A0 a1 v* F' _9 h  N
" ?) x( ^* B/ g- U=======================================# E2 O* V5 a7 Y4 V9 T
  1. 连接上 ssh7 D& i( C9 Y  E# i7 h; N) @8 K
  2. 8 C* k9 `, M, I+ u1 L

  3. : F- n; }$ ^' |0 L+ l; T5 T# U
  4. 第一步:下载redis. W& N8 l, Z/ Q* K
  5. # wget http://redis.googlecode.com/files/redis-2.6.10.tar.gz' c, J7 ^7 C7 A' k% S* ^
  6. # tar zxvf redis-2.6.10.tar.gz
    # A4 D6 R' `% ~- I
  7. # cd redis-2.6.10
    9 s( H0 l0 G# ]: @2 g
  8. # make
    - y# q4 U3 I. W. F: w2 G9 ]$ X
  9. # make install  
    & N9 v0 L& s4 z% n, ]' b
  10. #cp redis.conf  /etc/ #复制配置文件到etc目录下面0 [) d2 E$ h$ a
  11. 第二步:修改配置. y5 Q1 Z5 y- X1 Z5 y2 `( O
  12. #vi /etc/redis.conf
    : y. E/ i) }; |: t' S
  13. ######################下面是无措的配置文件 复制过去就成#########4 U" b" M# [8 @( a
  14. # Redis configuration file example  k/ Z& U- p* r5 S, j2 a: m2 k, x

  15. 0 ~# b! n% o( M; h5 Q+ ?& @3 ?
  16. # Note on units: when memory size is needed, it is possible to specify! }  M6 T& O7 H* `5 X2 @4 j7 H
  17. # it in the usual form of 1k 5GB 4M and so forth:
      d4 Q- M( ?# X3 [1 z( F
  18. #1 t; [# l9 J  Q3 v
  19. # 1k => 1000 bytes
    1 t9 L) e7 W7 g! }* P, s' }
  20. # 1kb => 1024 bytes
    5 N9 M3 \3 J4 m& e) g1 ~
  21. # 1m => 1000000 bytes* ~2 }: g5 Y" V4 W
  22. # 1mb => 1024*1024 bytes/ H$ o+ U' k) b
  23. # 1g => 1000000000 bytes) J0 |0 T( I! [  q7 F9 n
  24. # 1gb => 1024*1024*1024 bytes! `% P( c! C8 E: J( Q5 }/ f. t
  25. #
    ) y; u1 F* d  V2 d
  26. # units are case insensitive so 1GB 1Gb 1gB are all the same.
    / l" k5 P/ Q7 T/ I- I/ q$ \+ \

  27. 6 e, g, G/ |# ~) U$ C  |4 y$ j: Y/ t
  28. # By default Redis does not run as a daemon. Use 'yes' if you need it.
      Y4 q: c+ V1 X# d
  29. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
    6 l/ K/ c. z$ F" Z# J4 |, p
  30. daemonize yes& a9 w4 g/ C* R; M& C/ L
  31. 3 _/ P6 K0 I7 @* y
  32. # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
    ! C7 y1 q1 d/ i- q: }2 X# E" b: I; _
  33. # default. You can specify a custom pid file location here.% G1 }/ l, p2 _: r; J0 c
  34. pidfile /var/run/redis.pid, a0 @8 Y; s: J; l) X. d- h, ^

  35.   K$ \% @2 w! v$ w! ^9 |( s( @
  36. # Accept connections on the specified port, default is 6379.+ o6 S- J! R- {) L* e3 l* J
  37. # If port 0 is specified Redis will not listen on a TCP socket.! U" Y  n: N" \( J3 w- n6 d
  38. port 6379! q4 B! c, ^0 W; g6 G1 ~

  39. 4 W3 Z0 ?; \9 j# ?  A
  40. # If you want you can bind a single interface, if the bind option is not
    6 k; \5 R! u" Q4 A8 z" y" A
  41. # specified all the interfaces will listen for incoming connections.  f$ C* x# {  ^. b( M* k0 `$ @
  42. ## \& _2 M, x3 o
  43. # bind 127.0.0.1
    $ e: y& g2 `1 [
  44. 6 R7 Z6 f" l' [; Z" T, K- z( U
  45. # Specify the path for the unix socket that will be used to listen for1 K& G. y& p+ W' B
  46. # incoming connections. There is no default, so Redis will not listen0 `; U; C5 c: Q" {5 E/ h
  47. # on a unix socket when not specified.
    6 R7 T! k3 e! a
  48. #0 e( i& k% {9 w% T. q
  49. # unixsocket /tmp/redis.sock
    8 Z$ a, m" A  q! I6 ]1 A5 h$ A6 Z, p
  50. # unixsocketperm 755+ F1 h' p# |) m; q( f% a/ g
  51. ! P) v$ H% Q/ f$ `$ R
  52. # Close the connection after a client is idle for N seconds (0 to disable)( p  f2 O' v% e  l9 P
  53. timeout 300
    $ J. B5 \) `0 o7 \: b

  54. 3 k, j5 b, _) y
  55. # TCP keepalive.
    * W' a8 E: A+ r
  56. #
    $ _2 y' U$ B0 f1 `& u& `
  57. # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
    8 z/ Y# @7 X: t" Y, K+ t9 S
  58. # of communication. This is useful for two reasons:* N4 e8 [* m9 _$ b* j. d
  59. #$ t- J! L  x0 V& N
  60. # 1) Detect dead peers.
    9 \' j* d; [3 k; I: X$ w
  61. # 2) Take the connection alive from the point of view of network
    3 x0 S2 L  }$ G
  62. #    equipment in the middle.
    6 q( o' d- p* P& m% g4 x
  63. #
    . C4 E0 j$ \: D1 p
  64. # On Linux, the specified value (in seconds) is the period used to send ACKs.: u5 [1 E$ L* ~  p# D" V
  65. # Note that to close the connection the double of the time is needed.
    ! b* y1 W, b2 G% a
  66. # On other kernels the period depends on the kernel configuration.
    7 Z9 A; X3 l3 h- r6 N2 o0 c  n
  67. #+ C3 M% A$ E8 h* w* w) g
  68. # A reasonable value for this option is 60 seconds.
    6 k) {7 x6 Y: J! u$ I0 R/ a
  69. tcp-keepalive 0
    ( L3 ?8 N$ M% V3 U( x' n
  70. ( \& X* N% p/ H& z5 [# o
  71. # Specify the server verbosity level.8 @( b& v4 t; ?* ^
  72. # This can be one of:
    7 Y, ?. N" \" H: _# v0 ?
  73. # debug (a lot of information, useful for development/testing)
    * x; w& G" u, W- X! E' o0 z5 j8 ?
  74. # verbose (many rarely useful info, but not a mess like the debug level)
    & U+ ~2 C5 t7 d/ j% k
  75. # notice (moderately verbose, what you want in production probably)4 K. j! w4 O8 o9 N1 T
  76. # warning (only very important / critical messages are logged)# K, s4 ?8 J# w/ [
  77. loglevel warning
    7 q, M! h, l% V9 k: m, z9 p5 I& P- j
  78. ) j( u: s# D) i2 B0 s
  79. # Specify the log file name. Also 'stdout' can be used to force( @' _: _: M# U* g5 S, B0 ^
  80. # Redis to log on the standard output. Note that if you use standard
    3 U5 \2 ~6 R! h" H! y
  81. # output for logging but daemonize, logs will be sent to /dev/null& W  d! j4 T) Q1 P* t5 O' N5 O
  82. logfile /var/log/redis.log
    3 W# k1 c, [6 K# B& C
  83. - V( e  W5 N3 j3 _. d
  84. # To enable logging to the system logger, just set 'syslog-enabled' to yes,8 Z5 I( Q: @% Q' o  ?  ?6 Y  P
  85. # and optionally update the other syslog parameters to suit your needs.
    % {! y0 h* Y" l3 J
  86. syslog-enabled yes
    ) |0 ?1 \! K" t9 P

  87. ( |) V5 O! }: o/ G& {5 Z! H
  88. # Specify the syslog identity.# t$ ]  n# A, J0 [+ \* n+ C  m! d
  89. # syslog-ident redis
    ) G+ X3 @0 R& B; Q0 u

  90.   W+ i% g! U! \
  91. # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
    " d  k$ I( B5 T
  92. syslog-facility local0
    . T9 Z; |8 z, p2 k6 S1 d& [  K! F

  93. * R, u% P! Q2 P: Z* Y
  94. # Set the number of databases. The default database is DB 0, you can select8 x4 [4 T- ~! J! q8 `/ |  P* R
  95. # a different one on a per-connection basis using SELECT <dbid> where7 G# R+ y  r4 I6 i+ z* C# U
  96. # dbid is a number between 0 and 'databases'-12 K6 M* c# ]# v
  97. databases 16
    4 ^. S; @( I9 }' V; O

  98. - M2 D, Z) J8 \! t' u+ N
  99. ################################ SNAPSHOTTING  #################################8 f% G3 U  @$ m- E$ Z
  100. #5 n9 o, E. @; }8 i& V) n" k- z
  101. # Save the DB on disk:
    : ^5 O2 z: V! h. ~. S2 `. U
  102. #
    : |. p  c9 t% v" ~. A( G
  103. #   save <seconds> <changes>9 v7 M/ ]* v% n' e: Y9 j! }8 J
  104. #" @: i5 I/ v) P+ y- a
  105. #   Will save the DB if both the given number of seconds and the given0 W2 U4 M# e1 Z* a# a
  106. #   number of write operations against the DB occurred.
    * S( d1 R* ~9 z' u, b
  107. #
    $ e; b* S9 M! ]( H; t
  108. #   In the example below the behaviour will be to save:
    9 Z' g, i" f5 G; j- y
  109. #   after 900 sec (15 min) if at least 1 key changed
    * e& T' \4 Y! q: W1 Y) Z, o/ s
  110. #   after 300 sec (5 min) if at least 10 keys changed" u$ E$ k: }- W% [% w/ \& j
  111. #   after 60 sec if at least 10000 keys changed
    8 q& X8 T* z; S& \4 s
  112. #* i" g: a2 M+ m# M5 q
  113. #   Note: you can disable saving at all commenting all the "save" lines.- o+ j* U% X7 D5 {% b
  114. #3 Z; s9 ^. V/ R" W
  115. #   It is also possible to remove all the previously configured save
    / G% J" D; s  h, _
  116. #   points by adding a save directive with a single empty string argument
    3 B5 j  b- Q. R
  117. #   like in the following example:0 K2 w  h6 t; {3 C
  118. #5 L; p5 ?/ l9 \- D. j: N
  119. #   save ""
    0 N6 q4 ]6 I0 s& X

  120. # N- }; |& T; t5 ^1 F, ^
  121. save 900 16 [5 i% |4 U2 V
  122. save 300 10
    0 x0 i- `, V: E9 x7 d+ B
  123. save 60 10000
    6 Y# q+ o( y' J
  124. 2 J# {2 H/ i" D. y. s
  125. # By default Redis will stop accepting writes if RDB snapshots are enabled4 ?7 l& T$ d$ _$ C  M
  126. # (at least one save point) and the latest background save failed.' W* B8 a% N7 L' f; a, z2 }
  127. # This will make the user aware (in an hard way) that data is not persisting
    + ~! u4 r  o* L, e: X
  128. # on disk properly, otherwise chances are that no one will notice and some& S# k0 W% e: i8 v1 ~# C% i; v
  129. # distater will happen.$ y; v: K& E3 \: g2 \6 `" G
  130. #; Y6 b/ `: x! O" g9 T+ _! e4 f
  131. # If the background saving process will start working again Redis will# g. t+ E, I$ f4 S8 n
  132. # automatically allow writes again.
    : E) k" D: r. S; L
  133. #; d9 ]8 C: O; a0 O
  134. # However if you have setup your proper monitoring of the Redis server
    4 i) N) Q6 e& y9 w! y6 ?
  135. # and persistence, you may want to disable this feature so that Redis will
    , i" N# N/ M4 X) N9 h
  136. # continue to work as usually even if there are problems with disk,7 ], o6 @& [0 ~' X
  137. # permissions, and so forth.
    + W+ X# t+ F" Y; P1 r" D
  138. stop-writes-on-bgsave-error yes
    , J7 O1 i2 B. ]! \

  139. 4 m( G6 C* k' h; v! c
  140. # Compress string objects using LZF when dump .rdb databases?3 E9 s, v. ]; M1 {: p
  141. # For default that's set to 'yes' as it's almost always a win.0 S. ]4 V2 c; _4 I0 c* A7 m9 f
  142. # If you want to save some CPU in the saving child set it to 'no' but
    " B" Z  K- z$ ]
  143. # the dataset will likely be bigger if you have compressible values or keys.& w1 o: ^2 O# X
  144. rdbcompression yes
    ' U$ @" q) ~3 p8 ~! t. V
  145. 0 L/ V/ h5 W$ S( ~
  146. # Since version 5 of RDB a CRC64 checksum is placed at the end of the file.* g" g3 K  i% r, f. _8 |9 R
  147. # This makes the format more resistant to corruption but there is a performance
    * g9 q2 `# S4 }
  148. # hit to pay (around 10%) when saving and loading RDB files, so you can disable it
    3 N" T' Y- _  z% l) d; Z& `- A
  149. # for maximum performances.
    . o8 i! W: I) [
  150. #
    % h. \( _/ V1 x
  151. # RDB files created with checksum disabled have a checksum of zero that will
    4 }- m3 b/ b0 v
  152. # tell the loading code to skip the check.
    2 U3 y$ p& |+ w1 G3 l
  153. rdbchecksum yes
    ) t* Q; f& b$ x% V. R" L

  154. 0 \/ U8 G) W  k5 J2 a
  155. # The filename where to dump the DB
    8 O2 O  U3 V4 z/ K& ~/ X0 n/ N
  156. dbfilename dump.rdb
    & D$ q" v3 S7 w6 P: i# V6 j

  157. ( |9 J- `9 `5 Y
  158. # The working directory.) ?( M7 \* S; }& C
  159. #
    ) y' K3 J) f" [/ S5 _
  160. # The DB will be written inside this directory, with the filename specified
    3 q" i; j3 s* i- O% T
  161. # above using the 'dbfilename' configuration directive./ \) ^$ O6 ~+ g+ l, i
  162. # 9 L, k' y" z% ~6 B  D
  163. # The Append Only File will also be created inside this directory.' j+ K3 m8 n* ^, K& Z
  164. #
    + t9 t$ r5 n( u. ~' o- {) j
  165. # Note that you must specify a directory here, not a file name.
    " a: l2 z8 A0 J$ ^
  166. dir /var/db/redis
    0 |6 o7 v1 C" T" }9 X! [' B) B

  167. 6 F8 M7 F/ z) C# }+ m  o
  168. ################################# REPLICATION #################################9 R) I3 N! S5 i
  169. / i8 _( O. q1 O
  170. # Master-Slave replication. Use slaveof to make a Redis instance a copy of( \! Q' q! s" Z* b$ p3 F. o
  171. # another Redis server. Note that the configuration is local to the slave' A2 Q  \+ L5 ?2 X& T5 C0 O* z% t
  172. # so for example it is possible to configure the slave to save the DB with a
    ' I8 ]% N3 x% j+ T, T; V' q3 c
  173. # different interval, or to listen to another port, and so on.
    & O8 x4 T: K( {3 Q9 Q
  174. #2 F6 K' C$ ~2 @3 P& S2 s- I& t1 W
  175. # slaveof <masterip> <masterport>
    ( Z6 `1 ?. l6 t( H0 k

  176. # L& E' Y" {. Y
  177. # If the master is password protected (using the "requirepass" configuration/ j$ X& Z1 z# E; A' m8 g
  178. # directive below) it is possible to tell the slave to authenticate before
    . F* t* t1 s, [6 J4 U5 a
  179. # starting the replication synchronization process, otherwise the master will6 j, X# u6 @' ~5 C" n
  180. # refuse the slave request.
    3 w* B" W: {9 O. h( p
  181. #
    6 V9 f! e6 S. F$ k
  182. # masterauth <master-password>0 }8 ^) R2 X7 n# ^# B! r
  183. - g/ D& U" a6 V
  184. # When a slave loses its connection with the master, or when the replication4 h) L) F% Q% C+ R/ i3 ]9 v" l0 M: s% Y
  185. # is still in progress, the slave can act in two different ways:& }) g" @9 m2 R9 a! W
  186. #5 T/ }; Z$ |4 M) e& Z
  187. # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will( F6 O7 i6 n- q( I
  188. #    still reply to client requests, possibly with out of date data, or the" w7 R* U) S1 v. a
  189. #    data set may just be empty if this is the first synchronization.
    9 o8 V5 Y, G  M5 F% P' {0 z
  190. #
    6 W4 ~* ~  B! M  Y3 m; u2 y3 a
  191. # 2) if slave-serve-stale data is set to 'no' the slave will reply with
      q- A  ~: _, v; z8 ]* O8 R
  192. #    an error "SYNC with master in progress" to all the kind of commands8 |3 H( [' Z0 t8 N
  193. #    but to INFO and SLAVEOF.! x; s. |5 K- u
  194. #* _; S1 D$ s, }1 E$ m
  195. slave-serve-stale-data yes9 ^5 g& f8 ~8 f# Z

  196. / |7 J1 s) ]( g9 y, g2 A& U5 ?
  197. # You can configure a slave instance to accept writes or not. Writing against) R2 l% v  [' x4 V2 w) r- [
  198. # a slave instance may be useful to store some ephemeral data (because data1 E! \6 \% m! A0 `
  199. # written on a slave will be easily deleted after resync with the master) but
    6 a6 H4 }' [- z' B; B: T
  200. # may also cause problems if clients are writing to it because of a
    7 e/ _3 U2 l5 Z7 y2 V4 W
  201. # misconfiguration.4 j. [4 a( k1 F, Y* O8 i, l2 }
  202. #* o! J- |: _  h8 R  u2 U" z2 G
  203. # Since Redis 2.6 by default slaves are read-only.
    $ z" V; H4 S; R; o7 O
  204. #: g: z$ w) u$ ~( s3 b" p- O! F
  205. # Note: read only slaves are not designed to be exposed to untrusted clients
    8 V7 P  B$ X5 d$ w0 ~( F- w
  206. # on the internet. It's just a protection layer against misuse of the instance.9 j" {1 k8 o' A/ x2 i% B5 r
  207. # Still a read only slave exports by default all the administrative commands* _$ _; }9 L4 [% Q7 n4 F- b- y+ H
  208. # such as CONFIG, DEBUG, and so forth. To a limited extend you can improve- r9 m; I. c" k* f
  209. # security of read only slaves using 'rename-command' to shadow all the
    5 p( m& `# v! M1 r
  210. # administrative / dangerous commands./ Q4 D( t% A* l) O7 E1 H- M
  211. slave-read-only yes
    & C+ w0 |7 i: s0 j* b

  212. ) |" k) _/ X7 L: J
  213. # Slaves send PINGs to server in a predefined interval. It's possible to change- P* C" M7 A! d, W+ p
  214. # this interval with the repl_ping_slave_period option. The default value is 10
      a2 X1 W: A6 F& p3 y6 `, |
  215. # seconds.- e* e8 W; l- G
  216. #
    + \/ a# D& P2 R* F, G
  217. # repl-ping-slave-period 10& x7 W+ v6 s: E9 T3 Y% W
  218. # B5 u3 x: v2 `' r9 l: P. v% n' e
  219. # The following option sets a timeout for both Bulk transfer I/O timeout and
    3 a5 I- r+ J/ d9 v9 g8 o7 H6 _
  220. # master data or ping response timeout. The default value is 60 seconds.
    $ X. \; n& T* g2 N/ d# y
  221. #
    / b- }# |( L% d8 s/ ?
  222. # It is important to make sure that this value is greater than the value9 D; n" i3 U" X: i5 O' ^2 W
  223. # specified for repl-ping-slave-period otherwise a timeout will be detected" W1 W5 G5 h. \0 e
  224. # every time there is low traffic between the master and the slave." R/ J, X, Y8 Z! I: j! G+ y( n( v
  225. #" ]  F' l! f% ]9 a
  226. # repl-timeout 60
    0 q3 G7 |- c' }& y8 Z

  227. . P! ]( l8 f. P; `4 s0 ^4 w
  228. # Disable TCP_NODELAY on the slave socket after SYNC?
    4 p$ Q# a) R8 G1 o9 N
  229. #
    0 n" [1 k  d" d+ m
  230. # If you select "yes" Redis will use a smaller number of TCP packets and
    8 N: B+ G! D- Y6 L
  231. # less bandwidth to send data to slaves. But this can add a delay for
    : w/ V/ O+ Y& R2 B
  232. # the data to appear on the slave side, up to 40 milliseconds with+ ?6 k$ a( t0 a7 S
  233. # Linux kernels using a default configuration.
    " N0 D6 P0 s# v  A
  234. #
    + G5 G% [3 n3 F7 r5 U& ]' B& V; t
  235. # If you select "no" the delay for data to appear on the slave side will- f( g3 {2 ^- ~  k0 U
  236. # be reduced but more bandwidth will be used for replication.
    ( q2 k( g5 F. i2 u7 W3 K1 V; g! U
  237. #* o" u) e" k4 E; j4 j
  238. # By default we optimize for low latency, but in very high traffic conditions( }; P/ p1 Y$ X1 p9 G- T5 n7 ^8 J
  239. # or when the master and slaves are many hops away, turning this to "yes" may
    5 D+ {! H0 X/ I% F: d
  240. # be a good idea.4 d. ?2 n0 q9 _3 B6 b
  241. repl-disable-tcp-nodelay no+ `7 F, g6 \5 k* O

  242.   i2 w/ A, [: N# W5 t0 h! Q
  243. # The slave priority is an integer number published by Redis in the INFO output.
    4 t& v' M- J. s; }  \$ w
  244. # It is used by Redis Sentinel in order to select a slave to promote into a
    7 E3 Q, X$ N" H- m8 V
  245. # master if the master is no longer working correctly.
    / o/ `, v: p; g0 @4 M
  246. #6 ]& p6 f) J. {* h5 G( b" t) u
  247. # A slave with a low priority number is considered better for promotion, so
    $ J. f4 @* r) l$ I1 P; C; ?; A
  248. # for instance if there are three slaves with priority 10, 100, 25 Sentinel will8 i$ C, @  J0 a1 }/ z
  249. # pick the one wtih priority 10, that is the lowest.  G0 U: Q0 c: Z& s  s: T8 q
  250. #
    ; G- V+ S# C0 Q8 h
  251. # However a special priority of 0 marks the slave as not able to perform the% y: V  T4 q  Y, ?% G5 G
  252. # role of master, so a slave with priority of 0 will never be selected by+ a  h2 \, Q! h6 [/ S
  253. # Redis Sentinel for promotion.
    % e' c: O+ l% }5 ]/ X
  254. #6 P! z$ C* z" N7 u6 Q% p# b. w
  255. # By default the priority is 100.
    ; J# Q7 A% R. P' Q
  256. slave-priority 1002 Z( A& l, C+ n3 w, A: d1 A7 ~
  257. ' g2 L1 K8 X; [8 }
  258. ################################## SECURITY ###################################2 d* B" m# i( F# w- Y1 {  P0 E7 S( Q

  259. ' u- \1 m9 L' d, T1 d$ x
  260. # Require clients to issue AUTH <ASSWORD> before processing any other) y6 R( l: h6 i1 h
  261. # commands.  This might be useful in environments in which you do not trust# j4 N3 j4 m# n) f1 x3 O6 I) d
  262. # others with access to the host running redis-server.% O5 |1 v5 H' d
  263. #/ h; ?* t% @8 V
  264. # This should stay commented out for backward compatibility and because most
    6 q8 K; m9 `' G$ ^& q! ?9 c
  265. # people do not need auth (e.g. they run their own servers).
    $ Z, J8 Z( U' D! E) t
  266. # / L2 h8 ^( X- `7 @
  267. # Warning: since Redis is pretty fast an outside user can try up to
    ; m$ L2 x+ U4 J' ^0 ]
  268. # 150k passwords per second against a good box. This means that you should
    - t# K& ?, g. R' G8 J0 J& `$ E
  269. # use a very strong password otherwise it will be very easy to break.3 R' W5 A! E3 N7 p. E/ A, w6 p# M
  270. #; X4 V( Z7 R& A' `+ z: u- @, y+ g
  271. # requirepass foobared
    + ]& d6 a* A  ?, i7 g& g

  272. ! \3 ?0 e5 P+ g. f) g# @! \0 d3 o& K( d
  273. # Command renaming.3 x2 M4 X9 T7 T  i3 R
  274. #
    ( `! m8 G& z4 T- y
  275. # It is possible to change the name of dangerous commands in a shared
    $ W7 i. H( S% K' W& y! j
  276. # environment. For instance the CONFIG command may be renamed into something: S! q3 h% `( z
  277. # hard to guess so that it will still be available for internal-use tools8 e. C' l  C  f. s& E$ {
  278. # but not available for general clients.
    6 ^% P2 K7 v* M7 k
  279. #: j: Z( P8 M  I0 r# W# T/ V& G
  280. # Example:6 x, S3 M* }' x; \% `& C: H
  281. #9 a& q6 @4 ^+ o) [
  282. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c529 _, L/ r- c' l+ D( G* u8 r) d
  283. #9 T* {& @7 x1 u, r3 @3 C: [
  284. # It is also possible to completely kill a command by renaming it into
    6 O6 N0 H. D9 O( X7 [
  285. # an empty string:
    # @$ T" V0 J, _
  286. #; V2 K0 w' U8 l+ Y' z+ a% ^7 ?
  287. # rename-command CONFIG ""0 N$ d* Z8 y9 F
  288. 9 l7 F- ]3 Q; ^+ w
  289. ################################### LIMITS ####################################( W: S* w6 }( D9 X; f; x. F

  290. 3 K6 u! d4 e- N$ D3 V: t" t' D9 Y
  291. # Set the max number of connected clients at the same time. By default* p0 i" o" A4 I  r
  292. # this limit is set to 10000 clients, however if the Redis server is not
    8 J4 J- P9 T8 Z- L1 B* c2 o& C- o* h' U
  293. # able to configure the process file limit to allow for the specified limit4 z7 U# x+ m+ C3 o* m  |! v$ A
  294. # the max number of allowed clients is set to the current file limit- l: N2 M) `0 ^4 d
  295. # minus 32 (as Redis reserves a few file descriptors for internal uses).
    ' Q. R9 Z. x0 C" Q" J" I2 t3 `
  296. #- h) v% T# |$ T5 V
  297. # Once the limit is reached Redis will close all the new connections sending
    5 A& P' w( u/ \# \) g/ F
  298. # an error 'max number of clients reached'.
    ) D, _% K, b: N/ q! P; V9 D8 c) n$ o& a
  299. #, w5 A2 I( j# y: b1 ?- ^+ `
  300. maxclients 500$ }8 j! A: h9 e. e0 L' g1 V" J

  301. 9 Z* Z* a, H' P! H
  302. # Don't use more memory than the specified amount of bytes.
    1 d. a# `" [1 A' T  @/ G. `' C
  303. # When the memory limit is reached Redis will try to remove keys
    0 u6 `; l: @% Z3 W3 _# ?/ \
  304. # accordingly to the eviction policy selected (see maxmemmory-policy).
    + Z7 x4 o2 X. M  g- w
  305. #) r2 ?, A1 ^8 Q* q/ ^
  306. # If Redis can't remove keys according to the policy, or if the policy is
    4 O7 o+ a0 N) }+ S" ]" K
  307. # set to 'noeviction', Redis will start to reply with errors to commands
    ; E/ A7 N% K) K, g  t' D) y: ]3 X
  308. # that would use more memory, like SET, LPUSH, and so on, and will continue
    ) J9 }( @  n3 ?2 k4 H/ C( M5 J
  309. # to reply to read-only commands like GET.4 b# a' l. r! a
  310. #2 L3 u+ q- p& V4 Z/ f
  311. # This option is usually useful when using Redis as an LRU cache, or to set+ O( }: ]" C  c  v( q3 R
  312. # an hard memory limit for an instance (using the 'noeviction' policy).) s, w/ N. J* b
  313. #2 B/ @. N7 h! T$ E7 `3 k
  314. # WARNING: If you have slaves attached to an instance with maxmemory on,
    . p5 h( C# ~1 c, {) {
  315. # the size of the output buffers needed to feed the slaves are subtracted
    : t% B8 @- o; L1 g7 b8 Y
  316. # from the used memory count, so that network problems / resyncs will
    % j( K7 C9 e' H4 T: i% [
  317. # not trigger a loop where keys are evicted, and in turn the output
    , r# h4 j/ u- Q" w: {1 y4 m
  318. # buffer of slaves is full with DELs of keys evicted triggering the deletion- a$ N( v. z( w- d' i; O' Z
  319. # of more keys, and so forth until the database is completely emptied.  V/ x* X  u9 m* J
  320. #5 ?' H; {" I6 `0 i8 ^8 h
  321. # In short... if you have slaves attached it is suggested that you set a lower2 [" _& h4 b0 _$ [( z- c8 w+ m4 h
  322. # limit for maxmemory so that there is some free RAM on the system for slave
    ! T/ u1 ^, @6 A3 P
  323. # output buffers (but this is not needed if the policy is 'noeviction').
    - R( o8 Y  j7 ]
  324. #: }5 u5 j6 k, c( ^" W! _
  325. maxmemory 1280000006 B4 M/ \3 ~1 W6 u" ^

  326. , @& E/ N3 G0 S1 x  [5 v, B
  327. # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
    . k; @8 c7 \" v. S
  328. # is reached. You can select among five behaviors:
    ; S- V% C, o+ h4 |$ B4 r* w+ R
  329. # & `9 n- I) f, W9 P4 @. H/ M* I
  330. # volatile-lru -> remove the key with an expire set using an LRU algorithm
    $ u9 i8 e4 Y/ u
  331. # allkeys-lru -> remove any key accordingly to the LRU algorithm
    % D; E. B) l4 T
  332. # volatile-random -> remove a random key with an expire set
    ( a9 o' H( j* q5 a
  333. # allkeys-random -> remove a random key, any key" V8 W- }% L7 I4 v2 D4 b, M- e
  334. # volatile-ttl -> remove the key with the nearest expire time (minor TTL)
    ) v: k+ P' A' F' g+ s$ g( x% F
  335. # noeviction -> don't expire at all, just return an error on write operations0 a( |2 v$ K. _6 E
  336. #
    " p6 G7 B7 R4 {$ W
  337. # Note: with any of the above policies, Redis will return an error on write
    4 Y0 i. t4 m1 |
  338. #       operations, when there are not suitable keys for eviction.3 A* G2 i& m- M% A1 G: i' G
  339. #* P; N# v) y. S
  340. #       At the date of writing this commands are: set setnx setex append
    . z/ I; x0 M- y: k# Q8 K" r
  341. #       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
    3 x7 S: Q5 J. z3 e, H& J$ c
  342. #       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby! X1 F. c  Z8 A2 P  H8 `
  343. #       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby) Z" B: c/ F. s* H# s- p
  344. #       getset mset msetnx exec sort( u9 {, @( V; O3 j! j( m+ L! f
  345. #
    . u% G' b2 L  \4 D
  346. # The default is:. s% A) u% {# O, S3 p# a: w6 k
  347. #: C6 p5 Y6 ^( T9 `$ W. f/ z
  348. # maxmemory-policy volatile-lru8 Q' ~1 p$ t- M5 l; a1 q

  349. , b" y& S. Y! L0 p1 N
  350. # LRU and minimal TTL algorithms are not precise algorithms but approximated6 n% b2 ~) k: L2 |7 X6 \
  351. # algorithms (in order to save memory), so you can select as well the sample
    % N' Z& I0 M3 }+ q% U2 f' r: ]+ B3 Z
  352. # size to check. For instance for default Redis will check three keys and
    " @" w4 p. X% a/ Q7 B' _
  353. # pick the one that was used less recently, you can change the sample size
      i; r: B9 K6 E: Z
  354. # using the following configuration directive.
      R) k$ e4 |; m% p# e& q
  355. ## K; m( q+ Z& J8 n2 J/ z' a$ g
  356. # maxmemory-samples 3
    ) H% e0 G* H6 }5 O+ f/ R9 b/ [% U

  357. ( Y8 h/ A* H# ^0 i! X' Z0 l
  358. ############################## APPEND ONLY MODE ###############################1 i) ?: r1 ^& g# W# \+ g: X
  359. : I8 Q# T5 P  I1 Y  Y+ |2 V& q
  360. # By default Redis asynchronously dumps the dataset on disk. This mode is
    0 B% n7 `3 A8 A/ w% |5 [( v0 D4 p
  361. # good enough in many applications, but an issue with the Redis process or! \1 T9 d# C+ f  M7 ]
  362. # a power outage may result into a few minutes of writes lost (depending on8 F. B- }' a6 t3 ]& X9 `! `
  363. # the configured save points).* l0 s( j7 W1 @$ t1 ^
  364. #& q0 L6 Q/ _+ }$ k5 A
  365. # The Append Only File is an alternative persistence mode that provides
    & j# G2 N" W3 T' r
  366. # much better durability. For instance using the default data fsync policy9 ]* U  i/ W( |# T  P" V+ _. i( l
  367. # (see later in the config file) Redis can lose just one second of writes in a
    3 t+ D9 l9 k/ t  d, D! F3 W
  368. # dramatic event like a server power outage, or a single write if something
    % {9 _1 H5 A& [
  369. # wrong with the Redis process itself happens, but the operating system is; {# L' X' u. _% k& R- f7 M0 S
  370. # still running correctly., D. L2 g& G6 E" p( f9 k- G
  371. #/ i5 u. Q' H; l
  372. # AOF and RDB persistence can be enabled at the same time without problems.; H5 }9 X' p2 T0 P. G& I
  373. # If the AOF is enabled on startup Redis will load the AOF, that is the file
    ! j" A- B+ I3 ~. V% k: o
  374. # with the better durability guarantees." ?, [5 b4 ~. B- f3 Q
  375. #
    ; S* p; X! E9 A# F# U
  376. # Please check http://redis.io/topics/persistence for more information.5 B5 C; {& u8 c% j8 e! F; r

  377. * y! l7 J( m1 L: _, F7 o3 F: a$ D
  378. appendonly no
    $ {1 L( O$ o9 e2 @9 L
  379. 0 h, {2 T  b0 M6 x2 W
  380. # The name of the append only file (default: "appendonly.aof")5 P0 T( R+ a4 m* [! T
  381. # appendfilename appendonly.aof
    9 q9 F! h& l2 r6 D

  382. 1 {8 F. i3 F  d; R3 G3 [
  383. # The fsync() call tells the Operating System to actually write data on disk' x8 C6 d% G0 M1 f. }' p. M
  384. # instead to wait for more data in the output buffer. Some OS will really flush
    # Z/ @9 W2 o/ i% T. d& t) m
  385. # data on disk, some other OS will just try to do it ASAP.8 C- R. o2 f( B' u7 R
  386. #
    : P0 T0 \* e* X
  387. # Redis supports three different modes:/ M6 H& n9 @2 O
  388. #1 D* l" \4 X. _- H% X# S, @/ C
  389. # no: don't fsync, just let the OS flush the data when it wants. Faster.# c1 I+ P; p: ]; W% C: e
  390. # always: fsync after every write to the append only log . Slow, Safest.5 R0 V6 V4 C6 M, u9 _/ s# \
  391. # everysec: fsync only one time every second. Compromise." a' G+ Q: r# m
  392. #' H% r! z& |7 Z( o4 I$ I
  393. # The default is "everysec", as that's usually the right compromise between1 S8 {# m5 c$ M' H& m7 h; |& ~
  394. # speed and data safety. It's up to you to understand if you can relax this to
    ! \  u' ]: D+ d, q; ~5 G& V# G
  395. # "no" that will let the operating system flush the output buffer when( N& F4 W. ?/ u
  396. # it wants, for better performances (but if you can live with the idea of4 {! L& v; I. f/ e  z! d
  397. # some data loss consider the default persistence mode that's snapshotting),
      g- I3 V1 b: y4 c( Y
  398. # or on the contrary, use "always" that's very slow but a bit safer than9 ], V) e2 {( E) L( G
  399. # everysec.
    ' p" u1 E6 n4 p1 w( L9 m
  400. #
    / [  a6 c/ E) M4 y+ `5 J4 x
  401. # More details please check the following article:4 y' P) j! O0 ^5 `6 [* D
  402. # http://antirez.com/post/redis-persistence-demystified.html
      \/ F, y, a) z* B' w$ ~3 R
  403. #3 n) k* j- U/ Y5 ^
  404. # If unsure, use "everysec".
    5 }( ^2 l! k+ ~* p; g2 a5 {
  405. % k8 p. A0 B& l8 @+ b6 @8 Q. s
  406. # appendfsync always9 t, [3 J2 I) S. `4 _
  407. appendfsync everysec5 U" w3 H$ P( E. k9 q. J
  408. # appendfsync no: Z- d6 M) K7 k, U7 E
  409. : v- D/ Q# q3 ^
  410. # When the AOF fsync policy is set to always or everysec, and a background
    7 K/ {( g: W9 G9 W: u/ Y
  411. # saving process (a background save or AOF log background rewriting) is. q) w: i& F5 y
  412. # performing a lot of I/O against the disk, in some Linux configurations
    ' a6 X/ Z4 Q9 o1 Z% q2 k
  413. # Redis may block too long on the fsync() call. Note that there is no fix for5 P; E: {$ a' L' U. \* k
  414. # this currently, as even performing fsync in a different thread will block
    ! L7 O& f" G2 M$ R1 T0 I
  415. # our synchronous write(2) call.
    , N9 d- K+ q4 Z3 }7 b0 R, I
  416. #
    & n) c+ k& g+ w
  417. # In order to mitigate this problem it's possible to use the following option
    9 Y$ _3 S* h- S! F
  418. # that will prevent fsync() from being called in the main process while a; \2 C: J) b: G& A% X
  419. # BGSAVE or BGREWRITEAOF is in progress./ D. h" v& U0 H0 S3 ~2 `, l4 M! N
  420. #* d/ _! L7 f9 g& R% E. C6 n
  421. # This means that while another child is saving, the durability of Redis is0 i+ L- [3 |" q( l  x
  422. # the same as "appendfsync none". In practical terms, this means that it is, n6 Q0 M! P5 W6 k, R
  423. # possible to lose up to 30 seconds of log in the worst scenario (with the* m' \4 Y  g) \: ]; M+ ?: ^
  424. # default Linux settings).
    7 K+ o+ C3 F, l3 o: t
  425. # 4 x8 b( R( {$ M/ `2 D' g
  426. # If you have latency problems turn this to "yes". Otherwise leave it as
    2 J8 e8 Q  @( E* P1 |5 x
  427. # "no" that is the safest pick from the point of view of durability.& j0 k+ |- k0 A1 @  _& u
  428. no-appendfsync-on-rewrite no
    - P, x' L& N' i/ g" f2 U
  429. 8 N: @2 P+ ^3 L' l
  430. # Automatic rewrite of the append only file.
    6 t6 N/ M. W9 m* X9 C4 H9 }
  431. # Redis is able to automatically rewrite the log file implicitly calling
      f3 B" y% i$ ]  X0 P2 W
  432. # BGREWRITEAOF when the AOF log size grows by the specified percentage.
    / T7 Z+ z  s- y8 u
  433. #
    0 S9 T4 W7 [# {& V5 g
  434. # This is how it works: Redis remembers the size of the AOF file after the
    " F! k$ D/ o4 m
  435. # latest rewrite (if no rewrite has happened since the restart, the size of
    4 z$ J7 ]9 \5 e, x
  436. # the AOF at startup is used)." q. b1 U$ X2 U# ]9 n7 E1 O7 }, G
  437. #, p9 C" U3 C# g% v+ j: R
  438. # This base size is compared to the current size. If the current size is
    " z& e3 f0 M; }8 B% x* V
  439. # bigger than the specified percentage, the rewrite is triggered. Also
    9 o  ~% f) @' E
  440. # you need to specify a minimal size for the AOF file to be rewritten, this5 p3 O, \) E% }8 ~+ @7 k
  441. # is useful to avoid rewriting the AOF file even if the percentage increase
    % O! Z5 g/ p' Z0 w; H
  442. # is reached but it is still pretty small." L7 E2 n, O: G# |$ o. d
  443. #
    + N8 o- [# n! g% u! J
  444. # Specify a percentage of zero in order to disable the automatic AOF
    # w/ U5 L1 N4 }' l
  445. # rewrite feature.! [  C! t" `# T0 o
  446. " i, U, N: q( c% U
  447. auto-aof-rewrite-percentage 1007 t& ?! J: b8 ^2 v/ S2 m6 J6 }
  448. auto-aof-rewrite-min-size 64mb! x2 ^$ ~- ?8 B$ ?

  449. 1 r4 n- F& N8 p' J! f; G
  450. ################################ LUA SCRIPTING  ###############################
    / Y. i) q3 J/ \9 @+ D& y3 w
  451. . V# f' ~6 a" m
  452. # Max execution time of a Lua script in milliseconds./ `3 l- v6 t2 v0 Q2 a+ B
  453. #
    ) a; S) Q7 z9 M
  454. # If the maximum execution time is reached Redis will log that a script is
    / L$ ?1 |% \7 J1 o# K
  455. # still in execution after the maximum allowed time and will start to2 N. L* {% F2 m
  456. # reply to queries with an error.
    0 P, \' {: R6 {& G# w
  457. #
    1 I. |5 L$ ~' y: a% ^2 W
  458. # When a long running script exceed the maximum execution time only the( b0 J9 r. N* M5 |' Q; X
  459. # SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be
    * o$ e" x4 m+ C# a4 ^3 Q
  460. # used to stop a script that did not yet called write commands. The second
      N( G- d& ]+ J* b( ?6 X# i" B
  461. # is the only way to shut down the server in the case a write commands was
    3 d& f9 Z8 g# g0 Y. i- s5 ^0 d
  462. # already issue by the script but the user don't want to wait for the natural  {2 v) D: Y9 V% @2 U+ i+ x
  463. # termination of the script.
    : @4 _* ^. c* Q
  464. #
    " B8 b# h  O  |. b( q$ `1 @% G
  465. # Set it to 0 or a negative value for unlimited execution without warnings.* l, s# u0 [; k" M. E% R
  466. lua-time-limit 5000' r9 b7 [6 X, r; M: l- X# d
  467. 1 @7 \9 [2 Y+ U+ s- _
  468. ################################## SLOW LOG #################################### F7 w! Y& w6 Q# V' f5 U6 N" d

  469.   r* ]/ r9 W- r$ z) O! f5 E! l
  470. # The Redis Slow Log is a system to log queries that exceeded a specified
      w: K( S  Y1 N: e, b* w% S' S0 m' K7 K
  471. # execution time. The execution time does not include the I/O operations
    ; S' _+ I8 y% f5 d/ I
  472. # like talking with the client, sending the reply and so forth,
    0 A; s% r2 I! I" l2 B! ^# D% X
  473. # but just the time needed to actually execute the command (this is the only
    4 S7 ?0 }( S% j+ e4 X2 Z9 ~# [% P  U
  474. # stage of command execution where the thread is blocked and can not serve' i) U6 ~2 a. s, c
  475. # other requests in the meantime).
    ( i& X2 G1 v! s* J
  476. #
    1 v; g2 o( s: I  E9 r
  477. # You can configure the slow log with two parameters: one tells Redis
    " ~! O2 S1 B, E
  478. # what is the execution time, in microseconds, to exceed in order for the
    # a2 Z4 I- j2 R9 Z3 N, T
  479. # command to get logged, and the other parameter is the length of the$ D" U4 C) {/ `0 _
  480. # slow log. When a new command is logged the oldest one is removed from the0 M% A0 l( B& r4 i( Z0 d6 `1 U
  481. # queue of logged commands." B/ ~1 B9 D6 `! [/ N& p

  482. 5 W0 O" T1 w" S
  483. # The following time is expressed in microseconds, so 1000000 is equivalent
    - V, H; `+ q! \
  484. # to one second. Note that a negative number disables the slow log, while
    8 X/ p# V% x5 @. }5 v  u# `
  485. # a value of zero forces the logging of every command.8 x# R* [: q: R1 R3 D
  486. slowlog-log-slower-than 10000, C+ z, ]+ r! p, y, f

  487. ! X+ q9 M* Y9 d& ^  q) v2 W
  488. # There is no limit to this length. Just be aware that it will consume memory.
    + o. H; v9 x0 C/ @* C
  489. # You can reclaim memory used by the slow log with SLOWLOG RESET.  T+ i( F% J7 p; p
  490. slowlog-max-len 128
    # u" n$ z* a" L/ ^/ f6 h
  491. , h$ E- {" B# A2 j2 t) E. A. {6 j
  492. ############################### ADVANCED CONFIG ###############################$ @8 P; g0 s& R$ F
  493. ; s8 e; b/ F& X2 S
  494. # Hashes are encoded using a memory efficient data structure when they have a2 f1 n% ^  d1 w" m7 Q
  495. # small number of entries, and the biggest entry does not exceed a given
    ! J" x2 b, a6 o
  496. # threshold. These thresholds can be configured using the following directives., v1 N4 R9 O; E" ^) |2 j8 v
  497. hash-max-ziplist-entries 5121 \# n9 ~% W  W! Q  x
  498. hash-max-ziplist-value 64) G# x/ H9 R7 N4 o( V

  499. 7 Q  G9 b7 x; r$ e
  500. # Similarly to hashes, small lists are also encoded in a special way in order0 K, m* n9 J: j2 L% `" H9 W. |. X
  501. # to save a lot of space. The special representation is only used when
    6 }2 j6 c8 b4 q1 C3 v
  502. # you are under the following limits:- U1 J0 k) x5 {' O
  503. list-max-ziplist-entries 512
      w0 L$ o3 f5 e
  504. list-max-ziplist-value 64+ ~/ ~* A) s2 ^$ F( [7 N+ ~7 e- N
  505. 4 C7 C% a) E. @6 Z
  506. # Sets have a special encoding in just one case: when a set is composed
    6 |7 w4 |5 y  K+ |
  507. # of just strings that happens to be integers in radix 10 in the range8 P4 l& q% q- |3 ~5 N% k
  508. # of 64 bit signed integers.# t8 A8 e0 _( l/ C  G# q) c( s
  509. # The following configuration setting sets the limit in the size of the
      k# |3 x1 u# P" H- B, h
  510. # set in order to use this special memory saving encoding.
    - K- M: X. H* x0 a8 d/ }
  511. set-max-intset-entries 512( ^* l6 s) A' U) ?

  512. 7 _4 ?5 A4 `2 T  r; S
  513. # Similarly to hashes and lists, sorted sets are also specially encoded in
    5 ?* W; A* |- x% ^$ b; k2 z. |. Y
  514. # order to save a lot of space. This encoding is only used when the length and
    6 e* B4 C2 w: L* S, ?
  515. # elements of a sorted set are below the following limits:
    ) C8 r& d4 V3 B6 P
  516. zset-max-ziplist-entries 128
      u. S  n3 h* V3 N
  517. zset-max-ziplist-value 64
      q; A5 o. ~/ x3 P- _- y
  518. ) K3 w8 w7 |5 N3 Q0 S
  519. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
    1 ^' b% Y  }* _( H
  520. # order to help rehashing the main Redis hash table (the one mapping top-level& p( ]# f0 p7 G! ]. p
  521. # keys to values). The hash table implementation Redis uses (see dict.c): X% b- d; D' |3 f9 E- g
  522. # performs a lazy rehashing: the more operation you run into an hash table
    + d+ ?# {" L( R* D
  523. # that is rehashing, the more rehashing "steps" are performed, so if the+ P7 S+ }' N4 w, V) W1 D6 f
  524. # server is idle the rehashing is never complete and some more memory is used1 Y: T+ Q* g2 ]- Y! i$ z
  525. # by the hash table.
    $ z" M9 Q- p: V( c. u
  526. #
    8 |' o6 g& N, e: \
  527. # The default is to use this millisecond 10 times every second in order to
    * c; ^2 }9 e5 D4 f# r
  528. # active rehashing the main dictionaries, freeing memory when possible.
    7 o8 L8 U3 k$ z
  529. #
    ) ?: a/ ^) G* F# L
  530. # If unsure:% z( i" U2 J. M
  531. # use "activerehashing no" if you have hard latency requirements and it is
    + p$ T3 s$ `& n9 ]1 N
  532. # not a good thing in your environment that Redis can reply form time to time
    4 M/ i( l$ X& w- I
  533. # to queries with 2 milliseconds delay.0 K9 X& G0 {- ^0 ^5 G# Q
  534. #
    % J8 X2 |* S! {# h# G) [( U' d
  535. # use "activerehashing yes" if you don't have such hard requirements but+ {/ W2 T& n  j) V3 g! [8 s
  536. # want to free memory asap when possible.
    - I$ O2 `" }' `  a% }# q3 {
  537. activerehashing yes1 h, d" I3 T& K  i: N! @
  538. 4 r7 P0 S* P1 H/ t  V+ ]- I, E
  539. # The client output buffer limits can be used to force disconnection of clients* a1 v/ M2 d' h- L) M4 [% d1 n
  540. # that are not reading data from the server fast enough for some reason (a: k8 d2 j; T: A* g. \
  541. # common reason is that a Pub/Sub client can't consume messages as fast as the9 s, G2 _/ I0 `+ [
  542. # publisher can produce them).
    - ^# M0 u8 G8 k) p/ z; g7 |% ?+ C# X
  543. #
    ! k& O4 R8 y7 R3 Q
  544. # The limit can be set differently for the three different classes of clients:
    ; G+ B1 r' k( g: x
  545. #% v8 K. h4 f% B3 e3 @9 y
  546. # normal -> normal clients
    " F% _' a. ?6 t! T
  547. # slave  -> slave clients and MONITOR clients
    $ W( P3 m  y5 v. a5 i. K: l+ m
  548. # pubsub -> clients subcribed to at least one pubsub channel or pattern
    / X% P" `% h; U0 b9 M
  549. #
    9 G8 J* `1 i1 }4 R2 t' v8 ^( h
  550. # The syntax of every client-output-buffer-limit directive is the following:
    4 @  W4 y1 g+ J/ x& G# d
  551. #
    0 X  i0 m" i" W
  552. # client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>/ G$ u. ]3 ^" a- U+ y7 o8 s& w8 X
  553. #
    2 |; x. n2 p: L/ `
  554. # A client is immediately disconnected once the hard limit is reached, or if
    6 m/ r! O. f& |! M+ U" t
  555. # the soft limit is reached and remains reached for the specified number of
    ! j0 ~: W& H* |, O& Z* I$ i
  556. # seconds (continuously).# S+ ~0 O2 U$ X5 D
  557. # So for instance if the hard limit is 32 megabytes and the soft limit is8 T+ |; b/ k6 O% a. {. X0 x
  558. # 16 megabytes / 10 seconds, the client will get disconnected immediately
    4 v! s2 K* w6 W# G* Q) ^9 P
  559. # if the size of the output buffers reach 32 megabytes, but will also get
    6 C! m: X8 {/ l/ c  {* R, i4 }+ ]! _
  560. # disconnected if the client reaches 16 megabytes and continuously overcomes
    - @8 n- M* e& \9 J! T
  561. # the limit for 10 seconds.3 }* j2 p/ z$ [
  562. #
    0 T& r: L( F% G4 U6 ~
  563. # By default normal clients are not limited because they don't receive data
    ) d( T5 c7 Y# G% [( x/ z* M' x5 s
  564. # without asking (in a push way), but just after a request, so only; o+ s; o! ~# @. A; V' b4 e! ~
  565. # asynchronous clients may create a scenario where data is requested faster' @. K% I! H" A: g6 f
  566. # than it can read.
    ; B2 R9 g( ^7 E. Z8 a
  567. #
    ; c" c8 x5 h, @* e
  568. # Instead there is a default limit for pubsub and slave clients, since
    7 e# ^2 g: H" b
  569. # subscribers and slaves receive data in a push fashion.
    - X( [) u, `8 t: t
  570. #1 U2 u( @' c3 H; {4 _
  571. # Both the hard or the soft limit can be disabled by setting them to zero.
    ) |+ x- B, D$ d3 y3 ~% \
  572. client-output-buffer-limit normal 0 0 0, V0 k  R2 P. }/ n0 o6 a
  573. client-output-buffer-limit slave 256mb 64mb 608 ?) r$ M8 E  u, z9 X! [
  574. client-output-buffer-limit pubsub 32mb 8mb 60  K- K$ \2 ]% w  K  Z! u
  575. 6 j( C7 S8 w; G9 C5 p0 O
  576. ################################## INCLUDES ###################################( s; s4 `; \: `: k9 P1 a

  577. 0 D6 |7 s* R  a# f- [+ M. B
  578. # Include one or more other config files here.  This is useful if you0 ?" M; L/ K9 a: v: {
  579. # have a standard template that goes to all Redis server but also need6 r5 D* K# P4 R" z/ @  Q! P! r
  580. # to customize a few per-server settings.  Include files can include$ [+ L5 r. D: N
  581. # other files, so use this wisely.! t/ M9 q" o3 h3 A8 c5 n
  582. #0 B. e+ Z. v% t( |& K+ v* j) t
  583. # include /path/to/local.conf
    ; V( j* q, x+ E% a7 Z! _
  584. # include /path/to/other.conf        4 d0 M/ v! m1 a2 o
  585. ##########################配置文件结束################################ 8 ?3 r: J; `) K4 p# B$ F* U
  586. 第三步:启动进程$ M1 I5 H9 i3 ~3 `) o
  587. #redis-server /etc/redis.conf; W7 F8 A, m6 \4 ~5 u: R* r- J- P
  588. 查看进程有没有成功启动5 d* m5 D$ [: ~6 E1 k# \
  589. #ps -ef | grep redis
      p" z" X; n2 q& E
  590. 测试输入一个键值
    " r$ z; p& y2 F
  591. #redis-cli set test "testredis"
    / }  {+ H2 z+ u
  592. 获取键值2 ?& a( `; z+ Q" Y
  593. #redis-cli get test
    / v& _, z) u  z2 E8 o0 R- F
  594. 8 `+ G  H- ~% T
  595. % n' E: F' V5 `5 s$ e
  596. 第四步:关闭redis  (这个是更改配置文件后 正常的重启方式  不重新加载redis配置跳过)6 B) b" c, K) ^5 y8 A1 w
  597. # redis-cli shutdown      //关闭所有    $ p9 d5 R4 `% S. b( h
  598. 关闭某个端口上的redis   
    4 s, I+ K3 Q! ?6 |  X+ B
  599. # redis-cli -p 6397 shutdown  //关闭6397端口的redis  
    5 ]7 C8 d7 a5 A2 T
  600. 说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename  dump.rdb  ; B" E" R% `. e/ c6 U1 ~8 H

  601. + V0 Z5 f+ i/ s1 g
  602. 9 L+ v* |# R* Q! ~7 |+ ?) }
  603. 第5步:php扩展安装
    / m  K$ k- k5 `
  604. phpredis PHP扩展下载地址 7 L, `* _. W+ _. n- h4 `. z# \' _
  605. https://github.com/nicolasff/phpredis/tree/2.2.2
    " x6 t1 L9 k! x3 {" i6 R) Y- k
  606. 选择最新版本下载zip # O' N! z, h3 c

  607. & @" e  v  h4 `* e; H+ R
  608. 然后自己上传zip  用unzip解压到当前目录 unzip 文件名1 Q' [4 z) j+ ~1 k# f' H

  609. 4 a# K  @0 y& Y6 T+ f8 {
  610. # cd owlient-phpredis-90ecd17/   #打开解压后的文件夹里面  这个解压后的目录 要是不知道 可以输入 "dir" 查看
    : `% h6 B! e1 u3 R; j$ q* Y5 e5 R2 x
  611. # /www/nginx_php-5.2.17/bin 9 T- b: r, r& I
  612. # ./configure --with-php-config=/www/nginx_php-5.2.17/bin/php-config/ k0 e& w' Q  ?& _/ Q
  613. #make' k% b3 @/ {3 y+ Q" o
  614. #make install   #记录产生的redis.so路径
    / r, P! Z' p; q+ r
  615. 5 b& ?) M3 [" X$ y! u( c0 ^! m
  616. 修改php.ini文件: a+ F( m9 E3 A; _0 ?! `8 A- G
  617. 在php.ini中添加如下一行:
    7 \; @- S6 R7 O: i: S+ _. O
  618. extension=/?/redis.so  #是刚刚记录的产生redis.so的路 写在 ?那% J0 k8 j) p) w  r
  619. 重启 使之生效:
    ; E7 e) \+ r, F9 L( e6 @2 p; s
  620. /usr/local/php/sbin/php-fpm reload1 g8 i9 r4 d, P5 r0 ]! i7 ~
  621. /usr/local/nginx/sbin/nginx -s reload
    1 m5 v+ {* w3 @; }0 I: }: @. N

  622. 6 H" M7 D' s! n+ t5 d+ O1 C7 A
  623. 将 Redis 作为 Linux 服务随机启动7 W# z' X" b6 f: i
  624. vi /etc/rc.local, 加入代码:
    6 J" ^$ d% C2 I8 e: a4 J' C7 f5 x, K( q
  625. /root/redis-2.6.10/src/redis-serve  #路径看情况修改
    2 f7 o7 f/ _8 z- B7 m# N- X3 `
  626. * I6 ]. g8 y& D* \3 P; I' b
  627. redis-cli -h localhost -p 6379 info  #命令要在redis目录下面执行1 d( O" ]- w/ I0 S
  628. 提供host为localhost,端口为6379,redis服务的统计信息( Y6 @# ]5 z# G" b: M5 i
  629. ! C( x4 T9 L- I6 P4 @# y7 ]3 @) \: e% `

  630. $ l, y( z) F5 R  X5 q' m0 P
  631. 就这样你的web服务器就支持redis了 记得要在 给dz 的配置文件 加上12.0.0.1哦
    3 B9 T/ N2 m- U. y7 I
  632. dz配置文件在 config目录下面的 config_global.php
    - G* x3 |* l  y6 l7 _% W
  633. $_config['memory']['redis']['server'] = '127.0.0.1';3 i/ s5 M5 j8 L- I# J# z
  634. $_config['memory']['redis']['port'] = 6379;8 u- k+ x0 I! ?
  635. $_config['memory']['redis']['pconnect'] = 1;
    ; M7 Q# m# @% c( L; Y2 q" o
  636. $_config['memory']['redis']['timeout'] = '0';& m: @* E+ y: L4 l4 o0 q+ [7 O* M
  637. $_config['memory']['redis']['serializer'] = 1;; `( [. ~8 N3 i( A
复制代码
关注微信公众号《神采飞扬网》,即可获取最新回复通知!

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

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

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

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

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