{"id":1002,"date":"2013-10-16T09:23:42","date_gmt":"2013-10-16T01:23:42","guid":{"rendered":"http:\/\/www.poloo.org\/?p=1002"},"modified":"2013-10-16T09:23:42","modified_gmt":"2013-10-16T01:23:42","slug":"php-redis%e4%b8%ad%e6%96%87%e8%af%b4%e6%98%8e","status":"publish","type":"post","link":"https:\/\/www.poloo.org\/?p=1002","title":{"rendered":"PHP-redis\u4e2d\u6587\u8bf4\u660e"},"content":{"rendered":"<div id=\"defend_4\">\n<p>PhpRedis\u662fphp\u7684\u4e00\u4e2a\u6269\u5c55\uff0c\u6548\u7387\u662f\u76f8\u5f53\u9ad8\u6709\u94fe\u8868\u6392\u5e8f\u529f\u80fd\uff0c\u5bf9\u521b\u5efa\u5185\u5b58\u7ea7\u7684\u6a21\u5757\u4e1a\u52a1\u5173\u7cfb\u5f88\u6709\u7528;\u4ee5\u4e0b\u662fredis\u5b98\u65b9\u63d0\u4f9b\u7684\u547d\u4ee4\u4f7f\u7528\u6280\u5de7:<\/p>\n<p><strong>Redis::__construct<\/strong>\u6784\u9020\u51fd\u6570<\/p>\n<div id=\"highlighter_88841\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis = <\/code><code>new<\/code> <code>Redis();<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>connect, open <\/strong>\u94fe\u63a5redis\u670d\u52a1<\/p>\n<p>\u53c2\u6570\uff1a<\/p>\n<ul>\n<li>host: string\uff0c\u670d\u52a1\u5730\u5740<\/li>\n<li>port: int,\u7aef\u53e3\u53f7<\/li>\n<li>timeout: float,\u94fe\u63a5\u65f6\u957f (\u53ef\u9009, \u9ed8\u8ba4\u4e3a 0 \uff0c\u4e0d\u9650\u94fe\u63a5\u65f6\u95f4)<\/li>\n<\/ul>\n<p>\u6ce8: \u5728redis.conf\u4e2d\u4e5f\u6709\u65f6\u95f4\uff0c\u9ed8\u8ba4\u4e3a300<\/p>\n<p><strong>pconnect, popen <\/strong>\u4e0d\u4f1a\u4e3b\u52a8\u5173\u95ed\u7684\u94fe\u63a5<\/p>\n<p><!--more--><\/p>\n<p>\u53c2\u8003\u540c\u4e0a<\/p>\n<p><strong>setOption<\/strong> \u8bbe\u7f6eredis\u6a21\u5f0f<\/p>\n<p><strong>getOption<\/strong> \u67e5\u770bredis\u8bbe\u7f6e\u7684\u6a21\u5f0f<\/p>\n<p><strong>ping<\/strong> \u67e5\u770b\u8fde\u63a5\u72b6\u6001<\/p>\n<p><strong>get<\/strong> \u5f97\u5230\u67d0\u4e2akey\u7684\u503c\uff08string\u503c\uff09<\/p>\n<p>\u5982\u679c\u8be5key\u4e0d\u5b58\u5728\uff0creturn false<\/p>\n<p><strong>set <\/strong>\u5199\u5165key \u548c value\uff08string\u503c\uff09<\/p>\n<p>\u5982\u679c\u5199\u5165\u6210\u529f\uff0creturn ture<\/p>\n<p><strong>setex<\/strong> \u5e26\u751f\u5b58\u65f6\u95f4\u7684\u5199\u5165\u503c<\/p>\n<div id=\"highlighter_959457\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;setex(<\/code><code>'key'<\/code><code>, 3600, <\/code><code>'value'<\/code><code>); <\/code><code>\/\/ sets key \u2192 value, with 1h TTL.<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>setnx <\/strong>\u5224\u65ad\u662f\u5426\u91cd\u590d\u7684\uff0c\u5199\u5165\u503c<\/p>\n<div id=\"highlighter_406957\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;setnx(<\/code><code>'key'<\/code><code>, <\/code><code>'value'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>2<\/code><\/td>\n<td><code>$redis-&gt;setnx(<\/code><code>'key'<\/code><code>, <\/code><code>'value'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>delete<\/strong>\u00a0 \u5220\u9664\u6307\u5b9akey\u7684\u503c<\/p>\n<p>\u8fd4\u56de\u5df2\u7ecf\u5220\u9664key\u7684\u4e2a\u6570\uff08\u957f\u6574\u6570\uff09<\/p>\n<div id=\"highlighter_965032\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;delete(<\/code><code>'key1'<\/code><code>, <\/code><code>'key2'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>2<\/code><\/td>\n<td><code>$redis-&gt;delete(array(<\/code><code>'key3'<\/code><code>, <\/code><code>'key4'<\/code><code>, <\/code><code>'key5'<\/code><code>));<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>ttl<\/strong><\/p>\n<p>\u5f97\u5230\u4e00\u4e2akey\u7684\u751f\u5b58\u65f6\u95f4<\/p>\n<p><strong>persist<\/strong><\/p>\n<p>\u79fb\u9664\u751f\u5b58\u65f6\u95f4\u5230\u671f\u7684key<\/p>\n<p>\u5982\u679ckey\u5230\u671f true \u5982\u679c\u4e0d\u5230\u671f false<\/p>\n<p><strong>mset <\/strong>\uff08redis\u7248\u672c1.1\u4ee5\u4e0a\u624d\u53ef\u4ee5\u7528\uff09<\/p>\n<p>\u540c\u65f6\u7ed9\u591a\u4e2akey\u8d4b\u503c<\/p>\n<div id=\"highlighter_384892\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;mset(array(<\/code><code>'key0'<\/code> <code>=&gt; <\/code><code>'value0'<\/code><code>, <\/code><code>'key1'<\/code> <code>=&gt; <\/code><code>'value1'<\/code><code>));<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>multi, exec, discard<\/strong><\/p>\n<p>\u8fdb\u5165\u6216\u8005\u9000\u51fa\u4e8b\u52a1\u6a21\u5f0f<\/p>\n<p>\u53c2\u6570\u53ef\u9009Redis::MULTI\u6216Redis::PIPELINE. \u9ed8\u8ba4\u662f Redis::MULTI<\/p>\n<p>Redis::MULTI\uff1a\u5c06\u591a\u4e2a\u64cd\u4f5c\u5f53\u6210\u4e00\u4e2a\u4e8b\u52a1\u6267\u884c<\/p>\n<p>Redis::PIPELINE:\u8ba9\uff08\u591a\u6761\uff09\u6267\u884c\u547d\u4ee4\u7b80\u5355\u7684\uff0c\u66f4\u52a0\u5feb\u901f\u7684\u53d1\u9001\u7ed9\u670d\u52a1\u5668\uff0c\u4f46\u662f\u6ca1\u6709\u4efb\u4f55\u539f\u5b50\u6027\u7684\u4fdd\u8bc1<\/p>\n<p>discard:\u5220\u9664\u4e00\u4e2a\u4e8b\u52a1<\/p>\n<p>\u8fd4\u56de\u503c<\/p>\n<p>multi()\uff0c\u8fd4\u56de\u4e00\u4e2aredis\u5bf9\u8c61\uff0c\u5e76\u8fdb\u5165multi-mode\u6a21\u5f0f\uff0c\u4e00\u65e6\u8fdb\u5165multi-mode\u6a21\u5f0f\uff0c\u4ee5\u540e\u8c03\u7528\u7684\u6240\u6709\u65b9\u6cd5\u90fd\u4f1a\u8fd4\u56de\u76f8\u540c\u7684\u5bf9\u8c61\uff0c\u53ea\u5230exec(\uff09\u65b9\u6cd5\u88ab\u8c03\u7528\u3002<\/p>\n<p><strong>watch, unwatch<\/strong> \uff08\u4ee3\u7801\u6d4b\u8bd5\u540e\uff0c\u4e0d\u80fd\u8fbe\u5230\u6240\u8bf4\u7684\u6548\u679c\uff09<\/p>\n<p>\u76d1\u6d4b\u4e00\u4e2akey\u7684\u503c\u662f\u5426\u88ab\u5176\u5b83\u7684\u7a0b\u5e8f\u66f4\u6539\u3002\u5982\u679c\u8fd9\u4e2akey\u5728watch \u548c exec \uff08\u65b9\u6cd5\uff09\u95f4\u88ab\u4fee\u6539\uff0c\u8fd9\u4e2a MULTI\/EXEC \u4e8b\u52a1\u7684\u6267\u884c\u5c06\u5931\u8d25\uff08return false\uff09<\/p>\n<p>unwatch \u53d6\u6d88\u88ab\u8fd9\u4e2a\u7a0b\u5e8f\u76d1\u6d4b\u7684\u6240\u6709key<\/p>\n<p>\u53c2\u6570\uff0c\u4e00\u5bf9key\u7684\u5217\u8868<\/p>\n<div id=\"highlighter_154090\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;watch(<\/code><code>'x'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>2<\/code><\/td>\n<td><code>$ret = $redis-&gt;multi() -&gt;incr(<\/code><code>'x'<\/code><code>) -&gt;exec();<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>subscribe *<\/strong><\/p>\n<p>\u65b9\u6cd5\u56de\u8c03\u3002\u6ce8\u610f\uff0c\u8be5\u65b9\u6cd5\u53ef\u80fd\u5728\u672a\u6765\u91cc\u53d1\u751f\u6539\u53d8<\/p>\n<p><strong>publish *<\/strong><\/p>\n<p>\u53d1\u8868\u5185\u5bb9\u5230\u67d0\u4e00\u4e2a\u901a\u9053\u3002\u6ce8\u610f\uff0c\u8be5\u65b9\u6cd5\u53ef\u80fd\u5728\u672a\u6765\u91cc\u53d1\u751f\u6539\u53d8<\/p>\n<p><strong>exists<\/strong><\/p>\n<p>\u5224\u65adkey\u662f\u5426\u5b58\u5728\u3002\u5b58\u5728 true \u4e0d\u5728 false<\/p>\n<p><strong>incr, incrBy<\/strong><\/p>\n<p>key\u4e2d\u7684\u503c\u8fdb\u884c\u81ea\u589e1\uff0c\u5982\u679c\u586b\u5199\u4e86\u7b2c\u4e8c\u4e2a\u53c2\u6570\uff0c\u8005\u81ea\u589e\u7b2c\u4e8c\u4e2a\u53c2\u6570\u6240\u586b\u7684\u503c<\/p>\n<div id=\"highlighter_6952\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;incr(<\/code><code>'key1'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>2<\/code><\/td>\n<td><code>$redis-&gt;incrBy(<\/code><code>'key1'<\/code><code>, 10);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>decr, decrBy<\/strong><\/p>\n<p>\u505a\u51cf\u6cd5\uff0c\u4f7f\u7528\u65b9\u6cd5\u540cincr<\/p>\n<p><strong>getMultiple<\/strong><\/p>\n<p>\u4f20\u53c2<\/p>\n<p>\u7531key\u7ec4\u6210\u7684\u6570\u7ec4<\/p>\n<p>\u8fd4\u56de\u53c2\u6570<\/p>\n<p>\u5982\u679ckey\u5b58\u5728\u8fd4\u56devalue\uff0c\u4e0d\u5b58\u5728\u8fd4\u56defalse<\/p>\n<div id=\"highlighter_328311\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;<\/code><code>set<\/code><code>(<\/code><code>'key1'<\/code><code>, <\/code><code>'value1'<\/code><code>); <\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>2<\/code><\/td>\n<td><code>$redis-&gt;<\/code><code>set<\/code><code>(<\/code><code>'key2'<\/code><code>, <\/code><code>'value2'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>3<\/code><\/td>\n<td><code>$redis-&gt;<\/code><code>set<\/code><code>(<\/code><code>'key3'<\/code><code>, <\/code><code>'value3'<\/code><code>); <\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>4<\/code><\/td>\n<td><code>$redis-&gt;getMultiple(array(<\/code><code>'key1'<\/code><code>, <\/code><code>'key2'<\/code><code>, <\/code><code>'key3'<\/code><code>));<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>5<\/code><\/td>\n<td><code>$redis-&gt;lRem(<\/code><code>'key1'<\/code><code>, <\/code><code>'A'<\/code><code>, 2);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>6<\/code><\/td>\n<td><code>$redis-&gt;lRange(<\/code><code>'key1'<\/code><code>, 0, -1);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>List<strong>\u76f8\u5173<strong>\u64cd\u4f5c<\/strong><\/strong><\/strong><\/p>\n<p><strong>lPush<\/strong><\/p>\n<div id=\"highlighter_250335\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;lPush(key, value);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u5728\u540d\u79f0\u4e3akey\u7684list\u5de6\u8fb9\uff08\u5934\uff09\u6dfb\u52a0\u4e00\u4e2a\u503c\u4e3avalue\u7684\u5143\u7d20<\/p>\n<p><strong>rPush<\/strong><\/p>\n<div id=\"highlighter_205538\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;rPush(key, value);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u5728\u540d\u79f0\u4e3akey\u7684list\u53f3\u8fb9\uff08\u5c3e\uff09\u6dfb\u52a0\u4e00\u4e2a\u503c\u4e3avalue\u7684\u5143\u7d20<\/p>\n<p><strong>lPushx\/rPushx<\/strong><\/p>\n<div id=\"highlighter_252886\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;lPushx(key, value);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u5728\u540d\u79f0\u4e3akey\u7684list\u5de6\u8fb9(\u5934)\/\u53f3\u8fb9\uff08\u5c3e\uff09\u6dfb\u52a0\u4e00\u4e2a\u503c\u4e3avalue\u7684\u5143\u7d20,\u5982\u679cvalue\u5df2\u7ecf\u5b58\u5728\uff0c\u5219\u4e0d\u6dfb\u52a0<\/p>\n<p><strong>lPop\/rPop<\/strong><\/p>\n<div id=\"highlighter_542522\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;lPop(<\/code><code>'key'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8f93\u51fa\u540d\u79f0\u4e3akey\u7684list\u5de6(\u5934)\u8d77\/\u53f3\uff08\u5c3e\uff09\u8d77\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\uff0c\u5220\u9664\u8be5\u5143\u7d20<\/p>\n<p><strong>blPop\/brPop<\/strong><\/p>\n<div id=\"highlighter_619001\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;blPop(<\/code><code>'key1'<\/code><code>, <\/code><code>'key2'<\/code><code>, 10);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>lpop\u547d\u4ee4\u7684block\u7248\u672c\u3002\u5373\u5f53timeout\u4e3a0\u65f6\uff0c\u82e5\u9047\u5230\u540d\u79f0\u4e3akey i\u7684list\u4e0d\u5b58\u5728\u6216\u8be5list\u4e3a\u7a7a\uff0c\u5219\u547d\u4ee4\u7ed3\u675f\u3002\u5982\u679ctimeout&gt;0\uff0c\u5219\u9047\u5230\u4e0a\u8ff0\u60c5\u51b5\u65f6\uff0c\u7b49\u5f85timeout\u79d2\uff0c\u5982\u679c\u95ee\u9898\u6ca1\u6709\u89e3\u51b3\uff0c\u5219\u5bf9 keyi+1\u5f00\u59cb\u7684list\u6267\u884cpop\u64cd\u4f5c<\/p>\n<p><strong>lSize<\/strong><\/p>\n<div id=\"highlighter_44026\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;lSize(<\/code><code>'key'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8fd4\u56de\u540d\u79f0\u4e3akey\u7684list\u6709\u591a\u5c11\u4e2a\u5143\u7d20<\/p>\n<p><strong>lIndex, lGet<\/strong><\/p>\n<div id=\"highlighter_696239\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;lGet(<\/code><code>'key'<\/code><code>, 0);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8fd4\u56de\u540d\u79f0\u4e3akey\u7684list\u4e2dindex\u4f4d\u7f6e\u7684\u5143\u7d20<\/p>\n<p><strong>lSet<\/strong><\/p>\n<div id=\"highlighter_284460\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;lSet(<\/code><code>'key'<\/code><code>, 0, <\/code><code>'X'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u7ed9\u540d\u79f0\u4e3akey\u7684list\u4e2dindex\u4f4d\u7f6e\u7684\u5143\u7d20\u8d4b\u503c\u4e3avalue<\/p>\n<p><strong>lRange, lGetRange<\/strong><\/p>\n<div id=\"highlighter_100797\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;lRange(<\/code><code>'key1'<\/code><code>, 0, -1);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8fd4\u56de\u540d\u79f0\u4e3akey\u7684list\u4e2dstart\u81f3end\u4e4b\u95f4\u7684\u5143\u7d20\uff08end\u4e3a -1 \uff0c\u8fd4\u56de\u6240\u6709\uff09<\/p>\n<p><strong>lTrim, listTrim<\/strong><\/p>\n<div id=\"highlighter_449504\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;lTrim(<\/code><code>'key'<\/code><code>, start, end);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u622a\u53d6\u540d\u79f0\u4e3akey\u7684list\uff0c\u4fdd\u7559start\u81f3end\u4e4b\u95f4\u7684\u5143\u7d20<\/p>\n<p><strong>lRem, lRemove<\/strong><\/p>\n<div id=\"highlighter_860232\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;lRem(<\/code><code>'key'<\/code><code>, <\/code><code>'A'<\/code><code>, 2);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u5220\u9664count\u4e2a\u540d\u79f0\u4e3akey\u7684list\u4e2d\u503c\u4e3avalue\u7684\u5143\u7d20\u3002count\u4e3a0\uff0c\u5220\u9664\u6240\u6709\u503c\u4e3avalue\u7684\u5143\u7d20\uff0ccount&gt;0\u4ece\u5934\u81f3\u5c3e\u5220\u9664count\u4e2a\u503c\u4e3avalue\u7684\u5143\u7d20\uff0ccount&lt;0\u4ece\u5c3e\u5230\u5934\u5220\u9664|count|\u4e2a\u503c\u4e3avalue\u7684\u5143\u7d20<\/p>\n<p><strong>lInsert<\/strong><\/p>\n<p>\u5728\u540d\u79f0\u4e3a\u4e3akey\u7684list\u4e2d\uff0c\u627e\u5230\u503c\u4e3apivot \u7684value\uff0c\u5e76\u6839\u636e\u53c2\u6570Redis::BEFORE | Redis::AFTER\uff0c\u6765\u786e\u5b9a\uff0cnewvalue \u662f\u653e\u5728 pivot \u7684\u524d\u9762\uff0c\u6216\u8005\u540e\u9762\u3002\u5982\u679ckey\u4e0d\u5b58\u5728\uff0c\u4e0d\u4f1a\u63d2\u5165\uff0c\u5982\u679c pivot\u4e0d\u5b58\u5728\uff0creturn -1<\/p>\n<div id=\"highlighter_124900\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>01<\/code><\/td>\n<td><code>$redis-&gt;delete(<\/code><code>'key1'<\/code><code>); <\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>02<\/code><\/td>\n<td><code>$redis-&gt;lInsert(<\/code><code>'key1'<\/code><code>, Redis::AFTER, <\/code><code>'A'<\/code><code>, <\/code><code>'X'<\/code><code>); <\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>03<\/code><\/td>\n<td><code>$redis-&gt;lPush(<\/code><code>'key1'<\/code><code>, <\/code><code>'A'<\/code><code>); <\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>04<\/code><\/td>\n<td><code>$redis-&gt;lPush(<\/code><code>'key1'<\/code><code>, <\/code><code>'B'<\/code><code>); <\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>05<\/code><\/td>\n<td><code>$redis-&gt;lPush(<\/code><code>'key1'<\/code><code>, <\/code><code>'C'<\/code><code>); <\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>06<\/code><\/td>\n<td><code>$redis-&gt;lInsert(<\/code><code>'key1'<\/code><code>, Redis::BEFORE, <\/code><code>'C'<\/code><code>, <\/code><code>'X'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>07<\/code><\/td>\n<td><code>$redis-&gt;lRange(<\/code><code>'key1'<\/code><code>, 0, -1);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>08<\/code><\/td>\n<td><code>$redis-&gt;lInsert(<\/code><code>'key1'<\/code><code>, Redis::AFTER, <\/code><code>'C'<\/code><code>, <\/code><code>'Y'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>09<\/code><\/td>\n<td><code>$redis-&gt;lRange(<\/code><code>'key1'<\/code><code>, 0, -1);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>10<\/code><\/td>\n<td><code>$redis-&gt;lInsert(<\/code><code>'key1'<\/code><code>, Redis::AFTER, <\/code><code>'W'<\/code><code>, <\/code><code>'value'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>rpop\/lpush<\/strong><\/p>\n<div id=\"highlighter_74452\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>01<\/code><\/td>\n<td><code>$redis-&gt;delete(<\/code><code>'x'<\/code><code>, <\/code><code>'y'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>02<\/code><\/td>\n<td><code>$redis-&gt;lPush(<\/code><code>'x'<\/code><code>, <\/code><code>'abc'<\/code><code>); <\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>03<\/code><\/td>\n<td><code>$redis-&gt;lPush(<\/code><code>'x'<\/code><code>, <\/code><code>'def'<\/code><code>); <\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>04<\/code><\/td>\n<td><code>$redis-&gt;lPush(<\/code><code>'y'<\/code><code>, <\/code><code>'123'<\/code><code>); <\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>05<\/code><\/td>\n<td><code>$redis-&gt;lPush(<\/code><code>'y'<\/code><code>, <\/code><code>'456'<\/code><code>); <\/code><code>\/\/ move the last of x to the front of y. var_dump($redis-&gt;rpoplpush('x', 'y'));<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>06<\/code><\/td>\n<td><code>var_dump($redis-&gt;lRange(<\/code><code>'x'<\/code><code>, 0, -1));<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>07<\/code><\/td>\n<td><code>var_dump($redis-&gt;lRange(<\/code><code>'y'<\/code><code>, 0, -1)); <\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>08<\/code><\/td>\n<td><code>array<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>09<\/code><\/td>\n<td><code>\u00a0\u00a0<\/code><code>0 =&gt; <\/code><code>string<\/code> <code>'def'<\/code> <code>(length=3)<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>10<\/code><\/td>\n<td><code>\u00a0\u00a0<\/code><code>1 =&gt; <\/code><code>string<\/code> <code>'abc'<\/code> <code>(length=3)<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>11<\/code><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>12<\/code><\/td>\n<td><code>array<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>13<\/code><\/td>\n<td><code>\u00a0\u00a0<\/code><code>0 =&gt; <\/code><code>string<\/code> <code>'456'<\/code> <code>(length=3)<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>14<\/code><\/td>\n<td><code>\u00a0\u00a0<\/code><code>1 =&gt; <\/code><code>string<\/code> <code>'123'<\/code> <code>(length=3)<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8fd4\u56de\u5e76\u5220\u9664\u540d\u79f0\u4e3asrckey\u7684list\u7684\u5c3e\u5143\u7d20\uff0c\u5e76\u5c06\u8be5\u5143\u7d20\u6dfb\u52a0\u5230\u540d\u79f0\u4e3adstkey\u7684list\u7684\u5934\u90e8<\/p>\n<p><strong>SET<strong>\u76f8\u5173<strong>\u64cd\u4f5c<\/strong><\/strong><\/strong><\/p>\n<p><strong>sAdd<\/strong><\/p>\n<div id=\"highlighter_892116\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;sAdd(key , value);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u5411\u540d\u79f0\u4e3akey\u7684set\u4e2d\u6dfb\u52a0\u5143\u7d20value,\u5982\u679cvalue\u5b58\u5728\uff0c\u4e0d\u5199\u5165\uff0creturn false<\/p>\n<p><strong>sRem, sRemove<\/strong><\/p>\n<div id=\"highlighter_284613\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;sAdd(<\/code><code>'key1'<\/code> <code>, <\/code><code>'set1'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>2<\/code><\/td>\n<td><code>$redis-&gt;sAdd(<\/code><code>'key1'<\/code> <code>, <\/code><code>'set2'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>3<\/code><\/td>\n<td><code>$redis-&gt;sAdd(<\/code><code>'key1'<\/code> <code>, <\/code><code>'set3'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>4<\/code><\/td>\n<td><code>$redis-&gt;sRem(<\/code><code>'key1'<\/code><code>, <\/code><code>'set2'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u5220\u9664\u540d\u79f0\u4e3akey\u7684set\u4e2d\u7684\u5143\u7d20value<\/p>\n<p><strong>sMove<\/strong><\/p>\n<div id=\"highlighter_551113\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;sMove(seckey, dstkey, value);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u5c06value\u5143\u7d20\u4ece\u540d\u79f0\u4e3asrckey\u7684\u96c6\u5408\u79fb\u5230\u540d\u79f0\u4e3adstkey\u7684\u96c6\u5408<\/p>\n<p><strong>sIsMember, sContains<\/strong><\/p>\n<div id=\"highlighter_863109\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;sIsMember(key, value);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u540d\u79f0\u4e3akey\u7684\u96c6\u5408\u4e2d\u67e5\u627e\u662f\u5426\u6709value\u5143\u7d20\uff0c\u6709ture \u6ca1\u6709false<\/p>\n<p><strong>sCard, sSize<\/strong><\/p>\n<div id=\"highlighter_184388\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;sIsMember(key, value);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8fd4\u56de\u540d\u79f0\u4e3akey\u7684set\u7684\u5143\u7d20\u4e2a\u6570<\/p>\n<p><strong>sPop<\/strong><\/p>\n<p>\u968f\u673a\u8fd4\u56de\u5e76\u5220\u9664\u540d\u79f0\u4e3akey\u7684set\u4e2d\u4e00\u4e2a\u5143\u7d20<\/p>\n<p><strong>sRandMember<\/strong><\/p>\n<p>\u968f\u673a\u8fd4\u56de\u540d\u79f0\u4e3akey\u7684set\u4e2d\u4e00\u4e2a\u5143\u7d20\uff0c\u4e0d\u5220\u9664<\/p>\n<p><strong>sInter<\/strong><\/p>\n<p>\u6c42\u4ea4\u96c6<\/p>\n<p><strong>sInterStore<\/strong><\/p>\n<div id=\"highlighter_791241\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;sInterStore(<\/code><code>'output'<\/code><code>, <\/code><code>'key1'<\/code><code>, <\/code><code>'key2'<\/code><code>, <\/code><code>'key3'<\/code><code>)<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u6c42\u4ea4\u96c6\u5e76\u5c06\u4ea4\u96c6\u4fdd\u5b58\u5230output\u7684\u96c6\u5408<\/p>\n<p><strong>sUnion<\/strong><\/p>\n<div id=\"highlighter_450393\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;sUnion(<\/code><code>'s0'<\/code><code>, <\/code><code>'s1'<\/code><code>, <\/code><code>'s2'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>2<\/code><\/td>\n<td><code>\/\/s0,s1,s2 \u540c\u65f6\u6c42\u5e76\u96c6<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u6c42\u5e76\u96c6<\/p>\n<p><strong>sUnionStore<\/strong><\/p>\n<div id=\"highlighter_534558\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;sUnionStore(<\/code><code>'output'<\/code><code>, <\/code><code>'key1'<\/code><code>, <\/code><code>'key2'<\/code><code>, <\/code><code>'key3'<\/code><code>)\uff1b<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u6c42\u5e76\u96c6\u5e76\u5c06\u5e76\u96c6\u4fdd\u5b58\u5230output\u7684\u96c6\u5408<\/p>\n<p><strong>sDiff<\/strong><\/p>\n<p>\u6c42\u5dee\u96c6<\/p>\n<p><strong>sDiffStore<\/strong><\/p>\n<p>\u6c42\u5dee\u96c6\u5e76\u5c06\u5dee\u96c6\u4fdd\u5b58\u5230output\u7684\u96c6\u5408<\/p>\n<p><strong>sMembers, sGetMembers<\/strong><\/p>\n<p>\u8fd4\u56de\u540d\u79f0\u4e3akey\u7684set\u7684\u6240\u6709\u5143\u7d20<\/p>\n<p><strong>sort<\/strong><\/p>\n<p>\u6392\u5e8f\uff0c\u5206\u9875\u7b49<\/p>\n<p>\u53c2\u6570<\/p>\n<ul>\n<li>&#8216;by&#8217; =&gt; &#8216;some_pattern_*&#8217;<\/li>\n<li>&#8216;limit&#8217; =&gt; array(0, 1)<\/li>\n<li>&#8216;get&#8217; =&gt; &#8216;some_other_pattern_*&#8217; or an array of patterns<\/li>\n<li>&#8216;sort&#8217; =&gt; &#8216;asc&#8217; or &#8216;desc&#8217;<\/li>\n<li>&#8216;alpha&#8217; =&gt; TRUE<\/li>\n<li>&#8216;store&#8217; =&gt; &#8216;external-key&#8217;<\/li>\n<\/ul>\n<div id=\"highlighter_785003\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;delete(<\/code><code>'s'<\/code><code>); <\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>2<\/code><\/td>\n<td><code>$redis-&gt;sadd(<\/code><code>'s'<\/code><code>, 5); <\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>3<\/code><\/td>\n<td><code>$redis-&gt;sadd(<\/code><code>'s'<\/code><code>, 4); <\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>4<\/code><\/td>\n<td><code>$redis-&gt;sadd(<\/code><code>'s'<\/code><code>, 2); <\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>5<\/code><\/td>\n<td><code>$redis-&gt;sadd(<\/code><code>'s'<\/code><code>, 1); <\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>6<\/code><\/td>\n<td><code>$redis-&gt;sadd(<\/code><code>'s'<\/code><code>, 3);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>7<\/code><\/td>\n<td><code>var_dump($redis-&gt;sort(<\/code><code>'s'<\/code><code>)); <\/code><code>\/\/ 1,2,3,4,5<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>8<\/code><\/td>\n<td><code>var_dump($redis-&gt;sort(<\/code><code>'s'<\/code><code>, array(<\/code><code>'sort'<\/code> <code>=&gt; <\/code><code>'desc'<\/code><code>))); <\/code><code>\/\/ 5,4,3,2,1<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>9<\/code><\/td>\n<td><code>var_dump($redis-&gt;sort(<\/code><code>'s'<\/code><code>, array(<\/code><code>'sort'<\/code> <code>=&gt; <\/code><code>'desc'<\/code><code>, <\/code><code>'store'<\/code> <code>=&gt; <\/code><code>'out'<\/code><code>))); <\/code><code>\/\/ (int)5<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>string<strong>\u76f8\u5173<strong>\u64cd\u4f5c<\/strong><\/strong><\/strong><\/p>\n<p><strong>getSet<\/strong><\/p>\n<div id=\"highlighter_235414\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;<\/code><code>set<\/code><code>(<\/code><code>'x'<\/code><code>, <\/code><code>'42'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>2<\/code><\/td>\n<td><code>$exValue = $redis-&gt;getSet(<\/code><code>'x'<\/code><code>, <\/code><code>'lol'<\/code><code>); <\/code><code>\/\/ return '42', replaces x by 'lol'<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>3<\/code><\/td>\n<td><code>$newValue = $redis-&gt;<\/code><code>get<\/code><code>(<\/code><code>'x'<\/code><code>)<\/code><code>' \/\/ return '<\/code><code>lol'<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8fd4\u56de\u539f\u6765key\u4e2d\u7684\u503c\uff0c\u5e76\u5c06value\u5199\u5165key<\/p>\n<p><strong>append<\/strong><\/p>\n<div id=\"highlighter_74664\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;<\/code><code>set<\/code><code>(<\/code><code>'key'<\/code><code>, <\/code><code>'value1'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>2<\/code><\/td>\n<td><code>$redis-&gt;append(<\/code><code>'key'<\/code><code>, <\/code><code>'value2'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>3<\/code><\/td>\n<td><code>$redis-&gt;<\/code><code>get<\/code><code>(<\/code><code>'key'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>string\uff0c\u540d\u79f0\u4e3akey\u7684string\u7684\u503c\u5728\u540e\u9762\u52a0\u4e0avalue<\/p>\n<p><strong>getRange<\/strong> \uff08\u65b9\u6cd5\u4e0d\u5b58\u5728\uff09<\/p>\n<div id=\"highlighter_759482\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;<\/code><code>set<\/code><code>(<\/code><code>'key'<\/code><code>, <\/code><code>'string value'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>2<\/code><\/td>\n<td><code>$redis-&gt;getRange(<\/code><code>'key'<\/code><code>, 0, 5);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>3<\/code><\/td>\n<td><code>$redis-&gt;getRange(<\/code><code>'key'<\/code><code>, -5, -1);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8fd4\u56de\u540d\u79f0\u4e3akey\u7684string\u4e2dstart\u81f3end\u4e4b\u95f4\u7684\u5b57\u7b26<\/p>\n<p><strong>setRange<\/strong> \uff08\u65b9\u6cd5\u4e0d\u5b58\u5728\uff09<\/p>\n<div id=\"highlighter_712210\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;<\/code><code>set<\/code><code>(<\/code><code>'key'<\/code><code>, <\/code><code>'Hello world'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>2<\/code><\/td>\n<td><code>$redis-&gt;setRange(<\/code><code>'key'<\/code><code>, 6, <\/code><code>\"redis\"<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>3<\/code><\/td>\n<td><code>$redis-&gt;<\/code><code>get<\/code><code>(<\/code><code>'key'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u6539\u53d8key\u7684string\u4e2dstart\u81f3end\u4e4b\u95f4\u7684\u5b57\u7b26\u4e3avalue<\/p>\n<p><strong>strlen<\/strong><\/p>\n<div id=\"highlighter_915071\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;strlen(<\/code><code>'key'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u5f97\u5230key\u7684string\u7684\u957f\u5ea6<\/p>\n<p><strong>getBit\/setBit<\/strong><\/p>\n<p>\u8fd4\u56de2\u8fdb\u5236\u4fe1\u606f<\/p>\n<p><strong>zset\uff08sorted set\uff09<strong>\u76f8\u5173<strong>\u64cd\u4f5c<\/strong><\/strong><\/strong><\/p>\n<p><strong>zAdd(key, score, member)<\/strong><\/p>\n<div id=\"highlighter_264998\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;zAdd(<\/code><code>'key'<\/code><code>, 1, <\/code><code>'val1'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>2<\/code><\/td>\n<td><code>$redis-&gt;zAdd(<\/code><code>'key'<\/code><code>, 0, <\/code><code>'val0'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>3<\/code><\/td>\n<td><code>$redis-&gt;zAdd(<\/code><code>'key'<\/code><code>, 5, <\/code><code>'val5'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>4<\/code><\/td>\n<td><code>$redis-&gt;zRange(<\/code><code>'key'<\/code><code>, 0, -1); <\/code><code>\/\/ array(val0, val1, val5)<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u5411\u540d\u79f0\u4e3akey\u7684zset\u4e2d\u6dfb\u52a0\u5143\u7d20member\uff0cscore\u7528\u4e8e\u6392\u5e8f\u3002\u5982\u679c\u8be5\u5143\u7d20\u5df2\u7ecf\u5b58\u5728\uff0c\u5219\u6839\u636escore\u66f4\u65b0\u8be5\u5143\u7d20\u7684\u987a\u5e8f\u3002<\/p>\n<p><strong>zRange(key, start, end,withscores)<\/strong><\/p>\n<div id=\"highlighter_333951\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;zAdd(<\/code><code>'key1'<\/code><code>, 0, <\/code><code>'val0'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>2<\/code><\/td>\n<td><code>$redis-&gt;zAdd(<\/code><code>'key1'<\/code><code>, 2, <\/code><code>'val2'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>3<\/code><\/td>\n<td><code>$redis-&gt;zAdd(<\/code><code>'key1'<\/code><code>, 10, <\/code><code>'val10'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>4<\/code><\/td>\n<td><code>$redis-&gt;zRange(<\/code><code>'key1'<\/code><code>, 0, -1); <\/code><code>\/\/ with scores $redis-&gt;zRange('key1', 0, -1, true);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8fd4\u56de\u540d\u79f0\u4e3akey\u7684zset\uff08\u5143\u7d20\u5df2\u6309score\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\uff09\u4e2d\u7684index\u4ecestart\u5230end\u7684\u6240\u6709\u5143\u7d20<\/p>\n<p><strong>zDelete,zRem(key, member)<\/strong><\/p>\n<div id=\"highlighter_674301\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;zAdd(<\/code><code>'key'<\/code><code>, 0, <\/code><code>'val0'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>2<\/code><\/td>\n<td><code>$redis-&gt;zAdd(<\/code><code>'key'<\/code><code>, 2, <\/code><code>'val2'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>3<\/code><\/td>\n<td><code>$redis-&gt;zAdd(<\/code><code>'key'<\/code><code>, 10, <\/code><code>'val10'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>4<\/code><\/td>\n<td><code>$redis-&gt;zDelete(<\/code><code>'key'<\/code><code>, <\/code><code>'val2'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>5<\/code><\/td>\n<td><code>$redis-&gt;zRange(<\/code><code>'key'<\/code><code>, 0, -1);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u5220\u9664\u540d\u79f0\u4e3akey\u7684zset\u4e2d\u7684\u5143\u7d20member<\/p>\n<p><strong>zRevRange(key, start, end,withscores)<\/strong><\/p>\n<div id=\"highlighter_498514\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;zAdd(<\/code><code>'key'<\/code><code>, 0, <\/code><code>'val0'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>2<\/code><\/td>\n<td><code>$redis-&gt;zAdd(<\/code><code>'key'<\/code><code>, 2, <\/code><code>'val2'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>3<\/code><\/td>\n<td><code>$redis-&gt;zAdd(<\/code><code>'key'<\/code><code>, 10, <\/code><code>'val10'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>4<\/code><\/td>\n<td><code>$redis-&gt;zRevRange(<\/code><code>'key'<\/code><code>, 0, -1); <\/code><code>\/\/ with scores $redis-&gt;zRevRange('key', 0, -1, true);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8fd4\u56de\u540d\u79f0\u4e3akey\u7684zset\uff08\u5143\u7d20\u5df2\u6309score\u4ece\u5927\u5230\u5c0f\u6392\u5e8f\uff09\u4e2d\u7684index\u4ecestart\u5230end\u7684\u6240\u6709\u5143\u7d20.withscores: \u662f\u5426\u8f93\u51fasocre\u7684\u503c\uff0c\u9ed8\u8ba4false\uff0c\u4e0d\u8f93\u51fa<\/p>\n<p><strong>zRangeByScore, zRevRangeByScore<\/strong><\/p>\n<div id=\"highlighter_504914\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;zRangeByScore(key, star, end, array(withscores\uff0c limit ));<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8fd4\u56de\u540d\u79f0\u4e3akey\u7684zset\u4e2dscore &gt;= star\u4e14score &lt;= end\u7684\u6240\u6709\u5143\u7d20<\/p>\n<p><strong>zCount<\/strong><\/p>\n<div id=\"highlighter_426492\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;zCount(key, star, end);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8fd4\u56de\u540d\u79f0\u4e3akey\u7684zset\u4e2dscore &gt;= star\u4e14score &lt;= end\u7684\u6240\u6709\u5143\u7d20\u7684\u4e2a\u6570<\/p>\n<p><strong>zRemRangeByScore, zDeleteRangeByScore<\/strong><\/p>\n<div id=\"highlighter_205298\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;zRemRangeByScore(<\/code><code>'key'<\/code><code>, star, end);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u5220\u9664\u540d\u79f0\u4e3akey\u7684zset\u4e2dscore &gt;= star\u4e14score &lt;= end\u7684\u6240\u6709\u5143\u7d20\uff0c\u8fd4\u56de\u5220\u9664\u4e2a\u6570<\/p>\n<p><strong>zSize, zCard<\/strong><\/p>\n<p>\u8fd4\u56de\u540d\u79f0\u4e3akey\u7684zset\u7684\u6240\u6709\u5143\u7d20\u7684\u4e2a\u6570<\/p>\n<p><strong>zScore<\/strong><\/p>\n<div id=\"highlighter_800984\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;zScore(key, val2);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8fd4\u56de\u540d\u79f0\u4e3akey\u7684zset\u4e2d\u5143\u7d20val2\u7684score<\/p>\n<p><strong>zRank, zRevRank<\/strong><\/p>\n<div id=\"highlighter_192647\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;zRevRank(key, val);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8fd4\u56de\u540d\u79f0\u4e3akey\u7684zset\uff08\u5143\u7d20\u5df2\u6309score\u4ece\u5c0f\u5230\u5927\u6392\u5e8f\uff09\u4e2dval\u5143\u7d20\u7684rank\uff08\u5373index\uff0c\u4ece0\u5f00\u59cb\uff09\uff0c\u82e5\u6ca1\u6709val\u5143\u7d20\uff0c\u8fd4\u56de\u201cnull\u201d\u3002zRevRank \u662f\u4ece\u5927\u5230\u5c0f\u6392\u5e8f<\/p>\n<p><strong>zIncrBy<\/strong><\/p>\n<div id=\"highlighter_345427\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;zIncrBy(<\/code><code>'key'<\/code><code>, increment, <\/code><code>'member'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u5982\u679c\u5728\u540d\u79f0\u4e3akey\u7684zset\u4e2d\u5df2\u7ecf\u5b58\u5728\u5143\u7d20member\uff0c\u5219\u8be5\u5143\u7d20\u7684score\u589e\u52a0increment\uff1b\u5426\u5219\u5411\u96c6\u5408\u4e2d\u6dfb\u52a0\u8be5\u5143\u7d20\uff0c\u5176score\u7684\u503c\u4e3aincrement<\/p>\n<p><strong>zUnion\/zInter<\/strong><\/p>\n<p>\u53c2\u6570<\/p>\n<ul>\n<li>keyOutput<\/li>\n<li>arrayZSetKeys<\/li>\n<li>arrayWeights<\/li>\n<li>aggregateFunction Either &#8220;SUM&#8221;, &#8220;MIN&#8221;, or &#8220;MAX&#8221;: defines the behaviour to use on duplicate entries during the zUnion.<\/li>\n<\/ul>\n<p>\u5bf9N\u4e2azset\u6c42\u5e76\u96c6\u548c\u4ea4\u96c6\uff0c\u5e76\u5c06\u6700\u540e\u7684\u96c6\u5408\u4fdd\u5b58\u5728dstkeyN\u4e2d\u3002\u5bf9\u4e8e\u96c6\u5408\u4e2d\u6bcf\u4e00\u4e2a\u5143\u7d20\u7684score\uff0c\u5728\u8fdb\u884cAGGREGATE\u8fd0\u7b97\u524d\uff0c\u90fd\u8981\u4e58\u4ee5\u5bf9\u4e8e \u7684WEIGHT\u53c2\u6570\u3002\u5982\u679c\u6ca1\u6709\u63d0\u4f9bWEIGHT\uff0c\u9ed8\u8ba4\u4e3a1\u3002\u9ed8\u8ba4\u7684AGGREGATE\u662fSUM\uff0c\u5373\u7ed3\u679c\u96c6\u5408\u4e2d\u5143\u7d20\u7684score\u662f\u6240\u6709\u96c6\u5408\u5bf9\u5e94\u5143\u7d20\u8fdb\u884c SUM\u8fd0\u7b97\u7684\u503c\uff0c\u800cMIN\u548cMAX\u662f\u6307\uff0c\u7ed3\u679c\u96c6\u5408\u4e2d\u5143\u7d20\u7684score\u662f\u6240\u6709\u96c6\u5408\u5bf9\u5e94\u5143\u7d20\u4e2d\u6700\u5c0f\u503c\u548c\u6700\u5927\u503c\u3002<\/p>\n<p><strong>Hash<strong>\u76f8\u5173<strong>\u64cd\u4f5c<\/strong><\/strong><\/strong><\/p>\n<p><strong>hSet<\/strong><\/p>\n<div id=\"highlighter_305854\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;hSet(<\/code><code>'h'<\/code><code>, <\/code><code>'key1'<\/code><code>, <\/code><code>'hello'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u5411\u540d\u79f0\u4e3ah\u7684hash\u4e2d\u6dfb\u52a0\u5143\u7d20key1\u2014&gt;hello<\/p>\n<p><strong>hGet<\/strong><\/p>\n<div id=\"highlighter_991437\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;hGet(<\/code><code>'h'<\/code><code>, <\/code><code>'key1'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8fd4\u56de\u540d\u79f0\u4e3ah\u7684hash\u4e2dkey1\u5bf9\u5e94\u7684value\uff08hello\uff09<\/p>\n<p><strong>hLen<\/strong><\/p>\n<div id=\"highlighter_375072\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;hLen(<\/code><code>'h'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8fd4\u56de\u540d\u79f0\u4e3ah\u7684hash\u4e2d\u5143\u7d20\u4e2a\u6570<\/p>\n<p><strong>hDel<\/strong><\/p>\n<div id=\"highlighter_638762\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;hDel(<\/code><code>'h'<\/code><code>, <\/code><code>'key1'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u5220\u9664\u540d\u79f0\u4e3ah\u7684hash\u4e2d\u952e\u4e3akey1\u7684\u57df<\/p>\n<p><strong>hKeys<\/strong><\/p>\n<div id=\"highlighter_332591\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;hKeys(<\/code><code>'h'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8fd4\u56de\u540d\u79f0\u4e3akey\u7684hash\u4e2d\u6240\u6709\u952e<\/p>\n<p><strong>hVals<\/strong><\/p>\n<div id=\"highlighter_843056\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;hVals(<\/code><code>'h'<\/code><code>)<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8fd4\u56de\u540d\u79f0\u4e3ah\u7684hash\u4e2d\u6240\u6709\u952e\u5bf9\u5e94\u7684value<\/p>\n<p><strong>hGetAll<\/strong><\/p>\n<div id=\"highlighter_69787\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;hGetAll(<\/code><code>'h'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8fd4\u56de\u540d\u79f0\u4e3ah\u7684hash\u4e2d\u6240\u6709\u7684\u952e\uff08field\uff09\u53ca\u5176\u5bf9\u5e94\u7684value<\/p>\n<p><strong>hExists<\/strong><\/p>\n<div id=\"highlighter_636765\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;hExists(<\/code><code>'h'<\/code><code>, <\/code><code>'a'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u540d\u79f0\u4e3ah\u7684hash\u4e2d\u662f\u5426\u5b58\u5728\u952e\u540d\u5b57\u4e3aa\u7684\u57df<\/p>\n<p><strong>hIncrBy<\/strong><\/p>\n<div id=\"highlighter_653453\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;hIncrBy(<\/code><code>'h'<\/code><code>, <\/code><code>'x'<\/code><code>, 2);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u5c06\u540d\u79f0\u4e3ah\u7684hash\u4e2dx\u7684value\u589e\u52a02<\/p>\n<p><strong>hMset<\/strong><\/p>\n<div id=\"highlighter_454559\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;hMset(<\/code><code>'user:1'<\/code><code>, array(<\/code><code>'name'<\/code> <code>=&gt; <\/code><code>'Joe'<\/code><code>, <\/code><code>'salary'<\/code> <code>=&gt; 2000));<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u5411\u540d\u79f0\u4e3akey\u7684hash\u4e2d\u6279\u91cf\u6dfb\u52a0\u5143\u7d20<\/p>\n<p><strong>hMGet<\/strong><\/p>\n<div id=\"highlighter_216891\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;hmGet(<\/code><code>'h'<\/code><code>, array(<\/code><code>'field1'<\/code><code>, <\/code><code>'field2'<\/code><code>));<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8fd4\u56de\u540d\u79f0\u4e3ah\u7684hash\u4e2dfield1,field2\u5bf9\u5e94\u7684value<\/p>\n<p><strong>redis \u76f8\u5173<strong>\u64cd\u4f5c<\/strong><\/strong><\/p>\n<p><strong>flushDB<\/strong><\/p>\n<p>\u6e05\u7a7a\u5f53\u524d\u6570\u636e\u5e93<\/p>\n<p><strong>flushAll<\/strong><\/p>\n<p>\u6e05\u7a7a\u6240\u6709\u6570\u636e\u5e93<\/p>\n<p><strong>randomKey<\/strong><\/p>\n<div id=\"highlighter_126467\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$key = $redis-&gt;randomKey();<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u968f\u673a\u8fd4\u56dekey\u7a7a\u95f4\u7684\u4e00\u4e2akey<\/p>\n<p><strong>select<\/strong><\/p>\n<p>\u9009\u62e9\u4e00\u4e2a\u6570\u636e\u5e93<\/p>\n<p><strong>move<\/strong><\/p>\n<div id=\"highlighter_892370\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;select(0); <\/code><code>\/\/ switch to DB 0<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>2<\/code><\/td>\n<td><code>$redis-&gt;<\/code><code>set<\/code><code>(<\/code><code>'x'<\/code><code>, <\/code><code>'42'<\/code><code>); <\/code><code>\/\/ write 42 to x<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>3<\/code><\/td>\n<td><code>$redis-&gt;move(<\/code><code>'x'<\/code><code>, 1); <\/code><code>\/\/ move to DB 1<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>4<\/code><\/td>\n<td><code>$redis-&gt;select(1); <\/code><code>\/\/ switch to DB 1<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>5<\/code><\/td>\n<td><code>$redis-&gt;<\/code><code>get<\/code><code>(<\/code><code>'x'<\/code><code>); <\/code><code>\/\/ will return 42<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8f6c\u79fb\u4e00\u4e2akey\u5230\u53e6\u5916\u4e00\u4e2a\u6570\u636e\u5e93<\/p>\n<p><strong>rename, renameKey<\/strong><\/p>\n<div id=\"highlighter_464034\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;<\/code><code>set<\/code><code>(<\/code><code>'x'<\/code><code>, <\/code><code>'42'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>2<\/code><\/td>\n<td><code>$redis-&gt;rename(<\/code><code>'x'<\/code><code>, <\/code><code>'y'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>3<\/code><\/td>\n<td><code>$redis-&gt;<\/code><code>get<\/code><code>(<\/code><code>'y'<\/code><code>); <\/code><code>\/\/ \u2192 42<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>4<\/code><\/td>\n<td><code>$redis-&gt;<\/code><code>get<\/code><code>(<\/code><code>'x'<\/code><code>); <\/code><code>\/\/ \u2192 `FALSE`<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u7ed9key\u91cd\u547d\u540d<\/p>\n<p><strong>renameNx<\/strong><\/p>\n<p>\u4e0eremane\u7c7b\u4f3c\uff0c\u4f46\u662f\uff0c\u5982\u679c\u91cd\u65b0\u547d\u540d\u7684\u540d\u5b57\u5df2\u7ecf\u5b58\u5728\uff0c\u4e0d\u4f1a\u66ff\u6362\u6210\u529f<\/p>\n<p><strong>setTimeout, expire<\/strong><\/p>\n<div id=\"highlighter_248281\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;setTimeout(<\/code><code>'x'<\/code><code>, 3);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8bbe\u5b9a\u4e00\u4e2akey\u7684\u6d3b\u52a8\u65f6\u95f4\uff08s\uff09<\/p>\n<p><strong>expireAt<\/strong><\/p>\n<div id=\"highlighter_707691\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;expireAt(<\/code><code>'x'<\/code><code>, time() + 3);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>key\u5b58\u6d3b\u5230\u4e00\u4e2aunix\u65f6\u95f4\u6233\u65f6\u95f4<\/p>\n<p><strong>keys, getKeys<\/strong><\/p>\n<div id=\"highlighter_423414\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$keyWithUserPrefix = $redis-&gt;keys(<\/code><code>'user*'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u8fd4\u56de\u6ee1\u8db3\u7ed9\u5b9apattern\u7684\u6240\u6709key<\/p>\n<p><strong>dbSize<\/strong><\/p>\n<div id=\"highlighter_153055\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$count = $redis-&gt;dbSize();<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u67e5\u770b\u73b0\u5728\u6570\u636e\u5e93\u6709\u591a\u5c11key<\/p>\n<p><strong>auth<\/strong><\/p>\n<div id=\"highlighter_239819\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;auth(<\/code><code>'foobared'<\/code><code>);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u5bc6\u7801\u8ba4\u8bc1<\/p>\n<p><strong>bgrewriteaof<\/strong><\/p>\n<div id=\"highlighter_521791\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;bgrewriteaof();<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u4f7f\u7528aof\u6765\u8fdb\u884c\u6570\u636e\u5e93\u6301\u4e45\u5316<\/p>\n<p><strong>slaveof<\/strong><\/p>\n<div id=\"highlighter_142788\">\n<div>\n<div>\n<table>\n<tbody>\n<tr>\n<td><code>1<\/code><\/td>\n<td><code>$redis-&gt;slaveof(<\/code><code>'10.0.1.7'<\/code><code>, 6379);<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<\/div>\n<p>\u9009\u62e9\u4ece\u670d\u52a1\u5668<\/p>\n<p><strong>save<\/strong><\/p>\n<p>\u5c06\u6570\u636e\u540c\u6b65\u4fdd\u5b58\u5230\u78c1\u76d8<\/p>\n<p><strong>bgsave<\/strong><\/p>\n<p>\u5c06\u6570\u636e\u5f02\u6b65\u4fdd\u5b58\u5230\u78c1\u76d8<\/p>\n<p><strong>lastSave<\/strong><\/p>\n<p>\u8fd4\u56de\u4e0a\u6b21\u6210\u529f\u5c06\u6570\u636e\u4fdd\u5b58\u5230\u78c1\u76d8\u7684Unix\u65f6\u6233<\/p>\n<p><strong>info<\/strong><\/p>\n<p>\u8fd4\u56deredis\u7684\u7248\u672c\u4fe1\u606f\u7b49\u8be6\u60c5<\/p>\n<p><strong>type<\/strong><\/p>\n<p>\u8fd4\u56dekey\u7684\u7c7b\u578b\u503c<\/p>\n<p>string: Redis::REDIS_STRING<\/p>\n<p>set: Redis::REDIS_SET<\/p>\n<p>list: Redis::REDIS_LIST<\/p>\n<p>zset: Redis::REDIS_ZSET<\/p>\n<p>hash: Redis::REDIS_HASH<\/p>\n<p>other: Redis::REDIS_NOT_FOUND<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>PhpRedis\u662fphp\u7684\u4e00\u4e2a\u6269\u5c55\uff0c\u6548\u7387\u662f\u76f8\u5f53\u9ad8\u6709\u94fe\u8868\u6392\u5e8f\u529f\u80fd\uff0c\u5bf9\u521b&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,18],"tags":[36,160,32,55],"class_list":["post-1002","post","type-post","status-publish","format-standard","hentry","category-NetOS","category-Php","tag-php-2","tag-redis","tag-32","tag-55"],"_links":{"self":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/1002","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1002"}],"version-history":[{"count":2,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/1002\/revisions"}],"predecessor-version":[{"id":1004,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/1002\/revisions\/1004"}],"wp:attachment":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1002"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1002"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1002"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}