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

安装Redis

下载最新的

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

第一步:下载安装编译

#wgethttp://redis.googlecode.com/files/redis-2.4.4.tar.gz
#tar
zxvf redis-2.4.4.tar.gz
#cdredis-2.4.4
#make
#makeinstall
#cpredis.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的php扩展安装无错版

关闭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/

附录:无错配置
下面是本人配置的全文件
  1. #Redisconfigurationfileexample
  2. #Noteonunits:whenmemorysizeisneeded,itispossibletospecifiy
  3. #itintheusualformof1k5GB4Mandsoforth:
  4. #
  5. #1k=>1000bytes
  6. #1kb=>1024bytes
  7. #1m=>1000000bytes
  8. #1mb=>1024*1024bytes
  9. #1g=>1000000000bytes
  10. #1gb=>1024*1024*1024bytes
  11. #
  12. #unitsarecaseinsensitiveso1GB1Gb1gBareallthesame.
  13. #BydefaultRedisdoesnotrunasadaemon.Use'yes'ifyouneedit.
  14. #NotethatRediswillwriteapidfilein/var/run/redis.pidwhendaemonized.
  15. daemonizeyes
  16. #Whenrunningdaemonized,Rediswritesapidfilein/var/run/redis.pidby
  17. #default.Youcanspecifyacustompidfilelocationhere.
  18. pidfile/var/run/redis.pid
  19. #Acceptconnectionsonthespecifiedport,defaultis6379.
  20. #Ifport0isspecifiedRediswillnotlistenonaTCPsocket.
  21. port6379
  22. #Ifyouwantyoucanbindasingleinterface,ifthebindoptionisnot
  23. #specifiedalltheinterfaceswilllistenforincomingconnections.
  24. #
  25. bind127.0.0.1
  26. #Specifythepathfortheunixsocketthatwillbeusedtolistenfor
  27. #incomingconnections.Thereisnodefault,soRediswillnotlisten
  28. #onaunixsocketwhennotspecified.
  29. #
  30. #unixsocket/tmp/redis.sock
  31. #unixsocketperm755
  32. #ClosetheconnectionafteraclientisidleforNseconds(0todisable)
  33. timeout600
  34. #Setserververbosityto'debug'
  35. #itcanbeoneof:
  36. #debug(alotofinformation,usefulfordevelopment/testing)
  37. #verbose(manyrarelyusefulinfo,butnotamesslikethedebuglevel)
  38. #notice(moderatelyverbose,whatyouwantinproductionprobably)
  39. #warning(onlyveryimportant/criticalmessagesarelogged)
  40. loglevelverbose
  41. #Specifythelogfilename.Also'stdout'canbeusedtoforce
  42. #Redistologonthestandardoutput.Notethatifyouusestandard
  43. #outputforloggingbutdaemonize,logswillbesentto/dev/null
  44. logfilestdout
  45. #Toenableloggingtothesystemlogger,justset'syslog-enabled'toyes,
  46. #andoptionallyupdatetheothersyslogparameterstosuityourneeds.
  47. #syslog-enabledno
  48. #Specifythesyslogidentity.
  49. #syslog-identredis
  50. #Specifythesyslogfacility.MustbeUSERorbetweenLOCAL0-LOCAL7.
  51. #syslog-facilitylocal0
  52. #Setthenumberofdatabases.ThedefaultdatabaseisDB0,youcanselect
  53. #adifferentoneonaper-connectionbasisusingSELECT<dbid>where
  54. #dbidisanumberbetween0and'databases'-1
  55. databases16
  56. ################################SNAPSHOTTING#################################
  57. #
  58. #SavetheDBondisk:
  59. #
  60. #save<seconds><changes>
  61. #
  62. #WillsavetheDBifboththegivennumberofsecondsandthegiven
  63. #numberofwriteoperationsagainsttheDBoccurred.
  64. #
  65. #Intheexamplebelowthebehaviourwillbetosave:
  66. #after900sec(15min)ifatleast1keychanged
  67. #after300sec(5min)ifatleast10keyschanged
  68. #after60secifatleast10000keyschanged
  69. #
  70. #Note:youcandisablesavingatallcommentingallthe"save"lines.
  71. save9001
  72. save30010
  73. save6010000
  74. #CompressstringobjectsusingLZFwhendump.rdbdatabases?
  75. #Fordefaultthat'ssetto'yes'asit'salmostalwaysawin.
  76. #IfyouwanttosavesomeCPUinthesavingchildsetitto'no'but
  77. #thedatasetwilllikelybebiggerifyouhavecompressiblevaluesorkeys.
  78. rdbcompressionyes
  79. #ThefilenamewheretodumptheDB
  80. dbfilenamedump.rdb
  81. #Theworkingdirectory.
  82. #
  83. #TheDBwillbewritteninsidethisdirectory,withthefilenamespecified
  84. #aboveusingthe'dbfilename'configurationdirective.
  85. #
  86. #AlsotheAppendOnlyFilewillbecreatedinsidethisdirectory.
  87. #
  88. #Notethatyoumustspecifyadirectoryhere,notafilename.
  89. dir/usr/local/redis-2.4.4
  1. #################################REPLICATION#################################
  2. #Master-Slavereplication.UseslaveoftomakeaRedisinstanceacopyof
  3. #anotherRedisserver.Notethattheconfigurationislocaltotheslave
  4. #soforexampleitispossibletoconfiguretheslavetosavetheDBwitha
  5. #differentinterval,ortolistentoanotherport,andsoon.
  6. #
  7. #slaveof<masterip><masterport>
  8. #Ifthemasterispasswordprotected(usingthe"requirepass"configuration
  9. #directivebelow)itispossibletotelltheslavetoauthenticatebefore
  10. #startingthereplicationsynchronizationprocess,otherwisethemasterwill
  11. #refusetheslaverequest.
  12. #
  13. #masterauth<master-password>
  14. #Whenaslavelosttheconnectionwiththemaster,orwhenthereplication
  15. #isstillinprogress,theslavecanactintwodifferentways:
  16. #
  17. #1)ifslave-serve-stale-dataissetto'yes'(thedefault)theslavewill
  18. #stillreplytoclientrequests,possiblywithoutofdatadata,orthe
  19. #datasetmayjustbeemptyifthisisthefirstsynchronization.
  20. #
  21. #2)ifslave-serve-staledataissetto'no'theslavewillreplywith
  22. #anerror"SYNCwithmasterinprogress"toallthekindofcommands
  23. #buttoINFOandSLAVEOF.
  24. #
  25. slave-serve-stale-datayes
  26. ##################################SECURITY###################################
  27. #RequireclientstoissueAUTH<PASSWORD>beforeprocessinganyother
  28. #commands.Thismightbeusefulinenvironmentsinwhichyoudonottrust
  29. #otherswithaccesstothehostrunningredis-server.
  30. #
  31. #Thisshouldstaycommentedoutforbackwardcompatibilityandbecausemost
  32. #peopledonotneedauth(e.g.theyruntheirownservers).
  33. #
  34. #Warning:sinceRedisisprettyfastanoutsideusercantryupto
  35. #150kpasswordspersecondagainstagoodbox.Thismeansthatyoushould
  36. #useaverystrongpasswordotherwiseitwillbeveryeasytobreak.
  37. #
  38. #requirepassfoobared
  39. #Commandrenaming.
  40. #
  41. #Itispossilbetochangethenameofdangerouscommandsinashared
  42. #environment.ForinstancetheCONFIGcommandmayberenamedintosomething
  43. #ofhardtoguesssothatitwillbestillavailableforinternal-use
  44. #toolsbutnotavailableforgeneralclients.
  45. #
  46. #Example:
  47. #
  48. #rename-commandCONFIGb840fc02d524045429941cc15f59e41cb7be6c52
  49. #
  50. #Itisalsopossilbetocompletelykillacommandrenamingitinto
  51. #anemptystring:
  52. #
  53. #rename-commandCONFIG""
  54. ###################################LIMITS####################################
  55. #Setthemaxnumberofconnectedclientsatthesametime.Bydefaultthere
  56. #isnolimit,andit'suptothenumberoffiledescriptorstheRedisprocess
  57. #isabletoopen.Thespecialvalue'0'meansnolimits.
  58. #OncethelimitisreachedRediswillcloseallthenewconnectionssending
  59. #anerror'maxnumberofclientsreached'.
  60. #
  61. #maxclients128
  62. #Don'tusemorememorythanthespecifiedamountofbytes.
  63. #WhenthememorylimitisreachedRediswilltrytoremovekeyswithan
  64. #EXPIREset.Itwilltrytostartfreeingkeysthataregoingtoexpire
  65. #inlittletimeandpreservekeyswithalongertimetolive.
  66. #Rediswillalsotrytoremoveobjectsfromfreelistsifpossible.
  67. #
  68. #Ifallthisfails,Rediswillstarttoreplywitherrorstocommands
  69. #thatwillusemorememory,likeSET,LPUSH,andsoon,andwillcontinue
  70. #toreplytomostread-onlycommandslikeGET.
  71. #
  72. #WARNING:maxmemorycanbeagoodideamainlyifyouwanttouseRedisasa
  73. #'state'serverorcache,notasarealDB.WhenRedisisusedasareal
  74. #databasethememoryusagewillgrowovertheweeks,itwillbeobviousif
  75. #itisgoingtousetoomuchmemoryinthelongrun,andyou'llhavethetime
  76. #toupgrade.Withmaxmemoryafterthelimitisreachedyou'llstarttoget
  77. #errorsforwriteoperations,andthismayevenleadtoDBinconsistency.
  78. #
  79. #maxmemory<bytes>
  80. #MAXMEMORYPOLICY:howRediswillselectwhattoremovewhenmaxmemory
  81. #isreached?Youcanselectamongfivebehavior:
  82. #
  83. #volatile-lru->removethekeywithanexpiresetusinganLRUalgorithm
  84. #allkeys-lru->removeanykeyaccordinglytotheLRUalgorithm
  85. #volatile-random->removearandomkeywithanexpireset
  86. #allkeys->random->removearandomkey,anykey
  87. #volatile-ttl->removethekeywiththenearestexpiretime(minorTTL)
  88. #noeviction->don'texpireatall,justreturnanerroronwriteoperations
  89. #
  90. #Note:withallthekindofpolicies,Rediswillreturnanerroronwrite
  91. #operations,whentherearenotsuitablekeysforeviction.
  92. #
  93. #Atthedateofwritingthiscommandsare:setsetnxsetexappend
  94. #incrdecrrpushlpushrpushxlpushxlinsertlsetrpoplpushsadd
  95. #sintersinterstoresunionsunionstoresdiffsdiffstorezaddzincrby
  96. #zunionstorezinterstorehsethsetnxhmsethincrbyincrbydecrby
  97. #getsetmsetmsetnxexecsort
  98. #
  99. #Thedefaultis:
  100. #
  101. #maxmemory-policyvolatile-lru
  102. #LRUandminimalTTLalgorithmsarenotprecisealgorithmsbutapproximated
  103. #algorithms(inordertosavememory),soyoucanselectaswellthesample
  104. #sizetocheck.ForinstancefordefaultRediswillcheckthreekeysand
  105. #picktheonethatwasusedlessrecently,youcanchangethesamplesize
  106. #usingthefollowingconfigurationdirective.
  107. #
  108. #maxmemory-samples3
  109. ##############################APPENDONLYMODE###############################
  110. #BydefaultRedisasynchronouslydumpsthedatasetondisk.Ifyoucanlive
  111. #withtheideathatthelatestrecordswillbelostifsomethinglikeacrash
  112. #happensthisisthepreferredwaytorunRedis.Ifinsteadyoucarealot
  113. #aboutyourdataanddon'twanttothatasinglerecordcangetlostyoushould
  114. #enabletheappendonlymode:whenthismodeisenabledRediswillappend
  115. #everywriteoperationreceivedinthefileappendonly.aof.Thisfilewill
  116. #bereadonstartupinordertorebuildthefulldatasetinmemory.
  117. #
  118. #Notethatyoucanhaveboththeasyncdumpsandtheappendonlyfileifyou
  119. #like(youhavetocommentthe"save"statementsabovetodisablethedumps).
  120. #StillifappendonlymodeisenabledRediswillloadthedatafromthe
  121. #logfileatstartupignoringthedump.rdbfile.
  122. #
  123. #IMPORTANT:ChecktheBGREWRITEAOFtocheckhowtorewritetheappend
  124. #logfileinbackgroundwhenitgetstoobig.
  125. appendonlyyes
  126. #Thenameoftheappendonlyfile(default:"appendonly.aof")
  127. appendfilenameappendonly.aof
  128. #Thefsync()calltellstheOperatingSystemtoactuallywritedataondisk
  129. #insteadtowaitformoredataintheoutputbuffer.SomeOSwillreallyflush
  130. #dataondisk,someotherOSwilljusttrytodoitASAP.
  131. #
  132. #Redissupportsthreedifferentmodes:
  133. #
  134. #no:don'tfsync,justlettheOSflushthedatawhenitwants.Faster.
  135. #always:fsyncaftereverywritetotheappendonlylog.Slow,Safest.
  136. #everysec:fsynconlyifonesecondpassedsincethelastfsync.Compromise.
  137. #
  138. #Thedefaultis"everysec"that'susuallytherightcompromisebetween
  139. #speedanddatasafety.It'suptoyoutounderstandifyoucanrelaxthisto
  140. #"no"thatwillwilllettheoperatingsystemflushtheoutputbufferwhen
  141. #itwants,forbetterperformances(butifyoucanlivewiththeideaof
  142. #somedatalossconsiderthedefaultpersistencemodethat'ssnapshotting),
  143. #oronthecontrary,use"always"that'sveryslowbutabitsaferthan
  144. #everysec.
  145. #
  146. #Ifunsure,use"everysec".
  147. #appendfsyncalways
  148. appendfsynceverysec
  149. #appendfsyncno
  150. #WhentheAOFfsyncpolicyissettoalwaysoreverysec,andabackground
  151. #savingprocess(abackgroundsaveorAOFlogbackgroundrewriting)is
  152. #performingalotofI/Oagainstthedisk,insomeLinuxconfigurations
  153. #Redismayblocktoolongonthefsync()call.Notethatthereisnofixfor
  154. #thiscurrently,asevenperformingfsyncinadifferentthreadwillblock
  155. #oursynchronouswrite(2)call.
  156. #
  157. #Inordertomitigatethisproblemit'spossibletousethefollowingoption
  158. #thatwillpreventfsync()frombeingcalledinthemainprocesswhilea
  159. #BGSAVEorBGREWRITEAOFisinprogress.
  160. #
  161. #ThismeansthatwhileanotherchildissavingthedurabilityofRedisis
  162. #thesameas"appendfsyncnone",thatinpraticaltermsmeansthatitis
  163. #possibletolostupto30secondsoflogintheworstscenario(withthe
  164. #defaultLinuxsettings).
  165. #
  166. #Ifyouhavelatencyproblemsturnthisto"yes".Otherwiseleaveitas
  167. #"no"thatisthesafestpickfromthepointofviewofdurability.
  168. no-appendfsync-on-rewriteno
  169. #Automaticrewriteoftheappendonlyfile.
  170. #Redisisabletoautomaticallyrewritethelogfileimplicitlycalling
  171. #BGREWRITEAOFwhentheAOFlogsizewillgrowthbythespecifiedpercentage.
  172. #
  173. #Thisishowitworks:RedisremembersthesizeoftheAOFfileafterthe
  174. #latestrewrite(orifnorewritehappenedsincetherestart,thesizeof
  175. #theAOFatstartupisused).
  176. #
  177. #Thisbasesizeiscomparedtothecurrentsize.Ifthecurrentsizeis
  178. #biggerthanthespecifiedpercentage,therewriteistriggered.Also
  179. #youneedtospecifyaminimalsizefortheAOFfiletoberewritten,this
  180. #isusefultoavoidrewritingtheAOFfileevenifthepercentageincrease
  181. #isreachedbutitisstillprettysmall.
  182. #
  183. #SpecifyaprecentageofzeroinordertodisabletheautomaticAOF
  184. #rewritefeature.
  185. auto-aof-rewrite-percentage100
  186. auto-aof-rewrite-min-size64mb
  187. ##################################SLOWLOG###################################
  188. #TheRedisSlowLogisasystemtologqueriesthatexceededaspecified
  189. #executiontime.TheexecutiontimedoesnotincludetheI/Ooperations
  190. #liketalkingwiththeclient,sendingthereplyandsoforth,
  191. #butjustthetimeneededtoactuallyexecutethecommand(thisistheonly
  192. #stageofcommandexecutionwherethethreadisblockedandcannotserve
  193. #otherrequestsinthemeantime).
  194. #
  195. #Youcanconfiguretheslowlogwithtwoparameters:onetellsRedis
  196. #whatistheexecutiontime,inmicroseconds,toexceedinorderforthe
  197. #commandtogetlogged,andtheotherparameteristhelengthofthe
  198. #slowlog.Whenanewcommandisloggedtheoldestoneisremovedfromthe
  199. #queueofloggedcommands.
  200. #Thefollowingtimeisexpressedinmicroseconds,so1000000isequivalent
  201. #toonesecond.Notethatanegativenumberdisablestheslowlog,while
  202. #avalueofzeroforcestheloggingofeverycommand.
  203. slowlog-log-slower-than10000
  204. #Thereisnolimittothislength.Justbeawarethatitwillconsumememory.
  205. #YoucanreclaimmemoryusedbytheslowlogwithSLOWLOGRESET.
  206. slowlog-max-len1024
  207. ################################VIRTUALMEMORY###############################
  208. ###WARNING!VirtualMemoryisdeprecatedinRedis2.4
  209. ###TheuseofVirtualMemoryisstronglydiscouraged.
  210. #VirtualMemoryallowsRedistoworkwithdatasetsbiggerthantheactual
  211. #amountofRAMneededtoholdthewholedatasetinmemory.
  212. #Inordertodosoveryusedkeysaretakeninmemorywhiletheotherkeys
  213. #areswappedintoaswapfile,similarlytowhatoperatingsystemsdo
  214. #withmemorypages.
  215. #
  216. #ToenableVMjustset'vm-enabled'toyes,andsetthefollowingthree
  217. #VMparametersaccordinglytoyourneeds.
  218. vm-enabledno
  219. #vm-enabledyes
  220. #ThisisthepathoftheRedisswapfile.Asyoucanguess,swapfiles
  221. #can'tbesharedbydifferentRedisinstances,somakesuretouseaswap
  222. #fileforeveryredisprocessyouarerunning.Rediswillcomplainifthe
  223. #swapfileisalreadyinuse.
  224. #
  225. #ThebestkindofstoragefortheRedisswapfile(that'saccessedatrandom)
  226. #isaSolidStateDisk(SSD).
  227. #
  228. #***WARNING***ifyouareusingasharedhostingthedefaultofputting
  229. #theswapfileunder/tmpisnotsecure.Createadirwithaccessgranted
  230. #onlytoRedisuserandconfigureRedistocreatetheswapfilethere.
  231. vm-swap-file/tmp/redis.swap
  232. #vm-max-memoryconfigurestheVMtouseatmaxthespecifiedamountof
  233. #RAM.Everythingthatdeosnotfitwillbeswappedondisk*if*possible,that
  234. #is,ifthereisstillenoughcontiguousspaceintheswapfile.
  235. #
  236. #Withvm-max-memory0thesystemwillswapeverythingitcan.Notagood
  237. #default,justspecifythemaxamountofRAMyoucaninbytes,butit's
  238. #bettertoleavesomemargin.ForinstancespecifyanamountofRAM
  239. #that'smoreorlessbetween60and80%ofyourfreeRAM.
  240. vm-max-memory0
  241. #Redisswapfilesissplitintopages.Anobjectcanbesavedusingmultiple
  242. #contiguouspages,butpagescan'tbesharedbetweendifferentobjects.
  243. #Soifyourpageistoobig,smallobjectsswappedoutondiskwillwaste
  244. #alotofspace.Ifyoupageistoosmall,thereislessspaceintheswap
  245. #file(assumingyouconfiguredthesamenumberoftotalswapfilepages).
  246. #
  247. #Ifyouusealotofsmallobjects,useapagesizeof64or32bytes.
  248. #Ifyouusealotofbigobjects,useabiggerpagesize.
  249. #Ifunsure,usethedefault:)
  250. vm-page-size32
  251. #Numberoftotalmemorypagesintheswapfile.
  252. #Giventhatthepagetable(abitmapoffree/usedpages)istakeninmemory,
  253. #every8pagesondiskwillconsume1byteofRAM.
  254. #
  255. #Thetotalswapsizeisvm-page-size*vm-pages
  256. #
  257. #Withthedefaultof32-bytesmemorypagesand134217728pagesRediswill
  258. #usea4GBswapfile,thatwilluse16MBofRAMforthepagetable.
  259. #
  260. #It'sbettertousethesmallestacceptablevalueforyourapplication,
  261. #butthedefaultislargeinordertoworkinmostconditions.
  262. vm-pages134217728
  263. #MaxnumberofVMI/Othreadsrunningatthesametime.
  264. #Thisthreadsareusedtoread/writedatafrom/toswapfile,sincethey
  265. #alsoencodeanddecodeobjectsfromdisktomemoryorthereverse,abigger
  266. #numberofthreadscanhelpwithbigobjectseveniftheycan'thelpwith
  267. #I/Oitselfasthephysicaldevicemaynotbeabletocouplewithmany
  268. #reads/writesoperationsatthesametime.
  269. #
  270. #Thespecialvalueof0turnoffthreadedI/Oandenablestheblocking
  271. #VirtualMemoryimplementation.
  272. vm-max-threads4
  273. ###############################ADVANCEDCONFIG###############################
  274. #Hashesareencodedinaspecialway(muchmorememoryefficient)whenthey
  275. #haveatmaxagivennumerofelements,andthebiggestelementdoesnot
  276. #exceedagiventhreshold.Youcanconfigurethislimitswiththefollowing
  277. #configurationdirectives.
  278. hash-max-zipmap-entries512
  279. hash-max-zipmap-value64
  280. #Similarlytohashes,smalllistsarealsoencodedinaspecialwayinorder
  281. #tosavealotofspace.Thespecialrepresentationisonlyusedwhen
  282. #youareunderthefollowinglimits:
  283. list-max-ziplist-entries512
  284. list-max-ziplist-value64
  285. #Setshaveaspecialencodinginjustonecase:whenasetiscomposed
  286. #ofjuststringsthathappenstobeintegersinradix10intherange
  287. #of64bitsignedintegers.
  288. #Thefollowingconfigurationsettingsetsthelimitinthesizeofthe
  289. #setinordertousethisspecialmemorysavingencoding.
  290. set-max-intset-entries512
  291. #Similarlytohashesandlists,sortedsetsarealsospeciallyencodedin
  292. #ordertosavealotofspace.Thisencodingisonlyusedwhenthelengthand
  293. #elementsofasortedsetarebelowthefollowinglimits:
  294. zset-max-ziplist-entries128
  295. zset-max-ziplist-value64
  296. #Activerehashinguses1millisecondevery100millisecondsofCPUtimein
  297. #ordertohelprehashingthemainRedishashtable(theonemappingtop-level
  298. #keystovalues).Thehashtableimplementationredisuses(seedict.c)
  299. #performsalazyrehashing:themoreoperationyourunintoanhashtable
  300. #thatisrhashing,themorerehashing"steps"areperformed,soifthe
  301. #serverisidletherehashingisnevercompleteandsomemorememoryisused
  302. #bythehashtable.
  303. #
  304. #Thedefaultistousethismillisecond10timeseverysecondinorderto
  305. #activerehashingthemaindictionaries,freeingmemorywhenpossible.
  306. #
  307. #Ifunsure:
  308. #use"activerehashingno"ifyouhavehardlatencyrequirementsanditis
  309. #notagoodthinginyourenvironmentthatRediscanreplyformtimetotime
  310. #toquerieswith2millisecondsdelay.
  311. #
  312. #use"activerehashingyes"ifyoudon'thavesuchhardrequirementsbut
  313. #wanttofreememoryasapwhenpossible.
  314. activerehashingyes
  315. ##################################INCLUDES###################################
  316. #Includeoneormoreotherconfigfileshere.Thisisusefulifyou
  317. #haveastandardtemplatethatgoestoallredisserverbutalsoneed
  318. #tocustomizeafewper-serversettings.Includefilescaninclude
  319. #otherfiles,sousethiswisely.
  320. #
  321. #include/path/to/local.conf
  322. #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

#wgethttps://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

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

测试代码:

  1. <?php
  2. $redis=newRedis();
  3. $redis->connect('127.0.0.1',6379);
  4. $redis->set('test','helloworld!');
  5. echo$redis->get('test');
  6. ?>

参考:

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


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