Redis安装无错版

 

下载最新的

官网:http://redis.io/  或者  http://code.google.com/p/redis/downloads/list

第一步:下载安装编译

#wget http://redis.googlecode.com/files/redis-2.4.2.tar.gz
#tar 
zxvf redis-2.4.2.tar.gz
#cd redis-2.4.2
#make 
#make install
#cp redis.conf  /etc/

第二步:修改配置

#vi /etc/redis.conf
 
配置见附录
 

第三步:启动进程

#redis-server /etc/redis.conf

查看进程有没有成功启动
#ps -ef | grep redis 
测试输入一个键值
#redis-cli set test "123456"
获取键值
#redis-cli get test
 
 

关闭redis 
# redis-cli shutdown      //关闭所有    
关闭某个端口上的redis    
# redis-cli -p 6397 shutdown  //关闭6397端口的redis  

说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename  dump.rdb

 

PHP扩展

http://code.google.com/p/php-redis/

 
附录:无错配置
 
只要做如下配置即可:
daemonize yes
pidfile /var/run/redis.pid
port 6379

#bind 127.0.0.1
timeout 600
loglevel notice
logfile /elain/logs/redis/redis.log

databases 16

save 900 1
save 300 10
save 60 10000

rdbcompression yes
dbfilename dump.rdb

dir /elain/data/redis/

# maxclients 128

appendonly yes
appendfilename appendonly.aof

# appendfsync always
appendfsync everysec
# appendfsync no

requirepass elain

no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

slowlog-log-slower-than 10000

slowlog-max-len 1024

really-use-vm yes
vm-enabled no
vm-swap-file /tmp/redis.swap
vm-max-memory 0
vm-page-size 32
vm-pages 134217728
vm-max-threads 4

hash-max-zipmap-entries 512
hash-max-zipmap-value 64

list-max-ziplist-entries 512
list-max-ziplist-value 64

set-max-intset-entries 512

zset-max-ziplist-entries 128
zset-max-ziplist-value 64

activerehashing yes

# include /path/to/local.conf
# include /path/to/other.conf
 
 
下面是本人配置的全文件
  1. # Redis configuration file example  
  2.   
  3. # Note on units: when memory size is needed, it is possible to specifiy  
  4. # it in the usual form of 1k 5GB 4M and so forth:  
  5. #  
  6. # 1k => 1000 bytes  
  7. # 1kb => 1024 bytes  
  8. # 1m => 1000000 bytes  
  9. # 1mb => 1024*1024 bytes  
  10. # 1g => 1000000000 bytes  
  11. # 1gb => 1024*1024*1024 bytes  
  12. #  
  13. # units are case insensitive so 1GB 1Gb 1gB are all the same.  
  14.   
  15. # By default Redis does not run as a daemon. Use 'yes' if you need it.  
  16. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.  
  17. daemonize yes  
  18.   
  19. # When running daemonized, Redis writes a pid file in /var/run/redis.pid by  
  20. # default. You can specify a custom pid file location here.  
  21. pidfile /var/run/redis.pid  
  22.   
  23. # Accept connections on the specified port, default is 6379.  
  24. # If port 0 is specified Redis will not listen on a TCP socket.  
  25. port 6379  
  26.   
  27. # If you want you can bind a single interface, if the bind option is not  
  28. # specified all the interfaces will listen for incoming connections.  
  29. #  
  30.  bind 127.0.0.1  
  31.   
  32. # Specify the path for the unix socket that will be used to listen for  
  33. # incoming connections. There is no default, so Redis will not listen  
  34. # on a unix socket when not specified.  
  35. #  
  36. # unixsocket /tmp/redis.sock  
  37. # unixsocketperm 755  
  38.   
  39. # Close the connection after a client is idle for N seconds (0 to disable)  
  40. timeout 600  
  41.   
  42. # Set server verbosity to 'debug'  
  43. # it can be one of:  
  44. # debug (a lot of information, useful for development/testing)  
  45. # verbose (many rarely useful info, but not a mess like the debug level)  
  46. # notice (moderately verbose, what you want in production probably)  
  47. # warning (only very important / critical messages are logged)  
  48. loglevel verbose  
  49.   
  50. # Specify the log file name. Also 'stdout' can be used to force  
  51. # Redis to log on the standard output. Note that if you use standard  
  52. # output for logging but daemonize, logs will be sent to /dev/null  
  53. logfile stdout  
  54.   
  55. # To enable logging to the system logger, just set 'syslog-enabled' to yes,  
  56. # and optionally update the other syslog parameters to suit your needs.  
  57. # syslog-enabled no  
  58.   
  59. # Specify the syslog identity.  
  60. # syslog-ident redis  
  61.   
  62. # Specify the syslog facility.  Must be USER or between LOCAL0-LOCAL7.  
  63. # syslog-facility local0  
  64.   
  65. # Set the number of databases. The default database is DB 0, you can select  
  66. # a different one on a per-connection basis using SELECT <dbid> where  
  67. # dbid is a number between 0 and 'databases'-1  
  68. databases 16  
  69.   
  70. ################################ SNAPSHOTTING  #################################  
  71. #  
  72. # Save the DB on disk:  
  73. #  
  74. #   save <seconds> <changes>  
  75. #  
  76. #   Will save the DB if both the given number of seconds and the given  
  77. #   number of write operations against the DB occurred.  
  78. #  
  79. #   In the example below the behaviour will be to save:  
  80. #   after 900 sec (15 min) if at least 1 key changed  
  81. #   after 300 sec (5 min) if at least 10 keys changed  
  82. #   after 60 sec if at least 10000 keys changed  
  83. #  
  84. #   Note: you can disable saving at all commenting all the "save" lines.  
  85.   
  86. save 900 1  
  87. save 300 10  
  88. save 60 10000  
  89.   
  90. # Compress string objects using LZF when dump .rdb databases?  
  91. # For default that's set to 'yes' as it's almost always a win.  
  92. # If you want to save some CPU in the saving child set it to 'no' but  
  93. # the dataset will likely be bigger if you have compressible values or keys.  
  94. rdbcompression yes  
  95.   
  96. # The filename where to dump the DB  
  97. dbfilename dump.rdb  
  98.   
  99. # The working directory.  
  100. #  
  101. # The DB will be written inside this directory, with the filename specified  
  102. # above using the 'dbfilename' configuration directive.  
  103. #   
  104. # Also the Append Only File will be created inside this directory.  
  105. #   
  106. # Note that you must specify a directory here, not a file name.  
  107. dir /usr/local/redis_db  
  108.   
  109. ################################# REPLICATION #################################  
  110.   
  111. # Master-Slave replication. Use slaveof to make a Redis instance a copy of  
  112. # another Redis server. Note that the configuration is local to the slave  
  113. # so for example it is possible to configure the slave to save the DB with a  
  114. # different interval, or to listen to another port, and so on.  
  115. #  
  116. # slaveof <masterip> <masterport>  
  117.   
  118. # If the master is password protected (using the "requirepass" configuration  
  119. # directive below) it is possible to tell the slave to authenticate before  
  120. # starting the replication synchronization process, otherwise the master will  
  121. # refuse the slave request.  
  122. #  
  123. # masterauth <master-password>  
  124.   
  125. # When a slave lost the connection with the master, or when the replication  
  126. # is still in progress, the slave can act in two different ways:  
  127. #  
  128. # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will  
  129. #    still reply to client requests, possibly with out of data data, or the  
  130. #    data set may just be empty if this is the first synchronization.  
  131. #  
  132. # 2) if slave-serve-stale data is set to 'no' the slave will reply with  
  133. #    an error "SYNC with master in progress" to all the kind of commands  
  134. #    but to INFO and SLAVEOF.  
  135. #  
  136. slave-serve-stale-data yes  
  137.   
  138. ################################## SECURITY ###################################  
  139.   
  140. # Require clients to issue AUTH <PASSWORD> before processing any other  
  141. # commands.  This might be useful in environments in which you do not trust  
  142. # others with access to the host running redis-server.  
  143. #  
  144. # This should stay commented out for backward compatibility and because most  
  145. # people do not need auth (e.g. they run their own servers).  
  146. #   
  147. # Warning: since Redis is pretty fast an outside user can try up to  
  148. # 150k passwords per second against a good box. This means that you should  
  149. # use a very strong password otherwise it will be very easy to break.  
  150. #  
  151. # requirepass foobared  
  152.   
  153. # Command renaming.  
  154. #  
  155. # It is possilbe to change the name of dangerous commands in a shared  
  156. # environment. For instance the CONFIG command may be renamed into something  
  157. # of hard to guess so that it will be still available for internal-use  
  158. # tools but not available for general clients.  
  159. #  
  160. # Example:  
  161. #  
  162. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52  
  163. #  
  164. # It is also possilbe to completely kill a command renaming it into  
  165. # an empty string:  
  166. #  
  167. # rename-command CONFIG ""  
  168.   
  169. ################################### LIMITS ####################################  
  170.   
  171. # Set the max number of connected clients at the same time. By default there  
  172. # is no limit, and it's up to the number of file descriptors the Redis process  
  173. # is able to open. The special value '0' means no limits.  
  174. # Once the limit is reached Redis will close all the new connections sending  
  175. # an error 'max number of clients reached'.  
  176. #  
  177. # maxclients 128  
  178.   
  179. # Don't use more memory than the specified amount of bytes.  
  180. # When the memory limit is reached Redis will try to remove keys with an  
  181. # EXPIRE set. It will try to start freeing keys that are going to expire  
  182. # in little time and preserve keys with a longer time to live.  
  183. # Redis will also try to remove objects from free lists if possible.  
  184. #  
  185. # If all this fails, Redis will start to reply with errors to commands  
  186. # that will use more memory, like SET, LPUSH, and so on, and will continue  
  187. # to reply to most read-only commands like GET.  
  188. #  
  189. # WARNING: maxmemory can be a good idea mainly if you want to use Redis as a  
  190. # 'state' server or cache, not as a real DB. When Redis is used as a real  
  191. # database the memory usage will grow over the weeks, it will be obvious if  
  192. # it is going to use too much memory in the long run, and you'll have the time  
  193. # to upgrade. With maxmemory after the limit is reached you'll start to get  
  194. # errors for write operations, and this may even lead to DB inconsistency.  
  195. #  
  196. # maxmemory <bytes>  
  197.   
  198. # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory  
  199. # is reached? You can select among five behavior:  
  200. #   
  201. # volatile-lru -> remove the key with an expire set using an LRU algorithm  
  202. # allkeys-lru -> remove any key accordingly to the LRU algorithm  
  203. # volatile-random -> remove a random key with an expire set  
  204. # allkeys->random -> remove a random key, any key  
  205. # volatile-ttl -> remove the key with the nearest expire time (minor TTL)  
  206. # noeviction -> don't expire at all, just return an error on write operations  
  207. #   
  208. # Note: with all the kind of policies, Redis will return an error on write  
  209. #       operations, when there are not suitable keys for eviction.  
  210. #  
  211. #       At the date of writing this commands are: set setnx setex append  
  212. #       incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd  
  213. #       sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby  
  214. #       zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby  
  215. #       getset mset msetnx exec sort  
  216. #  
  217. # The default is:  
  218. #  
  219. # maxmemory-policy volatile-lru  
  220.   
  221. # LRU and minimal TTL algorithms are not precise algorithms but approximated  
  222. # algorithms (in order to save memory), so you can select as well the sample  
  223. # size to check. For instance for default Redis will check three keys and  
  224. # pick the one that was used less recently, you can change the sample size  
  225. # using the following configuration directive.  
  226. #  
  227. # maxmemory-samples 3  
  228.   
  229. ############################## APPEND ONLY MODE ###############################  
  230.   
  231. # By default Redis asynchronously dumps the dataset on disk. If you can live  
  232. # with the idea that the latest records will be lost if something like a crash  
  233. # happens this is the preferred way to run Redis. If instead you care a lot  
  234. # about your data and don't want to that a single record can get lost you should  
  235. # enable the append only mode: when this mode is enabled Redis will append  
  236. # every write operation received in the file appendonly.aof. This file will  
  237. # be read on startup in order to rebuild the full dataset in memory.  
  238. #  
  239. # Note that you can have both the async dumps and the append only file if you  
  240. # like (you have to comment the "save" statements above to disable the dumps).  
  241. # Still if append only mode is enabled Redis will load the data from the  
  242. # log file at startup ignoring the dump.rdb file.  
  243. #  
  244. # IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append  
  245. # log file in background when it gets too big.  
  246.   
  247. appendonly yes  
  248.   
  249. # The name of the append only file (default: "appendonly.aof")  
  250.  appendfilename appendonly.aof  
  251.   
  252. # The fsync() call tells the Operating System to actually write data on disk  
  253. # instead to wait for more data in the output buffer. Some OS will really flush   
  254. # data on disk, some other OS will just try to do it ASAP.  
  255. #  
  256. # Redis supports three different modes:  
  257. #  
  258. # no: don't fsync, just let the OS flush the data when it wants. Faster.  
  259. # always: fsync after every write to the append only log . Slow, Safest.  
  260. # everysec: fsync only if one second passed since the last fsync. Compromise.  
  261. #  
  262. # The default is "everysec" that's usually the right compromise between  
  263. # speed and data safety. It's up to you to understand if you can relax this to  
  264. # "no" that will will let the operating system flush the output buffer when  
  265. # it wants, for better performances (but if you can live with the idea of  
  266. # some data loss consider the default persistence mode that's snapshotting),  
  267. # or on the contrary, use "always" that's very slow but a bit safer than  
  268. # everysec.  
  269. #  
  270. # If unsure, use "everysec".  
  271.   
  272. # appendfsync always  
  273. appendfsync everysec  
  274. # appendfsync no  
  275.   
  276. # When the AOF fsync policy is set to always or everysec, and a background  
  277. # saving process (a background save or AOF log background rewriting) is  
  278. # performing a lot of I/O against the disk, in some Linux configurations  
  279. # Redis may block too long on the fsync() call. Note that there is no fix for  
  280. # this currently, as even performing fsync in a different thread will block  
  281. # our synchronous write(2) call.  
  282. #  
  283. # In order to mitigate this problem it's possible to use the following option  
  284. # that will prevent fsync() from being called in the main process while a  
  285. # BGSAVE or BGREWRITEAOF is in progress.  
  286. #  
  287. # This means that while another child is saving the durability of Redis is  
  288. # the same as "appendfsync none", that in pratical terms means that it is  
  289. # possible to lost up to 30 seconds of log in the worst scenario (with the  
  290. # default Linux settings).  
  291. #   
  292. # If you have latency problems turn this to "yes". Otherwise leave it as  
  293. # "no" that is the safest pick from the point of view of durability.  
  294. no-appendfsync-on-rewrite no  
  295.   
  296. # Automatic rewrite of the append only file.  
  297. # Redis is able to automatically rewrite the log file implicitly calling  
  298. # BGREWRITEAOF when the AOF log size will growth by the specified percentage.  
  299. #   
  300. # This is how it works: Redis remembers the size of the AOF file after the  
  301. # latest rewrite (or if no rewrite happened since the restart, the size of  
  302. # the AOF at startup is used).  
  303. #  
  304. # This base size is compared to the current size. If the current size is  
  305. # bigger than the specified percentage, the rewrite is triggered. Also  
  306. # you need to specify a minimal size for the AOF file to be rewritten, this  
  307. # is useful to avoid rewriting the AOF file even if the percentage increase  
  308. # is reached but it is still pretty small.  
  309. #  
  310. # Specify a precentage of zero in order to disable the automatic AOF  
  311. # rewrite feature.  
  312.   
  313. auto-aof-rewrite-percentage 100  
  314. auto-aof-rewrite-min-size 64mb  
  315.   
  316. ################################## SLOW LOG ###################################  
  317.   
  318. # The Redis Slow Log is a system to log queries that exceeded a specified  
  319. # execution time. The execution time does not include the I/O operations  
  320. # like talking with the client, sending the reply and so forth,  
  321. # but just the time needed to actually execute the command (this is the only  
  322. # stage of command execution where the thread is blocked and can not serve  
  323. # other requests in the meantime).  
  324. #   
  325. # You can configure the slow log with two parameters: one tells Redis  
  326. # what is the execution time, in microseconds, to exceed in order for the  
  327. # command to get logged, and the other parameter is the length of the  
  328. # slow log. When a new command is logged the oldest one is removed from the  
  329. # queue of logged commands.  
  330.   
  331. # The following time is expressed in microseconds, so 1000000 is equivalent  
  332. # to one second. Note that a negative number disables the slow log, while  
  333. # a value of zero forces the logging of every command.  
  334. slowlog-log-slower-than 10000  
  335.   
  336. # There is no limit to this length. Just be aware that it will consume memory.  
  337. # You can reclaim memory used by the slow log with SLOWLOG RESET.  
  338. slowlog-max-len 1024  
  339.   
  340. ################################ VIRTUAL MEMORY ###############################  
  341.   
  342. ### WARNING! Virtual Memory is deprecated in Redis 2.4  
  343. ### The use of Virtual Memory is strongly discouraged.  
  344.   
  345. # Virtual Memory allows Redis to work with datasets bigger than the actual  
  346. # amount of RAM needed to hold the whole dataset in memory.  
  347. # In order to do so very used keys are taken in memory while the other keys  
  348. # are swapped into a swap file, similarly to what operating systems do  
  349. # with memory pages.  
  350. #  
  351. # To enable VM just set 'vm-enabled' to yes, and set the following three  
  352. # VM parameters accordingly to your needs.  
  353.   
  354. vm-enabled no  
  355.  #vm-enabled yes  
  356.   
  357. # This is the path of the Redis swap file. As you can guess, swap files  
  358. # can't be shared by different Redis instances, so make sure to use a swap  
  359. # file for every redis process you are running. Redis will complain if the  
  360. # swap file is already in use.  
  361. #  
  362. # The best kind of storage for the Redis swap file (that's accessed at random)   
  363. # is a Solid State Disk (SSD).  
  364. #  
  365. # *** WARNING *** if you are using a shared hosting the default of putting  
  366. # the swap file under /tmp is not secure. Create a dir with access granted  
  367. # only to Redis user and configure Redis to create the swap file there.  
  368. vm-swap-file /tmp/redis.swap  
  369.   
  370. # vm-max-memory configures the VM to use at max the specified amount of  
  371. # RAM. Everything that deos not fit will be swapped on disk *if* possible, that  
  372. # is, if there is still enough contiguous space in the swap file.  
  373. #  
  374. # With vm-max-memory 0 the system will swap everything it can. Not a good  
  375. # default, just specify the max amount of RAM you can in bytes, but it's  
  376. # better to leave some margin. For instance specify an amount of RAM  
  377. # that's more or less between 60 and 80% of your free RAM.  
  378. vm-max-memory 0  
  379.   
  380. # Redis swap files is split into pages. An object can be saved using multiple  
  381. # contiguous pages, but pages can't be shared between different objects.  
  382. # So if your page is too big, small objects swapped out on disk will waste  
  383. # a lot of space. If you page is too small, there is less space in the swap  
  384. # file (assuming you configured the same number of total swap file pages).  
  385. #  
  386. # If you use a lot of small objects, use a page size of 64 or 32 bytes.  
  387. # If you use a lot of big objects, use a bigger page size.  
  388. # If unsure, use the default :)  
  389. vm-page-size 32  
  390.   
  391. # Number of total memory pages in the swap file.  
  392. # Given that the page table (a bitmap of free/used pages) is taken in memory,  
  393. # every 8 pages on disk will consume 1 byte of RAM.  
  394. #  
  395. # The total swap size is vm-page-size * vm-pages  
  396. #  
  397. # With the default of 32-bytes memory pages and 134217728 pages Redis will  
  398. # use a 4 GB swap file, that will use 16 MB of RAM for the page table.  
  399. #  
  400. # It's better to use the smallest acceptable value for your application,  
  401. # but the default is large in order to work in most conditions.  
  402. vm-pages 134217728  
  403.   
  404. # Max number of VM I/O threads running at the same time.  
  405. # This threads are used to read/write data from/to swap file, since they  
  406. # also encode and decode objects from disk to memory or the reverse, a bigger  
  407. # number of threads can help with big objects even if they can't help with  
  408. # I/O itself as the physical device may not be able to couple with many  
  409. # reads/writes operations at the same time.  
  410. #  
  411. # The special value of 0 turn off threaded I/O and enables the blocking  
  412. # Virtual Memory implementation.  
  413. vm-max-threads 4  
  414.   
  415. ############################### ADVANCED CONFIG ###############################  
  416.   
  417. # Hashes are encoded in a special way (much more memory efficient) when they  
  418. # have at max a given numer of elements, and the biggest element does not  
  419. # exceed a given threshold. You can configure this limits with the following  
  420. # configuration directives.  
  421. hash-max-zipmap-entries 512  
  422. hash-max-zipmap-value 64  
  423.   
  424. # Similarly to hashes, small lists are also encoded in a special way in order  
  425. # to save a lot of space. The special representation is only used when  
  426. # you are under the following limits:  
  427. list-max-ziplist-entries 512  
  428. list-max-ziplist-value 64  
  429.   
  430. # Sets have a special encoding in just one case: when a set is composed  
  431. # of just strings that happens to be integers in radix 10 in the range  
  432. # of 64 bit signed integers.  
  433. # The following configuration setting sets the limit in the size of the  
  434. # set in order to use this special memory saving encoding.  
  435. set-max-intset-entries 512  
  436.   
  437. # Similarly to hashes and lists, sorted sets are also specially encoded in  
  438. # order to save a lot of space. This encoding is only used when the length and  
  439. # elements of a sorted set are below the following limits:  
  440. zset-max-ziplist-entries 128  
  441. zset-max-ziplist-value 64  
  442.   
  443. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in  
  444. # order to help rehashing the main Redis hash table (the one mapping top-level  
  445. # keys to values). The hash table implementation redis uses (see dict.c)  
  446. # performs a lazy rehashing: the more operation you run into an hash table  
  447. # that is rhashing, the more rehashing "steps" are performed, so if the  
  448. # server is idle the rehashing is never complete and some more memory is used  
  449. # by the hash table.  
  450. #   
  451. # The default is to use this millisecond 10 times every second in order to  
  452. # active rehashing the main dictionaries, freeing memory when possible.  
  453. #  
  454. # If unsure:  
  455. # use "activerehashing no" if you have hard latency requirements and it is  
  456. # not a good thing in your environment that Redis can reply form time to time  
  457. # to queries with 2 milliseconds delay.  
  458. #  
  459. # use "activerehashing yes" if you don't have such hard requirements but  
  460. # want to free memory asap when possible.  
  461. activerehashing yes  
  462.   
  463. ################################## INCLUDES ###################################  
  464.   
  465. # Include one or more other config files here.  This is useful if you  
  466. # have a standard template that goes to all redis server but also need  
  467. # to customize a few per-server settings.  Include files can include  
  468. # other files, so use this wisely.  
  469. #  
  470. # include /path/to/local.conf  
  471. # include /path/to/other.conf  

中文说明:

1,是否以后台进程运行,默认为no
daemonize no

2,如以后台进程运行,则需指定一个pid,默认为/var/run/redis.pid
pidfile /var/run/redis.pid

3,监听端口,默认为6379
port 6379

4,绑定主机IP,默认值为127.0.0.1(注释)
bind 127.0.0.1

5,超时时间,默认为300(秒)
timeout 300

6,日志记录等级,有4个可选值,debug,verbose(默认值),notice,warning
loglevel verbose

7,日志记录方式,默认值为stdout
logfile stdout

8,可用数据库数,默认值为16,默认数据库为0
databases 16

9,指出在多长时间内,有多少次更新操作,就将数据同步到数据文件。这个可以多个条件配合,比如默认配置文件中的设置,就设置了三个条件。

900秒(15分钟)内至少有1个key被改变
save 900 1
300秒(5分钟)内至少有10个key被改变
save 300 10

10,存储至本地数据库时是否压缩数据,默认为yes
rdbcompression yes

11,本地数据库文件名,默认值为dump.rdb
dbfilename /root/redis_db/dump.rdb

12,本地数据库存放路径,默认值为 ./
dir /root/redis_db/

13,当本机为从服务时,设置主服务的IP及端口(注释)
slaveof <masterip> <masterport>

14,当本机为从服务时,设置主服务的连接密码(注释)
masterauth <master-password>

15,连接密码(注释)
requirepass foobared

16,最大客户端连接数,默认不限制(注释)
maxclients 128

17,设置最大内存,达到最大内存设置后,Redis会先尝试清除已到期或即将到期的Key,当此方法处理后,任到达最大内存设置,将无法再进行写入操作。(注释)
maxmemory <bytes>

18,是否在每次更新操作后进行日志记录,如果不开启,可能会在断电时导致一段时间内的数据丢失。因为redis本身同步数据文件是按上面save条件来同步的,所以有的数据会在一段时间内只存在于内存中。默认值为no
appendonly yes

19,更新日志文件名,默认值为appendonly.aof(注释)
appendfilename /root/redis_db/appendonly.aof

20,更新日志条件,共有3个可选值。no表示等操作系统进行数据缓存同步到磁盘,always表示每次更新操作后手动调用fsync()将数据写到磁盘,everysec表示每秒同步一次(默认值)。
appendfsync everysec

21,是否使用虚拟内存,默认值为no
vm-enabled yes

22,虚拟内存文件路径,默认值为/tmp/redis.swap,不可多个Redis实例共享
vm-swap-file /tmp/redis.swap

23,将所有大于vm-max-memory的数据存入虚拟内存,无论vm-max-memory设置多小,所有索引数据都是内存存储的 (Redis的索引数据就是keys),也就是说,当vm-max-memory设置为0的时候,其实是所有value都存在于磁盘。默认值为0。
vm-max-memory 0

24,虚拟内存文件以块存储,每块32bytes
vm-page-size 32

25,虚拟内在文件的最大数
vm-pages 134217728

26,可以设置访问swap文件的线程数,设置最好不要超过机器的核数,如果设置为0,那么所有对swap文件的操作都是串行的.可能会造成比较长时间的延迟,但是对数据完整性有很好的保证.
vm-max-threads 4

27,把小的输出缓存放在一起,以便能够在一个TCP packet中为客户端发送多个响应,具体原理和真实效果我不是很清楚。所以根据注释,你不是很确定的时候就设置成yes
glueoutputbuf yes

28,在redis 2.0中引入了hash数据结构。当hash中包含超过指定元素个数并且最大的元素没有超过临界时,hash将以一种特殊的编码方式(大大减少内存使用)来存储,这里可以设置这两个临界值
hash-max-zipmap-entries 64

29,hash中一个元素的最大值
hash-max-zipmap-value 512

30,开启之后,redis将在每100毫秒时使用1毫秒的CPU时间来对redis的hash表进行重新hash,可以降低内存的使用。当你的使 用场景中,有非常严格的实时性需要,不能够接受Redis时不时的对请求有2毫秒的延迟的话,把这项配置为no。如果没有这么严格的实时性要求,可以设置 为yes,以便能够尽可能快的释放内存
activerehashing yes

 

可以参考:

Redis的部署使用文档  http://www.elain.org/?p=505

 

posted @ 2011-11-15 17:22  方子尚  阅读(1477)  评论(0编辑  收藏  举报