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
#tarzxvf redis-2.4.4.tar.gz
#cdredis-2.4.4
#make
#makeinstall
#cpredis.conf/etc/
第二步:修改配置
第三步:启动进程
#redis-server /etc/redis.conf
查看进程有没有成功启动关闭redis
# redis-cli shutdown //关闭所有
关闭某个端口上的redis
# redis-cli -p 6397 shutdown //关闭6397端口的redis
说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename dump.rdb
PHP扩展
- #Redisconfigurationfileexample
- #Noteonunits:whenmemorysizeisneeded,itispossibletospecifiy
- #itintheusualformof1k5GB4Mandsoforth:
- #
- #1k=>1000bytes
- #1kb=>1024bytes
- #1m=>1000000bytes
- #1mb=>1024*1024bytes
- #1g=>1000000000bytes
- #1gb=>1024*1024*1024bytes
- #
- #unitsarecaseinsensitiveso1GB1Gb1gBareallthesame.
- #BydefaultRedisdoesnotrunasadaemon.Use'yes'ifyouneedit.
- #NotethatRediswillwriteapidfilein/var/run/redis.pidwhendaemonized.
- daemonizeyes
- #Whenrunningdaemonized,Rediswritesapidfilein/var/run/redis.pidby
- #default.Youcanspecifyacustompidfilelocationhere.
- pidfile/var/run/redis.pid
- #Acceptconnectionsonthespecifiedport,defaultis6379.
- #Ifport0isspecifiedRediswillnotlistenonaTCPsocket.
- port6379
- #Ifyouwantyoucanbindasingleinterface,ifthebindoptionisnot
- #specifiedalltheinterfaceswilllistenforincomingconnections.
- #
- bind127.0.0.1
- #Specifythepathfortheunixsocketthatwillbeusedtolistenfor
- #incomingconnections.Thereisnodefault,soRediswillnotlisten
- #onaunixsocketwhennotspecified.
- #
- #unixsocket/tmp/redis.sock
- #unixsocketperm755
- #ClosetheconnectionafteraclientisidleforNseconds(0todisable)
- timeout600
- #Setserververbosityto'debug'
- #itcanbeoneof:
- #debug(alotofinformation,usefulfordevelopment/testing)
- #verbose(manyrarelyusefulinfo,butnotamesslikethedebuglevel)
- #notice(moderatelyverbose,whatyouwantinproductionprobably)
- #warning(onlyveryimportant/criticalmessagesarelogged)
- loglevelverbose
- #Specifythelogfilename.Also'stdout'canbeusedtoforce
- #Redistologonthestandardoutput.Notethatifyouusestandard
- #outputforloggingbutdaemonize,logswillbesentto/dev/null
- logfilestdout
- #Toenableloggingtothesystemlogger,justset'syslog-enabled'toyes,
- #andoptionallyupdatetheothersyslogparameterstosuityourneeds.
- #syslog-enabledno
- #Specifythesyslogidentity.
- #syslog-identredis
- #Specifythesyslogfacility.MustbeUSERorbetweenLOCAL0-LOCAL7.
- #syslog-facilitylocal0
- #Setthenumberofdatabases.ThedefaultdatabaseisDB0,youcanselect
- #adifferentoneonaper-connectionbasisusingSELECT<dbid>where
- #dbidisanumberbetween0and'databases'-1
- databases16
- ################################SNAPSHOTTING#################################
- #
- #SavetheDBondisk:
- #
- #save<seconds><changes>
- #
- #WillsavetheDBifboththegivennumberofsecondsandthegiven
- #numberofwriteoperationsagainsttheDBoccurred.
- #
- #Intheexamplebelowthebehaviourwillbetosave:
- #after900sec(15min)ifatleast1keychanged
- #after300sec(5min)ifatleast10keyschanged
- #after60secifatleast10000keyschanged
- #
- #Note:youcandisablesavingatallcommentingallthe"save"lines.
- save9001
- save30010
- save6010000
- #CompressstringobjectsusingLZFwhendump.rdbdatabases?
- #Fordefaultthat'ssetto'yes'asit'salmostalwaysawin.
- #IfyouwanttosavesomeCPUinthesavingchildsetitto'no'but
- #thedatasetwilllikelybebiggerifyouhavecompressiblevaluesorkeys.
- rdbcompressionyes
- #ThefilenamewheretodumptheDB
- dbfilenamedump.rdb
- #Theworkingdirectory.
- #
- #TheDBwillbewritteninsidethisdirectory,withthefilenamespecified
- #aboveusingthe'dbfilename'configurationdirective.
- #
- #AlsotheAppendOnlyFilewillbecreatedinsidethisdirectory.
- #
- #Notethatyoumustspecifyadirectoryhere,notafilename.
- dir/usr/local/redis-2.4.4
- #################################REPLICATION#################################
- #Master-Slavereplication.UseslaveoftomakeaRedisinstanceacopyof
- #anotherRedisserver.Notethattheconfigurationislocaltotheslave
- #soforexampleitispossibletoconfiguretheslavetosavetheDBwitha
- #differentinterval,ortolistentoanotherport,andsoon.
- #
- #slaveof<masterip><masterport>
- #Ifthemasterispasswordprotected(usingthe"requirepass"configuration
- #directivebelow)itispossibletotelltheslavetoauthenticatebefore
- #startingthereplicationsynchronizationprocess,otherwisethemasterwill
- #refusetheslaverequest.
- #
- #masterauth<master-password>
- #Whenaslavelosttheconnectionwiththemaster,orwhenthereplication
- #isstillinprogress,theslavecanactintwodifferentways:
- #
- #1)ifslave-serve-stale-dataissetto'yes'(thedefault)theslavewill
- #stillreplytoclientrequests,possiblywithoutofdatadata,orthe
- #datasetmayjustbeemptyifthisisthefirstsynchronization.
- #
- #2)ifslave-serve-staledataissetto'no'theslavewillreplywith
- #anerror"SYNCwithmasterinprogress"toallthekindofcommands
- #buttoINFOandSLAVEOF.
- #
- slave-serve-stale-datayes
- ##################################SECURITY###################################
- #RequireclientstoissueAUTH<PASSWORD>beforeprocessinganyother
- #commands.Thismightbeusefulinenvironmentsinwhichyoudonottrust
- #otherswithaccesstothehostrunningredis-server.
- #
- #Thisshouldstaycommentedoutforbackwardcompatibilityandbecausemost
- #peopledonotneedauth(e.g.theyruntheirownservers).
- #
- #Warning:sinceRedisisprettyfastanoutsideusercantryupto
- #150kpasswordspersecondagainstagoodbox.Thismeansthatyoushould
- #useaverystrongpasswordotherwiseitwillbeveryeasytobreak.
- #
- #requirepassfoobared
- #Commandrenaming.
- #
- #Itispossilbetochangethenameofdangerouscommandsinashared
- #environment.ForinstancetheCONFIGcommandmayberenamedintosomething
- #ofhardtoguesssothatitwillbestillavailableforinternal-use
- #toolsbutnotavailableforgeneralclients.
- #
- #Example:
- #
- #rename-commandCONFIGb840fc02d524045429941cc15f59e41cb7be6c52
- #
- #Itisalsopossilbetocompletelykillacommandrenamingitinto
- #anemptystring:
- #
- #rename-commandCONFIG""
- ###################################LIMITS####################################
- #Setthemaxnumberofconnectedclientsatthesametime.Bydefaultthere
- #isnolimit,andit'suptothenumberoffiledescriptorstheRedisprocess
- #isabletoopen.Thespecialvalue'0'meansnolimits.
- #OncethelimitisreachedRediswillcloseallthenewconnectionssending
- #anerror'maxnumberofclientsreached'.
- #
- #maxclients128
- #Don'tusemorememorythanthespecifiedamountofbytes.
- #WhenthememorylimitisreachedRediswilltrytoremovekeyswithan
- #EXPIREset.Itwilltrytostartfreeingkeysthataregoingtoexpire
- #inlittletimeandpreservekeyswithalongertimetolive.
- #Rediswillalsotrytoremoveobjectsfromfreelistsifpossible.
- #
- #Ifallthisfails,Rediswillstarttoreplywitherrorstocommands
- #thatwillusemorememory,likeSET,LPUSH,andsoon,andwillcontinue
- #toreplytomostread-onlycommandslikeGET.
- #
- #WARNING:maxmemorycanbeagoodideamainlyifyouwanttouseRedisasa
- #'state'serverorcache,notasarealDB.WhenRedisisusedasareal
- #databasethememoryusagewillgrowovertheweeks,itwillbeobviousif
- #itisgoingtousetoomuchmemoryinthelongrun,andyou'llhavethetime
- #toupgrade.Withmaxmemoryafterthelimitisreachedyou'llstarttoget
- #errorsforwriteoperations,andthismayevenleadtoDBinconsistency.
- #
- #maxmemory<bytes>
- #MAXMEMORYPOLICY:howRediswillselectwhattoremovewhenmaxmemory
- #isreached?Youcanselectamongfivebehavior:
- #
- #volatile-lru->removethekeywithanexpiresetusinganLRUalgorithm
- #allkeys-lru->removeanykeyaccordinglytotheLRUalgorithm
- #volatile-random->removearandomkeywithanexpireset
- #allkeys->random->removearandomkey,anykey
- #volatile-ttl->removethekeywiththenearestexpiretime(minorTTL)
- #noeviction->don'texpireatall,justreturnanerroronwriteoperations
- #
- #Note:withallthekindofpolicies,Rediswillreturnanerroronwrite
- #operations,whentherearenotsuitablekeysforeviction.
- #
- #Atthedateofwritingthiscommandsare:setsetnxsetexappend
- #incrdecrrpushlpushrpushxlpushxlinsertlsetrpoplpushsadd
- #sintersinterstoresunionsunionstoresdiffsdiffstorezaddzincrby
- #zunionstorezinterstorehsethsetnxhmsethincrbyincrbydecrby
- #getsetmsetmsetnxexecsort
- #
- #Thedefaultis:
- #
- #maxmemory-policyvolatile-lru
- #LRUandminimalTTLalgorithmsarenotprecisealgorithmsbutapproximated
- #algorithms(inordertosavememory),soyoucanselectaswellthesample
- #sizetocheck.ForinstancefordefaultRediswillcheckthreekeysand
- #picktheonethatwasusedlessrecently,youcanchangethesamplesize
- #usingthefollowingconfigurationdirective.
- #
- #maxmemory-samples3
- ##############################APPENDONLYMODE###############################
- #BydefaultRedisasynchronouslydumpsthedatasetondisk.Ifyoucanlive
- #withtheideathatthelatestrecordswillbelostifsomethinglikeacrash
- #happensthisisthepreferredwaytorunRedis.Ifinsteadyoucarealot
- #aboutyourdataanddon'twanttothatasinglerecordcangetlostyoushould
- #enabletheappendonlymode:whenthismodeisenabledRediswillappend
- #everywriteoperationreceivedinthefileappendonly.aof.Thisfilewill
- #bereadonstartupinordertorebuildthefulldatasetinmemory.
- #
- #Notethatyoucanhaveboththeasyncdumpsandtheappendonlyfileifyou
- #like(youhavetocommentthe"save"statementsabovetodisablethedumps).
- #StillifappendonlymodeisenabledRediswillloadthedatafromthe
- #logfileatstartupignoringthedump.rdbfile.
- #
- #IMPORTANT:ChecktheBGREWRITEAOFtocheckhowtorewritetheappend
- #logfileinbackgroundwhenitgetstoobig.
- appendonlyyes
- #Thenameoftheappendonlyfile(default:"appendonly.aof")
- appendfilenameappendonly.aof
- #Thefsync()calltellstheOperatingSystemtoactuallywritedataondisk
- #insteadtowaitformoredataintheoutputbuffer.SomeOSwillreallyflush
- #dataondisk,someotherOSwilljusttrytodoitASAP.
- #
- #Redissupportsthreedifferentmodes:
- #
- #no:don'tfsync,justlettheOSflushthedatawhenitwants.Faster.
- #always:fsyncaftereverywritetotheappendonlylog.Slow,Safest.
- #everysec:fsynconlyifonesecondpassedsincethelastfsync.Compromise.
- #
- #Thedefaultis"everysec"that'susuallytherightcompromisebetween
- #speedanddatasafety.It'suptoyoutounderstandifyoucanrelaxthisto
- #"no"thatwillwilllettheoperatingsystemflushtheoutputbufferwhen
- #itwants,forbetterperformances(butifyoucanlivewiththeideaof
- #somedatalossconsiderthedefaultpersistencemodethat'ssnapshotting),
- #oronthecontrary,use"always"that'sveryslowbutabitsaferthan
- #everysec.
- #
- #Ifunsure,use"everysec".
- #appendfsyncalways
- appendfsynceverysec
- #appendfsyncno
- #WhentheAOFfsyncpolicyissettoalwaysoreverysec,andabackground
- #savingprocess(abackgroundsaveorAOFlogbackgroundrewriting)is
- #performingalotofI/Oagainstthedisk,insomeLinuxconfigurations
- #Redismayblocktoolongonthefsync()call.Notethatthereisnofixfor
- #thiscurrently,asevenperformingfsyncinadifferentthreadwillblock
- #oursynchronouswrite(2)call.
- #
- #Inordertomitigatethisproblemit'spossibletousethefollowingoption
- #thatwillpreventfsync()frombeingcalledinthemainprocesswhilea
- #BGSAVEorBGREWRITEAOFisinprogress.
- #
- #ThismeansthatwhileanotherchildissavingthedurabilityofRedisis
- #thesameas"appendfsyncnone",thatinpraticaltermsmeansthatitis
- #possibletolostupto30secondsoflogintheworstscenario(withthe
- #defaultLinuxsettings).
- #
- #Ifyouhavelatencyproblemsturnthisto"yes".Otherwiseleaveitas
- #"no"thatisthesafestpickfromthepointofviewofdurability.
- no-appendfsync-on-rewriteno
- #Automaticrewriteoftheappendonlyfile.
- #Redisisabletoautomaticallyrewritethelogfileimplicitlycalling
- #BGREWRITEAOFwhentheAOFlogsizewillgrowthbythespecifiedpercentage.
- #
- #Thisishowitworks:RedisremembersthesizeoftheAOFfileafterthe
- #latestrewrite(orifnorewritehappenedsincetherestart,thesizeof
- #theAOFatstartupisused).
- #
- #Thisbasesizeiscomparedtothecurrentsize.Ifthecurrentsizeis
- #biggerthanthespecifiedpercentage,therewriteistriggered.Also
- #youneedtospecifyaminimalsizefortheAOFfiletoberewritten,this
- #isusefultoavoidrewritingtheAOFfileevenifthepercentageincrease
- #isreachedbutitisstillprettysmall.
- #
- #SpecifyaprecentageofzeroinordertodisabletheautomaticAOF
- #rewritefeature.
- auto-aof-rewrite-percentage100
- auto-aof-rewrite-min-size64mb
- ##################################SLOWLOG###################################
- #TheRedisSlowLogisasystemtologqueriesthatexceededaspecified
- #executiontime.TheexecutiontimedoesnotincludetheI/Ooperations
- #liketalkingwiththeclient,sendingthereplyandsoforth,
- #butjustthetimeneededtoactuallyexecutethecommand(thisistheonly
- #stageofcommandexecutionwherethethreadisblockedandcannotserve
- #otherrequestsinthemeantime).
- #
- #Youcanconfiguretheslowlogwithtwoparameters:onetellsRedis
- #whatistheexecutiontime,inmicroseconds,toexceedinorderforthe
- #commandtogetlogged,andtheotherparameteristhelengthofthe
- #slowlog.Whenanewcommandisloggedtheoldestoneisremovedfromthe
- #queueofloggedcommands.
- #Thefollowingtimeisexpressedinmicroseconds,so1000000isequivalent
- #toonesecond.Notethatanegativenumberdisablestheslowlog,while
- #avalueofzeroforcestheloggingofeverycommand.
- slowlog-log-slower-than10000
- #Thereisnolimittothislength.Justbeawarethatitwillconsumememory.
- #YoucanreclaimmemoryusedbytheslowlogwithSLOWLOGRESET.
- slowlog-max-len1024
- ################################VIRTUALMEMORY###############################
- ###WARNING!VirtualMemoryisdeprecatedinRedis2.4
- ###TheuseofVirtualMemoryisstronglydiscouraged.
- #VirtualMemoryallowsRedistoworkwithdatasetsbiggerthantheactual
- #amountofRAMneededtoholdthewholedatasetinmemory.
- #Inordertodosoveryusedkeysaretakeninmemorywhiletheotherkeys
- #areswappedintoaswapfile,similarlytowhatoperatingsystemsdo
- #withmemorypages.
- #
- #ToenableVMjustset'vm-enabled'toyes,andsetthefollowingthree
- #VMparametersaccordinglytoyourneeds.
- vm-enabledno
- #vm-enabledyes
- #ThisisthepathoftheRedisswapfile.Asyoucanguess,swapfiles
- #can'tbesharedbydifferentRedisinstances,somakesuretouseaswap
- #fileforeveryredisprocessyouarerunning.Rediswillcomplainifthe
- #swapfileisalreadyinuse.
- #
- #ThebestkindofstoragefortheRedisswapfile(that'saccessedatrandom)
- #isaSolidStateDisk(SSD).
- #
- #***WARNING***ifyouareusingasharedhostingthedefaultofputting
- #theswapfileunder/tmpisnotsecure.Createadirwithaccessgranted
- #onlytoRedisuserandconfigureRedistocreatetheswapfilethere.
- vm-swap-file/tmp/redis.swap
- #vm-max-memoryconfigurestheVMtouseatmaxthespecifiedamountof
- #RAM.Everythingthatdeosnotfitwillbeswappedondisk*if*possible,that
- #is,ifthereisstillenoughcontiguousspaceintheswapfile.
- #
- #Withvm-max-memory0thesystemwillswapeverythingitcan.Notagood
- #default,justspecifythemaxamountofRAMyoucaninbytes,butit's
- #bettertoleavesomemargin.ForinstancespecifyanamountofRAM
- #that'smoreorlessbetween60and80%ofyourfreeRAM.
- vm-max-memory0
- #Redisswapfilesissplitintopages.Anobjectcanbesavedusingmultiple
- #contiguouspages,butpagescan'tbesharedbetweendifferentobjects.
- #Soifyourpageistoobig,smallobjectsswappedoutondiskwillwaste
- #alotofspace.Ifyoupageistoosmall,thereislessspaceintheswap
- #file(assumingyouconfiguredthesamenumberoftotalswapfilepages).
- #
- #Ifyouusealotofsmallobjects,useapagesizeof64or32bytes.
- #Ifyouusealotofbigobjects,useabiggerpagesize.
- #Ifunsure,usethedefault:)
- vm-page-size32
- #Numberoftotalmemorypagesintheswapfile.
- #Giventhatthepagetable(abitmapoffree/usedpages)istakeninmemory,
- #every8pagesondiskwillconsume1byteofRAM.
- #
- #Thetotalswapsizeisvm-page-size*vm-pages
- #
- #Withthedefaultof32-bytesmemorypagesand134217728pagesRediswill
- #usea4GBswapfile,thatwilluse16MBofRAMforthepagetable.
- #
- #It'sbettertousethesmallestacceptablevalueforyourapplication,
- #butthedefaultislargeinordertoworkinmostconditions.
- vm-pages134217728
- #MaxnumberofVMI/Othreadsrunningatthesametime.
- #Thisthreadsareusedtoread/writedatafrom/toswapfile,sincethey
- #alsoencodeanddecodeobjectsfromdisktomemoryorthereverse,abigger
- #numberofthreadscanhelpwithbigobjectseveniftheycan'thelpwith
- #I/Oitselfasthephysicaldevicemaynotbeabletocouplewithmany
- #reads/writesoperationsatthesametime.
- #
- #Thespecialvalueof0turnoffthreadedI/Oandenablestheblocking
- #VirtualMemoryimplementation.
- vm-max-threads4
- ###############################ADVANCEDCONFIG###############################
- #Hashesareencodedinaspecialway(muchmorememoryefficient)whenthey
- #haveatmaxagivennumerofelements,andthebiggestelementdoesnot
- #exceedagiventhreshold.Youcanconfigurethislimitswiththefollowing
- #configurationdirectives.
- hash-max-zipmap-entries512
- hash-max-zipmap-value64
- #Similarlytohashes,smalllistsarealsoencodedinaspecialwayinorder
- #tosavealotofspace.Thespecialrepresentationisonlyusedwhen
- #youareunderthefollowinglimits:
- list-max-ziplist-entries512
- list-max-ziplist-value64
- #Setshaveaspecialencodinginjustonecase:whenasetiscomposed
- #ofjuststringsthathappenstobeintegersinradix10intherange
- #of64bitsignedintegers.
- #Thefollowingconfigurationsettingsetsthelimitinthesizeofthe
- #setinordertousethisspecialmemorysavingencoding.
- set-max-intset-entries512
- #Similarlytohashesandlists,sortedsetsarealsospeciallyencodedin
- #ordertosavealotofspace.Thisencodingisonlyusedwhenthelengthand
- #elementsofasortedsetarebelowthefollowinglimits:
- zset-max-ziplist-entries128
- zset-max-ziplist-value64
- #Activerehashinguses1millisecondevery100millisecondsofCPUtimein
- #ordertohelprehashingthemainRedishashtable(theonemappingtop-level
- #keystovalues).Thehashtableimplementationredisuses(seedict.c)
- #performsalazyrehashing:themoreoperationyourunintoanhashtable
- #thatisrhashing,themorerehashing"steps"areperformed,soifthe
- #serverisidletherehashingisnevercompleteandsomemorememoryisused
- #bythehashtable.
- #
- #Thedefaultistousethismillisecond10timeseverysecondinorderto
- #activerehashingthemaindictionaries,freeingmemorywhenpossible.
- #
- #Ifunsure:
- #use"activerehashingno"ifyouhavehardlatencyrequirementsanditis
- #notagoodthinginyourenvironmentthatRediscanreplyformtimetotime
- #toquerieswith2millisecondsdelay.
- #
- #use"activerehashingyes"ifyoudon'thavesuchhardrequirementsbut
- #wanttofreememoryasapwhenpossible.
- activerehashingyes
- ##################################INCLUDES###################################
- #Includeoneormoreotherconfigfileshere.Thisisusefulifyou
- #haveastandardtemplatethatgoestoallredisserverbutalsoneed
- #tocustomizeafewper-serversettings.Includefilescaninclude
- #otherfiles,sousethiswisely.
- #
- #include/path/to/local.conf
- #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
测试代码:
- <?php
- $redis=newRedis();
- $redis->connect('127.0.0.1',6379);
- $redis->set('test','helloworld!');
- echo$redis->get('test');
- ?>
参考:
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