分享到:
发表于 2018-11-16 12:42:28 | 显示全部楼层 |阅读模式
环境配置
2 a# g7 a/ P7 T1 ?; n
3 |- h1 M0 `( j! X4 E) R+ f- u2 X* h
http://www.discuz.net/forum.php? ... amp;highlight=REDIS
关注微信公众号《神采飞扬网》,即可获取最新回复通知!
 楼主| 发表于 2018-11-16 12:43:33 | 显示全部楼层
http://www.discuz.net/forum.php? ... 648&highlight=REDIS
: C" H  D. K& Y6 K/ D  M无意间测试 单机状态 redis相当给力 测试1000请求/s  单纯的 get 和set 居然只用了 0.01秒 当时我惊呆了
3 y% p( S; A' }  ]% s3 W- b0 U8 y- I, K5 e% J( v/ W
http://www.discuz.net/forum.php? ... 731&highlight=REDIS1 K5 ?6 Z* [6 ^+ G

! O* o5 [  z! k- v) Y$ Khttps://wenku.baidu.com/view/265a5ce176a20029bc642d0b.html- G$ g! ~5 a. Q, s) ]! M

- D  ~* u: h+ H! k8 i=======================================
/ r' F( ~; u, w. S4 i  ?% U- R
  1. 连接上 ssh5 M9 g. b/ z$ n3 J4 ]- m

  2. 4 \5 k4 {0 d& h! R! h
  3. 6 H  W" L: O9 K& Q
  4. 第一步:下载redis
    % I0 `" z; t2 {0 i0 y' V
  5. # wget http://redis.googlecode.com/files/redis-2.6.10.tar.gz; i6 F; J; Z. \* @% z3 z; z
  6. # tar zxvf redis-2.6.10.tar.gz 9 x9 B; N4 s# T% z2 Q4 T
  7. # cd redis-2.6.10
    + x. O! q4 @7 ]6 R/ U8 Q
  8. # make
    + F' T9 _0 V, w5 p" W% B
  9. # make install    \& {& x9 X" B6 H8 n
  10. #cp redis.conf  /etc/ #复制配置文件到etc目录下面$ L1 Q# v0 G+ |) [/ _
  11. 第二步:修改配置+ X$ X# S3 D# M/ @
  12. #vi /etc/redis.conf
    9 }; k8 _/ T3 x6 K5 N3 o
  13. ######################下面是无措的配置文件 复制过去就成#########( [8 Q8 Y8 S/ A8 \
  14. # Redis configuration file example& o8 Y2 R6 Y* y. ~$ O4 D
  15. 1 x+ L! E" T+ R
  16. # Note on units: when memory size is needed, it is possible to specify' u# `3 p5 ?  d% }- U# k+ Y( b
  17. # it in the usual form of 1k 5GB 4M and so forth:
    . U4 V; |; n( B
  18. #
    # ?! m$ K) ~5 Y( g) h) _$ O
  19. # 1k => 1000 bytes0 j7 ^" F6 R. w" N7 `5 t
  20. # 1kb => 1024 bytes
    5 I0 w& ]6 l" Z( U$ a) J; J+ M; a
  21. # 1m => 1000000 bytes  R9 I; o+ a$ r% H( h
  22. # 1mb => 1024*1024 bytes
    # I0 ^! X' x4 U# @- `# ]5 ?; ~9 ?
  23. # 1g => 1000000000 bytes
    6 c: K$ M  U1 {+ [7 d# ~; j3 c
  24. # 1gb => 1024*1024*1024 bytes/ ~6 B% d0 R$ W" D8 K3 _
  25. #3 B1 |# y- n# r% c7 n8 e$ ^! V7 A
  26. # units are case insensitive so 1GB 1Gb 1gB are all the same.
    ! L6 F; ]+ O( V. J- ^0 y5 l1 e

  27. ( n9 b% r6 y9 W0 C5 \, ?
  28. # By default Redis does not run as a daemon. Use 'yes' if you need it.
    4 t- c6 X- d* Q5 h4 D
  29. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
    " S  j( n( }4 |) `3 O7 X2 S) S
  30. daemonize yes
    : P3 p8 |$ P( `, v' A, e$ O

  31. # M+ [7 r$ V( \& J* E- G$ O
  32. # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
    1 K0 u) e: z, s) P$ ^% A
  33. # default. You can specify a custom pid file location here.: c- U, [: w" L) R0 Q
  34. pidfile /var/run/redis.pid
    ! P$ t1 e8 S- l- f4 W

  35. 4 U3 z# \* ?/ y. r6 u
  36. # Accept connections on the specified port, default is 6379./ n. F+ C0 M- C( b6 ]
  37. # If port 0 is specified Redis will not listen on a TCP socket.0 y# K* A0 p( a3 q
  38. port 6379& X) ~& M: A- ~  e" A; d% n$ h

  39. % Q+ y6 Q+ e; ^- i$ u3 n8 Z! M. W
  40. # If you want you can bind a single interface, if the bind option is not0 a: B( u9 ?  S( w
  41. # specified all the interfaces will listen for incoming connections.8 b4 L, h. c# I7 c5 i) Z
  42. #
      q6 M, P6 s; w
  43. # bind 127.0.0.1
    9 ^# X8 Y9 z# C

  44. - B7 Q( g* d% e2 Y7 S
  45. # Specify the path for the unix socket that will be used to listen for# K8 l' a0 p* R1 c, J7 d4 D
  46. # incoming connections. There is no default, so Redis will not listen
    ( F  t( J7 [% `) ]/ l0 ]8 e- U$ ^
  47. # on a unix socket when not specified.8 [0 M/ |, p, y# X' K4 @7 U
  48. #
    + N5 n* ^6 _1 D0 ]. }- ^. q$ d, h
  49. # unixsocket /tmp/redis.sock+ a& N8 c: ^- s$ u+ K' P! @& r1 J
  50. # unixsocketperm 7559 [! I" F7 p$ }1 g6 D

  51. ( o7 [9 b' }" L# d& A
  52. # Close the connection after a client is idle for N seconds (0 to disable)
      V- G' O; i9 l, S- i: p) Q' Y- ~+ ^
  53. timeout 3009 D" C) A8 {) r8 Q5 o( b( A+ j
  54. 3 o) A3 N+ w4 W7 `) Z2 ]6 C
  55. # TCP keepalive.
    , o* V# O3 [5 s' f, i
  56. #
    0 J8 d# m; P$ K- @7 e
  57. # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence0 p* \, T: U: k& s- z) ~' {
  58. # of communication. This is useful for two reasons:
    8 w/ Z! l0 b/ R' ?5 T6 L
  59. #
    * ~1 s, w& ^5 s2 @: R
  60. # 1) Detect dead peers.
    ; U& t, R  w- y
  61. # 2) Take the connection alive from the point of view of network+ ]1 [- L0 t6 F* L
  62. #    equipment in the middle.
    7 y- W% [+ _' ~& r$ ]5 B  Y7 {8 U
  63. #
    $ p- r& _! W" y, P- G3 E* I7 X! y; }
  64. # On Linux, the specified value (in seconds) is the period used to send ACKs.
    % d9 @0 p( ]# R% ^& X0 X8 h" l
  65. # Note that to close the connection the double of the time is needed.9 o% @  v- J. L" p+ F# A) d4 k
  66. # On other kernels the period depends on the kernel configuration.
      ~8 B" m; J3 L4 s
  67. #
    / x$ u5 y4 l5 J2 X! f: k% u3 U
  68. # A reasonable value for this option is 60 seconds.; V% S  v9 f& ^5 Z) Y9 C3 y0 j
  69. tcp-keepalive 0/ s2 X1 `7 U4 z7 a$ K, m

  70. 1 [) [. g. q1 b0 P* H
  71. # Specify the server verbosity level.
    9 H/ L/ X* I% S. Y) Y2 M
  72. # This can be one of:
    " e' `/ Z+ e3 O' u' K' h2 |' Y' x
  73. # debug (a lot of information, useful for development/testing): ?% e9 Y: d2 f% Z. {
  74. # verbose (many rarely useful info, but not a mess like the debug level). Z6 X7 x2 ~, ?$ ?# @7 e
  75. # notice (moderately verbose, what you want in production probably)+ w3 E9 D1 a- T0 K, `
  76. # warning (only very important / critical messages are logged)
    ( i1 C) q. N' p3 ^" ?
  77. loglevel warning1 i2 R: `$ R* G: m) N

  78. , E5 }" U$ n) @
  79. # Specify the log file name. Also 'stdout' can be used to force1 j: u' q& k( P$ ~2 l4 }
  80. # Redis to log on the standard output. Note that if you use standard
    7 k# o, x' S! Y% ^" u- Y7 a- u
  81. # output for logging but daemonize, logs will be sent to /dev/null
    6 A4 C" N: X: |5 k% h2 m* x
  82. logfile /var/log/redis.log
    % K( v1 T, P( {1 y6 ?9 I* i

  83. ' s$ J& G( f5 E
  84. # To enable logging to the system logger, just set 'syslog-enabled' to yes,& z8 ^2 L8 E2 z7 a; L, X
  85. # and optionally update the other syslog parameters to suit your needs.
    ' l( m! f1 ?! U) V7 \5 p
  86. syslog-enabled yes
    # I: f) O2 U, N) U- P3 a

  87. ) z) n$ P2 e" @- M- j! V. i0 n
  88. # Specify the syslog identity./ ^$ [9 D3 k' b  ]% W8 J
  89. # syslog-ident redis
    7 ]2 p; E% `. W. y# M$ f; m

  90. 0 o8 ?0 u+ l5 C- w
  91. # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.4 p2 s( \) Z) n- ~! A0 g
  92. syslog-facility local0
    7 m- \/ e; k) i5 t" ^/ Z9 {

  93. ' }9 O: K3 n, s" w; g0 n6 I
  94. # Set the number of databases. The default database is DB 0, you can select
    9 t( V4 F2 H+ ?3 \( L& D9 I) x5 i
  95. # a different one on a per-connection basis using SELECT <dbid> where1 Z( f8 w3 ]9 W# i3 o+ l, C
  96. # dbid is a number between 0 and 'databases'-1
    3 l! b8 c" q$ v) v! b; _/ b+ s: K. G$ Z
  97. databases 164 H7 P- h; }/ g- B
  98. 3 @; K) }  g% Q- s4 f$ c3 v0 r
  99. ################################ SNAPSHOTTING  #################################
    : L4 ^, x' \8 ?. c% {
  100. #
    + K- W/ S9 [/ ]# F8 A6 N
  101. # Save the DB on disk:4 X- q% k$ h/ a0 l* x% t
  102. #
    - W# f, n& B, G* j' n
  103. #   save <seconds> <changes>9 p' S+ V! C( M; p7 _7 i
  104. #
    1 _, z0 y  V( c  A# K2 a+ U, n
  105. #   Will save the DB if both the given number of seconds and the given' o9 _8 Q% R% L/ r
  106. #   number of write operations against the DB occurred.
    9 R" S/ ?! k% k  d& M+ u% C
  107. #6 [5 B) r4 g- t0 x" ~$ }
  108. #   In the example below the behaviour will be to save:4 z" y$ s5 H% r% E% \# e
  109. #   after 900 sec (15 min) if at least 1 key changed
    ; c, @8 o6 `  n' C% r1 P1 C
  110. #   after 300 sec (5 min) if at least 10 keys changed
    / V. i7 A% d3 z$ F
  111. #   after 60 sec if at least 10000 keys changed; x* U! S0 ]4 y5 ]
  112. #
    ! z* \% Z8 `  d% d4 ?
  113. #   Note: you can disable saving at all commenting all the "save" lines.1 r" K& h, J. ?# s% ]. Y2 x
  114. #
    4 Y( b: m2 E7 J- R* d1 U, y
  115. #   It is also possible to remove all the previously configured save
    1 s. J! G8 ^# y8 t6 L7 f
  116. #   points by adding a save directive with a single empty string argument* a! X/ Q3 m) W" Z" G: |9 b2 B" w
  117. #   like in the following example:, H0 R) X6 p3 ?
  118. #" K% b  Q( l5 V
  119. #   save ""
    7 I7 s7 E1 w3 x' Y6 o* ~
  120. / _. h  Q. U' m5 p( ^+ I
  121. save 900 1
    4 q( ^- m2 c$ E1 I; ^) h& e& c
  122. save 300 10+ L) ^8 ^4 P: U6 M: @% t  @
  123. save 60 100002 U. k7 ~( I9 {! g' q( v

  124. ( h* S3 o! X5 `3 {* m
  125. # By default Redis will stop accepting writes if RDB snapshots are enabled$ x7 A" S5 r1 z9 k* G& L4 v0 d4 x
  126. # (at least one save point) and the latest background save failed.
    4 D$ f8 m/ Q5 o2 H# Z* W
  127. # This will make the user aware (in an hard way) that data is not persisting
    8 p1 L4 q) @4 ]% ]
  128. # on disk properly, otherwise chances are that no one will notice and some4 b5 r6 f7 c; x8 S9 ?1 U$ n  k" B% b2 R
  129. # distater will happen.- @( @7 ^1 W* i% Y- U
  130. #% P/ }% @3 j4 E/ D  m5 O- j& N
  131. # If the background saving process will start working again Redis will
      O, E9 h& J+ i$ I
  132. # automatically allow writes again.4 C5 e7 d& s) A, h
  133. #9 {- x; C0 `* t; y- H
  134. # However if you have setup your proper monitoring of the Redis server- w* T. u1 V& L. ]  ~
  135. # and persistence, you may want to disable this feature so that Redis will) @: L& \, G7 ?2 [2 D7 N; X" E
  136. # continue to work as usually even if there are problems with disk,
    0 e, g6 H- F/ c5 }% j) P
  137. # permissions, and so forth.
    # W+ R7 F! i1 o8 M2 \- S& ^0 t
  138. stop-writes-on-bgsave-error yes, C% P1 r' B8 {" y! ~6 ~

  139. " r5 t4 k$ c! B9 X
  140. # Compress string objects using LZF when dump .rdb databases?: n7 V6 l" q) j6 K
  141. # For default that's set to 'yes' as it's almost always a win.. J: x  K3 a/ H, w3 i4 k: a$ o
  142. # If you want to save some CPU in the saving child set it to 'no' but
    ) R& o: d- f7 u) l- Z2 y
  143. # the dataset will likely be bigger if you have compressible values or keys.( O  ^& Z9 r6 t( a
  144. rdbcompression yes0 Q9 B! X; R3 K. n; A% M! M# \

  145. # k' A# g4 \* T% S1 J) Q& L
  146. # Since version 5 of RDB a CRC64 checksum is placed at the end of the file.
    3 w2 U" V5 e( p- `1 W
  147. # This makes the format more resistant to corruption but there is a performance
      a2 }1 s5 t- Q$ Z- R) E! C- Q- W
  148. # hit to pay (around 10%) when saving and loading RDB files, so you can disable it4 f6 O  M0 u, Z8 G# _
  149. # for maximum performances.$ E$ B2 R' O, ^/ W& P, B  M$ |! L
  150. #
    & S/ |0 R. I1 J
  151. # RDB files created with checksum disabled have a checksum of zero that will1 y- O8 X3 f: V4 N) B7 x& m
  152. # tell the loading code to skip the check., M2 |  V* Q6 H5 e) z6 g8 w' `
  153. rdbchecksum yes( U" g/ Y3 h% {7 s3 K, A  D9 E
  154. $ O+ x% K. V% [
  155. # The filename where to dump the DB
    ! [& Y8 R* ~# y6 Q2 F7 \1 f
  156. dbfilename dump.rdb
    ) c' |7 j- @/ {5 I2 Y
  157. ! H  d8 i) Y5 j; x
  158. # The working directory.7 A" I. _# F2 e+ v2 y, j( k% v+ h" T" ?
  159. #8 Z5 `7 ?) z& A" e7 I: O
  160. # The DB will be written inside this directory, with the filename specified
    ( c, @8 M( s: c; @
  161. # above using the 'dbfilename' configuration directive." [& j0 z+ O" P- _/ ]* L2 l% x
  162. #
    / L; |' v# n* m( J5 ~
  163. # The Append Only File will also be created inside this directory.5 ~% ?. Q0 E& ?/ F7 F1 q) k
  164. # 5 m6 n0 C( }1 G
  165. # Note that you must specify a directory here, not a file name.
    / q/ b! J6 G* ?. {" u5 F* ]
  166. dir /var/db/redis
    + E& X' r: O* v& Z  k9 ?

  167. . v) y! `; V* {/ \# B% f
  168. ################################# REPLICATION #################################
    5 L; l! J( Q- ]+ l  H. `; }* g

  169. ( R1 V3 e9 ^# a/ r
  170. # Master-Slave replication. Use slaveof to make a Redis instance a copy of' Q/ V% T  V' e: X) b  i
  171. # another Redis server. Note that the configuration is local to the slave
    7 H( s- r1 P. R! S: i$ B
  172. # so for example it is possible to configure the slave to save the DB with a1 v. O4 ~1 W5 Z  `
  173. # different interval, or to listen to another port, and so on.
    2 P( i$ k3 L% c4 _
  174. #  p& f6 Z" E# a. @
  175. # slaveof <masterip> <masterport>% v: Q6 d/ s) o
  176. 8 r2 Z9 G" G+ A
  177. # If the master is password protected (using the "requirepass" configuration5 y* M9 i4 m, k  k4 |+ |8 F
  178. # directive below) it is possible to tell the slave to authenticate before$ d$ M: d  x& H: Q% i( P0 k. Q
  179. # starting the replication synchronization process, otherwise the master will
    ! g. N! t( Z) u& K1 n: W
  180. # refuse the slave request.( \5 Y( }% p5 l, K, c
  181. #& g' J7 _, J4 N0 K! b
  182. # masterauth <master-password>
    ! M5 K% k/ m# V1 {: C3 T/ g
  183. 5 M, x/ u4 z% D$ _8 V
  184. # When a slave loses its connection with the master, or when the replication
    + \. N, a& W  {
  185. # is still in progress, the slave can act in two different ways:
    , M8 R' {- v0 @9 Z# l9 V/ L$ W2 [' d
  186. #7 M  y/ u* p+ A' h* \% v0 E: T  x" b
  187. # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will
    2 k( G1 @) n" Q6 i' g
  188. #    still reply to client requests, possibly with out of date data, or the
    1 X# E+ u3 H. k* ~5 s- \4 Y! e
  189. #    data set may just be empty if this is the first synchronization.& j. [7 Y. R) e: h4 t8 v- T
  190. #
    & o6 Q1 E3 g4 q1 @% x5 d1 I
  191. # 2) if slave-serve-stale data is set to 'no' the slave will reply with
    7 V; W5 M, G  P  T; X2 k
  192. #    an error "SYNC with master in progress" to all the kind of commands1 Z% i# m: |; C" u, R
  193. #    but to INFO and SLAVEOF.
    * \, ]; o6 U4 O
  194. #; l% K1 y# G1 k; ?" X
  195. slave-serve-stale-data yes
    4 j: q# m( o5 ^7 K& Z' D
  196. + q* d* G6 l; j: |9 z
  197. # You can configure a slave instance to accept writes or not. Writing against
    ' q( v0 ]9 N. G9 L% w7 X! i0 o" x
  198. # a slave instance may be useful to store some ephemeral data (because data
    8 Q/ i8 N, i9 y& S0 h+ W  Z
  199. # written on a slave will be easily deleted after resync with the master) but" ^" G6 S9 v2 u4 h9 A9 M( d
  200. # may also cause problems if clients are writing to it because of a0 z. j; }7 ]$ i
  201. # misconfiguration.6 }# L" P2 }3 u1 ^: D) A
  202. #
    ' p# j7 v. z  A. ?, k5 a
  203. # Since Redis 2.6 by default slaves are read-only.
    . R. g7 B* M+ s; ?6 }# R7 i# Y
  204. #
      {: U, R* r0 w
  205. # Note: read only slaves are not designed to be exposed to untrusted clients
    8 a6 ~$ ~, Z3 V6 V* c8 c& N
  206. # on the internet. It's just a protection layer against misuse of the instance.( R2 n. ]2 u% F7 e6 o7 z
  207. # Still a read only slave exports by default all the administrative commands
    % f& K% e- ]1 d4 ~7 C
  208. # such as CONFIG, DEBUG, and so forth. To a limited extend you can improve
    ; Z. w* Q6 |, R7 A: h1 n/ ]
  209. # security of read only slaves using 'rename-command' to shadow all the/ [. X* j$ |, \# v! W1 ]7 Z9 s
  210. # administrative / dangerous commands.
    " X8 D$ H4 `1 P! H% z" {1 x
  211. slave-read-only yes
    % f/ T/ G% l/ Y3 i5 ]& w' h3 J1 [

  212. 7 `3 ^. `% Z9 L( I5 V* ^
  213. # Slaves send PINGs to server in a predefined interval. It's possible to change
    $ T) F; S3 D% w$ b) o, T0 o$ {
  214. # this interval with the repl_ping_slave_period option. The default value is 102 @' t) M- J6 a/ H( c3 {# ?) b
  215. # seconds.9 U% p. p! V) Z' y: M6 _' M  @  `
  216. #
    ' o' g8 t/ N+ ~8 m* m# G* H7 q+ Q5 G
  217. # repl-ping-slave-period 10
    / R4 V/ J4 W% m% U' _
  218. $ \6 c! e( }5 e( r1 D6 J; h5 v- y
  219. # The following option sets a timeout for both Bulk transfer I/O timeout and1 {0 W) {: x2 r5 Z& [2 |1 l6 L
  220. # master data or ping response timeout. The default value is 60 seconds.% l  X+ W2 Z$ U# z. k4 D! G
  221. #) u: }8 G1 `- g6 T
  222. # It is important to make sure that this value is greater than the value$ z1 F& [, q! b
  223. # specified for repl-ping-slave-period otherwise a timeout will be detected
    . J+ S. y  ]* v- M1 s
  224. # every time there is low traffic between the master and the slave.! b4 o5 X8 e. d3 H
  225. #
    # }/ R9 ~( T6 w+ C1 q7 Z; L8 w
  226. # repl-timeout 60
    , V1 y! G8 z: j. Q2 G8 S# A8 P0 Q7 l

  227. 4 F+ ?8 y: A5 d; k! n- i3 u
  228. # Disable TCP_NODELAY on the slave socket after SYNC?
    3 p4 ?( ~# U5 S/ }, P- W5 X
  229. #& p8 d9 ~8 t0 m: }2 }
  230. # If you select "yes" Redis will use a smaller number of TCP packets and6 j0 u4 L0 g8 `" ?; V
  231. # less bandwidth to send data to slaves. But this can add a delay for
    . R5 M) C2 j& I5 ]: M
  232. # the data to appear on the slave side, up to 40 milliseconds with
    % C' e8 Z' V  N$ y. j, q1 B8 m
  233. # Linux kernels using a default configuration.% ]7 B/ a/ K! H$ o
  234. #6 o4 A! h% L1 Z) x# {/ ]
  235. # If you select "no" the delay for data to appear on the slave side will
    % ^) |/ F0 D+ f: e2 z! I% l
  236. # be reduced but more bandwidth will be used for replication.
    $ Z* w# t* u  A( U+ e$ `
  237. #0 [4 V4 v- |& u! Q5 q! {9 k
  238. # By default we optimize for low latency, but in very high traffic conditions
    # R) Y; o7 [( h( E1 l3 }) [1 n- a
  239. # or when the master and slaves are many hops away, turning this to "yes" may
    9 M! k6 j% {1 _2 z. X
  240. # be a good idea.
    6 C6 F9 p2 J1 k' {
  241. repl-disable-tcp-nodelay no3 B$ F6 F9 S( e2 ^

  242. ( \. a! P. c$ x7 j* s3 @
  243. # The slave priority is an integer number published by Redis in the INFO output.
    . b  ^: V) R, u( T# b0 F3 S
  244. # It is used by Redis Sentinel in order to select a slave to promote into a, Y' x: d2 W, V4 D- M8 }$ \
  245. # master if the master is no longer working correctly.
    % ^8 \$ ?4 V" G4 h4 x
  246. #
    ) S6 n0 s. b9 m/ }5 |; P) [0 T
  247. # A slave with a low priority number is considered better for promotion, so2 a' c) y# B% g- I1 y' h- i: b( |3 F
  248. # for instance if there are three slaves with priority 10, 100, 25 Sentinel will
    $ K  \  Q/ {. Q
  249. # pick the one wtih priority 10, that is the lowest.' K! |# Y1 I. L5 b
  250. #$ N9 U& `" V( r" f  F2 ]
  251. # However a special priority of 0 marks the slave as not able to perform the
    ( B$ h+ c8 J" }/ p3 T
  252. # role of master, so a slave with priority of 0 will never be selected by) R7 M6 T0 u& G9 ]; O- z" Q
  253. # Redis Sentinel for promotion.# y8 \$ R0 E, X7 W' _- k/ |
  254. #' J4 v) M; q( I/ @
  255. # By default the priority is 100.
    # g4 {0 u' k/ a" e1 ]7 u% t
  256. slave-priority 100
    ) g1 v2 [$ Y" R4 C
  257. 5 _4 d) H8 ?1 d! Q/ h9 ]
  258. ################################## SECURITY ###################################
      z/ N- h8 ]6 r0 k+ k

  259. ' `7 V0 i3 u: b# B
  260. # Require clients to issue AUTH <ASSWORD> before processing any other  Y, ]. L8 q  v; N6 M! g
  261. # commands.  This might be useful in environments in which you do not trust
    4 }) E* |2 w4 h( `. e
  262. # others with access to the host running redis-server.8 d" \% K) T2 }! p; v
  263. #
    ; S5 r, o! c  o1 d1 l; ^; _! @0 [3 e
  264. # This should stay commented out for backward compatibility and because most3 a: l* |- R' z3 Z; R# X# f7 b
  265. # people do not need auth (e.g. they run their own servers).+ ~4 P' g; ?4 n; `/ v  F
  266. # 3 y( T  n3 Z7 l* I# g7 D
  267. # Warning: since Redis is pretty fast an outside user can try up to: b, @& A& L! r1 f$ l
  268. # 150k passwords per second against a good box. This means that you should
      r. d2 [- A& R$ y6 W8 n
  269. # use a very strong password otherwise it will be very easy to break.. y% u2 d% G2 `5 h) V
  270. #6 J' ^% c& E9 G) `
  271. # requirepass foobared3 M. b% P7 E6 E; a2 z0 d2 Z& P
  272. : }3 T, p5 w: W8 A- h* `: J
  273. # Command renaming.
    . i+ |* ^1 e/ ]9 v8 _9 g% l/ A
  274. #! [( D7 \/ Q1 T0 @8 N
  275. # It is possible to change the name of dangerous commands in a shared
    2 t( n5 F. h& e, ]
  276. # environment. For instance the CONFIG command may be renamed into something
    2 e3 T! ^) k% |) ^5 n8 c' @
  277. # hard to guess so that it will still be available for internal-use tools+ V: M; f- Q! b3 b# N
  278. # but not available for general clients.; l' y0 P) g9 ~' X1 `, b0 s
  279. #+ a9 X$ a5 b! k4 i2 q' _8 }3 T
  280. # Example:
    3 h4 D1 B; f3 C- a) c- F! A! n
  281. #) k1 e- p0 i: ~9 B1 a# c4 p
  282. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52& Z1 E8 q+ }4 z
  283. #  K3 D" l. ^" g8 S( A
  284. # It is also possible to completely kill a command by renaming it into
    4 }/ F8 [4 K& b2 m; `  @8 b( p# g
  285. # an empty string:
    1 H4 x3 Q9 t6 p- T& J$ A, q
  286. #
    0 d7 X5 U0 P% E+ _" t% b$ e& h+ ?
  287. # rename-command CONFIG ""
    , I# \. Y9 X" o' d% s, f

  288. ! Z4 K3 k! e, Q( A
  289. ################################### LIMITS ####################################8 Z0 R. ^1 N+ _; X

  290. . t) X/ C# e" a/ y1 K9 |  Z
  291. # Set the max number of connected clients at the same time. By default6 x7 O. P9 i2 w, Y
  292. # this limit is set to 10000 clients, however if the Redis server is not2 U5 v5 |7 x% t0 F
  293. # able to configure the process file limit to allow for the specified limit3 X' C8 L( B: `  z* B
  294. # the max number of allowed clients is set to the current file limit+ ]( i( K' P3 k9 [& o' l: d
  295. # minus 32 (as Redis reserves a few file descriptors for internal uses).
    ; n' L3 W2 z! @2 b
  296. #
    $ h- g6 C+ s; t* H
  297. # Once the limit is reached Redis will close all the new connections sending3 `: v9 L, U+ _! {4 }& g$ C5 K
  298. # an error 'max number of clients reached'.! G0 X; l) a5 k: V( a+ ^# C
  299. #) L" O2 {; L, O8 o$ Z
  300. maxclients 500
    $ \0 @  n/ q2 e8 r
  301. 1 l+ ]! K% s$ C, ^9 ~
  302. # Don't use more memory than the specified amount of bytes.+ P0 D& S. B! w) J/ y
  303. # When the memory limit is reached Redis will try to remove keys$ D0 ]+ ~# o4 E# _& g6 ]
  304. # accordingly to the eviction policy selected (see maxmemmory-policy).% X2 P' _2 L6 K( y4 D5 }
  305. #. Y, w- K8 `( G7 {8 W; l
  306. # If Redis can't remove keys according to the policy, or if the policy is
    6 g% a# i$ I, P  w- r
  307. # set to 'noeviction', Redis will start to reply with errors to commands
    1 }4 x8 C2 ~  J- T4 ~" t9 s$ A
  308. # that would use more memory, like SET, LPUSH, and so on, and will continue
      m+ k% [2 }: p  i
  309. # to reply to read-only commands like GET.% \9 s" K# d) W. q+ ]. d4 l
  310. #
    ) [8 _8 q  j5 t% z& f* U% R
  311. # This option is usually useful when using Redis as an LRU cache, or to set: T, m/ b" x% a
  312. # an hard memory limit for an instance (using the 'noeviction' policy).
    2 ~& b5 @1 c$ E# \
  313. #
    , t" r, q4 m; u8 Q- ?. Z9 N
  314. # WARNING: If you have slaves attached to an instance with maxmemory on,
      b/ Q. F, N9 B/ ]3 K6 {
  315. # the size of the output buffers needed to feed the slaves are subtracted
    $ Y6 \- F1 R5 o. l2 }- S; s3 m" Q
  316. # from the used memory count, so that network problems / resyncs will2 i+ z. c: @  P6 ~
  317. # not trigger a loop where keys are evicted, and in turn the output
    . H$ ?* Q! x2 H2 _: B
  318. # buffer of slaves is full with DELs of keys evicted triggering the deletion' n7 M! E/ k9 O+ B  z
  319. # of more keys, and so forth until the database is completely emptied.* H4 U2 a" A6 E( n
  320. #( S1 _4 K4 _- {* U. R; b
  321. # In short... if you have slaves attached it is suggested that you set a lower
    8 d" N! p4 y- U* b8 g6 ]
  322. # limit for maxmemory so that there is some free RAM on the system for slave
    7 R& d4 O" g% R3 x: Y9 X9 |
  323. # output buffers (but this is not needed if the policy is 'noeviction')., d  I: t) m" q: H7 Q
  324. #% j6 M  k2 h3 z4 ~; Y9 I) l
  325. maxmemory 1280000008 ~1 y1 T- o. m- ?
  326. - t- ]0 {& G1 c" K$ w" I% ~0 L- o
  327. # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
      |3 U% k- L9 J% s- k# k
  328. # is reached. You can select among five behaviors:
    0 }9 C( [$ S+ s* O' x6 f
  329. #
    + }: }& K8 }& J# f+ L6 k
  330. # volatile-lru -> remove the key with an expire set using an LRU algorithm
    ) a: E7 T; @$ ?6 `2 d4 y
  331. # allkeys-lru -> remove any key accordingly to the LRU algorithm
    ! D& {! Y2 `9 T% r8 F
  332. # volatile-random -> remove a random key with an expire set- t% e. o% g  y4 {# K" r% k
  333. # allkeys-random -> remove a random key, any key% U" V$ x: e' j/ Q# Y
  334. # volatile-ttl -> remove the key with the nearest expire time (minor TTL)
    # \6 G/ A/ H3 F/ r
  335. # noeviction -> don't expire at all, just return an error on write operations$ f4 u) L: J) s  u' @5 _" ?4 s
  336. #
    2 K/ K2 x: U# P  S( ?2 B6 u8 P* f
  337. # Note: with any of the above policies, Redis will return an error on write
    % U' A# J! R, ~3 E2 l: I' Z' Q9 `
  338. #       operations, when there are not suitable keys for eviction.
    9 Y' B" O9 w* @- O/ R% X) ^- N7 D8 U
  339. #
    ! E! w5 j# F+ s: A* X
  340. #       At the date of writing this commands are: set setnx setex append4 U. C" y. A+ Z) n% n
  341. #       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
    2 I9 Y; u1 u0 u' J5 v" D/ |
  342. #       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby' t  p, V( y, w% ~& G. W
  343. #       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby7 t) J  Q4 {# k" d! A$ n) w) h! h$ I
  344. #       getset mset msetnx exec sort' K3 v, X5 _1 @3 j! H
  345. #3 [2 {/ I) q( l8 j
  346. # The default is:
    6 K" c% d& w" _9 h/ @
  347. #
    * l! R& s" l& }5 x* _
  348. # maxmemory-policy volatile-lru
    ) z& w4 K4 J- m
  349. ! U2 {+ D. b) v1 M+ c) H5 B
  350. # LRU and minimal TTL algorithms are not precise algorithms but approximated9 u; e* g4 C' X2 [) _
  351. # algorithms (in order to save memory), so you can select as well the sample0 G! T6 x: ~* O' f
  352. # size to check. For instance for default Redis will check three keys and
    # R7 E3 h8 r% J
  353. # pick the one that was used less recently, you can change the sample size
    7 `" L5 H0 z! L) u" `; K
  354. # using the following configuration directive.+ L, F' C/ V5 |) d+ `" G
  355. #
    + ~& X, P8 Z2 u) a) }
  356. # maxmemory-samples 3
    , o, k, N, Y8 I- @. T$ U# D

  357. 3 I$ m5 g& d3 x2 R2 `# J: r, y
  358. ############################## APPEND ONLY MODE ###############################2 [0 G7 a, s: t  X- X4 N0 @
  359. 1 u# M( }: J: O4 ?2 b9 O: d5 G
  360. # By default Redis asynchronously dumps the dataset on disk. This mode is  C2 h8 @+ t/ s) r7 n# b' s
  361. # good enough in many applications, but an issue with the Redis process or% ?+ [# L, u0 t  I0 c" ?3 h
  362. # a power outage may result into a few minutes of writes lost (depending on1 P& E$ H! v2 I7 m/ L, Q
  363. # the configured save points).
    9 h7 \( R: \3 [- m
  364. #: Y0 P# x/ ], ^1 [
  365. # The Append Only File is an alternative persistence mode that provides$ L( b4 [7 \1 {/ I$ S' _# _
  366. # much better durability. For instance using the default data fsync policy
    6 C6 l& V3 M1 g! |' u
  367. # (see later in the config file) Redis can lose just one second of writes in a6 k% ?0 f6 o$ G
  368. # dramatic event like a server power outage, or a single write if something* q! Y" l- g3 F: Z& E
  369. # wrong with the Redis process itself happens, but the operating system is  X3 L0 O  w, P
  370. # still running correctly." l! j: g& j6 W5 i" R0 s6 l" N
  371. #
    $ `% `6 s* j: ]) N( ~
  372. # AOF and RDB persistence can be enabled at the same time without problems.7 E, R" V4 P: V3 m
  373. # If the AOF is enabled on startup Redis will load the AOF, that is the file
    - C% T+ q" |# x* Z* e
  374. # with the better durability guarantees.% Y$ q% i1 B8 x" o
  375. #3 a$ v- e1 a* @9 ^; D, O* E
  376. # Please check http://redis.io/topics/persistence for more information.
    3 I. s* ^! b1 }' w# w! w

  377. 1 q9 Q# l' X, Z6 f8 {
  378. appendonly no
    " `0 [2 y0 C: l. ~6 d

  379. , R' g' _0 f- r# l  p( q7 f: Q
  380. # The name of the append only file (default: "appendonly.aof")/ \  S5 T- r( F& T, Y9 P. h
  381. # appendfilename appendonly.aof! H0 v& v' ^( q5 r; W

  382. ' [0 ?5 u/ [+ U  I  m+ B8 K- s" c3 y
  383. # The fsync() call tells the Operating System to actually write data on disk9 @7 b. M  j7 ~" S9 N: l7 a# P8 K6 o1 {* G
  384. # instead to wait for more data in the output buffer. Some OS will really flush
      @6 {4 @+ q, a5 A" q
  385. # data on disk, some other OS will just try to do it ASAP., c8 K  [$ ^/ n: R$ p) C$ g7 R
  386. #
    ) G: b: c6 `7 F( k) ~1 }
  387. # Redis supports three different modes:8 P. K! B; |2 g) ?: n& G$ x; n9 x
  388. #
    ( o$ g8 l% Q) m5 e( e" J
  389. # no: don't fsync, just let the OS flush the data when it wants. Faster.6 _- ^. Y# G. k- {0 M8 W
  390. # always: fsync after every write to the append only log . Slow, Safest.5 X( i' J8 b; W( ~! `  \
  391. # everysec: fsync only one time every second. Compromise.+ r! U4 }  g; h/ i: q  ~. q: ?
  392. #
    " [: I% o4 {( e, @8 l" ^
  393. # The default is "everysec", as that's usually the right compromise between0 M! B" D* A. ^
  394. # speed and data safety. It's up to you to understand if you can relax this to
    8 H/ n$ W7 s" W+ A
  395. # "no" that will let the operating system flush the output buffer when
    4 y8 x4 [: d8 {# g9 l; m
  396. # it wants, for better performances (but if you can live with the idea of& `3 g, @. f7 }5 J
  397. # some data loss consider the default persistence mode that's snapshotting),7 T8 {# y; B6 ]7 N+ I5 O3 q
  398. # or on the contrary, use "always" that's very slow but a bit safer than
    / l4 g6 M9 \5 S* n+ f* R3 j
  399. # everysec.
    6 m% l8 w$ ^! g$ f% |- v: c
  400. #0 V; ]7 c( u' V9 j9 P+ Z
  401. # More details please check the following article:
    ) U" U1 O9 T5 a" a: W: t
  402. # http://antirez.com/post/redis-persistence-demystified.html8 v$ o# Z0 _5 v1 ?$ T
  403. #
    ; r5 u5 v$ ^0 F; E; }5 u% k! u- o
  404. # If unsure, use "everysec".
    " l: C  t7 W: i  G8 |# W, D7 R

  405. 3 ?0 Z3 S/ v( X! C  J( j
  406. # appendfsync always9 }. e( w9 D( ]; X0 I5 M8 N5 b
  407. appendfsync everysec
    + j; g% I# z3 u0 x) p9 N- q
  408. # appendfsync no9 b/ A8 u+ a0 q' @! U  r% d

  409. ! L- ^/ E0 w, D
  410. # When the AOF fsync policy is set to always or everysec, and a background
    8 G  H  ?6 o% G* Q7 q3 z& H
  411. # saving process (a background save or AOF log background rewriting) is9 E# I! e+ Q, i3 V
  412. # performing a lot of I/O against the disk, in some Linux configurations
    ) D% {* F; C9 R6 @
  413. # Redis may block too long on the fsync() call. Note that there is no fix for
    0 T' ?1 j( }. r2 e& M
  414. # this currently, as even performing fsync in a different thread will block6 H' F0 I+ V, p
  415. # our synchronous write(2) call.
    / W2 t5 C- `8 z6 x* u, \
  416. #2 S, I' S$ u8 I6 V/ _
  417. # In order to mitigate this problem it's possible to use the following option
    5 L: E' a8 s1 _
  418. # that will prevent fsync() from being called in the main process while a
    : W) P9 g8 k  ~/ |8 F1 {/ J
  419. # BGSAVE or BGREWRITEAOF is in progress.8 |/ T' ?# L1 U: d% h- e  C
  420. #6 |5 [. ~: g1 m3 D% B2 j) N* m
  421. # This means that while another child is saving, the durability of Redis is2 o1 h; F5 j, ^
  422. # the same as "appendfsync none". In practical terms, this means that it is
    & B) d  x. s* a9 o2 N8 k% Y7 ^) E3 e
  423. # possible to lose up to 30 seconds of log in the worst scenario (with the
    + k) v8 X7 R5 T, g" k2 j
  424. # default Linux settings).  v; f1 A! i- _  d
  425. # , f  Q) Y1 n/ |/ V
  426. # If you have latency problems turn this to "yes". Otherwise leave it as4 ]' ?: k: b( o: X
  427. # "no" that is the safest pick from the point of view of durability.
    ) P- P, V: }0 D
  428. no-appendfsync-on-rewrite no
    % @2 a" z9 g6 `( }1 _( T$ E
  429. ; E& E: \$ ]8 F0 O! f
  430. # Automatic rewrite of the append only file.
    % `/ l0 l+ a- |; O
  431. # Redis is able to automatically rewrite the log file implicitly calling: ^4 m5 p- M8 ]8 o( z4 c
  432. # BGREWRITEAOF when the AOF log size grows by the specified percentage./ h, V4 r& V4 ]
  433. #
    * b1 t- {$ {+ G, s
  434. # This is how it works: Redis remembers the size of the AOF file after the) k- R! ?) y7 T4 r
  435. # latest rewrite (if no rewrite has happened since the restart, the size of: q" B, Q0 |: r' d* E1 M0 O) ^
  436. # the AOF at startup is used).( q2 ?3 |6 R6 V/ O; ^
  437. #! I' k; a$ v6 ]
  438. # This base size is compared to the current size. If the current size is1 [! b  ?4 w4 \# B7 ^+ `+ J
  439. # bigger than the specified percentage, the rewrite is triggered. Also) t% n; m% o# W6 o- S4 ]$ O: g
  440. # you need to specify a minimal size for the AOF file to be rewritten, this+ }- L6 ^: r" @1 R6 ^
  441. # is useful to avoid rewriting the AOF file even if the percentage increase
    ( u! E0 e2 e7 i. B
  442. # is reached but it is still pretty small.
    # h) w" a) Q0 u! P+ l6 T5 q* Y
  443. #
    6 n& o% M( o7 a3 R2 B
  444. # Specify a percentage of zero in order to disable the automatic AOF# B% r0 r$ N3 H+ r0 j7 a+ v+ J
  445. # rewrite feature.% i4 b/ Z3 o* W! ]
  446. 2 m- B0 F9 l; E: x. `! Z8 S
  447. auto-aof-rewrite-percentage 100
    * `9 r1 G) o6 a; U8 v7 z* n( k! |
  448. auto-aof-rewrite-min-size 64mb
    % U: T) X1 M2 n: _! V; V

  449. * [$ i7 o. V. E# L
  450. ################################ LUA SCRIPTING  ###############################( _2 X& Q1 K% Q5 [7 B4 S
  451. 9 u; q) {0 w1 X8 H
  452. # Max execution time of a Lua script in milliseconds.+ t. b7 q' X6 d, l
  453. #
    " ?2 r1 y( W9 ~$ }7 u
  454. # If the maximum execution time is reached Redis will log that a script is! m5 j  v2 a" n7 @
  455. # still in execution after the maximum allowed time and will start to
    ) C' ^. q( H5 w" H0 `& K
  456. # reply to queries with an error.
    3 A9 z4 T, \, _/ Y" j. |. E  c
  457. #
    & i8 y1 |' @7 r6 M; I
  458. # When a long running script exceed the maximum execution time only the
      [+ Z, x/ `! \
  459. # SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be
    5 S. V# o) X; s
  460. # used to stop a script that did not yet called write commands. The second+ l- A; Q  X  p! X
  461. # is the only way to shut down the server in the case a write commands was
    ! T" e8 v/ J7 n/ T* q1 {( D" l: D
  462. # already issue by the script but the user don't want to wait for the natural9 p* C+ g6 i( _! V0 K  q
  463. # termination of the script.& w3 Z+ S. |' F
  464. #
    ) @) x( e! X" b! v$ N
  465. # Set it to 0 or a negative value for unlimited execution without warnings.
    " U$ M/ i& ?- n/ I5 x$ i
  466. lua-time-limit 50007 D# R' f: m. T: a4 G
  467. + Y, A7 F! X0 K6 M1 e4 g: `6 L
  468. ################################## SLOW LOG ###################################
    5 l- F) N' |0 c4 V1 Z, l' _

  469. 9 b+ d' o. g) ]7 a# }0 c
  470. # The Redis Slow Log is a system to log queries that exceeded a specified% ]; L7 {. g+ ?4 Q/ a/ t5 e
  471. # execution time. The execution time does not include the I/O operations" `1 z/ {3 V  O, q6 u
  472. # like talking with the client, sending the reply and so forth,) W: V/ n$ e! e6 f( o& v/ E* I! _# `
  473. # but just the time needed to actually execute the command (this is the only
    9 L6 x: @" {; y/ f; u
  474. # stage of command execution where the thread is blocked and can not serve/ U2 U' Y1 P4 w& f. ]6 U
  475. # other requests in the meantime).* t1 ~7 ~! W0 {! s! P5 E- W: _
  476. #
    $ E8 d; f0 h, w; Q
  477. # You can configure the slow log with two parameters: one tells Redis
    : T" ]( ^* Z  }  ~' t
  478. # what is the execution time, in microseconds, to exceed in order for the
    8 k3 d2 ]1 e5 S' m6 C7 a, X
  479. # command to get logged, and the other parameter is the length of the6 O7 e- p1 U+ y% @2 G% q$ T! }) `# u
  480. # slow log. When a new command is logged the oldest one is removed from the
    6 c' s1 y0 a  O$ m
  481. # queue of logged commands.
    " E$ ~% F7 X. |' s$ d
  482. ( P1 k. j" _  r& j# m' Q
  483. # The following time is expressed in microseconds, so 1000000 is equivalent
    2 a* r4 g9 l0 ^4 h
  484. # to one second. Note that a negative number disables the slow log, while, I. [) z' ~( O2 ~5 S7 U, c
  485. # a value of zero forces the logging of every command.
    4 J. E& z" l3 J. ?( {) ]
  486. slowlog-log-slower-than 10000
    , m# Q' H4 s7 r4 R4 H
  487. " a% W2 w! G) ]" k: M8 N2 F. e
  488. # There is no limit to this length. Just be aware that it will consume memory.3 ^7 i; E9 x/ B" P4 ?; F9 J6 H
  489. # You can reclaim memory used by the slow log with SLOWLOG RESET.
    8 ^7 O( Z. i* E, b/ M; q
  490. slowlog-max-len 128$ e  y6 f! S' \; S' F! E

  491. % u7 [' R8 g3 S/ |! Y' O( F* @
  492. ############################### ADVANCED CONFIG ###############################( K* z* a, x6 P1 R- M
  493. 0 Y8 X* O% U7 i: f# m
  494. # Hashes are encoded using a memory efficient data structure when they have a  k" ^$ q0 C; B, D5 w& u; c  M
  495. # small number of entries, and the biggest entry does not exceed a given& B" N6 D0 i; ^, J4 I, c% _
  496. # threshold. These thresholds can be configured using the following directives.5 j6 I' E" a8 ~$ d7 h
  497. hash-max-ziplist-entries 5129 |9 e. x+ m  k0 ~. @
  498. hash-max-ziplist-value 64
    6 j2 c! |! c$ ~3 L4 K) W/ N
  499. + {/ h9 k  e- I- ~0 M1 c
  500. # Similarly to hashes, small lists are also encoded in a special way in order5 {; v  X- O# L: j; w- w1 [
  501. # to save a lot of space. The special representation is only used when
    9 z( _" o- s, b3 |2 }. \& I
  502. # you are under the following limits:# m- A" f/ U6 S
  503. list-max-ziplist-entries 512% d0 Y& I2 Q2 p% M5 _. g
  504. list-max-ziplist-value 64, }% ~6 X8 M! N

  505. # V( o5 G. _+ t3 T8 g
  506. # Sets have a special encoding in just one case: when a set is composed7 h( [! P: D7 g* \
  507. # of just strings that happens to be integers in radix 10 in the range* v' a, Y  c0 \4 Z! j7 y+ q7 g0 a
  508. # of 64 bit signed integers." p! E) W5 U! E* v4 f$ N3 T* v6 {
  509. # The following configuration setting sets the limit in the size of the
    " E6 h6 S) F2 W
  510. # set in order to use this special memory saving encoding.5 d& U- J# j# M
  511. set-max-intset-entries 512: R) @& s6 k0 D% _% J6 J2 F

  512. 9 v4 m  t. s2 K3 P& ^
  513. # Similarly to hashes and lists, sorted sets are also specially encoded in
    ! a: t. M7 O$ N) L
  514. # order to save a lot of space. This encoding is only used when the length and
    , L6 o2 D! k/ G* D/ W- W
  515. # elements of a sorted set are below the following limits:6 K. n5 X. C6 l6 w0 |
  516. zset-max-ziplist-entries 1287 L- L! s& |& T0 S( E
  517. zset-max-ziplist-value 64* ?- q1 w3 X) ]! u# |! ^  O0 k. W# R

  518. ; m% T8 q  {/ y& B3 k+ h" q
  519. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in# \2 t' x; m# _- _* R- t
  520. # order to help rehashing the main Redis hash table (the one mapping top-level$ P8 _" D% }/ ]" w; M
  521. # keys to values). The hash table implementation Redis uses (see dict.c)5 \" Q; N1 I* j3 y8 [1 k
  522. # performs a lazy rehashing: the more operation you run into an hash table. R* \7 X6 d" H8 i7 T) W+ c8 r
  523. # that is rehashing, the more rehashing "steps" are performed, so if the
    9 z% W: M. N$ p: Z, m+ O3 X
  524. # server is idle the rehashing is never complete and some more memory is used$ J; B* l9 N6 h8 N  ~
  525. # by the hash table.3 e! ^& {" h9 c4 A
  526. # 3 e$ C' D7 N  g! K" D6 w* a
  527. # The default is to use this millisecond 10 times every second in order to
    ! ?5 u6 v" F  n7 v" O
  528. # active rehashing the main dictionaries, freeing memory when possible.7 I0 t; X+ Y3 G5 d
  529. #
    6 b9 Y+ {/ @3 d9 q2 g
  530. # If unsure:
    * S8 \' T% y6 H/ R
  531. # use "activerehashing no" if you have hard latency requirements and it is
    * |) E: N, M0 }  `1 N
  532. # not a good thing in your environment that Redis can reply form time to time
    ( v) t6 w0 T7 y: I4 G* c' Y, E
  533. # to queries with 2 milliseconds delay.
    ( R; q( U& Y0 R7 x4 }* t
  534. #0 m* b& L. a" c4 a6 u; _
  535. # use "activerehashing yes" if you don't have such hard requirements but- G0 ^( A' }: j1 E8 M" ?
  536. # want to free memory asap when possible.  _# K4 r( Q. `3 ]: o4 S
  537. activerehashing yes+ ^) g& z2 j/ t8 r

  538. $ a5 Q2 o' I9 v; j1 P( f9 w
  539. # The client output buffer limits can be used to force disconnection of clients
    , @3 M3 m7 A/ H" O# c% n" Q
  540. # that are not reading data from the server fast enough for some reason (a
    ' M# V0 U8 N8 W3 s+ f7 \$ L
  541. # common reason is that a Pub/Sub client can't consume messages as fast as the9 b  a7 o6 A  C, d* f2 N4 O' @
  542. # publisher can produce them)., c: s1 s! h8 g+ U( _
  543. #
    ! V$ L1 f$ L4 R- {7 O& N7 B
  544. # The limit can be set differently for the three different classes of clients:; e1 T0 L+ t0 p$ [1 I
  545. #1 E* P2 E8 G7 p% r& }4 m
  546. # normal -> normal clients
    1 s) x& R! _, d4 `4 v/ ?- x0 B
  547. # slave  -> slave clients and MONITOR clients
    2 W& u% Z3 O1 H$ g+ G+ P
  548. # pubsub -> clients subcribed to at least one pubsub channel or pattern
    1 h$ u9 T- I6 m/ H3 p
  549. #
    ' y2 a: V, a$ s: Q
  550. # The syntax of every client-output-buffer-limit directive is the following:3 R% I) b( k1 ^: b" f
  551. #
    2 R- M6 Q8 P8 I% }/ ?0 x) y
  552. # client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>
    + n5 V+ o" B9 P4 p
  553. #
    : E; e7 v0 t) h+ B6 m* {) c, u) I
  554. # A client is immediately disconnected once the hard limit is reached, or if
    ! T7 Q& a) O- C+ U! q+ j1 l, k
  555. # the soft limit is reached and remains reached for the specified number of- W- M0 `2 ^3 d4 a! K
  556. # seconds (continuously).+ f/ f) |, _$ Q+ U& M3 m4 a. @
  557. # So for instance if the hard limit is 32 megabytes and the soft limit is3 v1 S8 q5 Z7 }% j9 k
  558. # 16 megabytes / 10 seconds, the client will get disconnected immediately1 _$ ^4 n$ b. Z7 |( G  H: M5 L
  559. # if the size of the output buffers reach 32 megabytes, but will also get5 ~0 U+ D. r1 K3 z& \  }
  560. # disconnected if the client reaches 16 megabytes and continuously overcomes" g% c7 o$ O3 E( u! |  ]
  561. # the limit for 10 seconds.; q$ ^# o- b0 Y3 \: v
  562. #
    : c$ Q, S; V9 K1 ^& `1 k/ Y# `) U
  563. # By default normal clients are not limited because they don't receive data& N% M8 S  t* Y; O; j
  564. # without asking (in a push way), but just after a request, so only
    6 d% W; r8 M1 }) U: }
  565. # asynchronous clients may create a scenario where data is requested faster
    7 A+ W' ?5 b2 \# L) T: V+ ]! s+ P
  566. # than it can read.
    ( ]! a% E* {$ a( q( L
  567. #
    " ?9 A4 N4 V* d/ q
  568. # Instead there is a default limit for pubsub and slave clients, since
    - @* K, i9 i: A- X# C; t9 u; o
  569. # subscribers and slaves receive data in a push fashion.# m' @* a  \# ^% M) E; J& R9 x+ x
  570. #" E2 P* b  W/ Y0 }6 O6 [+ O
  571. # Both the hard or the soft limit can be disabled by setting them to zero." F( q8 \3 [0 v3 ?- C
  572. client-output-buffer-limit normal 0 0 0
    , y7 r" X; l8 T- S: B, O) K9 ~  }$ s, b
  573. client-output-buffer-limit slave 256mb 64mb 60+ G! J5 z6 A/ w) }" z( ^7 q+ X+ z
  574. client-output-buffer-limit pubsub 32mb 8mb 60: [5 H' C; k6 I, L4 {. c
  575. 2 i! f4 `$ G/ X' @5 y& a# s9 v
  576. ################################## INCLUDES ###################################( J! V" h: c. L; @) w+ O
  577. ' x. d$ b0 B/ W: ]* X
  578. # Include one or more other config files here.  This is useful if you
    6 r. v  r7 `  y. ~6 m8 O
  579. # have a standard template that goes to all Redis server but also need
    7 c+ l: L) a7 f; t$ Q
  580. # to customize a few per-server settings.  Include files can include
    9 [  `# s, N0 Q, N: d" \
  581. # other files, so use this wisely.
    . G. x! U2 d  Q  R
  582. #, A9 G5 V2 r/ V  h( P) g( [( v4 ]0 f
  583. # include /path/to/local.conf
    & G2 K' {' _3 Z# d
  584. # include /path/to/other.conf        
    5 t7 R: L$ g3 `
  585. ##########################配置文件结束################################
    ) P4 N$ a0 G) M. A; B' h
  586. 第三步:启动进程
      @7 z6 b. ?% B$ _6 x. B' D  X
  587. #redis-server /etc/redis.conf
      C7 c+ \% |* J& S. W, F
  588. 查看进程有没有成功启动
    ; @6 ?( e$ q. }7 {
  589. #ps -ef | grep redis
    4 |; d. t. ?0 h
  590. 测试输入一个键值
    / d+ G, y; s9 p/ S) p- `
  591. #redis-cli set test "testredis"2 u8 ]+ d3 }& }+ ^  X6 ?4 \2 b( D
  592. 获取键值
    ) v3 W3 S7 `3 U& J" u4 S& E
  593. #redis-cli get test
    : m7 w8 \9 ^8 `* Z7 u# a

  594. 9 D' o) C( Q1 ?' \" ~. x8 R
  595. . {+ q7 V0 |6 \+ C- Y
  596. 第四步:关闭redis  (这个是更改配置文件后 正常的重启方式  不重新加载redis配置跳过)8 U: I+ ^0 U* @, j4 z
  597. # redis-cli shutdown      //关闭所有   
    * A# [9 @3 d0 s# }8 e% t4 N- h
  598. 关闭某个端口上的redis   
    & g/ `( p- X( W0 `6 f. y7 `
  599. # redis-cli -p 6397 shutdown  //关闭6397端口的redis  0 s" [, ?# u& ^6 r
  600. 说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename  dump.rdb  5 k& U" `9 [4 Q* `4 \" b
  601. ) K2 Q; }+ y* q' p

  602. ) h8 Z4 d- ?( t4 Z0 |
  603. 第5步:php扩展安装# Y2 i7 E0 H3 b, I( A
  604. phpredis PHP扩展下载地址
    / w, l  p4 ?/ Z$ Y$ Q" s1 Z
  605. https://github.com/nicolasff/phpredis/tree/2.2.2 + y; `  q7 z0 L! ^4 v3 X2 t
  606. 选择最新版本下载zip
    + P: d4 @& Y/ ^/ l- \" d- P+ E& @

  607. 1 W3 A* l/ x* p$ J1 k, B
  608. 然后自己上传zip  用unzip解压到当前目录 unzip 文件名  R; V+ S$ W* a# K  L! V
  609. : m* M$ r/ @( k) _5 h
  610. # cd owlient-phpredis-90ecd17/   #打开解压后的文件夹里面  这个解压后的目录 要是不知道 可以输入 "dir" 查看- K, B9 w% W3 I7 `5 ~9 u; A
  611. # /www/nginx_php-5.2.17/bin
    % {  x# Q8 C8 u- v0 O" t5 R: Y
  612. # ./configure --with-php-config=/www/nginx_php-5.2.17/bin/php-config
    3 k2 n7 M8 U( K% v: P* R0 s
  613. #make" F8 u3 x2 S, S# E: O* `
  614. #make install   #记录产生的redis.so路径
    ! g4 M9 w/ D, N4 a$ I& C

  615. * P3 M5 X# b4 b8 l4 a2 g: P
  616. 修改php.ini文件; u7 h# {# ~( c) L
  617. 在php.ini中添加如下一行:% [" z6 V6 j6 a, p$ ^. W/ j
  618. extension=/?/redis.so  #是刚刚记录的产生redis.so的路 写在 ?那
    6 @$ ?: B  l7 F0 M
  619. 重启 使之生效:- ]2 o: o& ~3 j" I0 Q# d- A3 t
  620. /usr/local/php/sbin/php-fpm reload
    . r+ S* o! Z- G& K5 ~4 U! A
  621. /usr/local/nginx/sbin/nginx -s reload 5 s9 o0 j2 u& A* Q
  622. / y8 T6 U: C' j/ J8 j
  623. 将 Redis 作为 Linux 服务随机启动- \1 A9 n: h: i; e. \5 S1 d5 A
  624. vi /etc/rc.local, 加入代码:
    ! v% ^, p# g9 r; }. G! ]2 h
  625. /root/redis-2.6.10/src/redis-serve  #路径看情况修改
    9 s& |) Y% E  O" A6 A% o+ Q

  626. - L6 R. C8 {8 d' i
  627. redis-cli -h localhost -p 6379 info  #命令要在redis目录下面执行! ^* Z3 [. f+ |' c$ ]5 T
  628. 提供host为localhost,端口为6379,redis服务的统计信息
    & T) r' d1 C4 B2 k& Y% _
  629. - o" x1 ^1 u/ X; {* u

  630. % P( E  D3 ?8 p9 ]4 p# Q
  631. 就这样你的web服务器就支持redis了 记得要在 给dz 的配置文件 加上12.0.0.1哦6 Q" I* J) I' B  h& X
  632. dz配置文件在 config目录下面的 config_global.php( L% J+ e- P0 d3 r- Q' K
  633. $_config['memory']['redis']['server'] = '127.0.0.1';; C/ p' X+ I' N6 \1 @, l5 q
  634. $_config['memory']['redis']['port'] = 6379;
    : g) X+ Y8 A6 [, R9 Y5 \
  635. $_config['memory']['redis']['pconnect'] = 1;
    ( w! X$ U! H" C6 Q
  636. $_config['memory']['redis']['timeout'] = '0';6 J  f" i0 y3 J  K5 i# Z- ~
  637. $_config['memory']['redis']['serializer'] = 1;+ R# |7 G* w: s* H1 N) I
复制代码
关注微信公众号《神采飞扬网》,即可获取最新回复通知!

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

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

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

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

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