Redis以及Redis的php扩展安装无错版

安装Redis

下载最新的

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

 

第一步:下载安装编译

#wget http://redis.googlecode.com/files/redis-2.4.4.tar.gz
#tar zxvf redis-2.4.4.tar.gz
#cd redis-2.4.4
#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/

 

附录:无错配置

 

 

下面是本人配置的全文件

[plain] view plaincopy

  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-2.4.4  

[plain] view plaincopy

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

========================================================

安装PHP的Redis扩展

 

先去下载https://github.com/nicolasff/phpredis/downloads

#wget https://github.com/nicolasff/phpredis/downloads

# tar -zxvf nicolasff-phpredis-2.1.3-124-gd4ad907.tar.gz
# mv nicolasff-phpredis-d4ad907 php-5.3.8/ext/phpredis/
# cd php-5.3.8/ext/phpredis/
# /usr/local/php/bin/phpize
# ./configure --with-php-config=/usr/local/php/bin/php-config
# make && make install

 

配置php.ini

vi /usr/local/php/lib/php.ini
(加入:
extension=redis.so
)
先要看看有没有extension_dir=/…….
重启apache或者nginx

# /usr/local/apache2/bin/apachectl restart

 

测试代码:

[php] view plaincopy

  1. <?php  
  2.   
  3. $redis = new Redis();  
  4.   
  5. $redis->connect('127.0.0.1',6379);  
  6.   
  7. $redis->set('test','hello world!');  
  8.   
  9. echo $redis->get('test');  
  10.   
  11.    
  12. ?>  

 

 

参考:

Linux(CentOS 5.5) Redis 安装及RedisPHP拓展安装应用

http://www.linuxidc.com/Linux/2011-08/41404.htm
 

安装redis和phpredis模块

http://skandgjxa.blog.163.com/blog/static/14152982011712112933816/

 

RHEL5下编译安装Redis及其PHP扩展库

http://hi.baidu.com/zjstandup/blog/item/9f38b825d379c96c35a80f7f.html

 

转自: http://blog.csdn.net/21aspnet/article/details/6960757

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值