分享到:
发表于 2018-11-16 12:42:28 | 显示全部楼层 |阅读模式
环境配置. F6 k- W, |- `) O4 |  E

7 E" |1 C- }# M( k
$ r! P+ S: w6 a. q6 _: Vhttp://www.discuz.net/forum.php? ... amp;highlight=REDIS
关注微信公众号《神采飞扬网》,即可获取最新回复通知!
 楼主| 发表于 2018-11-16 12:43:33 | 显示全部楼层
http://www.discuz.net/forum.php? ... 648&highlight=REDIS: s" K5 a2 d3 y. J! Q
无意间测试 单机状态 redis相当给力 测试1000请求/s  单纯的 get 和set 居然只用了 0.01秒 当时我惊呆了. a* [4 [8 J9 f% T- p
# U+ Q+ J7 d5 z9 @" O
http://www.discuz.net/forum.php? ... 731&highlight=REDIS5 u  S2 L- S: J' v' w7 y- U7 U4 k

* I' g$ Q+ q0 T" R/ p7 O" s6 thttps://wenku.baidu.com/view/265a5ce176a20029bc642d0b.html& n" f4 |$ F/ L
, m. v" e# u) t8 i- e
=======================================# \4 a) j3 f  g, p2 f# g4 s
  1. 连接上 ssh
    ' o1 H% g4 ]+ L  Z

  2. - R" [- ^; Z  m7 I, v+ F+ ?
  3. & b3 s$ c* B2 R/ T- V) P6 j: @. \
  4. 第一步:下载redis
    * m: M: }" ?! V: S
  5. # wget http://redis.googlecode.com/files/redis-2.6.10.tar.gz: U! b$ w( i  l! p9 g
  6. # tar zxvf redis-2.6.10.tar.gz
    $ j- X# h: z+ D0 F: M
  7. # cd redis-2.6.10% e3 o8 V! h1 \
  8. # make 8 Q* R; i. s! n) P! _+ d9 i& F
  9. # make install  1 Z, ^9 \/ _% `0 n* ~) p
  10. #cp redis.conf  /etc/ #复制配置文件到etc目录下面) P# S1 q2 e' K- v2 n1 }
  11. 第二步:修改配置
    ; j: Y' n4 U0 A! _! {( R  V
  12. #vi /etc/redis.conf' w- E5 Z+ S1 F" o8 I
  13. ######################下面是无措的配置文件 复制过去就成#########
    4 }( @3 Y' R, p" m' a
  14. # Redis configuration file example& S( \! e& p6 n. b# O* C  ?
  15. % D) Y% @' [5 }6 S- c; U
  16. # Note on units: when memory size is needed, it is possible to specify& B$ D5 K  V7 W5 _$ S
  17. # it in the usual form of 1k 5GB 4M and so forth:1 f8 Q# J7 k% Y6 k& R2 k$ S
  18. #, F# @, G% d9 t4 F2 t# @
  19. # 1k => 1000 bytes" V1 K' Z) A; U7 o
  20. # 1kb => 1024 bytes7 X/ Z' f  D* A% \. p" w
  21. # 1m => 1000000 bytes, I, Q. T7 {, A0 e; ~. j
  22. # 1mb => 1024*1024 bytes
    ( y. o! M1 M% D
  23. # 1g => 1000000000 bytes* \( w" a6 P$ ], N  {% _
  24. # 1gb => 1024*1024*1024 bytes
      y5 O3 I; o- W- \) s. U& ?7 S
  25. #7 Q% {9 T8 N( [8 ]+ K( w, \
  26. # units are case insensitive so 1GB 1Gb 1gB are all the same.
    8 I- P" `8 Y4 A3 O& z
  27. + t! i# l" L: e- k) U
  28. # By default Redis does not run as a daemon. Use 'yes' if you need it./ x- ~5 B( }% {7 j" ~
  29. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
    , o( C! r" d" v9 @
  30. daemonize yes
    & [. L- x% N0 v, z5 _
  31. 6 B* S4 R) G- s$ q4 Z, m% F  j6 |
  32. # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
    8 b1 u9 R# v, L) z0 _
  33. # default. You can specify a custom pid file location here.
    7 }5 ?: T0 }+ g/ K
  34. pidfile /var/run/redis.pid4 B: z3 x6 }  o7 Q4 m

  35. # d. k$ N; ^9 ]$ B3 O: A0 ?
  36. # Accept connections on the specified port, default is 6379.- Q% ?2 L0 y/ j5 e
  37. # If port 0 is specified Redis will not listen on a TCP socket.* v( x  P; |0 x% Y% x+ G
  38. port 6379
    * e- b: |4 L6 W8 Z. y
  39. % u* ]% X. q& ^
  40. # If you want you can bind a single interface, if the bind option is not+ ?* ?! M  z& [$ f$ F* C
  41. # specified all the interfaces will listen for incoming connections.  x5 S5 [( I! v) N$ Z
  42. #
    % _3 E9 K1 l. e8 a$ K$ i. k2 l
  43. # bind 127.0.0.1
    $ c* O9 c9 W; P) C! e1 V! @8 y& G
  44. : I+ i" k& N5 n4 }* L
  45. # Specify the path for the unix socket that will be used to listen for
    # s3 k6 a4 c. s
  46. # incoming connections. There is no default, so Redis will not listen' d. @" V3 M& \, J6 j* p8 P
  47. # on a unix socket when not specified.
    3 Q; P+ q) T' l! E* m
  48. #$ B6 T& U3 F/ c
  49. # unixsocket /tmp/redis.sock0 v( ^3 E: C* D3 g2 `, N1 i% O
  50. # unixsocketperm 7550 z: n6 J) m) V4 W' h# h
  51. , E0 Y: r$ @2 M; L& {  I
  52. # Close the connection after a client is idle for N seconds (0 to disable)) M+ Y! Y+ ~" G
  53. timeout 300
    " B; H; @8 z) r7 [8 V
  54. 4 R7 C6 G4 j( P4 ~
  55. # TCP keepalive.& y2 Z; y! f$ p( v
  56. #( L/ q( F+ y) V  Q/ W, U
  57. # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence  {) Y: i0 x9 `0 w$ |& a
  58. # of communication. This is useful for two reasons:' b" r' E8 V( c, J3 ]  X
  59. #
    % [2 c% c3 \( N) a7 }, \
  60. # 1) Detect dead peers.
    ! _% j, Y2 A7 w# {. f
  61. # 2) Take the connection alive from the point of view of network
    - ~5 ~) c; c: u; I3 P& R
  62. #    equipment in the middle.
    % o# h7 y% R- s
  63. #
    3 |) T3 c# p& O* [1 e
  64. # On Linux, the specified value (in seconds) is the period used to send ACKs.3 {1 L% N* ^6 E9 j' \. H
  65. # Note that to close the connection the double of the time is needed./ L; `* T$ U& Q1 \2 v" W
  66. # On other kernels the period depends on the kernel configuration.
    3 }. J$ A* g/ u: _5 K; f
  67. #
    4 Q1 W8 N. [9 p: d4 ?
  68. # A reasonable value for this option is 60 seconds.# S$ @' i/ N% W, |5 h6 A
  69. tcp-keepalive 0( y& n* p" b& G1 e0 h8 h* v$ ^! u! D
  70. / ~% x# J" K% \4 W) }
  71. # Specify the server verbosity level.. j. f! W2 o" v- W; s
  72. # This can be one of:% d2 H7 Y8 D1 S4 {5 Q
  73. # debug (a lot of information, useful for development/testing)  t9 S- _: U+ M$ |1 J3 @) ?! X  G3 y
  74. # verbose (many rarely useful info, but not a mess like the debug level)& q# n' j( Z* P% Z
  75. # notice (moderately verbose, what you want in production probably)& I0 c/ y) q" x0 u
  76. # warning (only very important / critical messages are logged)  J+ t" E5 e2 j6 X
  77. loglevel warning
    7 t5 x$ [* j  x4 q
  78. , Y  N- J: L, s2 z
  79. # Specify the log file name. Also 'stdout' can be used to force
    # a# D! X9 T' V; N6 D# X# I
  80. # Redis to log on the standard output. Note that if you use standard1 {, G2 s  t+ x6 _
  81. # output for logging but daemonize, logs will be sent to /dev/null) m4 ^; h6 B: Y! g! [4 z+ `3 I
  82. logfile /var/log/redis.log4 S6 N' }5 z5 g
  83. ! t9 N1 W) Q1 @; ~8 Y2 r: `5 J
  84. # To enable logging to the system logger, just set 'syslog-enabled' to yes,  F0 |$ i0 U2 K  R
  85. # and optionally update the other syslog parameters to suit your needs.2 B- M1 [0 B/ Q# h  s
  86. syslog-enabled yes
    2 e( W3 S) L5 Z' z( e$ S
  87. 8 @7 f- y: f1 Q
  88. # Specify the syslog identity.
    5 b; c$ V2 c& q0 z, {' D0 v% l
  89. # syslog-ident redis  s8 x: _0 p( K' ^1 v9 i
  90. ) L, K$ Q! ~% H
  91. # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
    ) H  p2 V- ~! |+ r1 \6 ]
  92. syslog-facility local0, N, J; t$ J2 U  ~3 N4 S2 Z

  93. - Z: A0 k8 v8 ?1 _" N; P# O0 {
  94. # Set the number of databases. The default database is DB 0, you can select+ q. Y) ?0 a  Q0 O
  95. # a different one on a per-connection basis using SELECT <dbid> where9 G4 |, V. J/ i1 I; d) ?
  96. # dbid is a number between 0 and 'databases'-1
    & g/ @; Q) K% h
  97. databases 16( x7 f. E+ Y8 w, R

  98. 3 e+ h: v* }9 j  m8 ~' j# {2 g
  99. ################################ SNAPSHOTTING  #################################; [7 j3 J! f6 k. G" s- Q
  100. #' ~  r  B3 v& K- R
  101. # Save the DB on disk:
    : v/ k$ M  I- R4 p
  102. #
    % }* t  a4 n# Q9 e& M
  103. #   save <seconds> <changes>. c. p: s) F! ~8 S- H
  104. #
    3 D) T! N7 o! W, r
  105. #   Will save the DB if both the given number of seconds and the given2 j. `6 j7 Q. l0 y) @" C7 K
  106. #   number of write operations against the DB occurred.
    3 Q. d( i7 k$ I/ [
  107. #
    " h9 F! F2 N, _- K
  108. #   In the example below the behaviour will be to save:  _# H' P+ k$ d2 u
  109. #   after 900 sec (15 min) if at least 1 key changed
    ) U5 q; _2 |4 v+ ?
  110. #   after 300 sec (5 min) if at least 10 keys changed% Z7 q$ o* I2 u7 a8 j
  111. #   after 60 sec if at least 10000 keys changed+ b; a4 r' v7 l( j6 S# ?
  112. #: W+ i1 _0 }5 n9 V
  113. #   Note: you can disable saving at all commenting all the "save" lines.
    / \* ?0 A8 Y5 i7 l2 O4 Q: a
  114. #
    ) ]# y& o/ H7 ^7 ?. g; l2 c) U6 X, H
  115. #   It is also possible to remove all the previously configured save6 W! }8 C/ ^9 _; k5 b& z
  116. #   points by adding a save directive with a single empty string argument
    4 @  G7 a3 V" v7 \; {2 M
  117. #   like in the following example:; l/ h3 q3 q* d$ K) g8 |8 w
  118. #1 _' h+ w% k& `3 S- x" n( d, b  C; f
  119. #   save ""& r+ F" N" p9 L5 C0 I
  120. % x9 n0 H$ b% r% L& U, g
  121. save 900 1# v& L8 D5 R( m7 H
  122. save 300 108 f+ i! n% i1 Z6 |* Z
  123. save 60 10000& W/ ?% t- m( i4 W2 T4 ?

  124.   D; i; n+ @) y1 G' q' z9 [
  125. # By default Redis will stop accepting writes if RDB snapshots are enabled
    % ~% l) T" a) \8 W% g: `6 M9 }
  126. # (at least one save point) and the latest background save failed.
    , N) w" G1 j5 a# l1 b) z8 ?# ]
  127. # This will make the user aware (in an hard way) that data is not persisting
    # A6 Y* {0 ?3 [4 s, m% {& Z/ g: U
  128. # on disk properly, otherwise chances are that no one will notice and some6 @  A9 N( L# W' Y. @
  129. # distater will happen.
    5 I4 l9 v6 q) h6 I9 }: w: o
  130. #' G  @  a5 z8 a
  131. # If the background saving process will start working again Redis will
    % c$ L/ c) ^" j, h" m+ p  v3 }5 L
  132. # automatically allow writes again.
    $ n6 y4 U7 p. w* W6 e3 [
  133. #; ]( F/ P1 d$ B% J' \& m
  134. # However if you have setup your proper monitoring of the Redis server
    # ?0 [  Y9 l& \
  135. # and persistence, you may want to disable this feature so that Redis will2 W/ _3 ~. E! C" f5 m: E. q( g" V% [
  136. # continue to work as usually even if there are problems with disk,
    6 z) _. c2 _, |3 e
  137. # permissions, and so forth.7 \/ ]& j- C9 n9 {7 Y; W# y$ x
  138. stop-writes-on-bgsave-error yes
    " [5 `" P$ M+ z- b/ Z  W( }

  139. 9 ?6 w) N7 S, U5 \5 F. Z+ ~5 p! S0 R  p
  140. # Compress string objects using LZF when dump .rdb databases?% M: [. X0 H6 H: k, t
  141. # For default that's set to 'yes' as it's almost always a win.
    ) v3 L1 N& R; d
  142. # If you want to save some CPU in the saving child set it to 'no' but
    0 a; c' |: s% G2 G2 a) Z$ C
  143. # the dataset will likely be bigger if you have compressible values or keys.
    0 o7 \  ?- T5 n/ z9 w5 O
  144. rdbcompression yes
    . n5 e5 T1 Y7 _3 x

  145. / a6 X8 T' M5 Q
  146. # Since version 5 of RDB a CRC64 checksum is placed at the end of the file./ h$ G( w5 T; k; T+ X
  147. # This makes the format more resistant to corruption but there is a performance) u4 ?% W: O# a6 p  y: i, S
  148. # hit to pay (around 10%) when saving and loading RDB files, so you can disable it
    ( g7 x5 f7 i5 u1 |4 S% s% @1 N
  149. # for maximum performances.
    : t* m4 ]8 {$ g2 G) M
  150. #
    1 D) Z& h% `# o8 W- d
  151. # RDB files created with checksum disabled have a checksum of zero that will* u* S: y& g) q
  152. # tell the loading code to skip the check.
    0 Q  n2 |2 s, i! E) p
  153. rdbchecksum yes" C" k2 ]' y. D: h
  154. 9 i% x4 m2 Y( a( [: p+ S: e* O$ S
  155. # The filename where to dump the DB
    ! O. G. V2 R0 |3 E2 z, m2 q: g
  156. dbfilename dump.rdb
    * i6 g# D% e2 y9 O# L" i$ W
  157. ( g; u# f- F6 P5 ]5 C
  158. # The working directory.
    " |$ m+ n& s) _
  159. #
    ( @+ m; Y% C' Y1 x$ T+ X! q* S! V! h
  160. # The DB will be written inside this directory, with the filename specified1 l" E( C* b! @" b* W5 s* t8 D. e
  161. # above using the 'dbfilename' configuration directive.
    / H6 U' O9 Z6 N7 A
  162. # : s# s1 c, A# ]. m  D! N
  163. # The Append Only File will also be created inside this directory.) S4 Z1 g# Z* D2 A2 I6 J) d! ]
  164. #
    7 b% ?/ u; o5 f
  165. # Note that you must specify a directory here, not a file name.& Y. |+ i2 c5 q7 I1 ~
  166. dir /var/db/redis! b' {$ u9 e, s1 h0 v1 y
  167. & z# P' u! v( n2 C& D+ s; v
  168. ################################# REPLICATION #################################
    . M; U, h9 S; K) m7 E& v! J) e3 W
  169. " g6 l5 K' a6 O; _7 I1 u6 ?
  170. # Master-Slave replication. Use slaveof to make a Redis instance a copy of
    : G9 }7 y9 x. ~' W2 J8 {/ B
  171. # another Redis server. Note that the configuration is local to the slave! Z# X' W+ t* X
  172. # so for example it is possible to configure the slave to save the DB with a, N0 G% z: p9 |
  173. # different interval, or to listen to another port, and so on.% B; F$ F  [5 f
  174. #
    & C% [. f' O+ m& R" ?. P1 {* M! p. J
  175. # slaveof <masterip> <masterport>
    9 x% y4 _$ ~& V. Z  h' s( l
  176. 7 Q/ G3 m4 c) N9 Y' a' z
  177. # If the master is password protected (using the "requirepass" configuration+ m4 M- D  \& f! _6 g' m* Y& b
  178. # directive below) it is possible to tell the slave to authenticate before
    : i: o% r% w  F% A6 ^+ v, q
  179. # starting the replication synchronization process, otherwise the master will
    & I5 I8 @0 K0 q' K5 p: j
  180. # refuse the slave request.! U) L6 t, e4 _9 u+ n% ~
  181. #& ]* C& ~# a& X7 L/ y$ C  U
  182. # masterauth <master-password>1 U" c: k: }, x8 @3 I, b6 S# L

  183. ' V/ v+ ]! P; ~0 A/ Z1 y+ Z
  184. # When a slave loses its connection with the master, or when the replication* O1 `, m  Q4 |6 k5 ?: z9 x
  185. # is still in progress, the slave can act in two different ways:% P& V3 h: q$ n8 b  m
  186. #1 `$ q, B9 i8 C$ G8 L: A
  187. # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will. B: F6 T+ O- t
  188. #    still reply to client requests, possibly with out of date data, or the
    ( \; y7 H2 b  l. }
  189. #    data set may just be empty if this is the first synchronization.5 L, ~3 ?6 g+ {9 d; M, L2 `
  190. #% Q( [# ]: b( j$ `
  191. # 2) if slave-serve-stale data is set to 'no' the slave will reply with  d  L" A7 ], H* ^8 }
  192. #    an error "SYNC with master in progress" to all the kind of commands
    . ?6 T6 D0 I8 f
  193. #    but to INFO and SLAVEOF.% X( M" P2 V: Y6 D" H4 y
  194. #
    7 u- @& x  h' s5 [- U4 ^5 r
  195. slave-serve-stale-data yes
    2 E  Y2 q" L- |0 G! X0 y& }8 I3 D7 ?3 W
  196. 4 w4 \4 V+ n/ X, q6 E' l' ^
  197. # You can configure a slave instance to accept writes or not. Writing against6 m  E* z4 k0 `; `2 R" f( `, C
  198. # a slave instance may be useful to store some ephemeral data (because data
    % s- j) H3 C) D/ M
  199. # written on a slave will be easily deleted after resync with the master) but7 x4 m  O9 i- j0 H$ X' Q$ x
  200. # may also cause problems if clients are writing to it because of a/ U( z; @4 X+ d& M
  201. # misconfiguration.
    # \0 Y9 g  H; ~! ~; e* l9 S
  202. #* D; r& H5 Z9 M* r
  203. # Since Redis 2.6 by default slaves are read-only./ d: _) B: J1 R% r
  204. #
    3 }7 o& b4 n' W( U; e
  205. # Note: read only slaves are not designed to be exposed to untrusted clients
    ) ?7 R5 v' X! o' f0 W% b6 I/ V8 Z
  206. # on the internet. It's just a protection layer against misuse of the instance.
    9 ~* j+ U  `) W& R
  207. # Still a read only slave exports by default all the administrative commands  _2 k, j1 j7 x7 I
  208. # such as CONFIG, DEBUG, and so forth. To a limited extend you can improve- `, x* G: ~4 y  u3 |, i
  209. # security of read only slaves using 'rename-command' to shadow all the* j3 R; z3 `; h0 x; e! }
  210. # administrative / dangerous commands.0 Q! m$ u2 w) l# R
  211. slave-read-only yes
    9 G$ ]4 e1 M& Z4 E7 U2 \8 V
  212. ( o# Q: G: e1 t$ d) N& p% I
  213. # Slaves send PINGs to server in a predefined interval. It's possible to change# n& X3 s* w( F# [
  214. # this interval with the repl_ping_slave_period option. The default value is 10( H% w2 Y4 ]$ g/ h
  215. # seconds.
    5 p: [+ q5 ^8 j  d: D7 n, |% Y
  216. #
    1 s3 O2 i5 {# W+ r# A
  217. # repl-ping-slave-period 10
    $ G5 H/ y5 K2 k3 C4 H# i

  218. 8 R# R) G# |) R0 I1 E) d1 k, [
  219. # The following option sets a timeout for both Bulk transfer I/O timeout and# s( F+ y& {' }+ O1 \0 X. Y1 Z$ X  ~
  220. # master data or ping response timeout. The default value is 60 seconds.
    7 v2 }9 U8 m+ a! p  N% c  y
  221. #- F! D' |" |1 G
  222. # It is important to make sure that this value is greater than the value
    5 p( L4 h) s0 {, a" L+ d) W  m
  223. # specified for repl-ping-slave-period otherwise a timeout will be detected
    , k( V8 Y/ B' a( Z  K9 b' u
  224. # every time there is low traffic between the master and the slave.
    " p* m6 G( Y7 K/ N
  225. #
    , u. }. a) }- Y8 i5 Z
  226. # repl-timeout 60; T) t' y6 a  P0 c* @) b6 h# w
  227. ! ^4 s5 \- \9 R
  228. # Disable TCP_NODELAY on the slave socket after SYNC?6 ?5 B7 C# K, L5 w" e) Y
  229. #9 e! q" O$ m" _% @; X
  230. # If you select "yes" Redis will use a smaller number of TCP packets and
    0 \. m8 ~% O( k: ?: Z8 g
  231. # less bandwidth to send data to slaves. But this can add a delay for
    3 c% {  X8 }  d5 P
  232. # the data to appear on the slave side, up to 40 milliseconds with
    . U, U( G: l3 \( S# r- X9 X; p
  233. # Linux kernels using a default configuration.
    # `' M# ^: V; p/ Y
  234. #2 z) i3 ?9 n& a4 y/ b) `/ j3 V
  235. # If you select "no" the delay for data to appear on the slave side will
    0 j5 A5 u* d% X7 r& u
  236. # be reduced but more bandwidth will be used for replication.3 n* S4 j8 x6 _( H2 I# }
  237. #6 F2 i" l. d0 u0 N
  238. # By default we optimize for low latency, but in very high traffic conditions  o8 B2 z0 H! n: A; u. l( @
  239. # or when the master and slaves are many hops away, turning this to "yes" may4 F; z2 K( A: b$ ?3 ?$ e+ s
  240. # be a good idea.
    * B' v/ i! s+ ?1 ~6 W6 O
  241. repl-disable-tcp-nodelay no
    5 `2 p8 C3 L% p
  242. . k. n! q2 \4 R" Y/ g2 n! \" C5 Z# B
  243. # The slave priority is an integer number published by Redis in the INFO output.
    " _0 D3 O4 S/ e1 L/ L
  244. # It is used by Redis Sentinel in order to select a slave to promote into a; z8 t, N( R0 ^" e2 I* J7 ~
  245. # master if the master is no longer working correctly.
    4 D! ~( e; y- p# i9 g5 u( F
  246. #, t6 o& P; t' d7 f5 b0 u  ^# d, _
  247. # A slave with a low priority number is considered better for promotion, so& E: U; n; y! J  w8 D! V
  248. # for instance if there are three slaves with priority 10, 100, 25 Sentinel will
    / ?2 v5 J- F8 k: E/ ]
  249. # pick the one wtih priority 10, that is the lowest.
    ( R5 e% }3 @$ w3 D4 N3 \+ u) P
  250. #! E4 B& A" f& g- D( q1 C
  251. # However a special priority of 0 marks the slave as not able to perform the% u" _. [  a. `
  252. # role of master, so a slave with priority of 0 will never be selected by
    ; z( x( g5 Y* F$ R) t- Z! ^
  253. # Redis Sentinel for promotion.( z6 x. @4 W" m- f# U( Z
  254. #1 D3 B) F: u6 z% o/ l% x
  255. # By default the priority is 100.- c! f6 {* u+ ]& ?
  256. slave-priority 100' P7 ^3 O. p8 p$ U7 s% `

  257. 6 ], @; u1 ?% d
  258. ################################## SECURITY ###################################
    7 X5 F2 f- W; j* q( F/ q/ o

  259. 0 y+ o5 ]1 h5 u$ G1 X6 {
  260. # Require clients to issue AUTH <ASSWORD> before processing any other
    3 p8 f$ z1 D* i3 l( j( s0 D; f5 z
  261. # commands.  This might be useful in environments in which you do not trust
    ; O; L; N! t5 K
  262. # others with access to the host running redis-server.
    1 h) x  x7 s+ p: h# z0 t+ {
  263. #
    ( Y/ J. C# C9 v1 R1 j- s
  264. # This should stay commented out for backward compatibility and because most
    . G$ V4 T: J- c, t$ y% l  |
  265. # people do not need auth (e.g. they run their own servers).  ^% Z$ P# v! g  u+ [
  266. # / c1 o. u/ x: ?: p- i% u
  267. # Warning: since Redis is pretty fast an outside user can try up to
    . e" l% F; {$ O
  268. # 150k passwords per second against a good box. This means that you should
    9 P1 \+ f& p; m, q- H# r6 P  M
  269. # use a very strong password otherwise it will be very easy to break.# z6 Y5 O! l7 ~) z. l3 w8 v; G4 e
  270. #
    - X: y3 M& n$ O  p* t3 q
  271. # requirepass foobared: L$ J) g6 R, |% Y/ u
  272. 9 c; E! P# x7 H# `8 |' M6 f; P
  273. # Command renaming.
    6 E$ i. j4 k) @
  274. #2 ]- Y* C( [6 ]1 v" _
  275. # It is possible to change the name of dangerous commands in a shared2 ~6 l# p2 J% D% p/ W
  276. # environment. For instance the CONFIG command may be renamed into something. L6 x; B5 E( P! C
  277. # hard to guess so that it will still be available for internal-use tools* K3 G& W; D/ T
  278. # but not available for general clients.
    8 ^- J* [. ]$ L4 d/ |
  279. #
    - Z% |+ x, }; S1 h
  280. # Example:
    ' q/ n- d% l3 x
  281. #( [3 a: K# `( X  v  |
  282. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
    & z( Y) w4 X: p' S- M
  283. #
    * E5 B; ]3 z5 p
  284. # It is also possible to completely kill a command by renaming it into
    , j) y" h- K6 k- p) Q, }* L6 A+ X( `
  285. # an empty string:2 _2 Z7 n0 L7 T! ^& z" f( N: b
  286. #
    / m9 J0 T/ e+ o9 c' M
  287. # rename-command CONFIG ""
    & H+ E" s) ^$ l- Z) D) h, Z
  288. / m. M5 j6 h! J9 Q
  289. ################################### LIMITS ####################################( i$ x' ]/ [9 R! u5 H. q

  290. # e8 c. l7 n$ t2 r0 I2 x4 ~1 ~4 T
  291. # Set the max number of connected clients at the same time. By default
    ' {1 h7 B* R, _" W- i8 S
  292. # this limit is set to 10000 clients, however if the Redis server is not' V9 ~7 J2 q1 y: j: l2 @/ {! u
  293. # able to configure the process file limit to allow for the specified limit  L" S; ]. |) [5 i
  294. # the max number of allowed clients is set to the current file limit
    # n8 }: T9 @; l! W" r
  295. # minus 32 (as Redis reserves a few file descriptors for internal uses).. U0 k5 ^5 C* d& D! R! z4 j/ D
  296. #
    # b8 t8 e8 K1 _/ w, U$ w1 ^5 n, c
  297. # Once the limit is reached Redis will close all the new connections sending
    % q6 Z% r% t7 \+ t: S5 R
  298. # an error 'max number of clients reached'.. x3 I+ t( q& M) ?! |  X
  299. #
    ) ~/ s( _, S4 [- x' K2 K
  300. maxclients 5009 S0 p; ?) S( X+ v; J, t0 f

  301. 1 O/ Q7 `/ ~8 a
  302. # Don't use more memory than the specified amount of bytes.$ `$ g% L, q& Z. `5 |: Y
  303. # When the memory limit is reached Redis will try to remove keys
    ! w* |- j' o/ z. {0 m- _
  304. # accordingly to the eviction policy selected (see maxmemmory-policy).
    ' U8 _( R! K( p9 `' {8 j1 i
  305. ## e4 e+ N. K0 y6 t# N/ |
  306. # If Redis can't remove keys according to the policy, or if the policy is' w+ w) V" x; @6 i7 p6 R
  307. # set to 'noeviction', Redis will start to reply with errors to commands9 G6 M- K) V* i
  308. # that would use more memory, like SET, LPUSH, and so on, and will continue( }; N- Q; D# k' q& W8 D
  309. # to reply to read-only commands like GET.
    2 ]! J) P. S; }* u
  310. #% l8 i1 h( F; g& L
  311. # This option is usually useful when using Redis as an LRU cache, or to set
    , z4 t! Z% j: e6 X% D! ^6 T$ V" i
  312. # an hard memory limit for an instance (using the 'noeviction' policy).) o; a% P/ s7 v" \+ S1 _* ]
  313. #6 l' o5 w0 f+ c6 F
  314. # WARNING: If you have slaves attached to an instance with maxmemory on,
    0 I# a. [+ F3 h
  315. # the size of the output buffers needed to feed the slaves are subtracted
    # I! ?, U8 t( O3 X
  316. # from the used memory count, so that network problems / resyncs will6 F( }- U; ]; K2 L& y
  317. # not trigger a loop where keys are evicted, and in turn the output
    , T/ F- b. F' [- z/ h* k, o3 Z
  318. # buffer of slaves is full with DELs of keys evicted triggering the deletion
    2 K; m: q" f# M) c* k1 d/ b$ @* H
  319. # of more keys, and so forth until the database is completely emptied.
    3 L  q0 r4 P7 C( _6 d3 B# r& ^
  320. #& G* l0 }2 {) `) K
  321. # In short... if you have slaves attached it is suggested that you set a lower
    & y0 [- O8 I* ~' e/ j; h
  322. # limit for maxmemory so that there is some free RAM on the system for slave
    . B' A8 |. \$ P. n) \; J
  323. # output buffers (but this is not needed if the policy is 'noeviction').
    1 w) P/ W! n( T9 `5 v5 J
  324. #
    9 h( d" L! A5 Y+ u; r( r
  325. maxmemory 128000000* a/ h4 q+ @7 W# s* m
  326. - U  g& H. z* ]( i( _( B3 f8 N/ M
  327. # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
    - @" p) n. T# y0 U
  328. # is reached. You can select among five behaviors:$ f# K/ H& ]1 g, v  e
  329. #
    2 a1 Y8 U* d- ^# t
  330. # volatile-lru -> remove the key with an expire set using an LRU algorithm9 M9 s& s1 j6 I4 j" w. g
  331. # allkeys-lru -> remove any key accordingly to the LRU algorithm$ ?) O: Q% c' E
  332. # volatile-random -> remove a random key with an expire set& G& q, v8 t: X0 Z: Z
  333. # allkeys-random -> remove a random key, any key
    7 R' i& Z: H2 f1 ?
  334. # volatile-ttl -> remove the key with the nearest expire time (minor TTL)
    3 G$ d. q4 Q3 G! V8 E+ s
  335. # noeviction -> don't expire at all, just return an error on write operations
    ) N$ Z4 U! K; q3 v* \: {3 T
  336. #
    + i9 M; Z  a- W+ A) Z5 n
  337. # Note: with any of the above policies, Redis will return an error on write
    % f3 ]1 A( h6 I: f5 O
  338. #       operations, when there are not suitable keys for eviction.' z( [4 W& k* s- z/ b
  339. #
    , `. _# R% i3 y" `
  340. #       At the date of writing this commands are: set setnx setex append
    4 D8 [8 _2 t- d! s- N
  341. #       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
    + b4 `7 u; D( w' S3 g6 @# X
  342. #       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby) I9 `+ F% N1 V. d' x3 {" M4 v
  343. #       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby7 w5 i% p0 S1 d
  344. #       getset mset msetnx exec sort) V, H% R0 Z- u" ^; j
  345. #
    1 A" v  T" B' B/ L3 ~7 t- z
  346. # The default is:
    - I: i( b8 M. C" ?
  347. #
    ; x& N2 z- c' D
  348. # maxmemory-policy volatile-lru, ^7 t5 x0 X1 R& m
  349. 5 R9 i. ?4 V1 @8 l6 Y5 B& n3 f, k
  350. # LRU and minimal TTL algorithms are not precise algorithms but approximated5 d' ?0 s# Z5 M  r# B2 S
  351. # algorithms (in order to save memory), so you can select as well the sample
      F! w3 B" |3 D1 U0 ?
  352. # size to check. For instance for default Redis will check three keys and
    . W2 m: X' c1 T- n
  353. # pick the one that was used less recently, you can change the sample size
    % L" x  N2 [! ]5 S
  354. # using the following configuration directive.
    * S2 A  a- u" w" J6 `; y5 ]) p, F: [
  355. #
    * f3 b/ q9 Q: g0 q( {1 Q) e. w
  356. # maxmemory-samples 3
    6 j" B+ b2 P$ c6 D  X1 `
  357. 4 \+ x) Y3 m6 Y/ B  b
  358. ############################## APPEND ONLY MODE ###############################5 P: }+ w% v8 @
  359. 4 ?) N/ v; H: O. W' v- l, W
  360. # By default Redis asynchronously dumps the dataset on disk. This mode is
    2 l3 F7 H" U  |- P' Q+ \
  361. # good enough in many applications, but an issue with the Redis process or
    0 O8 W: F) r7 ~* \( e
  362. # a power outage may result into a few minutes of writes lost (depending on
    ( C8 M7 \3 j! ~% q$ A. j
  363. # the configured save points).
      a$ G  H5 E" m3 Q3 d
  364. #
    0 v7 }$ e6 p9 g/ z
  365. # The Append Only File is an alternative persistence mode that provides5 K7 }# ]. f& `. X, |
  366. # much better durability. For instance using the default data fsync policy
    ! O) D5 [: F1 T( V, U- p
  367. # (see later in the config file) Redis can lose just one second of writes in a
    ) A+ P$ R/ Y" v8 m
  368. # dramatic event like a server power outage, or a single write if something
    ; \$ l: \" P3 u+ f: a# m
  369. # wrong with the Redis process itself happens, but the operating system is# J, B% W3 E4 z+ F" \1 b
  370. # still running correctly.
    0 Z% O; `# K& ?$ f
  371. #
    . F0 J" h! p% d
  372. # AOF and RDB persistence can be enabled at the same time without problems.
    $ L1 u: K! ^9 j: Y7 n
  373. # If the AOF is enabled on startup Redis will load the AOF, that is the file
    0 w$ p2 d' c4 e+ J7 p
  374. # with the better durability guarantees.
    3 K  e- o* \) V" o) Y, v  z
  375. #3 p% o' ?6 i5 y2 n- Z
  376. # Please check http://redis.io/topics/persistence for more information.
    ' V& D' a5 _0 h3 [# R5 k, c/ B& j

  377. 4 n# `& E# d$ v  t& i, f: |
  378. appendonly no2 w3 O3 H) q! ]5 ^, d3 w
  379. / R- T# X/ Y2 F% }0 o* y
  380. # The name of the append only file (default: "appendonly.aof")2 i( ?. N# }; s. ^6 n/ n4 `
  381. # appendfilename appendonly.aof
    & I5 v' o3 n$ I1 Q  b
  382.   D# L" x% b& }8 L
  383. # The fsync() call tells the Operating System to actually write data on disk
    " A' d0 e6 S6 k& O) b
  384. # instead to wait for more data in the output buffer. Some OS will really flush ( V, B: V8 X- p6 f. {; k
  385. # data on disk, some other OS will just try to do it ASAP.
    ; {" \: B* t0 a6 F) {' u' D5 U# @
  386. #/ ~# m0 @8 S, {! W) I  q
  387. # Redis supports three different modes:
    - }0 f* J' M1 w3 `+ m. s
  388. #9 _3 @. K* L' {0 |2 i/ Y  v2 {
  389. # no: don't fsync, just let the OS flush the data when it wants. Faster.
    # g# o# o! F& N3 ^8 r4 r) K
  390. # always: fsync after every write to the append only log . Slow, Safest.+ {  y7 O) h/ a
  391. # everysec: fsync only one time every second. Compromise.; [, Y6 E# n. z. X4 d" O, T
  392. #
    , z+ B- s! \  W3 Y7 K3 }1 Z' B! {) ]% L
  393. # The default is "everysec", as that's usually the right compromise between
    2 ]4 _9 e4 K1 e; R
  394. # speed and data safety. It's up to you to understand if you can relax this to
    4 n, q6 {; ]# D. l
  395. # "no" that will let the operating system flush the output buffer when
    9 m0 e0 a9 J" L$ [  f
  396. # it wants, for better performances (but if you can live with the idea of
    6 N  l9 N1 T5 j9 y: P5 {  Z# ^$ ~  {
  397. # some data loss consider the default persistence mode that's snapshotting),# w5 B1 p& U8 v# T
  398. # or on the contrary, use "always" that's very slow but a bit safer than
    3 G6 k$ i# ~$ _+ [; F
  399. # everysec.9 @9 P  ^& X% o9 z$ o
  400. #& e$ n7 `$ E/ Y; Y' ?
  401. # More details please check the following article:
      ?; E7 i2 ~2 ?8 v; T$ p% Q
  402. # http://antirez.com/post/redis-persistence-demystified.html
    ! ~% y. w! z5 h' Y/ w& y7 B
  403. #
    & d" d* ~+ V2 m
  404. # If unsure, use "everysec".' ?3 \, Z1 J2 B8 g9 I) d

  405. & C$ J4 k: ^) ]/ o; x& x
  406. # appendfsync always
    & L5 Z5 C: J9 o* C, W  w0 y
  407. appendfsync everysec' N) c$ \* G. m1 t6 _" Y# M
  408. # appendfsync no
    # J9 s- v' p- m9 G7 P. M

  409.   p2 T* e7 u* a" z$ @
  410. # When the AOF fsync policy is set to always or everysec, and a background0 m0 o* x5 R: w% O6 Z
  411. # saving process (a background save or AOF log background rewriting) is6 k. [/ A& _7 a7 g0 l
  412. # performing a lot of I/O against the disk, in some Linux configurations
    . D- @3 b) h1 I  r0 b5 W
  413. # Redis may block too long on the fsync() call. Note that there is no fix for
    * ?) ]# v. g" r! ]0 X; y( |, B
  414. # this currently, as even performing fsync in a different thread will block* I. j7 o$ F/ q0 L# ]! F% x6 i
  415. # our synchronous write(2) call.) h$ z  A" p) x
  416. #
    & D9 X+ O! O8 z4 F2 Y8 }
  417. # In order to mitigate this problem it's possible to use the following option
    : Y$ B1 ~, _  r9 [+ U8 N; Y
  418. # that will prevent fsync() from being called in the main process while a
    # N2 d* m4 O  ~& C8 g, |( g% d9 ?
  419. # BGSAVE or BGREWRITEAOF is in progress.
    3 D+ Q8 B: V0 }# `
  420. #6 Y* l! _% A, Z4 N# T3 J9 m+ V8 A
  421. # This means that while another child is saving, the durability of Redis is
    : q- W6 J$ f$ k
  422. # the same as "appendfsync none". In practical terms, this means that it is& L$ o9 D5 i# w! _8 @& R- N. ^
  423. # possible to lose up to 30 seconds of log in the worst scenario (with the7 O/ H: H8 b7 W# U7 }# J
  424. # default Linux settings)., |* V4 Y0 c: _* f# h
  425. #
    8 @( i5 s- q: P; Z
  426. # If you have latency problems turn this to "yes". Otherwise leave it as- z: O+ r  ^) Z/ a9 n6 L! L
  427. # "no" that is the safest pick from the point of view of durability.
    , E, }# {0 E  T2 M" n+ S6 D4 F
  428. no-appendfsync-on-rewrite no
    8 y4 q0 J$ m* B, _/ d
  429. 9 y; T; f/ D. t* T  E, k
  430. # Automatic rewrite of the append only file.5 h; }8 J  {1 l+ K$ x
  431. # Redis is able to automatically rewrite the log file implicitly calling
    3 J& ^: ^$ }' D' M! R- _
  432. # BGREWRITEAOF when the AOF log size grows by the specified percentage.9 `7 `( p* S* p  `! ^3 N
  433. # $ }& E7 }1 I' @* i& T( }
  434. # This is how it works: Redis remembers the size of the AOF file after the3 c  A& j/ J4 s) W5 f9 c0 A$ C
  435. # latest rewrite (if no rewrite has happened since the restart, the size of# R! O- z& V. ^, g# ^  t
  436. # the AOF at startup is used).3 f0 {- v/ h* G& d6 }
  437. #
    ; H# }( E* H/ p& A4 |
  438. # This base size is compared to the current size. If the current size is5 T' `  q  M9 C: k7 i* c
  439. # bigger than the specified percentage, the rewrite is triggered. Also7 r* M3 J4 O1 W2 w1 m
  440. # you need to specify a minimal size for the AOF file to be rewritten, this
    9 ]4 S+ i9 A* [1 w& T( C8 c
  441. # is useful to avoid rewriting the AOF file even if the percentage increase
      d- L; B) o9 }  v& ^+ ?
  442. # is reached but it is still pretty small.
    2 ?* T0 x' {- Y: B6 m
  443. #
    0 @) A( c" b' M* M1 v: w" r
  444. # Specify a percentage of zero in order to disable the automatic AOF8 i2 ]% g( t* V( |  x
  445. # rewrite feature.
    4 W$ X4 _; a9 W. i& _+ c0 c! `

  446. 9 A$ A/ d% p, f  u( ^
  447. auto-aof-rewrite-percentage 1002 E& C( X0 |: j2 \  n9 O0 ?: Y) f( z
  448. auto-aof-rewrite-min-size 64mb
    ; ]9 T7 s4 B) @$ c& ~7 ~
  449. 5 S, b6 E3 s$ W7 R. J! x8 t: y/ T5 w
  450. ################################ LUA SCRIPTING  ###############################
    ; c) O  ^/ b6 x( `" |
  451. ; C# a9 u9 ~. B6 e& ^& Q5 w
  452. # Max execution time of a Lua script in milliseconds.7 t# ^) p1 p6 ]# ~* \
  453. #) V7 e! b. Q# {6 s$ t' k% ~
  454. # If the maximum execution time is reached Redis will log that a script is& m4 J- u' U2 }
  455. # still in execution after the maximum allowed time and will start to: u+ }! z( ^/ a3 n  _
  456. # reply to queries with an error.
    ! l5 i' Z1 b& a
  457. #
    $ Y5 A' Z: V' w  s1 p
  458. # When a long running script exceed the maximum execution time only the  D4 u# o6 \4 i3 d
  459. # SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be9 _# y8 i- ]% a" T/ h- b
  460. # used to stop a script that did not yet called write commands. The second
    $ b7 S2 d; f) o/ ~: j
  461. # is the only way to shut down the server in the case a write commands was
    8 ?6 h! D' E( j) p+ X* R
  462. # already issue by the script but the user don't want to wait for the natural/ S4 ]9 H3 Z7 M' {# w' |
  463. # termination of the script.
    - v( b- s8 K; ?
  464. #) O: j9 C  _3 p) T7 v
  465. # Set it to 0 or a negative value for unlimited execution without warnings.
    " I! ^0 N$ R6 j8 a! ~; H
  466. lua-time-limit 5000. ~6 P$ y0 E  Y6 `, ~$ P! `9 `

  467. # J  d) k/ Q9 ^3 c7 B7 I# p# P
  468. ################################## SLOW LOG ###################################( D2 J3 Y# j: T0 S
  469. ; M# x4 q8 u; B& ^$ e( A3 `% x4 D
  470. # The Redis Slow Log is a system to log queries that exceeded a specified
    2 }$ q  g+ A! y* \
  471. # execution time. The execution time does not include the I/O operations7 K. S2 Y1 k8 ]/ |6 H" Y2 W. A: u
  472. # like talking with the client, sending the reply and so forth,
      D" p) k& p# Z$ f) j
  473. # but just the time needed to actually execute the command (this is the only
    2 n# s& ~0 t( J5 u
  474. # stage of command execution where the thread is blocked and can not serve
    % t( V2 J' T" b! T3 l) L  _, s5 Z
  475. # other requests in the meantime).
    6 v  R( p5 D, y
  476. #
    0 C' w* h0 S) ~! @4 u& o
  477. # You can configure the slow log with two parameters: one tells Redis
    ! x. e$ @+ f& G3 E0 c
  478. # what is the execution time, in microseconds, to exceed in order for the
    8 n: \4 q7 @% A
  479. # command to get logged, and the other parameter is the length of the
    2 s) ?) J, P! N9 L. j, }: f5 z
  480. # slow log. When a new command is logged the oldest one is removed from the
    ; o8 A1 z9 \9 z3 G# _. v% D
  481. # queue of logged commands.
    " B6 n" v% V- r. G8 X3 T

  482. - ]+ F; E3 c: N7 c3 _" B$ V7 y
  483. # The following time is expressed in microseconds, so 1000000 is equivalent
    * f5 p' R$ A! T  c& L7 s
  484. # to one second. Note that a negative number disables the slow log, while
    - ~0 a" V2 }1 ^; n  f- J
  485. # a value of zero forces the logging of every command.$ x: B9 C! d" s; W/ W* Y
  486. slowlog-log-slower-than 10000
    * v5 ?$ C0 U$ C9 X/ p! g9 L9 T! r

  487. 8 j/ c& e  z" {5 y
  488. # There is no limit to this length. Just be aware that it will consume memory.) r) z* b( w5 I) Q1 ^& E  c
  489. # You can reclaim memory used by the slow log with SLOWLOG RESET.
    " }3 r0 l( P' M5 y& [' [
  490. slowlog-max-len 1287 E9 O! p; d" J2 t) }
  491. - Q$ d) c1 m. @! w3 Y; p* R
  492. ############################### ADVANCED CONFIG ###############################
    / `! v% j2 n6 O* W9 }+ s

  493. 0 G+ h: d# H! B! x8 V* t3 l- h
  494. # Hashes are encoded using a memory efficient data structure when they have a2 R$ z3 ]2 D- D; O
  495. # small number of entries, and the biggest entry does not exceed a given" E5 }2 A# j9 N% {" P
  496. # threshold. These thresholds can be configured using the following directives.
    # @4 n9 e6 z: Y
  497. hash-max-ziplist-entries 512( ~# H( W3 P2 h1 E3 C2 }* p" V9 s
  498. hash-max-ziplist-value 64! `  ], k$ Z- M6 C- m

  499. ! h! p$ y3 i" H) a+ j4 b$ Q7 r
  500. # Similarly to hashes, small lists are also encoded in a special way in order/ E" Y7 A7 k- T0 m
  501. # to save a lot of space. The special representation is only used when
    # D) K4 t' \6 h& @  R/ j
  502. # you are under the following limits:
    ( w# D5 b0 L* ~, w: c) p
  503. list-max-ziplist-entries 512
    ( ~( {  o6 d+ z
  504. list-max-ziplist-value 64
    4 r- g. s7 K! T9 X
  505. ! k8 C! u* G4 \$ S+ R$ i0 {* t
  506. # Sets have a special encoding in just one case: when a set is composed
    * x1 u, }4 o2 j8 f4 f) n+ j* j! V- m" Y
  507. # of just strings that happens to be integers in radix 10 in the range
    / y1 U2 x0 j% m# S& j# C
  508. # of 64 bit signed integers.) y$ q2 G6 j4 q8 }6 p0 O2 S5 G* }. m
  509. # The following configuration setting sets the limit in the size of the5 x6 n& u! d1 W7 N
  510. # set in order to use this special memory saving encoding.; X& f' a1 n9 V: ?2 ?( a/ C6 L
  511. set-max-intset-entries 512
    0 B" i8 d0 s6 U" G' B" C3 R& u: M8 ?
  512. / I9 n5 Y6 t/ Z" V' j
  513. # Similarly to hashes and lists, sorted sets are also specially encoded in5 S5 O; b( Z+ U0 c! \
  514. # order to save a lot of space. This encoding is only used when the length and. x* n. n7 \; T. y2 a2 Z
  515. # elements of a sorted set are below the following limits:( ^; r! }- l2 d8 K7 [
  516. zset-max-ziplist-entries 128
    ; a0 t9 d( m; o  N% c/ K1 c+ y
  517. zset-max-ziplist-value 64
    1 }; j7 s9 B! @) Y$ j8 S% f
  518. 8 L5 `6 a- Y9 f: b0 c
  519. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
    . N0 _: U) |/ W" \% A6 ~
  520. # order to help rehashing the main Redis hash table (the one mapping top-level+ H3 Q' L" k, Q4 \
  521. # keys to values). The hash table implementation Redis uses (see dict.c)
    . O% z6 i3 P: [( p  F9 n
  522. # performs a lazy rehashing: the more operation you run into an hash table. u4 H( R# k( u
  523. # that is rehashing, the more rehashing "steps" are performed, so if the
    ! j/ ^7 m" a# U
  524. # server is idle the rehashing is never complete and some more memory is used
    , T" J2 H; N4 [' N2 w+ _$ \8 D! q
  525. # by the hash table.  P2 {2 x7 r. w
  526. # 6 O8 U4 K9 }% m6 M% `7 Y
  527. # The default is to use this millisecond 10 times every second in order to7 b) x7 N* S  N- g( q( ^5 p
  528. # active rehashing the main dictionaries, freeing memory when possible.1 x0 Q% l$ g. V1 G1 l* a
  529. #
    3 z0 _; X3 C9 j- {
  530. # If unsure:8 ?6 J0 n$ q* n1 f6 E
  531. # use "activerehashing no" if you have hard latency requirements and it is
    9 I6 M/ V" M% r2 k  D/ V
  532. # not a good thing in your environment that Redis can reply form time to time
    0 t6 i  g: j1 R
  533. # to queries with 2 milliseconds delay.
    6 s  B1 E5 `7 v6 f9 E
  534. #" d) {* G) J' a6 w- j; Y
  535. # use "activerehashing yes" if you don't have such hard requirements but# u3 u0 a$ N! x) u2 R% I3 ]3 J+ o5 o
  536. # want to free memory asap when possible.
    - M/ P) F) d0 ~" U2 Y) k4 m
  537. activerehashing yes; ]* P# ^' N6 A$ w" C9 T7 M; x

  538. 4 W5 W1 j7 P* {9 N  @
  539. # The client output buffer limits can be used to force disconnection of clients3 j' d3 j" d8 `8 B
  540. # that are not reading data from the server fast enough for some reason (a
    + ^7 Y& {) \3 @  c3 i1 a0 ]% X6 P
  541. # common reason is that a Pub/Sub client can't consume messages as fast as the* w9 m7 d8 e9 q+ V* U" o5 b
  542. # publisher can produce them).* c4 Q" x/ ^5 A* g- _
  543. #
    ; t0 T  M+ z& U  `' v
  544. # The limit can be set differently for the three different classes of clients:
    & r6 S1 {; ~. Q9 n' L6 v
  545. #
    $ K- Y/ r2 O' T3 ?+ o9 A2 r+ t
  546. # normal -> normal clients
    3 J* F, f& x6 @$ o9 r6 ~
  547. # slave  -> slave clients and MONITOR clients
    2 F' x* E; X5 B# k' K# A5 c
  548. # pubsub -> clients subcribed to at least one pubsub channel or pattern" v2 Z/ _$ t6 ~( q8 O
  549. #2 D2 d6 T8 k0 v# X
  550. # The syntax of every client-output-buffer-limit directive is the following:! g, l  B! E% f! O- E
  551. #
    # r! ~  F2 c9 @" \6 r1 P
  552. # client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>2 M: T7 l* x6 H. r8 @, T0 O% n
  553. #
    - D: M8 q8 I2 |' w% |
  554. # A client is immediately disconnected once the hard limit is reached, or if2 v2 u( E! h/ b
  555. # the soft limit is reached and remains reached for the specified number of" F# N4 ]% I+ L: K6 y) p
  556. # seconds (continuously).5 ^5 }* c: c1 h' T3 M: e& J
  557. # So for instance if the hard limit is 32 megabytes and the soft limit is) N3 \- D- T$ l0 S7 Z  d5 z% @
  558. # 16 megabytes / 10 seconds, the client will get disconnected immediately
    , }1 ]( q: @& C# W/ i
  559. # if the size of the output buffers reach 32 megabytes, but will also get
    7 A+ N, _1 K5 [8 \3 h) _  U4 i
  560. # disconnected if the client reaches 16 megabytes and continuously overcomes
    8 X" ?# o* J$ O" L& {+ L
  561. # the limit for 10 seconds.* k9 I% A8 n; Q# I9 Q* M4 O8 \! Y
  562. #
    3 G& J6 v) I3 x2 Z
  563. # By default normal clients are not limited because they don't receive data/ |/ p5 d# l3 H, i6 Y- J1 P4 n9 w
  564. # without asking (in a push way), but just after a request, so only, o  _4 {  `3 E3 y' B" o! F$ ^8 ~
  565. # asynchronous clients may create a scenario where data is requested faster: q2 |- m3 E! H* o. e5 p- v
  566. # than it can read.  s" i! P, m0 ~8 u1 h, P% M
  567. #+ [& z; ]) H, y4 `2 |& T$ W
  568. # Instead there is a default limit for pubsub and slave clients, since* D) a( O8 L- E  j
  569. # subscribers and slaves receive data in a push fashion.
    " E, R. z3 R* G( z2 _% f7 [( v$ W3 T
  570. #; |/ ]) y4 y0 n) U) i9 Y
  571. # Both the hard or the soft limit can be disabled by setting them to zero.) [: A3 N5 }0 L$ g$ j7 A5 L
  572. client-output-buffer-limit normal 0 0 0
    ! K! a, l* ^! z5 |  N# l% D
  573. client-output-buffer-limit slave 256mb 64mb 60( B1 a1 \: _) u# `+ x, f9 O% ~
  574. client-output-buffer-limit pubsub 32mb 8mb 608 x; Y& J' q8 h7 i# b6 B" Z. B" a

  575. " P1 J6 y# P4 x9 Q5 N! ^* w6 s
  576. ################################## INCLUDES ###################################( L; p. T. h7 J; p
  577. - x9 o& Q3 X/ ?' U2 [
  578. # Include one or more other config files here.  This is useful if you
    / }/ }+ [; O! e& N! s! }
  579. # have a standard template that goes to all Redis server but also need5 H/ K" }* }" @+ O% ~
  580. # to customize a few per-server settings.  Include files can include& D" q9 ~6 A% j& T
  581. # other files, so use this wisely.7 w9 ~) A! ?" q
  582. #
    " k: A% {! Q+ [, Y8 a9 E4 l
  583. # include /path/to/local.conf# z2 d6 `& e/ j4 {0 ~' J. f
  584. # include /path/to/other.conf        
    9 e+ K% @/ w$ f  s
  585. ##########################配置文件结束################################
    " t$ s: p5 C# y  g( A
  586. 第三步:启动进程
    " I: g3 M% i! L' X& i0 L
  587. #redis-server /etc/redis.conf
    8 B0 }4 Y& N& y7 p8 m  ^
  588. 查看进程有没有成功启动
    " d: K+ ^8 h8 K* P8 A
  589. #ps -ef | grep redis
    8 X8 t8 i0 i! ?( K" U) y5 o
  590. 测试输入一个键值. u1 h4 W' r; G" I1 J' D+ l3 a1 l
  591. #redis-cli set test "testredis"
    + g- p3 M5 n4 y- s1 F& M' f' A
  592. 获取键值
    6 F2 R' b1 O: s7 X* R
  593. #redis-cli get test
    % V0 d, e- J% f. t, \9 @
  594. ) _# k6 j0 N3 [4 r, Z; o9 l* S

  595. 3 [$ [- l/ [+ k* t) d" A* [
  596. 第四步:关闭redis  (这个是更改配置文件后 正常的重启方式  不重新加载redis配置跳过)) R1 u# u9 f, w- u
  597. # redis-cli shutdown      //关闭所有    ( L, p% l: T4 S' d* N( A
  598. 关闭某个端口上的redis    " Z2 K5 I- z7 t/ j3 D. {' C8 i
  599. # redis-cli -p 6397 shutdown  //关闭6397端口的redis  
    5 y: F, T$ a9 q' C9 m6 `1 A
  600. 说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename  dump.rdb  
      G2 G/ Q9 _4 C+ I4 r. e# h9 d

  601. / D1 I& \: z6 E" C. d
  602. 7 Y$ ]4 Y! y; W; N& a" @6 f
  603. 第5步:php扩展安装1 o" C3 h, q/ J0 ~# Z# w
  604. phpredis PHP扩展下载地址
    ) k4 ~9 i* i9 z6 y, P* S4 a9 ^
  605. https://github.com/nicolasff/phpredis/tree/2.2.2   O8 h% C& U4 d* |
  606. 选择最新版本下载zip 0 m: p9 l0 v* M- i% e
  607. $ g" ?9 Q% p6 B8 L0 }! @
  608. 然后自己上传zip  用unzip解压到当前目录 unzip 文件名: e  c/ w8 F2 j5 F( o) Q. `

  609. + A  P" k; s1 ^7 S2 G
  610. # cd owlient-phpredis-90ecd17/   #打开解压后的文件夹里面  这个解压后的目录 要是不知道 可以输入 "dir" 查看% T( Q/ H6 j" Y$ M! C
  611. # /www/nginx_php-5.2.17/bin
    # D& ^2 M( M! @- n8 F' k
  612. # ./configure --with-php-config=/www/nginx_php-5.2.17/bin/php-config
    5 n6 T7 x/ Q' v5 v8 o0 ]
  613. #make! b2 Z4 b0 i5 f. q: {, ~$ {: r- o* N
  614. #make install   #记录产生的redis.so路径
    ' x6 D8 n7 A) h' D  m- u( h

  615. " V) O9 B" a' f, q
  616. 修改php.ini文件
    8 `: W' |" X9 |: T' s
  617. 在php.ini中添加如下一行:
    * K, S, C; g0 @1 S3 y3 x
  618. extension=/?/redis.so  #是刚刚记录的产生redis.so的路 写在 ?那
    & z/ X3 F$ ^  ?* u. C/ |
  619. 重启 使之生效:
    ) [0 \7 q+ \# U& O( f
  620. /usr/local/php/sbin/php-fpm reload
    4 ^$ D& ~- j& k; m- D9 c
  621. /usr/local/nginx/sbin/nginx -s reload * d' _! k7 @& j5 k2 Z
  622. : n7 A8 O0 g3 e& `( ?" l* v
  623. 将 Redis 作为 Linux 服务随机启动
    $ r& X4 h9 U* a" Y9 y
  624. vi /etc/rc.local, 加入代码:7 e9 W- @0 ^1 ~* F/ ?
  625. /root/redis-2.6.10/src/redis-serve  #路径看情况修改 # ~# G3 U: B* K! @7 M
  626. . l) j& G9 o1 _* z
  627. redis-cli -h localhost -p 6379 info  #命令要在redis目录下面执行
    * M) j! ?4 m( b/ d: J
  628. 提供host为localhost,端口为6379,redis服务的统计信息
    . T9 H, z& t6 ]$ X+ x, Q" M+ g9 a

  629. % N7 }7 @( s; v  z+ N' w
  630. 2 S8 a4 L, O9 b
  631. 就这样你的web服务器就支持redis了 记得要在 给dz 的配置文件 加上12.0.0.1哦0 y$ O, ?. ~8 g9 A7 Y
  632. dz配置文件在 config目录下面的 config_global.php
    $ f8 y" Z6 A; b) o2 z9 a8 H
  633. $_config['memory']['redis']['server'] = '127.0.0.1';* k/ j% O7 |1 F4 C4 R3 A
  634. $_config['memory']['redis']['port'] = 6379;0 U. J1 x, A4 x' o% v8 Y
  635. $_config['memory']['redis']['pconnect'] = 1;
    # V5 A8 \; F# K( g5 K0 ?
  636. $_config['memory']['redis']['timeout'] = '0';+ Z. z+ s2 a! u4 a
  637. $_config['memory']['redis']['serializer'] = 1;3 B- h/ W* |8 f5 N( Z
复制代码
关注微信公众号《神采飞扬网》,即可获取最新回复通知!

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

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

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

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

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