分享到:
发表于 2018-11-16 12:42:28 | 显示全部楼层 |阅读模式
环境配置9 u. Z! N) n! t7 u
+ s& C4 }4 p- {

# u9 z6 A3 l0 S2 K  Z8 F: L( Ahttp://www.discuz.net/forum.php? ... amp;highlight=REDIS
关注微信公众号《神采飞扬网》,即可获取最新回复通知!
 楼主| 发表于 2018-11-16 12:43:33 | 显示全部楼层
http://www.discuz.net/forum.php? ... 648&highlight=REDIS# F4 h$ I4 w, g. w
无意间测试 单机状态 redis相当给力 测试1000请求/s  单纯的 get 和set 居然只用了 0.01秒 当时我惊呆了
- F3 R  Y  W% ], j! O% C1 S  @7 B" j5 E( b: u$ |: E+ j
http://www.discuz.net/forum.php? ... 731&highlight=REDIS2 Q5 Z! Q6 u3 j4 t* ^  H
; e9 R4 q0 K, h$ I" k
https://wenku.baidu.com/view/265a5ce176a20029bc642d0b.html
' `6 @( V' j, w
2 w- U" F, ^7 O9 v5 E& Z- B' J4 W, i=======================================
' c, C) D2 Y% I& v3 a% z
  1. 连接上 ssh
    ' T. \7 J# W0 X/ S$ `  Z
  2. " I7 x4 B2 ^# d8 D- ~0 s

  3. ( o9 t5 L, e* L6 w% c7 i
  4. 第一步:下载redis
    + U. m' l( V: v% a3 R1 U& U2 K
  5. # wget http://redis.googlecode.com/files/redis-2.6.10.tar.gz
    0 L% m' p' z4 y* ?' g
  6. # tar zxvf redis-2.6.10.tar.gz 8 v% N7 {2 [. x" M0 C
  7. # cd redis-2.6.10. r) n# z2 B( [0 d; l5 f8 I
  8. # make ; A0 V9 \0 C- q/ `! {
  9. # make install  
    4 o& Z4 E! D8 m; E9 {& t; |, h
  10. #cp redis.conf  /etc/ #复制配置文件到etc目录下面
    # e) Z: `! @+ K( Y+ F
  11. 第二步:修改配置0 k. K. R- [' W" h2 `
  12. #vi /etc/redis.conf9 o- s7 \6 j0 h1 g6 L' A, `
  13. ######################下面是无措的配置文件 复制过去就成#########
    ' ~4 y5 b! ~  |4 R8 V4 o3 k
  14. # Redis configuration file example
    5 B, j# k. Y* A1 H! z6 `

  15. 8 {- {4 d1 c2 Z4 G; y) r$ p3 i
  16. # Note on units: when memory size is needed, it is possible to specify$ H* T9 s+ E! P6 Y
  17. # it in the usual form of 1k 5GB 4M and so forth:$ j% s4 ~* Q+ b
  18. #% f7 c0 T6 _, p5 k: T9 e3 i$ w
  19. # 1k => 1000 bytes% D6 Z8 A( Z$ g
  20. # 1kb => 1024 bytes" y& O! Y  V5 ^/ \5 o
  21. # 1m => 1000000 bytes' J2 y% }- n" o1 W
  22. # 1mb => 1024*1024 bytes4 J! _5 E7 R; K/ `
  23. # 1g => 1000000000 bytes# E7 [7 D: T- M
  24. # 1gb => 1024*1024*1024 bytes
    4 O" L4 g1 G; ]
  25. #
    5 |/ {  N& t0 W" [. o
  26. # units are case insensitive so 1GB 1Gb 1gB are all the same.
    $ L* E/ `5 E% O3 {
  27. 3 q' r1 C" B" V$ g; {
  28. # By default Redis does not run as a daemon. Use 'yes' if you need it.
    5 @( u9 p9 y3 c
  29. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
    3 x# `2 ?, _3 l( Q/ b) E$ U
  30. daemonize yes! a2 M9 y' B3 n! D6 u0 S- K
  31. 1 x! d0 A& D8 K* v
  32. # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
    " I: G, x6 U1 E# u& ^+ L
  33. # default. You can specify a custom pid file location here.
    ) K5 E9 U/ C' q& D
  34. pidfile /var/run/redis.pid5 R) b( x- v* p; t7 Z# t$ R% h
  35. 1 Y5 I; M8 U5 g
  36. # Accept connections on the specified port, default is 6379.
    9 L6 @' O; b) ^6 M8 b
  37. # If port 0 is specified Redis will not listen on a TCP socket.
    % k6 [) U+ Q3 H3 y( T9 w$ k
  38. port 63790 ?  W3 c6 I- M3 D3 H
  39. * ]* X6 h% {: i6 W# }! g  `6 L
  40. # If you want you can bind a single interface, if the bind option is not
    / i6 |( K8 \! N! {4 v, Q
  41. # specified all the interfaces will listen for incoming connections.- Y5 J8 ~3 C2 [. E, S! M5 m
  42. #' F! q. ?2 A( \
  43. # bind 127.0.0.1
    % r+ Q- E( n) W0 n/ j3 ^

  44. $ ]- K3 X+ Z& u6 x0 e7 Z
  45. # Specify the path for the unix socket that will be used to listen for$ E. d: k5 }3 w( N) X# S
  46. # incoming connections. There is no default, so Redis will not listen& H: w- A% E8 ^. H9 Y
  47. # on a unix socket when not specified.
    3 O0 m# h: ~  N( H
  48. #
    , t0 A: e' k. T6 @
  49. # unixsocket /tmp/redis.sock
    4 H8 S( q% _7 W1 O' ]
  50. # unixsocketperm 755
    ' F' A5 K' Q7 _; b: \) _4 g9 P# A) E

  51. . J# b. B4 r" }# a5 o
  52. # Close the connection after a client is idle for N seconds (0 to disable): t& N; }2 ]0 l) V9 e
  53. timeout 3008 L3 y9 I( n4 M
  54. $ x7 H7 n  n1 j% F
  55. # TCP keepalive.1 A' S! e* R( _5 S( c
  56. #
    3 O9 u/ L" N. b; r6 O
  57. # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence" U- E% D8 n% I. q4 |
  58. # of communication. This is useful for two reasons:
    6 L# ?; @; k, _( }$ @
  59. #+ ]' i. N  x/ [8 e" `2 a
  60. # 1) Detect dead peers.
      j3 q, Q: t: F! M7 u* F% w
  61. # 2) Take the connection alive from the point of view of network/ R1 b1 |, V) Y9 E( L# w
  62. #    equipment in the middle.1 [- Z4 Z1 H# V4 e/ {9 ?* L. P
  63. #
    ) R: `' V: x5 Q  q8 E
  64. # On Linux, the specified value (in seconds) is the period used to send ACKs.
    " H- v. {/ n- n$ c+ U% }0 ~' n
  65. # Note that to close the connection the double of the time is needed.% N6 F1 m5 G: k/ M* d
  66. # On other kernels the period depends on the kernel configuration.
    6 t; F; S# W. M( o7 F/ j* Y; x5 Y
  67. #
    : C0 I( H* n) ~5 _
  68. # A reasonable value for this option is 60 seconds.
    & _/ ~0 ?( c& T' W6 F# J$ i, D# \
  69. tcp-keepalive 01 s/ X  }& T- z: O, K% Z  L- b
  70. 9 [6 j& ^- [) n3 ^
  71. # Specify the server verbosity level.
    / z( E% U: D  g% i  h9 m" _7 b* V
  72. # This can be one of:/ N' V7 [7 ?$ k. j/ \
  73. # debug (a lot of information, useful for development/testing)
    - m+ o9 \% r9 F
  74. # verbose (many rarely useful info, but not a mess like the debug level)
    ( q7 Z: k4 T% S7 i" |. M
  75. # notice (moderately verbose, what you want in production probably)
    & u/ O; X. e' ~: ~! }5 b
  76. # warning (only very important / critical messages are logged), }3 }+ \0 W- T3 A5 U+ L2 h/ F
  77. loglevel warning
    ; d" m9 F3 K& a* \% l
  78. ( y, c9 ?$ V$ l& D' p& Z5 l1 i
  79. # Specify the log file name. Also 'stdout' can be used to force
    ) b. x" q" v  e( e( q+ g
  80. # Redis to log on the standard output. Note that if you use standard0 p0 V9 ]/ m4 V
  81. # output for logging but daemonize, logs will be sent to /dev/null0 ?! ]. z6 V" r7 K+ }% f
  82. logfile /var/log/redis.log
    ( F2 y# D: V( s& i4 ^

  83. 2 f' m# w% {% C/ }) `/ N
  84. # To enable logging to the system logger, just set 'syslog-enabled' to yes,* [5 s* Q# Q" Q
  85. # and optionally update the other syslog parameters to suit your needs.
    1 G) p* i4 U3 ~6 ~7 C8 r3 D$ A
  86. syslog-enabled yes! Y2 ]( Y9 |0 R8 Q: `

  87. . F& h$ k1 V7 j4 H& x6 [) f( A
  88. # Specify the syslog identity." I+ M% L- m, g# s  j: S) C9 t9 B
  89. # syslog-ident redis5 a7 ]6 V# [' s: q

  90. . A1 Q+ a" t, u5 v# }5 X
  91. # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
    ; _# N3 u' s, u7 `: a
  92. syslog-facility local0
    5 X1 R" E) J! e% o! m/ B, w6 N

  93. $ ~2 k6 H$ p- _% p& n9 c  k
  94. # Set the number of databases. The default database is DB 0, you can select( _! m9 k% a& z! |* H
  95. # a different one on a per-connection basis using SELECT <dbid> where/ ~; {/ F4 W& G5 t. N
  96. # dbid is a number between 0 and 'databases'-1
    ' {6 T2 T! a& j
  97. databases 16
    # l2 c3 c0 g! K. Z9 r

  98. * ]" U; z2 {) c8 y
  99. ################################ SNAPSHOTTING  #################################6 j0 s* o3 R( P9 n6 H
  100. #
    $ D8 `8 L8 [2 m5 h( a/ ]$ ~
  101. # Save the DB on disk:
    1 ~1 r* i  H4 x5 |% j; @
  102. #% m' \! j9 n& B& }' \2 ~/ X
  103. #   save <seconds> <changes>% R" @# D" h& B: A
  104. #
    ) i( o& {& |; l' e" O( W" Y, P
  105. #   Will save the DB if both the given number of seconds and the given/ q# P9 C" p2 }2 O
  106. #   number of write operations against the DB occurred.3 e/ T- C* M8 ]
  107. #3 A/ n/ Y4 e* i! }: T
  108. #   In the example below the behaviour will be to save:  Y2 D: M: V. Y& C2 v
  109. #   after 900 sec (15 min) if at least 1 key changed; x& e* f1 b3 ?
  110. #   after 300 sec (5 min) if at least 10 keys changed
    4 A* [3 G$ F! ?! @8 m" W1 \5 Y5 f
  111. #   after 60 sec if at least 10000 keys changed
    1 |; k. x! K" _9 y+ O" |2 s
  112. #" U( e2 R# c( F7 v% ]& c, e. N
  113. #   Note: you can disable saving at all commenting all the "save" lines.
      i, a8 N) k/ P0 g
  114. #
    : m; p3 N/ d5 H  m9 u
  115. #   It is also possible to remove all the previously configured save
    9 f$ z4 r$ D% {8 e, Z8 r, B5 }" ^
  116. #   points by adding a save directive with a single empty string argument1 A) V6 ^3 i) h# V
  117. #   like in the following example:
    + `* d$ J5 l1 a" }1 ?
  118. #
    4 @: q. z; ~5 Q3 j
  119. #   save ""
    6 |. ?* L& M& p5 m6 b- u# K
  120. ' `/ d6 n' w& I4 X; B* }$ q8 ^9 B
  121. save 900 14 H9 M8 e# m, Q( ?' q+ V
  122. save 300 10. |5 h9 b9 C: t+ i
  123. save 60 10000( G% S7 s/ v- o% N: U
  124. - X9 u3 d/ A- t
  125. # By default Redis will stop accepting writes if RDB snapshots are enabled
    5 I4 n. C; K$ K. H0 G% w
  126. # (at least one save point) and the latest background save failed.
    ; p, O5 w4 J7 M
  127. # This will make the user aware (in an hard way) that data is not persisting- k) D- P4 p  @, I8 z# v3 n8 M( C
  128. # on disk properly, otherwise chances are that no one will notice and some7 e- b% u' A& _+ d! k/ d
  129. # distater will happen.! \7 Z' B7 R9 F6 r" o5 f3 u& t2 N
  130. #
    5 x3 J8 }8 g3 ~2 w4 K' N
  131. # If the background saving process will start working again Redis will
    ) T8 T. i! M6 g4 ?
  132. # automatically allow writes again.2 e6 Y" ?% |# N8 B
  133. #
    3 x; t" f% e# M) r
  134. # However if you have setup your proper monitoring of the Redis server
    : A0 E8 D( }) Y3 k6 P, F- q5 @
  135. # and persistence, you may want to disable this feature so that Redis will
    5 r& Q1 ]1 M7 p* C) `: M
  136. # continue to work as usually even if there are problems with disk,
    6 d$ m- A, G8 b. ^) n
  137. # permissions, and so forth.
    $ h$ n+ N% m& L5 L4 y
  138. stop-writes-on-bgsave-error yes3 a+ d/ x4 r9 G4 f2 n4 B

  139. * k. b: D, m1 {
  140. # Compress string objects using LZF when dump .rdb databases?1 p8 c  t' b) ?! m; f* m, u
  141. # For default that's set to 'yes' as it's almost always a win.! h" c8 V4 z1 t: V5 |
  142. # If you want to save some CPU in the saving child set it to 'no' but; C8 H; g  Z: m. ^
  143. # the dataset will likely be bigger if you have compressible values or keys.
    4 h* b! p; Y% V6 I) G" M! p
  144. rdbcompression yes
    / ~5 A& ^# u2 P# V8 a/ j

  145. 0 t4 X* i. P4 \2 Q2 a
  146. # Since version 5 of RDB a CRC64 checksum is placed at the end of the file.7 a, J9 d6 H; B; c2 G' E- k
  147. # This makes the format more resistant to corruption but there is a performance% e  j; @2 c0 @9 z' X: y
  148. # hit to pay (around 10%) when saving and loading RDB files, so you can disable it0 h) \! B9 w- z, g! V7 s$ f
  149. # for maximum performances.
    ' Q) I( j* A+ J! Z8 j
  150. #/ h' A- ~2 S+ \" H# W
  151. # RDB files created with checksum disabled have a checksum of zero that will7 S% c4 {7 c0 Y! V& L3 @
  152. # tell the loading code to skip the check.# X1 ]) e" O4 M' A
  153. rdbchecksum yes: M& k: v4 c( V

  154. 7 D' M% c+ g! p5 l
  155. # The filename where to dump the DB
    ; `. Q8 }* b# |, O' B+ `3 C
  156. dbfilename dump.rdb
    + A* U$ _! w$ ^2 _
  157. 7 P5 m1 T( U  S% y, Z. S% {" Y
  158. # The working directory.3 ~6 n. F7 G2 y0 ~$ m- l' O- ^
  159. #
    . R* Z! Q2 u; B% m+ L) K
  160. # The DB will be written inside this directory, with the filename specified
    * k# f$ T8 c7 R* b) v
  161. # above using the 'dbfilename' configuration directive.
    5 h  j* i6 ?! Y  q
  162. # # w  d) l' z( F5 A
  163. # The Append Only File will also be created inside this directory.
    ' s1 h0 M; i/ }$ }! O* p
  164. # ! D  |( E' j$ N; l8 R! O% F( E
  165. # Note that you must specify a directory here, not a file name.
    3 l1 }4 i1 c$ ^4 ]7 R- L! B
  166. dir /var/db/redis
    5 h! R* l; }0 w9 `3 r
  167. $ a/ l, R* ?& w/ P& `
  168. ################################# REPLICATION #################################
    ( V, {" q. G4 u& Z; A. a+ q
  169. * m! W) d% j9 k% T$ w
  170. # Master-Slave replication. Use slaveof to make a Redis instance a copy of
    ! j; O" Z3 M7 q4 ^5 n7 j8 ?
  171. # another Redis server. Note that the configuration is local to the slave+ }; c4 @5 [3 `, H1 k. _5 N) l
  172. # so for example it is possible to configure the slave to save the DB with a# h+ m; T7 o9 |& P" L/ X
  173. # different interval, or to listen to another port, and so on.) {2 E  y8 V, }2 y: q$ \' ^
  174. #0 v. z7 A& C6 D' @
  175. # slaveof <masterip> <masterport>8 R  v: K% ]! \% t

  176.   M- q/ v  A! [! z* }
  177. # If the master is password protected (using the "requirepass" configuration% N' @: ~# _2 ]- `
  178. # directive below) it is possible to tell the slave to authenticate before
    / F* S4 {4 d& q" D
  179. # starting the replication synchronization process, otherwise the master will5 P6 V# ~' ~6 Q4 ~% k. G
  180. # refuse the slave request." S: d% O3 D2 O, o3 ]9 m+ M
  181. #" i3 X0 J$ Q/ p  x$ @9 y
  182. # masterauth <master-password>' V' ?3 I+ Z3 g$ i) ^; s" Z) I+ ?. [

  183. 5 K  \1 `& ?8 b$ C3 }& e3 \% w
  184. # When a slave loses its connection with the master, or when the replication
    - z4 Q( f" n7 Z3 d4 p
  185. # is still in progress, the slave can act in two different ways:( ]( j. H3 q+ |/ U
  186. #
    , f0 t  f$ z$ Z; _! A( E* w
  187. # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will
    1 Y5 r* f% h. K* B& v
  188. #    still reply to client requests, possibly with out of date data, or the
    / ?3 Z% j0 E  J- F
  189. #    data set may just be empty if this is the first synchronization.) g- \! j) r7 {! H2 P
  190. #
    : k/ k1 V4 w3 \3 D- T+ y
  191. # 2) if slave-serve-stale data is set to 'no' the slave will reply with' u6 V+ F& n- a7 A& F1 S% `
  192. #    an error "SYNC with master in progress" to all the kind of commands; y, u" D# n9 x5 a5 c# Z6 }
  193. #    but to INFO and SLAVEOF.
    " x/ `& X+ e4 q5 G
  194. #
    9 j5 V+ |0 Y9 `3 A7 l% d
  195. slave-serve-stale-data yes
    1 ~4 \- d: C5 {1 i

  196. : V. v7 q- U7 A2 L
  197. # You can configure a slave instance to accept writes or not. Writing against
    3 ^" N% f' a, t- Q: n
  198. # a slave instance may be useful to store some ephemeral data (because data
    / {/ Z* u# M) d. G$ c& |
  199. # written on a slave will be easily deleted after resync with the master) but% R- ~& E; H/ D
  200. # may also cause problems if clients are writing to it because of a
    ' ~, J4 o1 y# w& Z3 r
  201. # misconfiguration.- P, d4 _" {2 t
  202. #
    : C( E* d. Y: a- K& V
  203. # Since Redis 2.6 by default slaves are read-only.
    2 ?3 s0 y4 ^7 w- Z# i( t4 F
  204. #. l0 [+ o' I; W& [; x" S
  205. # Note: read only slaves are not designed to be exposed to untrusted clients  s! L9 b0 P3 Y+ s. G: h. Q
  206. # on the internet. It's just a protection layer against misuse of the instance.
    4 A7 T( W, j8 }
  207. # Still a read only slave exports by default all the administrative commands
    & N" @! v. I5 `3 N' W% c4 I
  208. # such as CONFIG, DEBUG, and so forth. To a limited extend you can improve
    ; o' R2 ]6 c' W# o' p( b
  209. # security of read only slaves using 'rename-command' to shadow all the
    ' x+ }* |5 h, K. [7 G
  210. # administrative / dangerous commands.
    4 I1 ^  S; }2 L' N
  211. slave-read-only yes/ L+ ?8 X% q7 i( B2 Z- n8 S
  212. ; H0 F( L$ u/ ?# F( p
  213. # Slaves send PINGs to server in a predefined interval. It's possible to change4 F' c$ K7 F7 ^+ O9 j/ y
  214. # this interval with the repl_ping_slave_period option. The default value is 10
    : D; S1 r( V3 ]. C* v4 g4 b4 T
  215. # seconds.
    + ?0 h9 l, d3 m$ c, ?: l9 l
  216. #. ^7 F# W0 s+ g( v" f( I, H
  217. # repl-ping-slave-period 107 e  W# Q' r2 m8 |) _/ s1 l
  218. - |$ X$ f, R: q/ v
  219. # The following option sets a timeout for both Bulk transfer I/O timeout and
    " }  H2 u, O! u" i+ e
  220. # master data or ping response timeout. The default value is 60 seconds.
    1 z7 J4 ~# Y8 P+ X/ t2 [
  221. #
    4 J+ F- B; x0 ^8 a) {, W
  222. # It is important to make sure that this value is greater than the value
    + E, ^% h( h1 y+ T- X4 C2 V
  223. # specified for repl-ping-slave-period otherwise a timeout will be detected4 W; D3 P1 D  Z9 }7 [4 p
  224. # every time there is low traffic between the master and the slave.
    4 f: {8 K$ |7 g" r
  225. #/ w9 c9 W& k9 F! S) A, h
  226. # repl-timeout 606 B3 S, S8 {. V/ }' c

  227. 6 R0 F3 X* i" Q# g: f& J6 ]
  228. # Disable TCP_NODELAY on the slave socket after SYNC?
    4 Y/ p" y# y% `9 c. z, O! S
  229. #% `, H% z7 S" g9 J1 p
  230. # If you select "yes" Redis will use a smaller number of TCP packets and8 A6 N8 z7 c$ o' _
  231. # less bandwidth to send data to slaves. But this can add a delay for
    - i* r: J% ^3 f8 k0 M+ d
  232. # the data to appear on the slave side, up to 40 milliseconds with: v+ I6 ^! r  |4 o! J- g2 V
  233. # Linux kernels using a default configuration.
    0 @, g- L2 T  M' d1 M
  234. #
    , p: v! b. z8 C0 r/ E" o
  235. # If you select "no" the delay for data to appear on the slave side will& \- g1 y( G8 h: a- D0 \+ c6 s
  236. # be reduced but more bandwidth will be used for replication.( s2 Y7 T7 V2 E+ P$ p+ ]( b
  237. #$ ^) h! n( [1 y+ p* v
  238. # By default we optimize for low latency, but in very high traffic conditions5 L4 g: \, j3 Z/ N
  239. # or when the master and slaves are many hops away, turning this to "yes" may
    , G" H0 ]% @$ M0 a: L% C$ o* t
  240. # be a good idea.1 M0 i. c7 I, K# d6 o( p
  241. repl-disable-tcp-nodelay no
    5 J3 m9 y2 j$ W. C, u1 e

  242. $ Q) e9 `$ C5 \3 s4 E
  243. # The slave priority is an integer number published by Redis in the INFO output.
    % O. U( F- T1 W9 G: n. H4 ^: k
  244. # It is used by Redis Sentinel in order to select a slave to promote into a
    3 I( y4 c- s+ ]$ D; a' L
  245. # master if the master is no longer working correctly.6 U' o2 Y) L5 T  ]
  246. #
    ' Y! n3 C9 N# }
  247. # A slave with a low priority number is considered better for promotion, so. ^6 M) T( X* V& z5 L  W
  248. # for instance if there are three slaves with priority 10, 100, 25 Sentinel will
    , t+ g3 s* S' m" a0 o3 A
  249. # pick the one wtih priority 10, that is the lowest.
    : A  y" D# g3 s7 \' r
  250. #2 U" ]$ f' d0 }$ C$ ^
  251. # However a special priority of 0 marks the slave as not able to perform the
    ! O: A- u; i0 Y% v1 L: g% f; |
  252. # role of master, so a slave with priority of 0 will never be selected by2 K- k% _! s+ h6 `* ^
  253. # Redis Sentinel for promotion.1 s$ h; q8 M$ P0 V9 Z1 L
  254. #
    + ^; M9 [# f9 S( e9 R4 ]# ~, L# i
  255. # By default the priority is 100., F% S/ p6 h# K: v
  256. slave-priority 100
    , n) b+ v/ G7 p  d

  257. $ S7 V/ O# J+ @: g
  258. ################################## SECURITY ###################################3 `9 Y  J( O6 Z: m9 t

  259. 8 L; H8 r$ @9 Y& a  u, m
  260. # Require clients to issue AUTH <ASSWORD> before processing any other
    : p! X* ~5 _& p8 D* V: r
  261. # commands.  This might be useful in environments in which you do not trust
      B4 p+ S1 l* t/ U/ t# C+ E8 N) d1 r; B; u
  262. # others with access to the host running redis-server.' l( i: I1 l, L' `7 k
  263. #
    - H4 ~9 r) i1 z; [1 k
  264. # This should stay commented out for backward compatibility and because most3 D) W5 d8 ?4 i
  265. # people do not need auth (e.g. they run their own servers).
    " p" v4 C9 J2 c( [5 A. R
  266. # , s/ U: D1 E5 b, K2 T
  267. # Warning: since Redis is pretty fast an outside user can try up to$ i6 B% \. n7 j
  268. # 150k passwords per second against a good box. This means that you should, C* D2 ?4 r$ L5 B, m
  269. # use a very strong password otherwise it will be very easy to break.
    4 z: i  M- B. w* X  E. F
  270. #
    # G8 `: i1 R0 m7 ]+ p2 V
  271. # requirepass foobared
    # |/ `' A9 x4 q6 ^/ q

  272. 0 b# B5 S; o0 P$ t
  273. # Command renaming.4 D8 b5 Q3 G: }2 a
  274. #8 o- p% K! Q' z. B! @: Z7 ~: U" Q
  275. # It is possible to change the name of dangerous commands in a shared( ~! u/ V# K; L) R
  276. # environment. For instance the CONFIG command may be renamed into something
    + |# V. f# \1 e" h8 E% ]# |4 v
  277. # hard to guess so that it will still be available for internal-use tools0 H9 s, o2 F% w
  278. # but not available for general clients.2 n7 ~/ `1 m' m6 ~- m$ s
  279. #  ?& }, ?; Z+ t" s% z  g# _
  280. # Example:5 q( H7 ^6 H# J
  281. #- B6 y3 K+ @$ H2 C
  282. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
    ( _. U. d) J% Z+ S% h
  283. #- ]2 ~! X0 S+ W3 ^) `2 N
  284. # It is also possible to completely kill a command by renaming it into
    - M3 t9 k* a( Q: q- ~) ~4 c
  285. # an empty string:
    3 q3 w, c) X5 H/ [
  286. #
    / `% k4 z' _+ a3 t
  287. # rename-command CONFIG ""
    * R! v- t% ]1 S9 {

  288. ! I& m$ W& ~$ `2 `
  289. ################################### LIMITS ####################################! E/ P3 V; ~% {: f- Z
  290. / |- B* t, {! P$ `$ K/ _7 A
  291. # Set the max number of connected clients at the same time. By default+ o& ^# w" f+ p! ]7 h
  292. # this limit is set to 10000 clients, however if the Redis server is not
    ( c- L! G7 X6 t& u
  293. # able to configure the process file limit to allow for the specified limit& m: n- S" m: \5 T
  294. # the max number of allowed clients is set to the current file limit9 H: h- @( E- H$ t5 M# {
  295. # minus 32 (as Redis reserves a few file descriptors for internal uses).3 O, [; x- H2 p
  296. #1 K* [% A1 \; F) q7 w
  297. # Once the limit is reached Redis will close all the new connections sending" @' X8 o  w$ d8 B
  298. # an error 'max number of clients reached'.
    / @$ r4 D4 J% e* m  \9 w
  299. #
    ! |2 t) A# T4 u$ V! M" e
  300. maxclients 500
    ' s8 h9 k0 X+ ]2 g- |; p

  301. 8 m& a" X) j! d+ j0 i, n* r
  302. # Don't use more memory than the specified amount of bytes.
    % e  q2 [' K6 C, c
  303. # When the memory limit is reached Redis will try to remove keys1 }5 A9 a" p& W1 ]
  304. # accordingly to the eviction policy selected (see maxmemmory-policy).
    1 ?7 L; ?4 W$ m8 M0 P
  305. #: M  c% {2 w$ {% |+ q* D
  306. # If Redis can't remove keys according to the policy, or if the policy is
    ' S" b; f8 W7 ~0 B, B" ]
  307. # set to 'noeviction', Redis will start to reply with errors to commands
    : Z9 f4 i) J5 Q7 P& W1 Z
  308. # that would use more memory, like SET, LPUSH, and so on, and will continue/ _" C+ u0 _2 }+ b5 Y) G8 ]
  309. # to reply to read-only commands like GET.
    , ]* C: Q$ K. V0 P7 c. v
  310. #, W# V  j8 G; v' f. p
  311. # This option is usually useful when using Redis as an LRU cache, or to set3 T* R  _+ F, G0 P$ Q+ C
  312. # an hard memory limit for an instance (using the 'noeviction' policy).
    & w  T( D6 w6 U, V
  313. #* W6 ?$ K# h9 j& b7 a$ {+ {, L5 f
  314. # WARNING: If you have slaves attached to an instance with maxmemory on,
    5 G$ h4 B! a/ d5 g
  315. # the size of the output buffers needed to feed the slaves are subtracted  |$ s9 P. ~- ^' a
  316. # from the used memory count, so that network problems / resyncs will
    9 b2 E8 a% B8 {* v  x9 [, \: G; S
  317. # not trigger a loop where keys are evicted, and in turn the output* l6 q1 @' F) t! `, W6 B
  318. # buffer of slaves is full with DELs of keys evicted triggering the deletion, s9 u; B+ s( d8 y7 z3 N% h8 j
  319. # of more keys, and so forth until the database is completely emptied.
    * |% h" d3 l3 f( _& i( u; f4 N
  320. #
    , p9 p' X; v* M5 j: j
  321. # In short... if you have slaves attached it is suggested that you set a lower, H/ a0 f# q7 i: Q! `8 g
  322. # limit for maxmemory so that there is some free RAM on the system for slave
    % b7 g6 I; N4 m7 l) v
  323. # output buffers (but this is not needed if the policy is 'noeviction').: p( M1 h% @! x3 B% J8 M6 M$ q
  324. #
    8 s% I7 a4 x0 D1 V8 F
  325. maxmemory 128000000% \! k. ]& \! C! z+ q

  326. 4 C4 Z* A5 E; I+ B0 l" \9 a+ x7 E
  327. # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
    ' p/ n. t# [! Q' O, I
  328. # is reached. You can select among five behaviors:
    # ~7 ^, L- A, W8 x& Q
  329. # 7 p6 t" J$ y& P+ x1 F
  330. # volatile-lru -> remove the key with an expire set using an LRU algorithm
    ! Y2 N0 W: v" p' j
  331. # allkeys-lru -> remove any key accordingly to the LRU algorithm$ d& [6 ~& b- H  m0 p) S. Q
  332. # volatile-random -> remove a random key with an expire set8 |* A, j. }: W% l. |& U2 K3 R
  333. # allkeys-random -> remove a random key, any key
    1 q' P3 g1 q( x8 Y
  334. # volatile-ttl -> remove the key with the nearest expire time (minor TTL)0 R- x2 W8 `8 ]/ G% c) f# B
  335. # noeviction -> don't expire at all, just return an error on write operations
    ! M7 q- x' c' k/ S( b4 t2 u. L2 m
  336. # * Z$ t# j, Y9 _6 m, g
  337. # Note: with any of the above policies, Redis will return an error on write
      s7 n6 s, v3 i2 c
  338. #       operations, when there are not suitable keys for eviction.% c3 R: }6 }4 W# N* j+ N7 N& I8 W
  339. #) T( `, Z) C3 a! l# b. ]
  340. #       At the date of writing this commands are: set setnx setex append
    , Q+ ?) V' H8 s7 Z; g; |/ A1 d
  341. #       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd) B- B3 W4 L5 [. p' O
  342. #       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby3 y# K; v7 q9 [  P0 d1 ?) A$ {. o
  343. #       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby/ m/ R9 y" n% Y& L  b# q
  344. #       getset mset msetnx exec sort1 `: L9 D$ ^# Y, n% X9 e
  345. #
    : {/ ?" ?) u" T
  346. # The default is:
    # W: c1 D8 m3 J( }* c0 M
  347. #
    ( P/ Q( `1 l8 z8 l" G
  348. # maxmemory-policy volatile-lru
    & t2 F& O$ `. |  e, w* a& n
  349. : e2 U: A/ F7 z: y1 J3 M( l
  350. # LRU and minimal TTL algorithms are not precise algorithms but approximated2 L- `- ]+ e# _9 }1 x7 ?: Q
  351. # algorithms (in order to save memory), so you can select as well the sample
    . r" z7 }! i9 k! w
  352. # size to check. For instance for default Redis will check three keys and' B" t( b7 x2 B9 _& |" D% O
  353. # pick the one that was used less recently, you can change the sample size0 j' _# X* @6 h$ |
  354. # using the following configuration directive.+ W" E  V) _! v( U3 @. M
  355. #" l7 l/ B! k9 b- ?  R; O
  356. # maxmemory-samples 3
    8 d1 A( b" v6 D& q1 R2 G( R

  357. 6 g+ B* c- }, [; \
  358. ############################## APPEND ONLY MODE ###############################) `0 |* f; c. w, A* _

  359. " Y; R! {6 m& c+ D$ `1 k
  360. # By default Redis asynchronously dumps the dataset on disk. This mode is9 i, t- U% J8 u, ^% l
  361. # good enough in many applications, but an issue with the Redis process or
    - ?8 C( v: }$ S# F$ t
  362. # a power outage may result into a few minutes of writes lost (depending on
    2 V9 F3 {" t' b8 m! \3 a
  363. # the configured save points)." n, A0 h4 z5 P$ J  Y/ @
  364. #
    * m$ m! Z" Q5 C* U- m* Y8 W2 C
  365. # The Append Only File is an alternative persistence mode that provides
    $ L" `( L% s! O5 k/ s6 m6 O
  366. # much better durability. For instance using the default data fsync policy
    0 z" Y# [9 {9 a3 M
  367. # (see later in the config file) Redis can lose just one second of writes in a
    ! U" f6 |+ x6 f7 ]# [
  368. # dramatic event like a server power outage, or a single write if something4 b: ?& p9 |  F$ a" Z
  369. # wrong with the Redis process itself happens, but the operating system is* O' W4 e+ |' }# m+ e
  370. # still running correctly.
    " @" z$ L1 [9 b; A
  371. #
    : e7 _$ Q4 m# `0 Q' L% i
  372. # AOF and RDB persistence can be enabled at the same time without problems.; K0 }9 Z; h- J/ y  B
  373. # If the AOF is enabled on startup Redis will load the AOF, that is the file
    ) E" X3 Z/ X: {" A, V) x
  374. # with the better durability guarantees.
    : D: @' @8 \# m& ^% l
  375. #
    # w8 D- p  Y5 @2 W7 X% F( i
  376. # Please check http://redis.io/topics/persistence for more information.
    # Z( `! H: R+ n! X5 C) ^9 O1 L/ |

  377. 0 H5 S3 k3 r8 W
  378. appendonly no+ G, N% h2 \2 q
  379. ! o' i7 X% _' p+ Z! H8 K0 p
  380. # The name of the append only file (default: "appendonly.aof")0 P( h( h% k& w0 F. H# E6 o) c& z
  381. # appendfilename appendonly.aof! B, f# z+ f4 \/ D2 c% G$ M
  382. 9 W) g: `6 g2 e* Z. Z
  383. # The fsync() call tells the Operating System to actually write data on disk
    # m! p) z" P1 U" n1 w/ i
  384. # instead to wait for more data in the output buffer. Some OS will really flush
    # p/ ]4 @+ K' T: U8 L! L: y: j+ f
  385. # data on disk, some other OS will just try to do it ASAP.$ g+ G$ I- N- t. r4 M
  386. #
    - X" ?( \) n+ W
  387. # Redis supports three different modes:" J5 U* P; n6 U0 i
  388. #
    ) F. }& Z2 `# |8 `$ z: M, [
  389. # no: don't fsync, just let the OS flush the data when it wants. Faster.
    8 r5 w) U& o6 N- G7 L' h3 K
  390. # always: fsync after every write to the append only log . Slow, Safest.7 o2 b) Y6 F3 k/ @3 C* }2 R2 t: N
  391. # everysec: fsync only one time every second. Compromise.
    7 N* \: }! C. g% ~& i" i$ t) O
  392. #
    / I$ p7 y9 X& Y
  393. # The default is "everysec", as that's usually the right compromise between/ q; y- f8 p% }9 ^6 m2 I# a5 A* V% i
  394. # speed and data safety. It's up to you to understand if you can relax this to
    ! b$ a+ I" y5 l3 o) Q" _
  395. # "no" that will let the operating system flush the output buffer when/ L: C3 b2 k8 E, W5 j  {. P
  396. # it wants, for better performances (but if you can live with the idea of: C% t$ d  ^' D, r- k" y5 }
  397. # some data loss consider the default persistence mode that's snapshotting),: G; X; Q) j2 \; _# L5 X- b
  398. # or on the contrary, use "always" that's very slow but a bit safer than" r/ M0 N5 X) ?0 S
  399. # everysec.5 W6 r1 u  U7 r/ _! V
  400. #- O  \0 I; R. O& F& k. U
  401. # More details please check the following article:
    ' w, m4 u! }2 h: H% F
  402. # http://antirez.com/post/redis-persistence-demystified.html
    ! n: M( ?& v+ E' {: Y
  403. #8 W/ O/ h& z# z
  404. # If unsure, use "everysec".
    ; a4 u4 B. U0 n$ K5 `2 m7 S2 b
  405. 8 d/ q  |$ o, d2 ?* y) H
  406. # appendfsync always% c6 u/ v" v) \$ K  g
  407. appendfsync everysec1 B8 i! m4 A" }" k' \. L& p
  408. # appendfsync no
    4 h2 m0 g$ m' i4 M* }  z
  409. ; B; R# b9 }* N& M
  410. # When the AOF fsync policy is set to always or everysec, and a background% L! h  t3 f) y- Q) S- {
  411. # saving process (a background save or AOF log background rewriting) is
    $ d) U5 ]0 c. e5 k; \( {' W
  412. # performing a lot of I/O against the disk, in some Linux configurations6 G( Q' e$ @, c* L6 Z, E) k4 E
  413. # Redis may block too long on the fsync() call. Note that there is no fix for" ~) f, O- |" m; z9 ]
  414. # this currently, as even performing fsync in a different thread will block4 A8 L1 n5 X; g) Z: I
  415. # our synchronous write(2) call.
    6 o: j* w6 P4 u0 i; c5 x
  416. #8 d1 |: g5 i3 o1 j
  417. # In order to mitigate this problem it's possible to use the following option
    1 _/ r. v! O* I% s
  418. # that will prevent fsync() from being called in the main process while a! L  r0 @) l6 s! t
  419. # BGSAVE or BGREWRITEAOF is in progress.4 y- z* g) U6 [1 n1 l
  420. #
    8 A; F& A0 E' D4 M- j& y- z
  421. # This means that while another child is saving, the durability of Redis is- p' O4 n1 S5 j
  422. # the same as "appendfsync none". In practical terms, this means that it is  P/ g: K. j7 V
  423. # possible to lose up to 30 seconds of log in the worst scenario (with the
    , l, p5 p# ?) T% P( d2 v
  424. # default Linux settings)." \2 t8 R& X' d2 o8 e7 G* H4 q
  425. #
    7 O  _) \- D1 H
  426. # If you have latency problems turn this to "yes". Otherwise leave it as
    1 u/ a/ |: Q6 D, r) l) [  N
  427. # "no" that is the safest pick from the point of view of durability.
    ( W- r4 x& b* c7 J
  428. no-appendfsync-on-rewrite no
      }# L3 `: U- P3 o" R7 n
  429. / G- k& E5 P: o1 y0 q9 d
  430. # Automatic rewrite of the append only file.: C9 {4 \$ U% _' Y
  431. # Redis is able to automatically rewrite the log file implicitly calling: [& y0 ~: o5 W9 G. W( _! s
  432. # BGREWRITEAOF when the AOF log size grows by the specified percentage.
    $ E- v( \3 G9 O9 ]
  433. #
    + B8 ^9 @! Z, W! a8 @
  434. # This is how it works: Redis remembers the size of the AOF file after the
    # l2 g7 x9 O9 O2 ?
  435. # latest rewrite (if no rewrite has happened since the restart, the size of
    - i. d: f5 o. @. ~, @1 O
  436. # the AOF at startup is used).) c0 {# M9 l3 ]3 V; M8 E2 k- t) R
  437. #
    ! L" k2 \# A$ V! w, r
  438. # This base size is compared to the current size. If the current size is
    & {: G& ~$ i& X# s  j- D3 S* u
  439. # bigger than the specified percentage, the rewrite is triggered. Also) Y/ E5 x% q. T  ~
  440. # you need to specify a minimal size for the AOF file to be rewritten, this* [/ o1 {  _: P9 m% F8 V8 O' S
  441. # is useful to avoid rewriting the AOF file even if the percentage increase# q) K! o0 g0 g; i6 `
  442. # is reached but it is still pretty small.' m" J! _& {7 `) N" H0 [
  443. #8 T/ P: i( e' G% `$ U
  444. # Specify a percentage of zero in order to disable the automatic AOF, w: J4 b) X5 Q6 W. p
  445. # rewrite feature.) {1 h$ `) c3 \) J# x! S- J

  446. ( H! R8 Z. S' w: s9 Z* H
  447. auto-aof-rewrite-percentage 1004 |6 \) j( t/ F6 @* C) B0 L
  448. auto-aof-rewrite-min-size 64mb) g1 ]) Z2 D0 Q- c! a

  449. , i4 q7 C# B$ L- K9 b* T$ W
  450. ################################ LUA SCRIPTING  ###############################
    % K2 W( X. g! C  h& V. D. C
  451. / K; X" P+ F5 n0 C" F* h) x, @
  452. # Max execution time of a Lua script in milliseconds.
    5 Z6 i' \3 t+ M) H& i6 A
  453. #
    + u3 Z! t. f6 V! S7 L! a- p
  454. # If the maximum execution time is reached Redis will log that a script is
    8 v+ ?; ~' z. d3 |7 b
  455. # still in execution after the maximum allowed time and will start to
    % P8 w) H" I+ e  U, p6 g
  456. # reply to queries with an error.
    7 f% t5 ^5 p$ L& ^3 {& R# r
  457. #
    9 f5 b( b" x2 Y. O
  458. # When a long running script exceed the maximum execution time only the6 Q$ s9 Q0 r; o8 h, i+ L
  459. # SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be
      X: _  n# d4 h- q! C) I0 m% c
  460. # used to stop a script that did not yet called write commands. The second
    2 H( F6 V, H4 h' q; S! D. C/ z5 b8 ]
  461. # is the only way to shut down the server in the case a write commands was' V9 \1 Z  m* S7 o% C$ V
  462. # already issue by the script but the user don't want to wait for the natural
    9 d( c+ L" S. c8 C
  463. # termination of the script.0 v0 o( \: d  v$ w
  464. #$ B! C  ~0 |6 m& X1 g% |
  465. # Set it to 0 or a negative value for unlimited execution without warnings.3 x5 y9 ~) H3 O
  466. lua-time-limit 50007 M! V' T8 c) b  D& Z) G  E  o

  467. 5 P9 _3 Z  A, v) V; x
  468. ################################## SLOW LOG ###################################' Z6 B* j" ^3 B7 O. ^

  469. # ?, ?+ W1 U+ k) l
  470. # The Redis Slow Log is a system to log queries that exceeded a specified) N, P* ^/ c. T. G; C
  471. # execution time. The execution time does not include the I/O operations
    / L2 C$ \' n  _$ f) P
  472. # like talking with the client, sending the reply and so forth,$ T0 `  Y+ m% D. J8 L$ i( U
  473. # but just the time needed to actually execute the command (this is the only- Q& n! f4 y$ a- S% Y. |. U: z
  474. # stage of command execution where the thread is blocked and can not serve+ C3 `0 s! Y5 h# u& ~2 p
  475. # other requests in the meantime).& z! N: O* ?" x) |
  476. # / \0 z5 U+ ^/ W/ `# W
  477. # You can configure the slow log with two parameters: one tells Redis
    2 k- J4 D( [* D+ y
  478. # what is the execution time, in microseconds, to exceed in order for the
    & @( J$ c$ R6 F$ z" ]
  479. # command to get logged, and the other parameter is the length of the
    ; W. [3 x; u7 @$ \1 r
  480. # slow log. When a new command is logged the oldest one is removed from the
    3 O9 [) f& o' G5 L! z: ^6 \
  481. # queue of logged commands.# r9 E" n/ C& l# ?5 ~/ [
  482. ' o0 y4 P, |/ M6 `$ @
  483. # The following time is expressed in microseconds, so 1000000 is equivalent
    ) `: ~# |8 u/ R( J: }0 p+ |. Y% c3 E5 c
  484. # to one second. Note that a negative number disables the slow log, while' X# S, E9 Z0 T6 H& h% G# T
  485. # a value of zero forces the logging of every command.
    ' K; Q3 g* X, Y; o. k: n2 H
  486. slowlog-log-slower-than 10000
    % `! c3 S5 @" q" H7 Z9 H5 w' `
  487. # i) N9 ]  F5 S% }) M5 v
  488. # There is no limit to this length. Just be aware that it will consume memory.
    & y# A% W+ f' R  `  j
  489. # You can reclaim memory used by the slow log with SLOWLOG RESET., o& b; X) x" A4 N9 M& x: M
  490. slowlog-max-len 128/ q7 s1 Z- M# {( c2 x9 B, g4 m

  491. : a9 O$ ], @3 E, m6 p
  492. ############################### ADVANCED CONFIG ###############################- B7 Y. [. k+ }+ i
  493. & o, h# F( _! F4 N
  494. # Hashes are encoded using a memory efficient data structure when they have a, x' }$ i* q1 R1 X: J  b& ^' a
  495. # small number of entries, and the biggest entry does not exceed a given
    1 i& ^8 u$ D& p
  496. # threshold. These thresholds can be configured using the following directives.$ p3 J% u0 C0 {
  497. hash-max-ziplist-entries 512( l( J( F; \) i; G9 c
  498. hash-max-ziplist-value 64( ^4 [% o9 [, C; ?
  499. ( G9 F$ b3 n4 E
  500. # Similarly to hashes, small lists are also encoded in a special way in order
    + \5 I% w$ B, r# T- Z% |/ Q0 F
  501. # to save a lot of space. The special representation is only used when! t5 A! \9 s5 q* m5 H
  502. # you are under the following limits:
    ! u8 E. L3 V/ k/ m' C$ Y7 Z" _
  503. list-max-ziplist-entries 512) q9 Y5 C: @, O
  504. list-max-ziplist-value 64  B! q3 F( _# w0 J9 P! U

  505. # E) Y: A1 n2 L' _, v3 S
  506. # Sets have a special encoding in just one case: when a set is composed, H' a5 ?/ ^/ v4 b
  507. # of just strings that happens to be integers in radix 10 in the range
    9 a4 j; z) H0 d4 m$ T
  508. # of 64 bit signed integers., t' w0 `  b+ t8 i5 k' {3 e7 t0 z  ~
  509. # The following configuration setting sets the limit in the size of the
    ! ?- n: K, S, N& j; U8 _
  510. # set in order to use this special memory saving encoding.. t; M, W) O3 z4 l. J% ?
  511. set-max-intset-entries 5122 {0 T# Z" M- `
  512. & i& _9 F* _/ V% P3 E" q" Z
  513. # Similarly to hashes and lists, sorted sets are also specially encoded in
    + r1 f) i/ }% g+ ^
  514. # order to save a lot of space. This encoding is only used when the length and
    , N2 C9 k$ O6 o( M
  515. # elements of a sorted set are below the following limits:' a1 n2 d5 M, j# x2 f' s* n
  516. zset-max-ziplist-entries 128
    6 j) x9 u* x8 |9 U, _
  517. zset-max-ziplist-value 64' D9 V0 H* H. s8 \( S& o& R" Z

  518. ' E" X  b& b) k: j6 u- {2 I
  519. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in0 \) q+ b- H" _5 S4 f( h' |
  520. # order to help rehashing the main Redis hash table (the one mapping top-level
    : K' g1 V/ Y: ]
  521. # keys to values). The hash table implementation Redis uses (see dict.c)! \  b: v: s. M  @
  522. # performs a lazy rehashing: the more operation you run into an hash table( a1 X& u; |6 t, `* O% ^/ ]
  523. # that is rehashing, the more rehashing "steps" are performed, so if the/ N6 r' C3 q9 D
  524. # server is idle the rehashing is never complete and some more memory is used
    * p' O1 a& `# _2 s! }
  525. # by the hash table./ l! i4 c  }9 C( C' M, M
  526. #
    9 g& v+ a2 J5 N  z8 }9 f8 {# r
  527. # The default is to use this millisecond 10 times every second in order to+ }1 R/ o6 |3 G# }1 S
  528. # active rehashing the main dictionaries, freeing memory when possible.( J6 p7 `2 B* t4 S) x* u
  529. #
    2 X- ^: ~# g" b7 P- g
  530. # If unsure:" _0 _& [$ i0 z$ j
  531. # use "activerehashing no" if you have hard latency requirements and it is6 J. ^) A: S/ E
  532. # not a good thing in your environment that Redis can reply form time to time+ _; C4 L, K5 {  B1 M+ J& K- }& Z
  533. # to queries with 2 milliseconds delay.
    " ]& k2 x  ^# G$ P7 S
  534. #7 f) m& I2 L. F; v$ D
  535. # use "activerehashing yes" if you don't have such hard requirements but
    ' {/ o- S) B9 ]% B
  536. # want to free memory asap when possible.
    $ k  ]& i7 h2 u* Z
  537. activerehashing yes: i. T  m2 {/ X/ i9 N# ?
  538. & j$ {/ Q8 U) ?9 f
  539. # The client output buffer limits can be used to force disconnection of clients, M. y' v6 y) m3 G) X' b, Y) P- r
  540. # that are not reading data from the server fast enough for some reason (a
    4 v2 ]3 n9 B. U# }! j
  541. # common reason is that a Pub/Sub client can't consume messages as fast as the( q8 m- s8 M8 D8 X4 A9 T
  542. # publisher can produce them).  v$ [  A: |& w" s
  543. #
    . r4 U7 q$ d* }! O. \) o
  544. # The limit can be set differently for the three different classes of clients:9 \, f& U( L6 R9 X& A% O0 c: K: ?( M
  545. #2 n/ I. B# c# A  ^1 {% D. c
  546. # normal -> normal clients9 C9 g+ i8 Z* _! F( T
  547. # slave  -> slave clients and MONITOR clients
    6 r/ D/ d# N3 j: [* o% @. ~  t
  548. # pubsub -> clients subcribed to at least one pubsub channel or pattern
    ! @9 }4 Z0 _0 \: R) [1 |  s/ G
  549. #4 z( _0 t% ^1 [/ w# N
  550. # The syntax of every client-output-buffer-limit directive is the following:
    # }$ `1 z7 h) V
  551. #
    8 p# j: h; ]3 b4 C8 u" y, d9 i
  552. # client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>
    ) v$ @, ^; t  U# v8 U, {6 ^1 }+ W
  553. #7 g2 E9 a# M  o5 ?+ s9 @# F
  554. # A client is immediately disconnected once the hard limit is reached, or if
    ! c% ?6 h. x; ~+ o3 o. D* N- Y* j
  555. # the soft limit is reached and remains reached for the specified number of( w) A7 ?5 d! \- v; |
  556. # seconds (continuously).9 G# b4 P7 y- l# {0 g
  557. # So for instance if the hard limit is 32 megabytes and the soft limit is
    7 l9 B4 J7 d) M8 Z! r0 Z. G) F
  558. # 16 megabytes / 10 seconds, the client will get disconnected immediately
    - N) j/ Q8 X; i: ~6 `
  559. # if the size of the output buffers reach 32 megabytes, but will also get
    0 e9 A- l" A3 \- N! a; D$ a
  560. # disconnected if the client reaches 16 megabytes and continuously overcomes! l0 l. J' ~$ n
  561. # the limit for 10 seconds.
    / W5 Y, [4 J" {3 Q7 B. S% W  }) X+ c
  562. #0 V7 V' m6 J! c3 k6 B: U" f
  563. # By default normal clients are not limited because they don't receive data
    8 _# o* g9 J; D1 e9 c, }
  564. # without asking (in a push way), but just after a request, so only
    $ \3 J& n- L0 O* v7 A- n1 b% N* g; P
  565. # asynchronous clients may create a scenario where data is requested faster
    6 O1 i: V, K. [
  566. # than it can read.: C" C& B1 W/ @9 ?6 [! g6 @
  567. #% y( F3 p6 G; i; B( ]% P6 y
  568. # Instead there is a default limit for pubsub and slave clients, since# n3 n* I) L* J: Y) J
  569. # subscribers and slaves receive data in a push fashion.8 @1 j! O. \$ [
  570. #
    + d1 F, u/ \" m" y& c
  571. # Both the hard or the soft limit can be disabled by setting them to zero.& _) x6 A) R/ t& Y
  572. client-output-buffer-limit normal 0 0 0" n8 ?" C* ]; [4 j3 x& D; u
  573. client-output-buffer-limit slave 256mb 64mb 601 ~" A$ l, e4 w0 d( [  j
  574. client-output-buffer-limit pubsub 32mb 8mb 60
    . \5 s. q& `4 p% V& P
  575. 1 j: s/ v7 G8 l" ^5 Q, X& z9 S
  576. ################################## INCLUDES ###################################
    2 V# H  b( ^5 _1 S, c5 L. n
  577. - {" U+ g0 q+ S( I
  578. # Include one or more other config files here.  This is useful if you, i9 n( ^$ I6 @! z. G! f
  579. # have a standard template that goes to all Redis server but also need
    + M( }" ]. _3 Q; J1 U# F
  580. # to customize a few per-server settings.  Include files can include% R5 A" z! G# x; m
  581. # other files, so use this wisely.1 y% M# Y) T$ S; D& r
  582. #
    6 W+ H# A2 f5 A) w0 _0 p2 \2 i0 v
  583. # include /path/to/local.conf" `* M: h/ a! a! l: l
  584. # include /path/to/other.conf        4 f0 v$ x7 f3 E/ m+ J4 a( v; e
  585. ##########################配置文件结束################################
    & }! @: Q$ s. Y  g
  586. 第三步:启动进程
    2 i# c- A2 t& p
  587. #redis-server /etc/redis.conf
    - Y) P& t: \' M
  588. 查看进程有没有成功启动
    ' C& K' |- a, J* R+ [5 @0 l8 i$ A
  589. #ps -ef | grep redis
    4 C* l& z4 Z  I+ m4 c, a
  590. 测试输入一个键值
    * ~9 ?5 I+ I8 A, F& h" Y# }4 [
  591. #redis-cli set test "testredis"9 k: ~" u: {* @
  592. 获取键值
    4 p$ w2 y% a( w% R/ I( K
  593. #redis-cli get test
    " {: M5 E4 n# N$ _3 u. k* p' [
  594. 5 a( b$ p% y8 `' {% C

  595. / @; {$ ~5 S/ K" W" z& |5 b
  596. 第四步:关闭redis  (这个是更改配置文件后 正常的重启方式  不重新加载redis配置跳过); B8 a0 Q. Q# ?) U
  597. # redis-cli shutdown      //关闭所有   
    " K! ^4 O$ p2 X/ d5 q- G/ o3 V
  598. 关闭某个端口上的redis   
    , A! r) j3 p" x& j
  599. # redis-cli -p 6397 shutdown  //关闭6397端口的redis  4 a" n1 ~9 h( c2 M+ U) T
  600. 说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename  dump.rdb  
    0 W) L: S' A$ J* w

  601. # i* A+ Q- T6 `; _; [- f

  602. & \: x# `& h3 V$ N: {6 P
  603. 第5步:php扩展安装
    ' B5 X* S6 e7 g$ o/ m8 o% D
  604. phpredis PHP扩展下载地址
    7 \: b# O7 e0 D0 S, F7 G2 @
  605. https://github.com/nicolasff/phpredis/tree/2.2.2
    , H6 ^! U- ~! B5 ]6 W
  606. 选择最新版本下载zip
    & D& C! \: Q: s( W
  607. - L- Y: q2 O- W+ v# W( D& Y
  608. 然后自己上传zip  用unzip解压到当前目录 unzip 文件名" u6 t2 f3 [) ~8 R- M
  609. 4 l: [9 f4 N' P8 b+ `6 [
  610. # cd owlient-phpredis-90ecd17/   #打开解压后的文件夹里面  这个解压后的目录 要是不知道 可以输入 "dir" 查看
    2 |6 A& J1 H2 I
  611. # /www/nginx_php-5.2.17/bin ; p8 q2 k( w/ v  f4 m3 @) u
  612. # ./configure --with-php-config=/www/nginx_php-5.2.17/bin/php-config" F  a; n0 g8 W5 e' E. `2 Z% B7 l
  613. #make
    8 C/ x4 p. C! ]* m6 p
  614. #make install   #记录产生的redis.so路径
    ; q' R, Z, b' d; X

  615. ' v, i' d9 M9 C6 M) j9 F
  616. 修改php.ini文件
    7 J+ b/ }6 B- p  r6 Y) v: Y
  617. 在php.ini中添加如下一行:: C2 H1 R1 P! Z0 }/ P2 v6 b
  618. extension=/?/redis.so  #是刚刚记录的产生redis.so的路 写在 ?那: ]6 @1 D4 @" x$ e
  619. 重启 使之生效:
    . O( `0 a( V9 O' ]# d
  620. /usr/local/php/sbin/php-fpm reload
    ! H2 Q& P# P6 b, U0 Z% _$ N# `
  621. /usr/local/nginx/sbin/nginx -s reload 4 p9 p) v" _% p/ @4 n( U4 t

  622. ! [  q/ t* |; t' U
  623. 将 Redis 作为 Linux 服务随机启动
    6 E2 z% W) n! R" ~) M/ n5 ~$ g
  624. vi /etc/rc.local, 加入代码:
    9 O* r8 O% f1 C* ~
  625. /root/redis-2.6.10/src/redis-serve  #路径看情况修改
    ( h# w9 V. U$ G0 ^7 c3 J

  626. , N+ W3 v6 G+ R% H
  627. redis-cli -h localhost -p 6379 info  #命令要在redis目录下面执行
    $ x2 L: `" H  M, n4 d
  628. 提供host为localhost,端口为6379,redis服务的统计信息
    + H, X: j$ i% z7 t3 `7 y
  629. 1 {6 b& K8 F9 P. }8 A

  630. . _& {. J: k3 P/ V9 e5 u
  631. 就这样你的web服务器就支持redis了 记得要在 给dz 的配置文件 加上12.0.0.1哦5 F0 V( F' f4 V9 T8 F
  632. dz配置文件在 config目录下面的 config_global.php/ W' ]; Y. }' U  j# `  F0 M# R
  633. $_config['memory']['redis']['server'] = '127.0.0.1';" }4 G$ H" y9 v+ V; e7 E5 ^) y
  634. $_config['memory']['redis']['port'] = 6379;
    7 l  E  I. e/ h9 m0 f
  635. $_config['memory']['redis']['pconnect'] = 1;
    ; X* A* T) B8 a6 K; i, A+ X, D
  636. $_config['memory']['redis']['timeout'] = '0';
    . z2 U4 m5 A$ b0 @
  637. $_config['memory']['redis']['serializer'] = 1;
    $ G% b! `, I* u7 [. ]& j5 Y5 {
复制代码
关注微信公众号《神采飞扬网》,即可获取最新回复通知!

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

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

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

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