windows下的环境搭建配置redis

下载地址:https://github.com/dmajkic/redis/downloads 下载下来的包里有两个,
一个是32位的,一个是64位的。根据自己的实情情况选择,我的是32bit,
把这个文件夹复制到其它地方,比如D:\redis 目录下。
打开一个cmd窗口  使用cd命令切换目录到d:\redis  运行 redis-server.exe redis.conf  
如果想方便的话,可以把redis的路径加到系统的环境变量里,这样就省得再输路径了,后面的那个redis.conf可以省略,如果省略,会启用默认的。输入之后,会显示如下界面:

 
这时候别启一个cmd窗口,原来的不要关闭,不然就无法访问服务端了
切换到redis目录下运行 redis-cli.exe -h 127.0.0.1 -p 6379 出现下图:

 
这时候,就已经完成配置了,现在说下它的的redis.conf配置文件。

[plain]  view plain copy
  1. 001  
  2. # Redis configuration file example  
  3. 002  
  4.    
  5. 003  
  6. # Note on units: when memory size is needed, it is possible to specifiy  
  7. 004  
  8. # it in the usual form of 1k 5GB 4M and so forth:  
  9. 005  
  10. #  
  11. 006  
  12. # 1k => 1000 bytes  
  13. 007  
  14. # 1kb => 1024 bytes  
  15. 008  
  16. # 1m => 1000000 bytes  
  17. 009  
  18. # 1mb => 1024*1024 bytes  
  19. 010  
  20. # 1g => 1000000000 bytes  
  21. 011  
  22. # 1gb => 1024*1024*1024 bytes  
  23. 012  
  24. #  
  25. 013  
  26. # units are case insensitive so 1GB 1Gb 1gB are all the same.  
  27. 014  
  28.    
  29. 015  
  30. # By default Redis does not run as a daemon. Use 'yes' if you need it.  
  31. 016  
  32. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.  
  33. 017  
  34. daemonize no   
  35. 018  
  36. Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程  
  37. 019  
  38.    
  39. 020  
  40. # When running daemonized, Redis writes a pid file in /var/run/redis.pid by  
  41. 021  
  42. # default. You can specify a custom pid file location here.  
  43. 022  
  44. pidfile /var/run/redis.pid  
  45. 023  
  46. 当Redis以守护进程方式运行时,Redis默认会把pid写入/var/run/redis.pid文件,可以通过pidfile指定  
  47. 024  
  48. # Accept connections on the specified port, default is 6379.  
  49. 025  
  50. # If port 0 is specified Redis will not listen on a TCP socket.  
  51. 026  
  52. port 6379  
  53. 027  
  54. 指定Redis监听端口,默认端口为6379  
  55. 028  
  56. # If you want you can bind a single interface, if the bind option is not  
  57. 029  
  58. # specified all the interfaces will listen for incoming connections.  
  59. 030  
  60. #  
  61. 031  
  62. # bind 127.0.0.1  
  63. 032  
  64. 绑定的主机地址  
  65. 033  
  66. # Specify the path for the unix socket that will be used to listen for  
  67. 034  
  68. # incoming connections. There is no default, so Redis will not listen  
  69. 035  
  70. # on a unix socket when not specified.  www.2cto.com    
  71. 036  
  72. #  
  73. 037  
  74. # unixsocket /tmp/redis.sock  
  75. 038  
  76. # unixsocketperm 755  
  77. 039  
  78.    
  79. 040  
  80. # Close the connection after a client is idle for N seconds (0 to disable)  
  81. 041  
  82. timeout 0  
  83. 042  
  84. 当 客户端闲置多长时间后关闭连接,如果指定为0,表示关闭该功能  
  85. 043  
  86. # Set server verbosity to 'debug'  
  87. 044  
  88. # it can be one of:  
  89. 045  
  90. # debug (a lot of information, useful for development/testing)  
  91. 046  
  92. # verbose (many rarely useful info, but not a mess like the debug level)  
  93. 047  
  94. # notice (moderately verbose, what you want in production probably)  
  95. 048  
  96. # warning (only very important / critical messages are logged)  
  97. 049  
  98. loglevel verbose  
  99. 050  
  100. 指定日志记录级别,Redis总共支持四个级别:debug、verbose、notice、warning,默认为verbose  
  101. 051  
  102. # Specify the log file name. Also 'stdout' can be used to force  
  103. 052  
  104. # Redis to log on the standard output. Note that if you use standard  
  105. 053  
  106. # output for logging but daemonize, logs will be sent to /dev/null  
  107. 054  
  108. logfile stdout  
  109. 055  
  110. 日志记录方式,默认为标准输出,如果配置Redis为守护进程方式运行,而这里又配置为日志记录方式为标准输出,则日志将会发送给/dev/null  
  111. 056  
  112. # To enable logging to the system logger, just set 'syslog-enabled' to yes,  
  113. 057  
  114. # and optionally update the other syslog parameters to suit your needs.  
  115. 058  
  116. # syslog-enabled no  
  117. 059  
  118.    
  119. 060  
  120. # Specify the syslog identity.  
  121. 061  
  122. # syslog-ident redis  
  123. 062  
  124.    
  125. 063  
  126. # Specify the syslog facility.  Must be USER or between LOCAL0-LOCAL7.  
  127. 064  
  128. # syslog-facility local0  
  129. 065  
  130.    
  131. 066  
  132. # Set the number of databases. The default database is DB 0, you can select  
  133. 067  
  134. # a different one on a per-connection basis using SELECT <dbid> where  
  135. 068  
  136. # dbid is a number between 0 and 'databases'-1  
  137. 069  
  138. databases 16  www.2cto.com    
  139. 070  
  140. 设置数据库的数量,默认数据库为0,可以使用SELECT <dbid>命令在连接上指定数据库id  
  141. 071  
  142. ################################ SNAPSHOTTING  #################################  
  143. 072  
  144. #  
  145. 073  
  146. # Save the DB on disk:  
  147. 074  
  148. #  
  149. 075  
  150. #   save <seconds> <changes>  
  151. 076  
  152. #  
  153. 077  
  154. #   Will save the DB if both the given number of seconds and the given  
  155. 078  
  156. #   number of write operations against the DB occurred.  
  157. 079  
  158. #  
  159. 080  
  160. #   In the example below the behaviour will be to save:  
  161. 081  
  162. #   after 900 sec (15 min) if at least 1 key changed  
  163. 082  
  164. #   after 300 sec (5 min) if at least 10 keys changed  
  165. 083  
  166. #   after 60 sec if at least 10000 keys changed  
  167. 084  
  168. #  
  169. 085  
  170. #   Note: you can disable saving at all commenting all the "save" lines.  
  171. 086  
  172.    
  173. 087  
  174. save 900 1  
  175. 088  
  176. save 300 10  
  177. 089  
  178. save 60 10000  
  179. 090  
  180. 分别表示900秒(15分钟)内有1个更改,300秒(5分钟)内有10个更改以及60秒内有10000个更改。  
  181. 091  
  182. 指定在多长时间内,有多少次更新操作,就将数据同步到数据文件,可以多个条件配合  
  183. 092  
  184. # Compress string objects using LZF when dump .rdb databases?  
  185. 093  
  186. # For default that's set to 'yes' as it's almost always a win.  
  187. 094  
  188. # If you want to save some CPU in the saving child set it to 'no' but  
  189. 095  
  190. # the dataset will likely be bigger if you have compressible values or keys.  
  191. 096  
  192. rdbcompression yes  
  193. 097  
  194. 指定存储至本地数据库时是否压缩数据,默认为yes,Redis采用LZF压缩,如果为了节省CPU时间,可以关闭该选项,但会导致数据库文件变的巨大  
  195. 098  
  196. # The filename where to dump the DB  
  197. 099  
  198. dbfilename dump.rdb  
  199. 100  
  200. 指定本地数据库文件名,默认值为dump.rdb  
  201. 101  
  202. # The working directory.  
  203. 102  
  204. #  
  205. 103  
  206. # The DB will be written inside this directory, with the filename specified  
  207. 104  
  208. # above using the 'dbfilename' configuration directive.  
  209. 105  
  210. #  
  211. 106  
  212. # Also the Append Only File will be created inside this directory.  
  213. 107  
  214. #  
  215. 108  
  216. # Note that you must specify a directory here, not a file name.  
  217. 109  
  218. dir ./  
  219. 110  
  220. 指定本地数据库存放目录  
  221. 111  
  222. ################################# REPLICATION #################################  
  223. 112  
  224.    
  225. 113  
  226. # Master-Slave replication. Use slaveof to make a Redis instance a copy of  
  227. 114  
  228. # another Redis server. Note that the configuration is local to the slave  
  229. 115  
  230. # so for example it is possible to configure the slave to save the DB with a  
  231. 116  
  232. # different interval, or to listen to another port, and so on.  www.2cto.com    
  233. 117  
  234. #  
  235. 118  
  236. # slaveof <masterip> <masterport>  
  237. 119  
  238. slaveof <masterip> <masterport> 设置当本机为slav服务时,设置master服务的IP地址及端口,在Redis启动时,它会自动从master进行数据同步  
  239. 120  
  240. # If the master is password protected (using the "requirepass" configuration  
  241. 121  
  242. # directive below) it is possible to tell the slave to authenticate before  
  243. 122  
  244. # starting the replication synchronization process, otherwise the master will  
  245. 123  
  246. # refuse the slave request.  
  247. 124  
  248. #  
  249. 125  
  250. # masterauth <master-password>  
  251. 126  
  252. masterauth <master-password> 当master服务设置了密码保护时,slav服务连接master的密码  
  253. 127  
  254. # When a slave lost the connection with the master, or when the replication  
  255. 128  
  256. # is still in progress, the slave can act in two different ways:  
  257. 129  
  258. #  
  259. 130  
  260. # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will  
  261. 131  
  262. #    still reply to client requests, possibly with out of data data, or the  
  263. 132  
  264. #    data set may just be empty if this is the first synchronization.  
  265. 133  
  266. #  
  267. 134  
  268. # 2) if slave-serve-stale data is set to 'no' the slave will reply with  
  269. 135  
  270. #    an error "SYNC with master in progress" to all the kind of commands  
  271. 136  
  272. #    but to INFO and SLAVEOF.  
  273. 137  
  274. #  
  275. 138  
  276. slave-serve-stale-data yes  
  277. 139  
  278.    
  279. 140  
  280. # Slaves send PINGs to server in a predefined interval. It's possible to change  
  281. 141  
  282. # this interval with the repl_ping_slave_period option. The default value is 10  
  283. 142  
  284. # seconds.  www.2cto.com    
  285. 143  
  286. #  
  287. 144  
  288. # repl-ping-slave-period 10  
  289. 145  
  290.    
  291. 146  
  292. # The following option sets a timeout for both Bulk transfer I/O timeout and  
  293. 147  
  294. # master data or ping response timeout. The default value is 60 seconds.  
  295. 148  
  296. #  
  297. 149  
  298. # It is important to make sure that this value is greater than the value  
  299. 150  
  300. # specified for repl-ping-slave-period otherwise a timeout will be detected  
  301. 151  
  302. # every time there is low traffic between the master and the slave.  
  303. 152  
  304. #  
  305. 153  
  306. # repl-timeout 60  
  307. 154  
  308.    
  309. 155  
  310. ################################## SECURITY ###################################  
  311. 156  
  312.    
  313. 157  
  314. # Require clients to issue AUTH <PASSWORD> before processing any other  
  315. 158  
  316. # commands.  This might be useful in environments in which you do not trust  
  317. 159  
  318. # others with access to the host running redis-server.  
  319. 160  
  320. #  
  321. 161  
  322. # This should stay commented out for backward compatibility and because most  
  323. 162  
  324. # people do not need auth (e.g. they run their own servers).  
  325. 163  
  326. #  
  327. 164  
  328. # Warning: since Redis is pretty fast an outside user can try up to  
  329. 165  
  330. # 150k passwords per second against a good box. This means that you should  
  331. 166  
  332. # use a very strong password otherwise it will be very easy to break.  
  333. 167  
  334. #  
  335. 168  
  336. # requirepass foobared  
  337. 169  
  338.  requirepass foobared 设置Redis连接密码,如果配置了连接密码,客户端在连接Redis时需要通过AUTH <password>命令提供密码,默认关闭  
  339. 170  
  340. # Command renaming.  
  341. 171  
  342. #  
  343. 172  
  344. # It is possilbe to change the name of dangerous commands in a shared  
  345. 173  
  346. # environment. For instance the CONFIG command may be renamed into something  
  347. 174  
  348. # of hard to guess so that it will be still available for internal-use  
  349. 175  
  350. # tools but not available for general clients.  
  351. 176  
  352. #  
  353. 177  
  354. # Example:  
  355. 178  
  356. #  
  357. 179  
  358. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52  
  359. 180  
  360. #  
  361. 181  
  362. # It is also possilbe to completely kill a command renaming it into  
  363. 182  
  364. # an empty string:  
  365. 183  
  366. #  
  367. 184  
  368. # rename-command CONFIG ""  
  369. 185  
  370.    
  371. 186  
  372. ################################### LIMITS ####################################  
  373. 187  
  374.    
  375. 188  
  376. # Set the max number of connected clients at the same time. By default there  
  377. 189  
  378. # is no limit, and it's up to the number of file descriptors the Redis process  
  379. 190  
  380. # is able to open. The special value '0' means no limits.  
  381. 191  
  382. # Once the limit is reached Redis will close all the new connections sending  
  383. 192  
  384. # an error 'max number of clients reached'.  www.2cto.com    
  385. 193  
  386. #  
  387. 194  
  388. # maxclients 128  
  389. 195  
  390. maxclients 128 设置同一时间最大客户端连接数,默认无限制,Redis可以同时打开的客户端连接数为Redis进程可以打开的最大文件描述符数,如果设置 maxclients 0,表示不作限制。当客户端连接数到达限制时,Redis会关闭新的连接并向客户端返回max number of clients reached错误信息  
  391. 196  
  392. # Don't use more memory than the specified amount of bytes.  
  393. 197  
  394. # When the memory limit is reached Redis will try to remove keys with an  
  395. 198  
  396. # EXPIRE set. It will try to start freeing keys that are going to expire  
  397. 199  
  398. # in little time and preserve keys with a longer time to live.  
  399. 200  
  400. # Redis will also try to remove objects from free lists if possible.  
  401. 201  
  402. #  
  403. 202  
  404. # If all this fails, Redis will start to reply with errors to commands  
  405. 203  
  406. # that will use more memory, like SET, LPUSH, and so on, and will continue  
  407. 204  
  408. # to reply to most read-only commands like GET.  
  409. 205  
  410. #  
  411. 206  
  412. # WARNING: maxmemory can be a good idea mainly if you want to use Redis as a  
  413. 207  
  414. # 'state' server or cache, not as a real DB. When Redis is used as a real  
  415. 208  
  416. # database the memory usage will grow over the weeks, it will be obvious if  
  417. 209  
  418. # it is going to use too much memory in the long run, and you'll have the time  
  419. 210  
  420. # to upgrade. With maxmemory after the limit is reached you'll start to get  
  421. 211  
  422. # errors for write operations, and this may even lead to DB inconsistency.  
  423. 212  
  424. #  
  425. 213  
  426. # maxmemory <bytes>  
  427. 214  
  428.  maxmemory <bytes>指定Redis最大内存限制,Redis在启动时会把数据加载到内存中,达到最大内存后,Redis会先尝试清除已到期或即将到期的Key,当此方法处理 后,仍然到达最大内存设置,将无法再进行写入操作,但仍然可以进行读取操作。Redis新的vm机制,会把Key存放内存,Value会存放在swap区  
  429. 215  
  430. # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory  
  431. 216  
  432. # is reached? You can select among five behavior:  
  433. 217  
  434. #  
  435. 218  
  436. # volatile-lru -> remove the key with an expire set using an LRU algorithm  
  437. 219  
  438. # allkeys-lru -> remove any key accordingly to the LRU algorithm  
  439. 220  
  440. # volatile-random -> remove a random key with an expire set  
  441. 221  
  442. # allkeys->random -> remove a random key, any key  
  443. 222  
  444. # volatile-ttl -> remove the key with the nearest expire time (minor TTL)  
  445. 223  
  446. # noeviction -> don't expire at all, just return an error on write operations  
  447. 224  
  448. #  
  449. 225  
  450. # Note: with all the kind of policies, Redis will return an error on write  
  451. 226  
  452. #       operations, when there are not suitable keys for eviction.  
  453. 227  
  454. #  
  455. 228  
  456. #       At the date of writing this commands are: set setnx setex append  
  457. 229  
  458. #       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd  
  459. 230  
  460. #       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby  
  461. 231  
  462. #       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby  
  463. 232  
  464. #       getset mset msetnx exec sort  www.2cto.com    
  465. 233  
  466. #  
  467. 234  
  468. # The default is:  
  469. 235  
  470. #  
  471. 236  
  472. # maxmemory-policy volatile-lru  
  473. 237  
  474.    
  475. 238  
  476. # LRU and minimal TTL algorithms are not precise algorithms but approximated  
  477. 239  
  478. # algorithms (in order to save memory), so you can select as well the sample  
  479. 240  
  480. # size to check. For instance for default Redis will check three keys and  
  481. 241  
  482. # pick the one that was used less recently, you can change the sample size  
  483. 242  
  484. # using the following configuration directive.  
  485. 243  
  486. #  
  487. 244  
  488. # maxmemory-samples 3  
  489. 245  
  490.    
  491. 246  
  492. ############################## APPEND ONLY MODE ###############################  
  493. 247  
  494.    
  495. 248  
  496. # By default Redis asynchronously dumps the dataset on disk. If you can live  
  497. 249  
  498. # with the idea that the latest records will be lost if something like a crash  
  499. 250  
  500. # happens this is the preferred way to run Redis. If instead you care a lot  
  501. 251  
  502. # about your data and don't want to that a single record can get lost you should  
  503. 252  
  504. # enable the append only mode: when this mode is enabled Redis will append  
  505. 253  
  506. # every write operation received in the file appendonly.aof. This file will  
  507. 254  
  508. # be read on startup in order to rebuild the full dataset in memory.  
  509. 255  
  510. #  
  511. 256  
  512. # Note that you can have both the async dumps and the append only file if you  
  513. 257  
  514. # like (you have to comment the "save" statements above to disable the dumps).  
  515. 258  
  516. # Still if append only mode is enabled Redis will load the data from the  
  517. 259  
  518. # log file at startup ignoring the dump.rdb file.  
  519. 260  
  520. #  
  521. 261  
  522. # IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append  
  523. 262  
  524. # log file in background when it gets too big.  
  525. 263  
  526.    
  527. 264  
  528. appendonly no  
  529. 265  
  530. appendonly no指定是否在每次更新操作后进行日志记录,Redis在默认情况下是异步的把数据写入磁盘,如果不开启,可能会在断电时导致一段时间内的数据丢失。因为 redis本身同步数据文件是按上面save条件来同步的,所以有的数据会在一段时间内只存在于内存中。默认为no  
  531. 266  
  532. # The name of the append only file (default: "appendonly.aof")  
  533. 267  
  534. # appendfilename appendonly.aof  
  535. 268  
  536.  appendfilename appendonly.aof指定更新日志文件名,默认为appendonly.aof  
  537. 269  
  538. # The fsync() call tells the Operating System to actually write data on disk  
  539. 270  
  540. # instead to wait for more data in the output buffer. Some OS will really flush  
  541. 271  
  542. # data on disk, some other OS will just try to do it ASAP.  
  543. 272  
  544. #  
  545. 273  
  546. # Redis supports three different modes:  
  547. 274  
  548. #  
  549. 275  
  550. # no: don't fsync, just let the OS flush the data when it wants. Faster.  
  551. 276  
  552. # always: fsync after every write to the append only log . Slow, Safest.  
  553. 277  
  554. # everysec: fsync only if one second passed since the last fsync. Compromise.  
  555. 278  
  556. #  
  557. 279  
  558. # The default is "everysec" that's usually the right compromise between  
  559. 280  
  560. # speed and data safety. It's up to you to understand if you can relax this to  
  561. 281  
  562. # "no" that will will let the operating system flush the output buffer when  
  563. 282  
  564. # it wants, for better performances (but if you can live with the idea of  
  565. 283  
  566. # some data loss consider the default persistence mode that's snapshotting),  
  567. 284  
  568. # or on the contrary, use "always" that's very slow but a bit safer than  
  569. 285  
  570. # everysec.  www.2cto.com    
  571. 286  
  572. #  
  573. 287  
  574. # If unsure, use "everysec".  
  575. 288  
  576.    
  577. 289  
  578. # appendfsync always  
  579. 290  
  580. appendfsync everysec  
  581. 291  
  582. # appendfsync no  
  583. 292  
  584. 指定更新日志条件,共有3个可选值:  
  585. 293  
  586. no:表示等操作系统进行数据缓存同步到磁盘(快)  
  587. 294  
  588. always:表示每次更新操作后手动调用fsync()将数据写到磁盘(慢,安全)  
  589. 295  
  590. everysec:表示每秒同步一次(折衷,默认值)  
  591. 296  
  592. # When the AOF fsync policy is set to always or everysec, and a background  
  593. 297  
  594. # saving process (a background save or AOF log background rewriting) is  
  595. 298  
  596. # performing a lot of I/O against the disk, in some Linux configurations  
  597. 299  
  598. # Redis may block too long on the fsync() call. Note that there is no fix for  
  599. 300  
  600. # this currently, as even performing fsync in a different thread will block  
  601. 301  
  602. # our synchronous write(2) call.  
  603. 302  
  604. #  
  605. 303  
  606. # In order to mitigate this problem it's possible to use the following option  
  607. 304  
  608. # that will prevent fsync() from being called in the main process while a  
  609. 305  
  610. # BGSAVE or BGREWRITEAOF is in progress.  
  611. 306  
  612. #  
  613. 307  
  614. # This means that while another child is saving the durability of Redis is  
  615. 308  
  616. # the same as "appendfsync none", that in pratical terms means that it is  
  617. 309  
  618. # possible to lost up to 30 seconds of log in the worst scenario (with the  
  619. 310  
  620. # default Linux settings).  
  621. 311  
  622. #  
  623. 312  
  624. # If you have latency problems turn this to "yes". Otherwise leave it as  
  625. 313  
  626. # "no" that is the safest pick from the point of view of durability.  
  627. 314  
  628. no-appendfsync-on-rewrite no  
  629. 315  
  630.    
  631. 316  
  632. # Automatic rewrite of the append only file.  
  633. 317  
  634. # Redis is able to automatically rewrite the log file implicitly calling  
  635. 318  
  636. # BGREWRITEAOF when the AOF log size will growth by the specified percentage.  
  637. 319  
  638. #  
  639. 320  
  640. # This is how it works: Redis remembers the size of the AOF file after the  
  641. 321  
  642. # latest rewrite (or if no rewrite happened since the restart, the size of  
  643. 322  
  644. # the AOF at startup is used).  
  645. 323  
  646. #  
  647. 324  
  648. # This base size is compared to the current size. If the current size is  
  649. 325  
  650. # bigger than the specified percentage, the rewrite is triggered. Also  
  651. 326  
  652. # you need to specify a minimal size for the AOF file to be rewritten, this  
  653. 327  
  654. # is useful to avoid rewriting the AOF file even if the percentage increase  
  655. 328  
  656. # is reached but it is still pretty small.  
  657. 329  
  658. #  
  659. 330  
  660. # Specify a precentage of zero in order to disable the automatic AOF  
  661. 331  
  662. # rewrite feature.  www.2cto.com    
  663. 332  
  664.    
  665. 333  
  666. auto-aof-rewrite-percentage 100  
  667. 334  
  668. auto-aof-rewrite-min-size 64mb  
  669. 335  
  670.    
  671. 336  
  672. ################################## SLOW LOG ###################################  
  673. 337  
  674.    
  675. 338  
  676. # The Redis Slow Log is a system to log queries that exceeded a specified  
  677. 339  
  678. # execution time. The execution time does not include the I/O operations  
  679. 340  
  680. # like talking with the client, sending the reply and so forth,  
  681. 341  
  682. # but just the time needed to actually execute the command (this is the only  
  683. 342  
  684. # stage of command execution where the thread is blocked and can not serve  
  685. 343  
  686. # other requests in the meantime).  
  687. 344  
  688. #  
  689. 345  
  690. # You can configure the slow log with two parameters: one tells Redis  
  691. 346  
  692. # what is the execution time, in microseconds, to exceed in order for the  
  693. 347  
  694. # command to get logged, and the other parameter is the length of the  
  695. 348  
  696. # slow log. When a new command is logged the oldest one is removed from the  
  697. 349  
  698. # queue of logged commands.  
  699. 350  
  700.    
  701. 351  
  702. # The following time is expressed in microseconds, so 1000000 is equivalent  
  703. 352  
  704. # to one second. Note that a negative number disables the slow log, while  
  705. 353  
  706. # a value of zero forces the logging of every command.  
  707. 354  
  708. slowlog-log-slower-than 10000  
  709. 355  
  710.    
  711. 356  
  712. # There is no limit to this length. Just be aware that it will consume memory.  
  713. 357  
  714. # You can reclaim memory used by the slow log with SLOWLOG RESET.  
  715. 358  
  716. slowlog-max-len 1024  
  717. 359  
  718.    
  719. 360  
  720. ################################ VIRTUAL MEMORY ###############################  
  721. 361  
  722.    
  723. 362  
  724. ### WARNING! Virtual Memory is deprecated in Redis 2.4  
  725. 363  
  726. ### The use of Virtual Memory is strongly discouraged.  
  727. 364  
  728.    
  729. 365  
  730. ### WARNING! Virtual Memory is deprecated in Redis 2.4  
  731. 366  
  732. ### The use of Virtual Memory is strongly discouraged.  
  733. 367  
  734.    
  735. 368  
  736. # Virtual Memory allows Redis to work with datasets bigger than the actual  
  737. 369  
  738. # amount of RAM needed to hold the whole dataset in memory.  
  739. 370  
  740. # In order to do so very used keys are taken in memory while the other keys  
  741. 371  
  742. # are swapped into a swap file, similarly to what operating systems do  
  743. 372  
  744. # with memory pages.  www.2cto.com    
  745. 373  
  746. #  
  747. 374  
  748. # To enable VM just set 'vm-enabled' to yes, and set the following three  
  749. 375  
  750. # VM parameters accordingly to your needs.  
  751. 376  
  752.    
  753. 377  
  754. vm-enabled no  
  755. 378  
  756. 指定是否启用虚拟内存机制,默认值为no,简单的介绍一下,VM机制将数据分页存放,由Redis将访问量较少的页即冷数据swap到磁盘上,访问多的页面由磁盘自动换出到内存中(在后面的文章我会仔细分析Redis的VM机制)  
  757. 379  
  758. # vm-enabled yes  
  759. 380  
  760.    
  761. 381  
  762. # This is the path of the Redis swap file. As you can guess, swap files  
  763. 382  
  764. # can't be shared by different Redis instances, so make sure to use a swap  
  765. 383  
  766. # file for every redis process you are running. Redis will complain if the  
  767. 384  
  768. # swap file is already in use.  
  769. 385  
  770. #  
  771. 386  
  772. # The best kind of storage for the Redis swap file (that's accessed at random)  
  773. 387  
  774. # is a Solid State Disk (SSD).  
  775. 388  
  776. #  
  777. 389  
  778. # *** WARNING *** if you are using a shared hosting the default of putting  
  779. 390  
  780. # the swap file under /tmp is not secure. Create a dir with access granted  
  781. 391  
  782. # only to Redis user and configure Redis to create the swap file there.  
  783. 392  
  784. vm-swap-file /tmp/redis.swap  
  785. 393  
  786. 虚拟内存文件路径,默认值为/tmp/redis.swap,不可多个Redis实例共享  
  787. 394  
  788. # vm-max-memory configures the VM to use at max the specified amount of  
  789. 395  
  790. # RAM. Everything that deos not fit will be swapped on disk *if* possible, that  
  791. 396  
  792. # is, if there is still enough contiguous space in the swap file.  
  793. 397  
  794. #  
  795. 398  
  796. # With vm-max-memory 0 the system will swap everything it can. Not a good  
  797. 399  
  798. # default, just specify the max amount of RAM you can in bytes, but it's  
  799. 400  
  800. # better to leave some margin. For instance specify an amount of RAM  
  801. 401  
  802. # that's more or less between 60 and 80% of your free RAM.  
  803. 402  
  804. vm-max-memory 0  www.2cto.com    
  805. 403  
  806. 将所有大于vm-max-memory的数据存入虚拟内存,无论vm-max-memory设置多小,所有索引数据都是内存存储的(Redis的索引数据 就是keys),也就是说,当vm-max-memory设置为0的时候,其实是所有value都存在于磁盘。默认值为0  
  807. 404  
  808. # Redis swap files is split into pages. An object can be saved using multiple  
  809. 405  
  810. # contiguous pages, but pages can't be shared between different objects.  
  811. 406  
  812. # So if your page is too big, small objects swapped out on disk will waste  
  813. 407  
  814. # a lot of space. If you page is too small, there is less space in the swap  
  815. 408  
  816. # file (assuming you configured the same number of total swap file pages).  
  817. 409  
  818. #  
  819. 410  
  820. # If you use a lot of small objects, use a page size of 64 or 32 bytes.  
  821. 411  
  822. # If you use a lot of big objects, use a bigger page size.  
  823. 412  
  824. # If unsure, use the default :)  
  825. 413  
  826. vm-page-size 32  
  827. 414  
  828. Redis swap文件分成了很多的page,一个对象可以保存在多个page上面,但一个page上不能被多个对象共享,vm-page-size是要根据存储的 数据大小来设定的,作者建议如果存储很多小对象,page大小最好设置为32或者64bytes;如果存储很大大对象,则可以使用更大的page,如果不 确定,就使用默认值  
  829. 415  
  830. # Number of total memory pages in the swap file.  
  831. 416  
  832. # Given that the page table (a bitmap of free/used pages) is taken in memory,  
  833. 417  
  834. # every 8 pages on disk will consume 1 byte of RAM.  
  835. 418  
  836. #  
  837. 419  
  838. # The total swap size is vm-page-size * vm-pages  
  839. 420  
  840. #  
  841. 421  
  842. # With the default of 32-bytes memory pages and 134217728 pages Redis will  
  843. 422  
  844. # use a 4 GB swap file, that will use 16 MB of RAM for the page table.  
  845. 423  
  846. #  
  847. 424  
  848. # It's better to use the smallest acceptable value for your application,  
  849. 425  
  850. # but the default is large in order to work in most conditions.  
  851. 426  
  852. vm-pages 134217728  
  853. 427  
  854. 设置swap文件中的page数量,由于页表(一种表示页面空闲或使用的bitmap)是在放在内存中的,,在磁盘上每8个pages将消耗1byte的内存。  
  855. 428  
  856. # Max number of VM I/O threads running at the same time.  
  857. 429  
  858. # This threads are used to read/write data from/to swap file, since they  
  859. 430  
  860. # also encode and decode objects from disk to memory or the reverse, a bigger  
  861. 431  
  862. # number of threads can help with big objects even if they can't help with  
  863. 432  
  864. # I/O itself as the physical device may not be able to couple with many  
  865. 433  
  866. # reads/writes operations at the same time.  www.2cto.com    
  867. 434  
  868. #  
  869. 435  
  870. # The special value of 0 turn off threaded I/O and enables the blocking  
  871. 436  
  872. # Virtual Memory implementation.  
  873. 437  
  874. vm-max-threads 4  
  875. 438  
  876. 设置访问swap文件的线程数,最好不要超过机器的核数,如果设置为0,那么所有对swap文件的操作都是串行的,可能会造成比较长时间的延迟。默认值为4  
  877. 439  
  878. ############################### ADVANCED CONFIG ###############################  
  879. 440  
  880.    
  881. 441  
  882. # Hashes are encoded in a special way (much more memory efficient) when they  
  883. 442  
  884. # have at max a given numer of elements, and the biggest element does not  
  885. 443  
  886. # exceed a given threshold. You can configure this limits with the following  
  887. 444  
  888. # configuration directives.  
  889. 445  
  890. hash-max-zipmap-entries 512  
  891. 446  
  892. hash-max-zipmap-value 64  
  893. 447  
  894. 指定在超过一定的数量或者最大的元素超过某一临界值时,采用一种特殊的哈希算法  
  895. 448  
  896. # Similarly to hashes, small lists are also encoded in a special way in order  
  897. 449  
  898. # to save a lot of space. The special representation is only used when  
  899. 450  
  900. # you are under the following limits:  
  901. 451  
  902. list-max-ziplist-entries 512  
  903. 452  
  904. list-max-ziplist-value 64  
  905. 453  
  906.    
  907. 454  
  908. # Sets have a special encoding in just one case: when a set is composed  
  909. 455  
  910. # of just strings that happens to be integers in radix 10 in the range  
  911. 456  
  912. # of 64 bit signed integers.  
  913. 457  
  914. # The following configuration setting sets the limit in the size of the  
  915. 458  
  916. # set in order to use this special memory saving encoding.  
  917. 459  
  918. set-max-intset-entries 512  www.2cto.com    
  919. 460  
  920.    
  921. 461  
  922. # Similarly to hashes and lists, sorted sets are also specially encoded in  
  923. 462  
  924. # order to save a lot of space. This encoding is only used when the length and  
  925. 463  
  926. # elements of a sorted set are below the following limits:  
  927. 464  
  928. zset-max-ziplist-entries 128  
  929. 465  
  930. zset-max-ziplist-value 64  
  931. 466  
  932.    
  933. 467  
  934. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in  
  935. 468  
  936. # order to help rehashing the main Redis hash table (the one mapping top-level  
  937. 469  
  938. # keys to values). The hash table implementation redis uses (see dict.c)  
  939. 470  
  940. # performs a lazy rehashing: the more operation you run into an hash table  
  941. 471  
  942. # that is rhashing, the more rehashing "steps" are performed, so if the  
  943. 472  
  944. # server is idle the rehashing is never complete and some more memory is used  
  945. 473  
  946. # by the hash table.  
  947. 474  
  948. #  
  949. 475  
  950. # The default is to use this millisecond 10 times every second in order to  
  951. 476  
  952. # active rehashing the main dictionaries, freeing memory when possible.  
  953. 477  
  954. #  
  955. 478  
  956. # If unsure:  
  957. 479  
  958. # use "activerehashing no" if you have hard latency requirements and it is  
  959. 480  
  960. # not a good thing in your environment that Redis can reply form time to time  
  961. 481  
  962. # to queries with 2 milliseconds delay.  
  963. 482  
  964. #  
  965. 483  
  966. # use "activerehashing yes" if you don't have such hard requirements but  
  967. 484  
  968. # want to free memory asap when possible.  
  969. 485  
  970. activerehashing yes  www.2cto.com    
  971. 486  
  972.    
  973. 487  
  974. ################################## INCLUDES ###################################  
  975. 488  
  976.    
  977. 489  
  978. # Include one or more other config files here.  This is useful if you  
  979. 490  
  980. # have a standard template that goes to all redis server but also need  
  981. 491  
  982. # to customize a few per-server settings.  Include files can include  
  983. 492  
  984. # other files, so use this wisely.  
  985. 493  
  986. #  
  987. 494  
  988. # include /path/to/local.conf  
  989. 495  
  990. # include /path/to/other.conf  
  991. 496  

指定包含其它的配置文件,可以在同一主机上多个Redis实例之间使用同一份配置文件,而同时各个实例又拥有自己的特定配置文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值