分享到:
发表于 2018-11-16 12:42:28 | 显示全部楼层 |阅读模式
环境配置4 f$ L) X  D0 w. E% O, i' Y
6 P& u" K$ V! i  S; M" c1 `
: H1 o/ U/ X. m, _% F( |
http://www.discuz.net/forum.php? ... amp;highlight=REDIS
关注微信公众号《神采飞扬网》,即可获取最新回复通知!
 楼主| 发表于 2018-11-16 12:43:33 | 显示全部楼层
http://www.discuz.net/forum.php? ... 648&highlight=REDIS
" K# K3 r; d/ ~; @! N1 u# m5 |无意间测试 单机状态 redis相当给力 测试1000请求/s  单纯的 get 和set 居然只用了 0.01秒 当时我惊呆了
2 s2 j" q: q* q3 J7 \! B7 \1 v
* A$ d+ {" g2 m2 A4 e* e7 \http://www.discuz.net/forum.php? ... 731&highlight=REDIS
. A& U2 _. m: }
/ V3 o/ j4 |$ e6 d8 x# N. H5 ahttps://wenku.baidu.com/view/265a5ce176a20029bc642d0b.html, e7 s6 s; V( f* d# Z6 D
" I- k9 b8 y1 x- [* s+ Y* s+ n. ?
=======================================2 V( d1 U2 C+ d0 \
  1. 连接上 ssh! ^; q8 ~" h- N1 R

  2. " c/ M* d2 k- P5 p+ C/ P
  3. . u" h7 v+ {6 v
  4. 第一步:下载redis: l: ^- [7 z% v, E) F
  5. # wget http://redis.googlecode.com/files/redis-2.6.10.tar.gz
    # S) u- Z. n1 D, K4 k. T; l4 F& q# A
  6. # tar zxvf redis-2.6.10.tar.gz 1 T5 b" v1 c0 D' {" p
  7. # cd redis-2.6.105 }% K+ p) E7 q
  8. # make
    , \3 ^5 b: c+ S" z& ^0 P
  9. # make install  
    6 E" J- ?" W! W$ @* G0 v6 |
  10. #cp redis.conf  /etc/ #复制配置文件到etc目录下面! }( n* q0 _% j; K( K0 t
  11. 第二步:修改配置
    & k( S7 ]* |' U5 g
  12. #vi /etc/redis.conf
    4 D: K) Z/ o) _6 |; L
  13. ######################下面是无措的配置文件 复制过去就成#########- n+ }1 t) m/ i/ Y! H. Y+ o
  14. # Redis configuration file example
    # r; Y6 X" ~. v5 a4 n4 A5 T
  15. 7 |6 w! D3 |$ j
  16. # Note on units: when memory size is needed, it is possible to specify
    . q3 s5 W# N6 e- n
  17. # it in the usual form of 1k 5GB 4M and so forth:7 N% D2 O6 o) S
  18. #0 w% D! j8 \3 B$ V" J# l( ~  V9 C
  19. # 1k => 1000 bytes2 y) y% }) H! l0 z
  20. # 1kb => 1024 bytes
    * G( |: a/ B5 D
  21. # 1m => 1000000 bytes, z3 V# H- c6 [( E6 v
  22. # 1mb => 1024*1024 bytes* o% u1 e( J- o/ n4 O! k+ O
  23. # 1g => 1000000000 bytes) q4 b- A. B! ~( S# [9 h
  24. # 1gb => 1024*1024*1024 bytes2 q* M( T2 e( v( Z/ c% U
  25. #
    % w; q) U  ]  H
  26. # units are case insensitive so 1GB 1Gb 1gB are all the same.
    - q  M' S0 K' {, e4 m$ C
  27. 5 B% [% v/ ]' e4 U8 X* Z
  28. # By default Redis does not run as a daemon. Use 'yes' if you need it.7 H* x7 A8 m+ r! u  P  z  k
  29. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.8 _  @: ]8 g( |, X  ^7 W! D0 U
  30. daemonize yes* d( H2 m6 T+ F+ x: ]0 h  H
  31. & T( E0 S8 h# T; g
  32. # When running daemonized, Redis writes a pid file in /var/run/redis.pid by/ X8 M3 @- ^# O# J2 m, m$ O0 u- q
  33. # default. You can specify a custom pid file location here.
    . F# O6 C+ H& q4 F) g2 S- `& m0 h
  34. pidfile /var/run/redis.pid
    3 M$ V& {3 g6 P0 A' S( p* p

  35. & p# j7 i& c, t) q* m1 d
  36. # Accept connections on the specified port, default is 6379.
    & Q( k; S: ~0 n3 ^5 E
  37. # If port 0 is specified Redis will not listen on a TCP socket.- I7 |. h. \9 F0 P  e; f
  38. port 6379, H7 X+ ^( c/ R6 L6 o
  39. ) ~2 L" k2 _" U
  40. # If you want you can bind a single interface, if the bind option is not
    $ ^; k! C4 N' l8 _
  41. # specified all the interfaces will listen for incoming connections.
    ; t  l0 x) R2 }: O8 B# z3 S; n
  42. #
    ' i1 i7 G, J+ @9 S% S
  43. # bind 127.0.0.18 y( X' E) z; r( M

  44. 9 `3 |+ R- Y/ \8 a1 k
  45. # Specify the path for the unix socket that will be used to listen for; C* T6 W  C* V9 h) u
  46. # incoming connections. There is no default, so Redis will not listen" i6 s5 T" j, Z4 B
  47. # on a unix socket when not specified.: n  f0 X$ y9 U% M
  48. #
    $ s3 |9 O: Y4 f! M; N# Q
  49. # unixsocket /tmp/redis.sock2 c& K) _+ r, l. z$ e: e- X
  50. # unixsocketperm 755
    " Q' ?* z2 I9 j% r+ m6 G5 w

  51. ' d& H( Z1 x5 r- g: G, p% A
  52. # Close the connection after a client is idle for N seconds (0 to disable)0 e- U7 i# @+ O" \0 n' r
  53. timeout 300+ |: y' e. j4 D( \! |" H
  54. 9 d2 E- Z) j8 Q: S$ \
  55. # TCP keepalive.) L; t' h8 q, `& |. ^4 \% \
  56. #  r; E  p  c7 j4 T+ |9 w
  57. # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
    ) I7 s. k9 B7 j  v  E3 C3 e
  58. # of communication. This is useful for two reasons:' L: N! J" z& n+ [. n, w
  59. #$ x) l) i7 J$ p
  60. # 1) Detect dead peers.
    ( l2 Q0 f( X4 ]: ~7 d6 x  Z* u$ ~, W1 z
  61. # 2) Take the connection alive from the point of view of network* O$ b$ P. Y# v1 o! o9 p: P  d# y
  62. #    equipment in the middle.. e  F1 V* q0 ^( g
  63. #% M/ T5 {; L: w( U
  64. # On Linux, the specified value (in seconds) is the period used to send ACKs." H* z: X' C; W
  65. # Note that to close the connection the double of the time is needed.
    , q" j& W$ m; Z
  66. # On other kernels the period depends on the kernel configuration.7 a- t- _3 D2 T5 n. d% A6 |2 J* q9 [
  67. #
    # b$ y0 I6 o" R0 [  m
  68. # A reasonable value for this option is 60 seconds.
    6 {1 E* L# N0 j+ H8 h. e. u
  69. tcp-keepalive 0) H; k8 J6 S/ z& H  h8 Z
  70. 9 V' f: [2 w* N' |* z0 `, v0 U8 x( J7 ~
  71. # Specify the server verbosity level.
    5 q8 c! e/ H' @" K1 O
  72. # This can be one of:; p/ l# @1 @; `
  73. # debug (a lot of information, useful for development/testing)$ p/ i# o1 l# E$ u8 f6 U
  74. # verbose (many rarely useful info, but not a mess like the debug level)
    / @# }! o* }& |' Q
  75. # notice (moderately verbose, what you want in production probably)
    & y" j5 A* b( T2 j  X
  76. # warning (only very important / critical messages are logged)
    & {' {( D4 f! [/ Q; M
  77. loglevel warning
    ' o1 {5 `7 F  ?# Y3 M6 X$ Q
  78. 6 V/ H9 ?" G$ n( F
  79. # Specify the log file name. Also 'stdout' can be used to force1 J  b; n+ ?7 o/ N) `
  80. # Redis to log on the standard output. Note that if you use standard
    % _* j4 Q7 \# e  E
  81. # output for logging but daemonize, logs will be sent to /dev/null% q, S3 h, l6 h2 ?0 m$ ?
  82. logfile /var/log/redis.log" J5 E1 a7 W* i+ V( f5 e6 z- I7 R& l
  83.   [% `9 Q! {; E
  84. # To enable logging to the system logger, just set 'syslog-enabled' to yes,
    ! w$ Z0 W0 z+ L  B" J6 ?" F
  85. # and optionally update the other syslog parameters to suit your needs.. u$ T8 \1 x- J/ T
  86. syslog-enabled yes; r9 I% U) H$ d

  87. 5 d% Q* [/ n1 M; G- \
  88. # Specify the syslog identity.7 L  W+ E5 ]: c% b% x  w% j7 M7 ^
  89. # syslog-ident redis! O) Q5 ^$ H! ?/ v1 w- _2 g
  90. $ g. M  o3 H0 ^8 u8 ?& t6 R3 g
  91. # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
    4 X* N/ @! a" m7 T* c' T7 z
  92. syslog-facility local0: n8 j( o1 W' K8 ^, y
  93. , P" m' N+ j9 p, e) t
  94. # Set the number of databases. The default database is DB 0, you can select, x$ m/ Z( k" |, {( T; k& Z3 ]
  95. # a different one on a per-connection basis using SELECT <dbid> where$ L6 R3 @- X' T: K8 y( j0 l
  96. # dbid is a number between 0 and 'databases'-16 z8 ?% D6 ~: d3 Y
  97. databases 161 |* G4 M, [  x9 O0 _; f

  98. ' B! E' V% C3 H3 j. n# H( D2 A
  99. ################################ SNAPSHOTTING  #################################4 o! w9 \9 B( S( Q
  100. #" \" }( K/ H4 F* R
  101. # Save the DB on disk:
    ( q) |! q7 I+ i6 E
  102. #
    6 K. r& ~- f8 k' ~
  103. #   save <seconds> <changes>
    & ^9 o, R5 j8 {/ l; A7 ]
  104. #
    - U" r# |7 Y: g6 r. {- H
  105. #   Will save the DB if both the given number of seconds and the given
    * X6 [* e# X% a3 E
  106. #   number of write operations against the DB occurred.
    4 o  P( S$ O: ]
  107. #9 P/ O6 ^0 `0 p. U
  108. #   In the example below the behaviour will be to save:7 {5 s  v4 V3 E6 \# t% N' Y
  109. #   after 900 sec (15 min) if at least 1 key changed
    2 G1 ]: ?* Q1 W" G
  110. #   after 300 sec (5 min) if at least 10 keys changed# k( k; F9 X$ M, |9 j* i
  111. #   after 60 sec if at least 10000 keys changed/ C7 Z; d' g3 K' h! f) ~; E
  112. #( x: m2 \  _0 I  i6 `
  113. #   Note: you can disable saving at all commenting all the "save" lines.
    0 i. K1 ]$ M9 s% j
  114. #1 V. _, @, c+ }" O5 E8 ]2 ~, ~
  115. #   It is also possible to remove all the previously configured save; n# X, V; C' l- t+ _4 q
  116. #   points by adding a save directive with a single empty string argument
    $ R: Z0 L7 F4 d- t2 k" V" [
  117. #   like in the following example:; B* o# Z' J  m" l4 c4 G
  118. #
    ) j. K$ [+ m' C  S. H+ y" ^
  119. #   save ""
    : E3 C  [& |7 d
  120. , @8 W( I# J* y8 P' P2 L' I
  121. save 900 1
    - R$ u2 z$ ?" a8 q
  122. save 300 10- l" v9 q+ O8 @- ^1 y
  123. save 60 10000
    ( x8 y$ t3 [( O. P, E$ ], y7 H

  124. - h, ?9 K, R: p/ L5 _- }
  125. # By default Redis will stop accepting writes if RDB snapshots are enabled5 m/ V+ R# T6 ~$ w
  126. # (at least one save point) and the latest background save failed.
    , v6 p( _. v  b
  127. # This will make the user aware (in an hard way) that data is not persisting
    3 N* A' J  b& i) q  V
  128. # on disk properly, otherwise chances are that no one will notice and some
    0 F4 n9 ]( C$ }
  129. # distater will happen.5 q/ O# G( B/ z7 j% D2 D
  130. #
    + f! u8 N: F% S1 L, ?2 b1 k
  131. # If the background saving process will start working again Redis will7 d0 B2 s- t) ]4 ]5 d
  132. # automatically allow writes again.& W9 K0 c2 z" Q/ {4 o& ^$ Q
  133. #
    2 a5 ]+ E* ?2 Y1 W5 n. K
  134. # However if you have setup your proper monitoring of the Redis server0 o: X% u/ U% @' q( t
  135. # and persistence, you may want to disable this feature so that Redis will7 A: [9 q$ p; V. D; Z
  136. # continue to work as usually even if there are problems with disk,% d; h! W' v0 V1 s$ @
  137. # permissions, and so forth.+ b  F+ N$ ^0 S! Y! T8 B- p
  138. stop-writes-on-bgsave-error yes) j% o# D0 j+ n  |& B- @
  139. # U0 F% V! S8 z3 L3 ]8 C- `
  140. # Compress string objects using LZF when dump .rdb databases?
    + n% w5 l& S) v0 O; \. s
  141. # For default that's set to 'yes' as it's almost always a win.
    5 Q3 o* e0 Q2 L2 _% N" z7 T; {
  142. # If you want to save some CPU in the saving child set it to 'no' but) ^, ?# a; W3 z6 G9 C
  143. # the dataset will likely be bigger if you have compressible values or keys.
    ( G& E. ~7 E) v' |
  144. rdbcompression yes( e- d+ h' V" Z) j0 W
  145. " M& o( q8 D9 X, j3 d1 r
  146. # Since version 5 of RDB a CRC64 checksum is placed at the end of the file.( C# I  Z- j. q3 B' T; L- r3 H, X
  147. # This makes the format more resistant to corruption but there is a performance! G% e& o3 r; B
  148. # hit to pay (around 10%) when saving and loading RDB files, so you can disable it
    / I+ \7 m; s0 l% J
  149. # for maximum performances.. a  L0 V  `6 L; g* N
  150. #
    ! l3 [+ H. A# F1 l
  151. # RDB files created with checksum disabled have a checksum of zero that will4 H, f. u/ Y8 B, O1 d; ~
  152. # tell the loading code to skip the check.' M9 ]! q1 v4 q& ]) w8 G
  153. rdbchecksum yes
    8 ^: ~4 |# v4 O% U
  154. ; G' x- j3 f  |$ j$ X
  155. # The filename where to dump the DB
    6 V1 H; W0 P" f: q3 U. G* Q! `9 K, @
  156. dbfilename dump.rdb
    : J4 t& ^9 `/ V6 O+ C$ j+ d; Q

  157. $ k$ M. o, z( i" s3 H
  158. # The working directory.5 s) m5 B) V" O2 {
  159. #
    0 Q# u9 ^5 G* E( L/ g
  160. # The DB will be written inside this directory, with the filename specified1 S+ P+ l3 L6 m
  161. # above using the 'dbfilename' configuration directive.* l& n! C; O. C& q0 q2 n6 J  }0 b$ t
  162. # : J$ Q& Q* _- H2 I! \
  163. # The Append Only File will also be created inside this directory., b8 Q1 h' w$ y7 ?7 j( A
  164. # $ g: W# |$ c" ]' i: _
  165. # Note that you must specify a directory here, not a file name.
    $ x) M' ^6 J4 k
  166. dir /var/db/redis. w7 j. ^! R/ u
  167. # s' k& u9 e! ~; g
  168. ################################# REPLICATION #################################3 X  F. w' k4 t" Q8 v; p

  169. * c5 u* I# U9 [; W/ Y% [
  170. # Master-Slave replication. Use slaveof to make a Redis instance a copy of
    8 ^8 Z6 P% b7 Y) H
  171. # another Redis server. Note that the configuration is local to the slave3 J+ J) _. ~& w1 S% E( P$ f- |
  172. # so for example it is possible to configure the slave to save the DB with a
    7 W$ }8 c# o- u  `9 O
  173. # different interval, or to listen to another port, and so on.! Y. s0 M5 Q; k6 _( d- A- q1 \
  174. #
    7 G3 ^- q; D& E; T# Q2 ?: }: O
  175. # slaveof <masterip> <masterport>' T3 W" ]5 V2 A; A8 O8 q

  176. ; {' E" ~& }/ [5 K6 J7 C
  177. # If the master is password protected (using the "requirepass" configuration2 L, A* G) ]$ Q4 o$ ^6 x
  178. # directive below) it is possible to tell the slave to authenticate before# b. C& r5 h# `+ t# u4 G3 o8 }
  179. # starting the replication synchronization process, otherwise the master will  t! f% C7 }1 o+ p; B) C
  180. # refuse the slave request.4 O3 W1 u# ]+ g# }6 ]- N
  181. #6 ~* j6 Z3 @6 P5 O" _3 N
  182. # masterauth <master-password>- E- X# @  n& O% T7 g3 T
  183. : }1 R& E$ H+ c% }: V8 d
  184. # When a slave loses its connection with the master, or when the replication: `! ?8 Y+ M4 s: A9 l6 a, m
  185. # is still in progress, the slave can act in two different ways:0 u6 K# f8 K) L
  186. #, u$ q6 A; G- ]5 S: O, ]
  187. # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will
    ) A1 D2 ~7 {; Q( S& t
  188. #    still reply to client requests, possibly with out of date data, or the7 N7 p& |- J: v: T
  189. #    data set may just be empty if this is the first synchronization.
    7 w2 r, p5 {3 l# ^
  190. #
      u( P8 _) x! g( z  f
  191. # 2) if slave-serve-stale data is set to 'no' the slave will reply with4 |; p2 T: o: @6 s
  192. #    an error "SYNC with master in progress" to all the kind of commands
    - Y/ ?( j7 V/ [, h# A1 q
  193. #    but to INFO and SLAVEOF.8 b5 E3 q7 t6 o* K8 Q% d: ]
  194. ## R. P$ @- K/ v( k
  195. slave-serve-stale-data yes
    ' @8 e* e! R+ p( S' ]9 N
  196. ' D$ i! p4 Q. I. M7 a9 i% c
  197. # You can configure a slave instance to accept writes or not. Writing against
    0 G1 }7 k4 G9 ?! y( |
  198. # a slave instance may be useful to store some ephemeral data (because data" \8 y, ^4 _: `; R# ?! t3 n% Y3 ^
  199. # written on a slave will be easily deleted after resync with the master) but, \7 f, [! t  T' N2 E( M
  200. # may also cause problems if clients are writing to it because of a8 l' e" B9 e% ^, H
  201. # misconfiguration.2 E) v( w6 I/ K; B9 D
  202. #
    % e+ n( ~- u* X% u4 K! E
  203. # Since Redis 2.6 by default slaves are read-only.
    8 T, y! Y7 _! ^6 }+ r, [( L* g
  204. #
    " _8 d& ?9 L: r" R' _0 y
  205. # Note: read only slaves are not designed to be exposed to untrusted clients! ?/ h1 _5 F, l4 ~9 [- l& r6 G
  206. # on the internet. It's just a protection layer against misuse of the instance.% v! X( [" H4 L" Q
  207. # Still a read only slave exports by default all the administrative commands* u1 Q# M6 {, M3 A6 ?  S1 b
  208. # such as CONFIG, DEBUG, and so forth. To a limited extend you can improve
    ! ~' |* t" c2 N- ^! M9 L
  209. # security of read only slaves using 'rename-command' to shadow all the
    / M8 _* l3 N( L" n6 U7 v
  210. # administrative / dangerous commands.
    # d" s4 `6 G3 x# B; k9 {
  211. slave-read-only yes- r9 C# S* A* n+ I

  212. ( Q: V9 X* Y" P# `
  213. # Slaves send PINGs to server in a predefined interval. It's possible to change
    7 I: }* a, m) @2 T
  214. # this interval with the repl_ping_slave_period option. The default value is 10
    , f& A) ?+ o2 W& M" i
  215. # seconds./ s  B& |1 Q/ X# _
  216. ## ]5 ~# h1 h- }, |! H/ ^
  217. # repl-ping-slave-period 10
    3 k" f" h) t7 |3 T4 _
  218. / u% R( t  Q# o' X( Q0 h+ ~
  219. # The following option sets a timeout for both Bulk transfer I/O timeout and
    , N! H& M1 \# }7 ]7 r' `  n, H4 `
  220. # master data or ping response timeout. The default value is 60 seconds.
    , j3 K9 N# y) U2 D+ u
  221. #
    ; f, ]! U! e! N" @
  222. # It is important to make sure that this value is greater than the value. z4 x6 Q: J/ U4 r: ?: A& a" Q" v
  223. # specified for repl-ping-slave-period otherwise a timeout will be detected
    # h8 A5 q4 Y2 W: d" q5 D
  224. # every time there is low traffic between the master and the slave.
    & v% s4 N$ g( T5 s$ a  T5 H! G4 t
  225. #
      M1 {, ]3 I5 e
  226. # repl-timeout 60! z2 l1 @; Y1 e- B& ?3 t
  227. ) C3 q) B, H7 L" s& w
  228. # Disable TCP_NODELAY on the slave socket after SYNC?: C& A* S) a; a5 j0 z; x0 `5 b* m
  229. #$ y$ n& z- ?3 M; n6 J
  230. # If you select "yes" Redis will use a smaller number of TCP packets and
    6 d7 i9 s( S; }/ ~3 N3 D  r
  231. # less bandwidth to send data to slaves. But this can add a delay for  b) K; E6 a9 P" k4 D
  232. # the data to appear on the slave side, up to 40 milliseconds with
    " B1 I/ U. A. w, M, F
  233. # Linux kernels using a default configuration.
    1 C- v2 H7 H) C4 E! D
  234. #
    0 {# v0 H0 }* S: u1 M3 T" v' q
  235. # If you select "no" the delay for data to appear on the slave side will' Y( ~8 {2 v$ |* Z
  236. # be reduced but more bandwidth will be used for replication.; T2 ^7 x+ D/ C+ q1 o
  237. #1 ~, W9 R% _  A, r# L
  238. # By default we optimize for low latency, but in very high traffic conditions* G. w; A- l7 @1 X0 L
  239. # or when the master and slaves are many hops away, turning this to "yes" may
    , h7 ^* E+ H4 F# y+ }
  240. # be a good idea.
    ( N7 V6 J+ {. b2 z
  241. repl-disable-tcp-nodelay no
    : c' a, ~! J# j  d1 P, T

  242. 9 n( {4 c! M1 T) O$ t/ |
  243. # The slave priority is an integer number published by Redis in the INFO output.
    , R  G" o& P5 W& m- L& x
  244. # It is used by Redis Sentinel in order to select a slave to promote into a
    5 M$ I+ K8 q' v
  245. # master if the master is no longer working correctly.$ U& p3 k' q' N4 D& J5 k* ]1 J
  246. #
    7 i. K2 q+ a: h$ g" |! \
  247. # A slave with a low priority number is considered better for promotion, so: Z' ~( z2 e* t5 K* F9 I: v3 L1 L
  248. # for instance if there are three slaves with priority 10, 100, 25 Sentinel will
    * a# Z- Q% c- z. w
  249. # pick the one wtih priority 10, that is the lowest.5 l9 J5 \; i; C& Q0 q# s* x. ]7 }6 o
  250. #
    8 K8 u! k/ @" f  S' g5 ]" d
  251. # However a special priority of 0 marks the slave as not able to perform the
    ! E, l( R# l4 V/ {8 M7 |
  252. # role of master, so a slave with priority of 0 will never be selected by8 o) [5 T& |6 y; g9 E
  253. # Redis Sentinel for promotion.
    # d) ?6 \5 B, v4 [  M7 i1 `3 {' v
  254. #
    / P( K8 x( W* l- s. N% [% d( n8 d, f
  255. # By default the priority is 100.
    # L; v9 V3 P, d0 F  n9 B- g3 Y' F
  256. slave-priority 100
    % B- |2 ]0 |( I" _- o
  257. + y! r4 u0 @% o
  258. ################################## SECURITY ###################################2 t% }$ Q6 v! m3 ~

  259. / W8 z! v6 r: V3 }  @* H) y9 L
  260. # Require clients to issue AUTH <ASSWORD> before processing any other
    5 d8 F/ h: z$ P9 Y4 C' A
  261. # commands.  This might be useful in environments in which you do not trust  c/ G0 i) g& t
  262. # others with access to the host running redis-server.) s: [2 X$ F# X; J- J' e
  263. #
    / L. E9 K2 s5 h) n+ O/ N1 q% l5 W
  264. # This should stay commented out for backward compatibility and because most
    2 r$ D* G/ K# [3 }2 q- y$ j2 z
  265. # people do not need auth (e.g. they run their own servers).: L0 G+ L9 Z2 g5 i' x
  266. #
      s' U( t* L! B0 R# ~8 B
  267. # Warning: since Redis is pretty fast an outside user can try up to
      H  D( F3 {8 u2 q
  268. # 150k passwords per second against a good box. This means that you should
    / u3 v* l* d9 h& }, a; d
  269. # use a very strong password otherwise it will be very easy to break.% \) y9 O. P; u- s
  270. #9 W, d- o0 t4 @5 [  z- H/ x
  271. # requirepass foobared' L7 c  T. z# M% g, @  J' c

  272. # ]1 h: E# c% }1 J- e
  273. # Command renaming.
    & C) {/ n3 Q, X' B6 m
  274. #' K- C2 o0 l4 v, m
  275. # It is possible to change the name of dangerous commands in a shared
    ( G6 v" \8 |* d0 ]7 x
  276. # environment. For instance the CONFIG command may be renamed into something
    . v' g, r+ Q* l/ v- w7 w# g8 k" }
  277. # hard to guess so that it will still be available for internal-use tools
    # ^6 j% z6 k; c: o; Z- g4 Q' F, w
  278. # but not available for general clients.
    * m7 u) u& I7 I, _
  279. #, W7 M( Z+ y) x: D4 q
  280. # Example:2 Q0 F  Q7 X* i4 K
  281. #. W9 a, ~: x% n* e! A
  282. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
    ' S. J) ?. `$ D3 a& ]/ b
  283. #
    3 G  i( a! p. J/ w1 }- [  C
  284. # It is also possible to completely kill a command by renaming it into% u; ~5 F. M, |& x! `; R( P
  285. # an empty string:
    3 E+ S7 i- f9 r" ?  K2 {7 B5 L
  286. #% L; {/ K; ~# _/ E& J: h4 Q7 M! ^
  287. # rename-command CONFIG ""
    9 g9 }, J! E# O" P

  288. 1 \' }" Y0 `+ _. A' o& x* I
  289. ################################### LIMITS ####################################" _" B% y6 Q4 ^

  290. 5 p7 t; h6 t' n+ [% l5 p6 P" T  F
  291. # Set the max number of connected clients at the same time. By default9 {7 u- q( @4 i! t
  292. # this limit is set to 10000 clients, however if the Redis server is not9 I/ x* p' [  U* t- \7 @% V4 T4 `. Q5 N
  293. # able to configure the process file limit to allow for the specified limit. P# j4 e% K5 j3 n9 x
  294. # the max number of allowed clients is set to the current file limit( n7 V/ y: c% g0 |# p9 s2 m
  295. # minus 32 (as Redis reserves a few file descriptors for internal uses).
    . }! N: {2 L& C) U- F% |
  296. #/ W: j. Q. r7 R! q  w6 j0 x
  297. # Once the limit is reached Redis will close all the new connections sending
    * h( H& j9 N; f7 G! T9 D6 S
  298. # an error 'max number of clients reached'.  K% ^/ e. A6 ~+ Q' j
  299. #' W$ ^9 \; X; Y1 k* f* W3 e
  300. maxclients 500# `: s' m; c3 Z! a4 E9 Y
  301. 2 S  m- e# c* N3 x
  302. # Don't use more memory than the specified amount of bytes.
    5 D  v6 y7 h! Q; u) r5 b7 ]: f2 y' V
  303. # When the memory limit is reached Redis will try to remove keys8 R/ h- H' {: N
  304. # accordingly to the eviction policy selected (see maxmemmory-policy).( R9 j2 f8 _- f0 r* u
  305. #
    & {; y$ z4 Y0 z) z! N  k
  306. # If Redis can't remove keys according to the policy, or if the policy is
    ) }6 q7 N: m. x
  307. # set to 'noeviction', Redis will start to reply with errors to commands  h3 G' x" d1 g) i* I% p
  308. # that would use more memory, like SET, LPUSH, and so on, and will continue  G, R  X) i, ]
  309. # to reply to read-only commands like GET.- e1 m* O/ f1 F6 I0 k8 M( Q# j  U
  310. #
    : c, L# S! u* i" Z7 o
  311. # This option is usually useful when using Redis as an LRU cache, or to set9 y4 F) ?8 O& \
  312. # an hard memory limit for an instance (using the 'noeviction' policy).
    ) M' `; B( h- V
  313. #4 T+ c1 f$ x* ?$ ?/ p$ c* _8 j
  314. # WARNING: If you have slaves attached to an instance with maxmemory on,( S, ]# v4 c% _2 Y; k1 _
  315. # the size of the output buffers needed to feed the slaves are subtracted2 u9 B; Y+ t. q
  316. # from the used memory count, so that network problems / resyncs will7 r! v2 Q/ n0 `: |3 b
  317. # not trigger a loop where keys are evicted, and in turn the output( I5 v5 f# p7 @2 d1 M
  318. # buffer of slaves is full with DELs of keys evicted triggering the deletion
    9 l$ J& y2 h  ^( z, @7 X  q
  319. # of more keys, and so forth until the database is completely emptied.! a* }. e  L, q7 m  r9 Y
  320. #8 `9 g- A- B8 f
  321. # In short... if you have slaves attached it is suggested that you set a lower
    * d5 l$ h6 Q& @$ N5 b6 i
  322. # limit for maxmemory so that there is some free RAM on the system for slave( x, b9 {! E& P2 y3 o4 i
  323. # output buffers (but this is not needed if the policy is 'noeviction').
    3 p' Q6 c6 Z0 ~- A) n/ \) y/ O
  324. #
    . _( }# i1 G+ F. b* P
  325. maxmemory 128000000
    " e% {* W1 l! W
  326. 6 D9 {+ ~. M2 ^, ^
  327. # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
    : }# J$ F2 \' P5 l( g% }
  328. # is reached. You can select among five behaviors:; ^+ q$ d( x" ~2 L1 W8 D2 @6 J
  329. # . }' L; A& U& `" R2 `4 @
  330. # volatile-lru -> remove the key with an expire set using an LRU algorithm5 @6 I5 \7 I% R/ F, C! q8 V
  331. # allkeys-lru -> remove any key accordingly to the LRU algorithm* B* y2 V' K& F$ N3 W
  332. # volatile-random -> remove a random key with an expire set
    : U# M7 _- h6 f0 d$ J
  333. # allkeys-random -> remove a random key, any key
    9 j$ m% E: _+ D  f' v
  334. # volatile-ttl -> remove the key with the nearest expire time (minor TTL)$ }3 B- e2 [. `. o0 b/ v" Q+ [
  335. # noeviction -> don't expire at all, just return an error on write operations
    $ I( ?, H2 y* F1 H4 z& b; B- G4 H
  336. #
    + L3 S8 d) _. R; H, f
  337. # Note: with any of the above policies, Redis will return an error on write
    9 m3 a! w% \. m5 g0 h/ I
  338. #       operations, when there are not suitable keys for eviction.. |/ z7 h, z2 u; I( a# c( _
  339. #
    3 t# C1 ^* E7 L7 I1 h) Y
  340. #       At the date of writing this commands are: set setnx setex append5 L( ~& c6 l. ?& p* v  P% f( b
  341. #       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
    " F; @' O' v' Y' P. ^
  342. #       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
    3 Z' ^2 v! p( E
  343. #       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby* b- s, \" u! h/ l( D# e( r
  344. #       getset mset msetnx exec sort
    1 ^# }. q/ A. q  R7 |
  345. #* @6 W% n( {/ L$ k5 ^2 \7 f% n  D) d
  346. # The default is:; J  j0 W! H# z9 g& e" T
  347. #
    ( v5 O0 c- Z/ H; n' E- g
  348. # maxmemory-policy volatile-lru; a* |, _2 i* G$ z$ C
  349. : Q( R( D5 D3 o5 Q
  350. # LRU and minimal TTL algorithms are not precise algorithms but approximated
    6 B6 U& H: [) Y
  351. # algorithms (in order to save memory), so you can select as well the sample) b# \: R% X2 B+ ]% {+ J+ n2 X
  352. # size to check. For instance for default Redis will check three keys and' [  t0 W: X; U) s  u
  353. # pick the one that was used less recently, you can change the sample size
    8 `! T. H! M- `* }8 r; f2 ?7 \
  354. # using the following configuration directive.
    ' G/ X& e, U# K8 ^2 F: ^
  355. #
    % i6 U0 r6 O) Y* x& a: y
  356. # maxmemory-samples 3
    9 ^( d; a. {9 n# a3 m! `

  357. * ~9 v% H9 h  M
  358. ############################## APPEND ONLY MODE ###############################2 @8 P6 E% _: m) |/ j5 F! |5 ~

  359. 0 d! k1 E( T2 ]9 n) F. q
  360. # By default Redis asynchronously dumps the dataset on disk. This mode is
    7 @7 z7 [. y4 b- e) w; h
  361. # good enough in many applications, but an issue with the Redis process or
    5 Q0 p$ x) J. a9 V
  362. # a power outage may result into a few minutes of writes lost (depending on0 p( c4 o3 s$ n4 j0 u
  363. # the configured save points).8 `0 H( C- g$ `/ d* h
  364. #, v7 k% c% `# x
  365. # The Append Only File is an alternative persistence mode that provides6 @  K6 D- v# x$ V: S' V
  366. # much better durability. For instance using the default data fsync policy6 s$ g" ?9 k$ e) p2 R% P4 G/ P8 m
  367. # (see later in the config file) Redis can lose just one second of writes in a
    , n5 ^  g  N' I# a3 ]7 m* [- T
  368. # dramatic event like a server power outage, or a single write if something
    6 Z, L8 D, G5 l! ~3 t: N
  369. # wrong with the Redis process itself happens, but the operating system is" @& E' i% d  S6 @" a3 H# F
  370. # still running correctly.
      V* {0 k3 n4 ^* l7 n0 ]& w
  371. #
    6 U" j4 J$ p6 E" l6 d( ]. j6 L4 Z1 y
  372. # AOF and RDB persistence can be enabled at the same time without problems.
    2 L: c: S) Q/ |* r  p
  373. # If the AOF is enabled on startup Redis will load the AOF, that is the file: P" c: ^# I; G6 B6 Z
  374. # with the better durability guarantees.
    1 |# h3 L2 o7 k$ f! E, V: Y/ L
  375. #
      ^* c9 a( j' Q& L: ]; j% w
  376. # Please check http://redis.io/topics/persistence for more information.
    5 F6 R3 u9 F3 k8 ?, ?2 w$ S

  377. 2 W+ g  o8 d8 o3 p2 d' M1 q
  378. appendonly no, N) {: Q3 c$ O+ A2 ]

  379. ( ^+ f) }, d& U' {- a5 A% P( S
  380. # The name of the append only file (default: "appendonly.aof")
    6 }. p1 q# q4 e) V
  381. # appendfilename appendonly.aof4 }* l0 t1 v3 r

  382. 7 Y' e" W0 t/ r7 \/ m3 S
  383. # The fsync() call tells the Operating System to actually write data on disk
    0 W. N' D  h+ v& g4 @3 J  E; s; R* T
  384. # instead to wait for more data in the output buffer. Some OS will really flush
    ) m  j5 n& C! j( D6 j" Q3 c: r
  385. # data on disk, some other OS will just try to do it ASAP.
    7 u* C; `# |, L! L! I
  386. #, q( M3 J# y  w$ R9 r
  387. # Redis supports three different modes:6 @- J" Y) f' d. Z; Q7 h
  388. #, }/ l7 u& Y& k4 W+ i$ B: B& N0 S1 H
  389. # no: don't fsync, just let the OS flush the data when it wants. Faster.
    0 j$ L  {4 s5 P/ ~# {# N
  390. # always: fsync after every write to the append only log . Slow, Safest.* r/ Q  Y3 r2 ?( F9 e
  391. # everysec: fsync only one time every second. Compromise.. o7 ~# D5 i" L6 [- C1 E" r! [
  392. #
    9 i! ]& @+ o$ {
  393. # The default is "everysec", as that's usually the right compromise between
    ; K/ \  M2 I) @$ p0 w$ z. l
  394. # speed and data safety. It's up to you to understand if you can relax this to
    ! E2 m! `8 ]6 P7 c; ]# m
  395. # "no" that will let the operating system flush the output buffer when6 c& [& f/ z# @2 ~8 {
  396. # it wants, for better performances (but if you can live with the idea of
    ' Z3 F" S% W+ F5 _
  397. # some data loss consider the default persistence mode that's snapshotting),! N8 g, u6 T" H) ]. V! F1 I
  398. # or on the contrary, use "always" that's very slow but a bit safer than
    % g% e, A, S- x6 L/ y, T
  399. # everysec.
    ) C) K! |# E% o6 Q+ O& W
  400. #0 g% O9 x+ j4 K  L/ b/ d
  401. # More details please check the following article:
    ( B0 M% y9 @; W/ N" d: J
  402. # http://antirez.com/post/redis-persistence-demystified.html
    # J/ v7 c3 g# \1 U6 ?5 ?- h
  403. #6 ~8 T, Q; S5 {1 P" V
  404. # If unsure, use "everysec".
    / q3 W- N! Z$ y2 K: N% M0 n! X

  405. * k, ?$ J( z$ N4 p
  406. # appendfsync always
    1 _# l+ g1 z/ [  f1 J
  407. appendfsync everysec
    % v2 k; e2 W7 [1 \" U) t  e
  408. # appendfsync no
    ' D' _/ P3 S, x# ~
  409.   }2 K9 G! M& W. c! `" a
  410. # When the AOF fsync policy is set to always or everysec, and a background
    5 J. h8 V# {8 Z
  411. # saving process (a background save or AOF log background rewriting) is- z. n, r- {- q9 @. s% h& [% ]
  412. # performing a lot of I/O against the disk, in some Linux configurations
    . \, E8 I5 ~3 t! {5 l# }
  413. # Redis may block too long on the fsync() call. Note that there is no fix for+ X! a+ J9 h$ Z
  414. # this currently, as even performing fsync in a different thread will block
    7 J% ?/ O. t2 \) i
  415. # our synchronous write(2) call.1 t- Z& R9 T2 W9 W* h
  416. #2 r2 Z) o' R, c$ q2 U
  417. # In order to mitigate this problem it's possible to use the following option' n: Q# Y5 h5 M  i
  418. # that will prevent fsync() from being called in the main process while a
    ( k  Z# \$ H% L
  419. # BGSAVE or BGREWRITEAOF is in progress.4 ^; \9 _( t) }$ A. n
  420. #
    ! }2 ~4 D) t6 T/ r4 U8 z0 F
  421. # This means that while another child is saving, the durability of Redis is
    0 @3 D/ b  ^3 o2 y$ J4 K4 u
  422. # the same as "appendfsync none". In practical terms, this means that it is' `8 @2 z: X' y4 s
  423. # possible to lose up to 30 seconds of log in the worst scenario (with the2 K7 n( R. q( k1 h3 y) U3 X
  424. # default Linux settings).6 ^5 s+ V! {3 w. P
  425. #
    8 c) R  ?9 \1 s# Q
  426. # If you have latency problems turn this to "yes". Otherwise leave it as
    " L- _2 ~5 u( H0 c* k
  427. # "no" that is the safest pick from the point of view of durability.. u7 W0 h) J% `! z$ S
  428. no-appendfsync-on-rewrite no0 \& t+ O2 O* S. x# H# q
  429. $ A7 t1 Q& o4 \7 _
  430. # Automatic rewrite of the append only file.
    ) q: T( ^( ]2 O0 b9 P' F: D# c
  431. # Redis is able to automatically rewrite the log file implicitly calling
    : V# t, m8 i% A, r
  432. # BGREWRITEAOF when the AOF log size grows by the specified percentage.
      D- e3 H3 U4 x8 H
  433. #
    2 a  Z' l5 X2 N
  434. # This is how it works: Redis remembers the size of the AOF file after the4 {- Q, u5 _& P+ C4 y
  435. # latest rewrite (if no rewrite has happened since the restart, the size of0 d# K  T3 R% a" L* _: ]+ q3 N- C# F* O
  436. # the AOF at startup is used).
    / D+ [$ A! c$ X4 B
  437. #
    7 n, a( v0 B/ J9 S# }
  438. # This base size is compared to the current size. If the current size is' R8 V5 ]& l# B9 ~; R, \
  439. # bigger than the specified percentage, the rewrite is triggered. Also  w0 Z& l2 b. D3 M' k" x% Z
  440. # you need to specify a minimal size for the AOF file to be rewritten, this; @4 U* M* l" x5 N" F# W. E
  441. # is useful to avoid rewriting the AOF file even if the percentage increase
      v1 P) ]* ~6 b9 Y" |+ \8 G1 S
  442. # is reached but it is still pretty small./ {/ c: G8 e( j! l6 S: {
  443. #; \) w& Q( ?6 m/ Y2 ~5 [
  444. # Specify a percentage of zero in order to disable the automatic AOF
    # D  j" B  O' `/ ]' V+ p
  445. # rewrite feature.2 F6 c' |0 I* |* n% g& h; }& ?
  446. # ^7 G. W2 {$ N( ^% p6 ^
  447. auto-aof-rewrite-percentage 100; f4 T7 Z0 ]* X
  448. auto-aof-rewrite-min-size 64mb
    ( d/ t3 Q& c1 D( t7 A
  449. & y/ Q4 A; y# z$ w5 B3 V3 ?$ E
  450. ################################ LUA SCRIPTING  ###############################; B8 c5 e% q6 y8 [. K

  451. : k5 y$ K/ x4 w7 t- ]7 z9 ?; S. b. v
  452. # Max execution time of a Lua script in milliseconds.& e5 P1 H" P9 Q. ?( o( y9 f
  453. #
    + c2 B& C8 Z6 _
  454. # If the maximum execution time is reached Redis will log that a script is
    * m; ~. u; O0 Y9 S  V' r2 ~
  455. # still in execution after the maximum allowed time and will start to
    7 w$ o8 ^+ e3 ~0 l7 F1 K  h  U
  456. # reply to queries with an error.
    % f$ P! q/ y% r: _, h. _3 w4 c
  457. #
    3 J- Y  ?2 j" \  A( J0 V
  458. # When a long running script exceed the maximum execution time only the. O+ o$ M- r' A- R2 t
  459. # SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be
    1 y4 \, A# A% @" w6 Y) m! B
  460. # used to stop a script that did not yet called write commands. The second. w4 Y- j& Z5 z7 b/ o' o: K
  461. # is the only way to shut down the server in the case a write commands was
    + S0 N; e3 R0 }/ y4 W
  462. # already issue by the script but the user don't want to wait for the natural; C) Y& I  ?3 J2 ?) |  L2 J3 i& {1 [
  463. # termination of the script.
    6 o3 ]$ x9 Z  [
  464. #
    - |$ u  p3 C% M+ ^* A1 e
  465. # Set it to 0 or a negative value for unlimited execution without warnings.
    # A6 U5 W4 P" V( c2 ]
  466. lua-time-limit 5000, p# Z+ ]/ u3 I
  467. # j* H3 v* `7 C1 c
  468. ################################## SLOW LOG ###################################
    ; V) T4 w, Y4 U& M* w

  469. . E% }) M& j) I4 X4 g3 J
  470. # The Redis Slow Log is a system to log queries that exceeded a specified- X& x: V4 t% w
  471. # execution time. The execution time does not include the I/O operations5 [7 H6 C0 n) p, c
  472. # like talking with the client, sending the reply and so forth,
    4 n# J" J) r, A. V" z
  473. # but just the time needed to actually execute the command (this is the only
    ! ^9 n' ]7 I5 ~+ c, x
  474. # stage of command execution where the thread is blocked and can not serve
    2 c: D! k, y* l& k8 M$ o! S0 x
  475. # other requests in the meantime).$ v3 u  c/ [% {+ g3 Z( d
  476. #
    $ c3 E4 X& Y7 a" P
  477. # You can configure the slow log with two parameters: one tells Redis$ x) _+ l! P5 j
  478. # what is the execution time, in microseconds, to exceed in order for the
    & [; [6 ^* ?- A2 `
  479. # command to get logged, and the other parameter is the length of the
    , F8 D, J" C2 x3 F4 Y: \
  480. # slow log. When a new command is logged the oldest one is removed from the- F8 o; z3 Z2 R; e9 W3 ~2 q8 y
  481. # queue of logged commands.
    4 d' t( M) e2 e
  482. 0 j2 B0 j- ~. _* b1 k
  483. # The following time is expressed in microseconds, so 1000000 is equivalent' j' F# P1 U( |1 {1 Q! L
  484. # to one second. Note that a negative number disables the slow log, while
    7 H. {) H& C) A  \) E- B& J/ t
  485. # a value of zero forces the logging of every command.
    ; K! G% C1 V) Q$ G2 Y; K
  486. slowlog-log-slower-than 100004 Q; C; ]6 E! U8 t* C' i

  487. # M/ o) `/ a8 |+ `  U; E
  488. # There is no limit to this length. Just be aware that it will consume memory.
    3 }% K& @4 w  b; M3 _; Y' [4 D
  489. # You can reclaim memory used by the slow log with SLOWLOG RESET.
    " M2 S) F9 Q/ Z% k
  490. slowlog-max-len 1286 t3 J; S2 b* M6 u& m- X' z

  491. $ E: q' B5 E5 Q, P! B5 p- V
  492. ############################### ADVANCED CONFIG ###############################4 g# a2 ?  \! B4 j; G
  493. , i4 @, Y% \2 S4 B: J
  494. # Hashes are encoded using a memory efficient data structure when they have a
    9 N4 \0 P$ h/ u% _! M5 _1 i+ w
  495. # small number of entries, and the biggest entry does not exceed a given: z) s. `7 }+ |. U0 X- \2 z
  496. # threshold. These thresholds can be configured using the following directives.
    + P: [% i( r$ v! }, @2 |& _
  497. hash-max-ziplist-entries 512/ f8 K+ M: {2 `, w" t9 u
  498. hash-max-ziplist-value 64
    & W4 P) Q9 i4 x7 E
  499. - N# V+ ~" J1 Y+ K5 ?7 J
  500. # Similarly to hashes, small lists are also encoded in a special way in order
    % M1 V  s' T1 V2 T# H, F
  501. # to save a lot of space. The special representation is only used when! m- R( F4 g0 |3 I" F2 m$ r3 N( q
  502. # you are under the following limits:7 b5 U) t$ l+ d( j) m* _* J
  503. list-max-ziplist-entries 512
    ; v1 N, j$ p" L2 _* i
  504. list-max-ziplist-value 64; P1 j1 j: z- c6 b/ E9 [1 O* K

  505. 7 Q) i$ T' L" n$ J
  506. # Sets have a special encoding in just one case: when a set is composed/ V7 o+ b6 z% ?7 s& K$ E; |$ B
  507. # of just strings that happens to be integers in radix 10 in the range
    7 ^8 L  V5 E3 l' o% R
  508. # of 64 bit signed integers.0 L6 S) v# B2 [5 m
  509. # The following configuration setting sets the limit in the size of the
    % r. P4 W- j; r+ u5 ?% f' j
  510. # set in order to use this special memory saving encoding.
    - e% Y/ w# [, c( A6 a9 [/ r
  511. set-max-intset-entries 512
    , M/ C) C5 v* U! H
  512. ( e1 O; s* f. v' s& [
  513. # Similarly to hashes and lists, sorted sets are also specially encoded in1 F$ E. a! o1 O: R% \" Q
  514. # order to save a lot of space. This encoding is only used when the length and! F8 u% X- z. M7 Y
  515. # elements of a sorted set are below the following limits:
    6 z& _- O3 b  t" R
  516. zset-max-ziplist-entries 128% A  d7 v6 G7 H! Z& w% ~
  517. zset-max-ziplist-value 64$ T8 I+ K: _" B3 Y& N" O
  518. " S5 F3 E8 d( F3 z
  519. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
    6 v; _- M+ G  l1 d
  520. # order to help rehashing the main Redis hash table (the one mapping top-level' k- t. d! V8 c# E1 `% {
  521. # keys to values). The hash table implementation Redis uses (see dict.c), ^4 k! d8 N) `6 \; v; \% S8 ?
  522. # performs a lazy rehashing: the more operation you run into an hash table$ F& @2 b: [6 }0 f
  523. # that is rehashing, the more rehashing "steps" are performed, so if the4 V  G& H& w$ J! B7 u4 w, l
  524. # server is idle the rehashing is never complete and some more memory is used& e) {. a/ m+ d. T! |# S
  525. # by the hash table.( @: i  D& G- E: v8 v
  526. # 9 L/ w6 @5 \  J) @
  527. # The default is to use this millisecond 10 times every second in order to9 C; p$ ?; ^, S, B2 H0 t
  528. # active rehashing the main dictionaries, freeing memory when possible.' B+ E& s1 E& F" E( M3 J! g% i1 ?: N& f
  529. #
    ! o' C6 T" z% @) d+ @6 O( `- R
  530. # If unsure:0 ]. I# H. e) j. K
  531. # use "activerehashing no" if you have hard latency requirements and it is1 U9 ~& q# m) ?2 h3 C
  532. # not a good thing in your environment that Redis can reply form time to time
    3 x2 B* ?) `& m: r- H" O+ q
  533. # to queries with 2 milliseconds delay.
    % q( H1 E3 t; O0 c/ t9 j
  534. #4 |( h$ f' j7 H' ~& Y2 \" m
  535. # use "activerehashing yes" if you don't have such hard requirements but
    ( d: F  X2 ]1 A: h$ ^/ I
  536. # want to free memory asap when possible.
    ! ?- B$ }5 p- m
  537. activerehashing yes
    ) [- Y7 `4 W# @. {
  538. + H1 t: O6 Z5 J3 n0 Y
  539. # The client output buffer limits can be used to force disconnection of clients* A1 g* M1 i% j" J
  540. # that are not reading data from the server fast enough for some reason (a
    ! x, }! \- }0 Q& R6 f$ }; u. @% i. l
  541. # common reason is that a Pub/Sub client can't consume messages as fast as the+ o) E7 F# t# S9 u- ~) c* B; P# `. L8 f
  542. # publisher can produce them).3 u3 J* U' p: }# i- x. g
  543. #
    8 D" C% y+ V4 S5 E- m
  544. # The limit can be set differently for the three different classes of clients:
    + E- Y. o1 r# b) j+ g
  545. #
    4 j5 L) E# b0 H; H1 K
  546. # normal -> normal clients1 V$ ]' m( Z/ b; ?
  547. # slave  -> slave clients and MONITOR clients' b: [) k. ^9 ?5 R8 J' D* @
  548. # pubsub -> clients subcribed to at least one pubsub channel or pattern
    4 K3 ]7 b7 ^" {. I% g
  549. #, M8 `$ [5 c! |! x
  550. # The syntax of every client-output-buffer-limit directive is the following:
    2 C4 l) q2 k$ f7 ~+ T) i
  551. #, {) Z) B0 K; ]  t2 ]0 g
  552. # client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>
    * M# x+ p6 t6 G, s$ i: l
  553. #" B, Z! e9 f: ~/ V6 e1 }6 y3 t- y! V
  554. # A client is immediately disconnected once the hard limit is reached, or if
    , i' H! s( T% Z/ f/ a7 ?6 h. W
  555. # the soft limit is reached and remains reached for the specified number of$ }2 q% ^( v: ]0 D$ ~0 A
  556. # seconds (continuously).
    ( _+ w/ Z1 Y! R$ }+ O& j
  557. # So for instance if the hard limit is 32 megabytes and the soft limit is
    1 ?7 F/ l% L5 a) |' G1 Z
  558. # 16 megabytes / 10 seconds, the client will get disconnected immediately
    0 ?; ~3 I: J. Z& p
  559. # if the size of the output buffers reach 32 megabytes, but will also get
    ) b8 S& }% ?4 P3 Q/ ?6 c
  560. # disconnected if the client reaches 16 megabytes and continuously overcomes
    8 M& S. o" ^" V7 a* v0 s* Z
  561. # the limit for 10 seconds.- q2 B- U- e' ?2 m! s5 v
  562. #. o8 m9 s& O  H. g9 ~) j* q; T7 ~
  563. # By default normal clients are not limited because they don't receive data
    ! F/ Q; ~9 }' c2 r
  564. # without asking (in a push way), but just after a request, so only
    ! R% p! n% Y7 ?" d
  565. # asynchronous clients may create a scenario where data is requested faster- E" J2 S( ]' k0 a
  566. # than it can read.
    + r; n  S* l- K1 X! e- f8 W( u
  567. #* T1 W3 T0 A7 G# C
  568. # Instead there is a default limit for pubsub and slave clients, since
    " F$ d8 F/ Z3 K
  569. # subscribers and slaves receive data in a push fashion.. }- a% X% ?+ c
  570. #
    - V5 y+ c: w* X) _( F
  571. # Both the hard or the soft limit can be disabled by setting them to zero., W: t8 J9 [* z* a8 e: S
  572. client-output-buffer-limit normal 0 0 0( v% n, R0 Q5 g% ]" H+ i+ a
  573. client-output-buffer-limit slave 256mb 64mb 60( B' t1 @! g2 S/ C+ t
  574. client-output-buffer-limit pubsub 32mb 8mb 60
    3 h5 l* S1 j2 F4 Z
  575. 6 c' U3 m3 A4 L( X8 {+ y
  576. ################################## INCLUDES ###################################9 M. b2 m/ z$ c% S3 p

  577. : D% {; g" x" n9 B( l
  578. # Include one or more other config files here.  This is useful if you1 c1 [* T* W% B- b4 d6 A5 |! W! g
  579. # have a standard template that goes to all Redis server but also need
    , j% h& d0 i4 S' Z& f7 {
  580. # to customize a few per-server settings.  Include files can include+ j: s/ @$ R: d, B* G
  581. # other files, so use this wisely.
    ) h+ R: s( G1 f+ E/ A6 B& M7 f) x
  582. #
    2 I5 {/ C) B8 g! S+ a
  583. # include /path/to/local.conf/ ]# G/ P$ J/ U6 T) j% k$ i7 x
  584. # include /path/to/other.conf        5 H3 S  b4 j4 M  y% k5 u
  585. ##########################配置文件结束################################ 5 @3 R/ @' W) E7 g4 t6 Z" k
  586. 第三步:启动进程
    2 W$ O" L7 i# k* Y8 c' @- {, R
  587. #redis-server /etc/redis.conf
    ) L  ?4 J% A. V. A) k" n
  588. 查看进程有没有成功启动
    + U9 K8 `# t0 I
  589. #ps -ef | grep redis 1 l9 R: d' x* G( f% @/ z
  590. 测试输入一个键值, ]$ U1 I' j4 U) d& h
  591. #redis-cli set test "testredis"! Y9 v$ L8 P( u$ A% }/ q( B
  592. 获取键值
    * _' u( _) i/ L0 D' X2 V- g" n
  593. #redis-cli get test, Y/ S& `' y( S2 P8 K3 K6 j
  594. . g/ k6 }, B+ b

  595. , ^: b+ d' X% g6 ^
  596. 第四步:关闭redis  (这个是更改配置文件后 正常的重启方式  不重新加载redis配置跳过)
    ' J: F  M$ x6 O, N
  597. # redis-cli shutdown      //关闭所有    & |1 f4 O0 P: N2 l: b  L
  598. 关闭某个端口上的redis      Z" \9 y+ U/ \/ R  F! G
  599. # redis-cli -p 6397 shutdown  //关闭6397端口的redis  
    & ^; C- o( `6 k! Z
  600. 说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename  dump.rdb  
    & B; x# y9 `) w  B. a: Q: @0 w1 I
  601. 6 B, C! y' L. E$ J  y0 m4 a

  602. ; l5 U& M6 z" s4 H/ H
  603. 第5步:php扩展安装/ f1 l: F0 a' E7 D9 Z3 N7 Y
  604. phpredis PHP扩展下载地址
    . Z" y# ]9 x8 ]# L5 z2 B5 `) B  V
  605. https://github.com/nicolasff/phpredis/tree/2.2.2
    0 C; z- q1 d' X  k( F* ~
  606. 选择最新版本下载zip
    4 c; Q3 y' K- H# A8 s; b: r6 j

  607. 4 ?. A9 }7 g" j- F) N5 j# D, L, X! N
  608. 然后自己上传zip  用unzip解压到当前目录 unzip 文件名
      r+ Y! \, \, a
  609. 0 Q' B' T: n2 [2 _) A; R
  610. # cd owlient-phpredis-90ecd17/   #打开解压后的文件夹里面  这个解压后的目录 要是不知道 可以输入 "dir" 查看# K( m; A; B* P( F+ f9 Z
  611. # /www/nginx_php-5.2.17/bin
    ) D9 x' h! t/ ~* K
  612. # ./configure --with-php-config=/www/nginx_php-5.2.17/bin/php-config4 e7 I/ i7 R6 v
  613. #make
    7 B. q& {) E; N% A1 R6 I
  614. #make install   #记录产生的redis.so路径( i+ E$ n7 [. d+ |+ g* a0 ?
  615. 7 C9 }) F) S# w
  616. 修改php.ini文件
    ! t  R' \' M6 W! u  o* m, P% w
  617. 在php.ini中添加如下一行:- }5 V0 Q, T% N7 b, \3 N9 m
  618. extension=/?/redis.so  #是刚刚记录的产生redis.so的路 写在 ?那
    7 |+ q7 N, H' c1 S
  619. 重启 使之生效:
    * u. E" m: y  q! `
  620. /usr/local/php/sbin/php-fpm reload; l0 E1 e8 t9 ^% }
  621. /usr/local/nginx/sbin/nginx -s reload
    $ [2 ?" U/ ^: F% o) B

  622. 0 ^  F% w" D/ h' |! Y+ I, I& ]
  623. 将 Redis 作为 Linux 服务随机启动
    ) Q: t; w, Q+ x7 B9 w6 l
  624. vi /etc/rc.local, 加入代码:! o6 V: F: a- d8 s
  625. /root/redis-2.6.10/src/redis-serve  #路径看情况修改 ' I3 g9 e* c9 q3 l2 t7 E4 Q2 l
  626. 8 c0 A$ `+ l; `% I
  627. redis-cli -h localhost -p 6379 info  #命令要在redis目录下面执行
    1 j- Q; F! _+ C$ `' W% b" N
  628. 提供host为localhost,端口为6379,redis服务的统计信息2 E" f5 B. B9 n8 C; j

  629. ( g2 v5 o; e( r1 \8 L

  630. 1 j9 g: A# B$ M; \( j/ @
  631. 就这样你的web服务器就支持redis了 记得要在 给dz 的配置文件 加上12.0.0.1哦
    : j  A$ Y1 `( v9 T5 i; t
  632. dz配置文件在 config目录下面的 config_global.php8 l# M/ Q* O4 R- O; D
  633. $_config['memory']['redis']['server'] = '127.0.0.1';
    ! y+ G6 u/ ?% j2 Y! i) p& p- B- K. m
  634. $_config['memory']['redis']['port'] = 6379;$ a0 a9 k* q$ ~, e# g2 |: R1 {' x4 S
  635. $_config['memory']['redis']['pconnect'] = 1;
    & w1 n' H- w* j/ E3 j5 f
  636. $_config['memory']['redis']['timeout'] = '0';
    + e+ b& g6 [4 d2 c3 s
  637. $_config['memory']['redis']['serializer'] = 1;
    # Y# s5 ~; f2 s) c  a( m
复制代码
关注微信公众号《神采飞扬网》,即可获取最新回复通知!

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

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

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

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

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