Redis操作大全Redis::__construct描述:创建一个Redis客户端范例:$redis=newRedis();connect,open描述:实例连接到一个Redis.参数:host:stringport:int返回值:BOOL成功返回:TRUE;失败返回:FALSE范例:$redis-connect('127.0.0.1′,6379);get描述:获取有关指定键的值参数:key返回值:string或BOLL如果键不存在,则返回FALSE。否则,与此相关的关键值返回。范例:$redis-get('key');set描述:设置关键值参数Redis操作大全参数:KeyValue返回值:BOOL范例:$redis-set('key','value')setnx描述:如果在数据库中不存在该键,设置关键值参数参数:keyvalue返回值:BOOL范例:$this-redis-setnx('key','value');$this-redis-setnx('key','value');delete描述:删除指定的键参数:一个键,或不确定数目的参数,每一个关键的数组:key1key2key3…keyN返回值:删除的项数范例:$redis-set('key1′,'val1′);$redis-set('key2′,'val2′);$redis-set('key3′,'val3′);$redis-set('key4′,'val4′);Redis操作大全$redis-delete('key1′,'key2′);$redis-delete(array('key3′,'key4′));exists描述:验证指定的键是否存在参数key返回值:Bool范例:$this-set('key','value');$this-exists('key');$this-exists('NonExistingKey');incr描述:数字递增存储键值键.如果第二个参数被填满,它将被用来作为整数值递增Incrementthenumberstoredatkeybyone.Ifthesecondargumentisfilled,itwillbeusedastheintegervalueoftheincrement.参数:keyvalue:将被添加到键的值返回值:INTthenewvalue范例:$redis-incr('key1′);$redis-incr('key1′);$redis-incr('key1′);Redis操作大全$redis-incr('key1′);decr描述:数字递减存储键值。如果第二个参数被填满,它将被用来作为整数值递减Decrementthenumberstoredatkeybyone.Ifthesecondargumentisfilled,itwillbeusedastheintegervalueofthedecrement.参数:keyvalue:将被添加到键的值返回值:INTthenewvalue范例:$redis-decr('key1′);$redis-decr('key1′);$redis-decr('key1′);getMultiple描述:取得所有指定键的值。如果一个或多个键不存在,该数组中该键的值为假参数:其中包含键值的列表数组返回值:返回包含所有键的值的数组范例:$redis-set('key1′,'value1′);$redis-set('key2′,'value2′);$redis-set('key3′,'value3′);$redis-getMultiple(array('key1′,'key2′,'key3′));Redis操作大全rPush描述:由列表头部添加字符串值。如果不存在该键则创建该列表。如果该键存在,而且不是一个列表,返回FALSE。参数:key,value返回值:LONGThenewlengthofthelistincaseofsuccess,FALSEincaseofFailure.范例:$redis-delete('key1′);$redis-lPush('key1′,'C');//returns1$redis-lPush('key1′,'B');//returns2$redis-lPush('key1′,'A');//returns3lPop描述:返回和移除列表的最后一个元素参数:key返回值:STRINGifcommandexecutedsuccessfullyBOOLFALSEincaseoffailure(emptylist)范例:$redis-rPush('key1′,'A');$redis-rPush('key1′,'B');$redis-rPush('key1′,'C');$redis-lPop('key1′);Redis操作大全rPop描述:返回和移除列表的第一个元素参数:key返回值:STRINGifcommandexecutedsuccessfullyBOOLFALSEincaseoffailure(emptylist)范例:$redis-rPush('key1′,'A');$redis-rPush('key1′,'B');$redis-rPush('key1′,'C');$redis-rPop('key1′);lSize描述:返回的列表的大小。如果列表不存在或为空,该命令返回0。如果该键不是列表,该命令返回FALSE。参数:Key返回值:LONGThesizeofthelistidentifiedbyKeyexists.BOOLFALSEifthedatatypeidentifiedbyKeyisnotlist范例:$redis-rPush('key1′,'A');$redis-rPush('key1′,'B');Redis操作大全$redis-rPush('key1′,'C');$redis-lSize('key1′);$redis-rPop('key1′);$redis-lSize('key1′);lGet描述:返回指定键存储在列表中指定的元素。0第一个元素,1第二个…-1最后一个元素,-2的倒数第二…错误的索引或键不指向列表则返回FALSE。参数:keyindex返回值:StringtheelementatthisindexBoolFALSEifthekeyidentifiesanon-stringdatatype,ornovaluecorrespondstothisindexinthelistKey.范例:$redis-rPush('key1′,'A');$redis-rPush('key1′,'B');$redis-rPush('key1′,'C');$redis-lGet('key1′,0);$redis-lGet('key1′,-1);$redis-lGet('key1′,10);lSet描述:Redis操作大全为列表指定的索引赋新的值,若不存在该索引返回false.参数:keyindexvalue返回值:BOOLTRUEifthenewvalueissetted.FALSEiftheindexisoutofrange,ordatatypeidentifiedbykeyisnotalist.范例:$redis-rPush('key1′,'A');$redis-rPush('key1′,'B');$redis-rPush('key1′,'C');$redis-lGet('key1′,0);$redis-lSet('key1′,0,'X');$redis-lGet('key1′,0);lGetRange描述:返回在该区域中的指定键列表中开始到结束存储的指定元素,lGetRange(key,start,end)。0第一个元素,1第二个元素…-1最后一个元素,-2的倒数第二…参数:keystartend返回值:Arraycontainingthevaluesinspecifiedrange.范例:$redis-rPush('key1′,'A');$redis-rPush('key1′,'B');$redis-rPush('key1′,'C');Redis操作大全$redis-lGetRange('key1′,0,-1);lRemove描述:从列表中从头部开始移除count个匹配的值。如果count为零,所有匹配的元素都被删除。如果count是负数,内容从尾部开始删除。参数:keycountvalue返回值:LONGthenumberofelementstoremoveBOOLFALSEifthevalueidentifiedbykeyisnotalist.范例:$redis-lPush('key1′,'A');$redis-lPush('key1′,'B');$redis-lPush('key1′,'C');$redis-lPush('key1′,'A');$redis-lPush('key1′,'A');$redis-lGetRange('key1′,0,-1);$redis-lRemove('key1′,'A',2);$redis-lGetRange('key1′,0,-1);sAdd描述:为一个Key添加一个值。如果这个值已经在这个Key中,则返回FALSE。参数:keyvalueRedis操作大全返回值:BOOLTRUEifvaluedidn'texistandwasaddedsuccessfully,FALSEifthevalueisalreadypresent.范例:$redis-sAdd('key1′,'set1′);$redis-sAdd('key1′,'set2′);$redis-sAdd('key1′,'set2′);sRemove描述:删除Key中指定的value值参数:keymember返回值:BOOLTRUEifthememberwaspresentintheset,FALSEifitdidn't.范例:$redis-sAdd('key1′,'set1′);$redis-sAdd('key1′,'set2′);$redis-sAdd('key1′,'set3′);$redis-sRemove('key1′,'set2′);sMove描述:将Key1中的value移动到Key2中参数:srcKeydstKeymember返回值:BOOLIftheoperationissuccessful,returnTRUE.IfthesrcKeyand/ordstKeyRedis操作大全didn'texist,and/orthememberdidn'texistinsrcKey,FALSEisreturned.范例:$redis-sAdd('key1′,'set11′);$redis-sAdd('key1′,'set12′);$redis-sAdd('key1′,'set13′);$redis-sAdd('key2′,'set21′);$redis-sAdd('key2′,'set22′);$redis-sMove('key1′,'key2′,'set13′);sContains描述:检查集合中是否存在指定的值。参数:keyvalue返回值:BOOLTRUEifvalueisamemberofthesetatkeykey,FALSEotherwise.范例:$redis-sAdd('key1′,'set1′);$redis-sAdd('key1′,'set2′);$redis-sAdd('key1′,'set3′);$redis-sContains('key1′,'set1′);$redis-sContains('key1′,'setX');sSize描述:返回集合中