{"id":1006,"date":"2013-10-17T10:44:13","date_gmt":"2013-10-17T02:44:13","guid":{"rendered":"http:\/\/www.poloo.org\/?p=1006"},"modified":"2013-10-17T10:44:13","modified_gmt":"2013-10-17T02:44:13","slug":"redis%e5%9c%a8php%e4%b8%ad%e7%9a%84%e5%9f%ba%e6%9c%ac%e4%bd%bf%e7%94%a8%e6%a1%88%e4%be%8b","status":"publish","type":"post","link":"https:\/\/www.poloo.org\/?p=1006","title":{"rendered":"redis\u5728PHP\u4e2d\u7684\u57fa\u672c\u4f7f\u7528\u6848\u4f8b"},"content":{"rendered":"<p><strong>\/\/\u666e\u901aset\/get\u64cd\u4f5c<\/strong><br \/>\n$redis-&gt;set(\u2018library\u2019, \u2018predis\u2019);<br \/>\n$retval = $redis-&gt;get(\u2018library\u2019);<br \/>\necho $retval; \/\/\u663e\u793a \u2018predis\u2019<\/p>\n<p><strong>\/\/setex set\u4e00\u4e2a\u5b58\u50a8\u65f6\u6548<\/strong><br \/>\n$redis-&gt;setex(\u2018str\u2019, 10, \u2018bar\u2019); \/\/\u8868\u793a\u5b58\u50a8\u6709\u6548\u671f\u4e3a10\u79d2<\/p>\n<p><strong>\/\/setnx\/msetnx\u76f8\u5f53\u4e8eadd\u64cd\u4f5c,\u4e0d\u4f1a\u8986\u76d6\u5df2\u6709\u503c<\/strong><br \/>\n$redis-&gt;setnx(\u2018foo\u2019,12); \/\/true<br \/>\n$redis-&gt;setnx(\u2018foo\u2019,34); \/\/false<\/p>\n<p><strong>\/\/getset\u64cd\u4f5c,set\u7684\u53d8\u79cd,\u7ed3\u679c\u8fd4\u56de\u66ff\u6362\u524d\u7684\u503c<\/strong><br \/>\n$redis-&gt;getset(\u2018foo\u2019,56);\/\/\u8fd4\u56de34<\/p>\n<p><strong>\/\/ incrby\/incr\/decrby\/decr \u5bf9\u503c\u7684\u9012\u589e\u548c\u9012\u51cf<\/strong><br \/>\n$redis-&gt;incr(\u2018foo\u2019); \/\/foo\u4e3a57<br \/>\n$redis-&gt;incrby(\u2018foo\u2019,2); \/\/foo\u4e3a59<\/p>\n<p><strong>\/\/exists\u68c0\u6d4b\u662f\u5426\u5b58\u5728\u67d0\u503c<\/strong><br \/>\n$redis-&gt;exists(\u2018foo\u2019);\/\/true<\/p>\n<p><!--more--><\/p>\n<p><strong>\/\/del \u5220\u9664<\/strong><br \/>\n$redis-&gt;del(\u2018foo\u2019);\/\/true<\/p>\n<p><strong>\/\/type \u7c7b\u578b\u68c0\u6d4b,\u5b57\u7b26\u4e32\u8fd4\u56destring,\u5217\u8868\u8fd4\u56de list,set\u8868\u8fd4\u56deset\/zset,hash\u8868\u8fd4\u56dehash<\/strong><br \/>\n$redis-&gt;type(\u2018foo\u2019);\/\/\u4e0d\u5b58\u5728,\u8fd4\u56denone<br \/>\n$redis-&gt;set(\u2018str\u2019,&#8217;test\u2019);<br \/>\n$redis-&gt;type(\u2018str\u2019); \/\/\u5b57\u7b26\u4e32\uff0c\u8fd4\u56destring<\/p>\n<p><strong>\/\/append \u8fde\u63a5\u5230\u5df2\u5b58\u5728\u5b57\u7b26\u4e32<\/strong><br \/>\n$redis-&gt;append(\u2018str\u2019,&#8217;_123\u2032); \/\/\u8fd4\u56de\u7d2f\u52a0\u540e\u7684\u5b57\u7b26\u4e32\u957f\u5ea68,\u6b64\u8fdbstr\u4e3a \u2018test_123\u2032<\/p>\n<p><strong>\/\/setrange \u90e8\u5206\u66ff\u6362\u64cd\u4f5c<\/strong><br \/>\n$redis-&gt;setrange(\u2018str\u2019,0,\u2019abc\u2019); \/\/\u8fd4\u56de3,\u53c2\u65702\u4e3a0\u65f6\u7b49\u540c\u4e8eset\u64cd\u4f5c<br \/>\n$redis-&gt;setrange(\u2018str\u2019,2,\u2019cd\u2019);\/\/\u8fd4\u56de4,\u8868\u793a\u4ece\u7b2c2\u4e2a\u5b57\u7b26\u540e\u66ff\u6362,\u8fd9\u65f6\u2019str\u2019\u4e3a\u2019abcd\u2019<\/p>\n<p><strong>\/\/substr \u90e8\u5206\u83b7\u53d6\u64cd\u4f5c<\/strong><br \/>\n$redis-&gt;substr(\u2018str\u2019,0,2);\/\/\u8868\u793a\u4ece\u7b2c0\u4e2a\u8d77\uff0c\u53d6\u5230\u7b2c2\u4e2a\u5b57\u7b26\uff0c\u51713\u4e2a\uff0c\u8fd4\u56de\u2019abc\u2019<\/p>\n<p><strong>\/\/strlen \u83b7\u53d6\u5b57\u7b26\u4e32\u957f\u5ea6<\/strong><br \/>\n$redis-&gt;strlen(\u2018str\u2019); \/\/\u8fd4\u56de4<\/p>\n<p><strong>\/\/setbit\/getbit \u4f4d\u5b58\u50a8\u548c\u83b7\u53d6<\/strong><br \/>\n$redis-&gt;setbit(\u2018binary\u2019,31,1);\u00a0 \/\/\u8868\u793a\u5728\u7b2c31\u4f4d\u5b58\u51651,\u8fd9\u8fb9\u53ef\u80fd\u4f1a\u6709\u5927\u5c0f\u7aef\u95ee\u9898?\u4e0d\u8fc7\u6ca1\u5173\u7cfb,getbit \u5e94\u8be5\u4e0d\u4f1a\u6709\u95ee\u9898<br \/>\n$redis-&gt;getbit(\u2018binary\u2019,31);\u00a0\u00a0\u00a0 \/\/\u8fd4\u56de1<\/p>\n<p><strong>\/\/keys \u6a21\u7cca\u67e5\u627e\u529f\u80fd,\u652f\u6301*\u53f7\u4ee5\u53ca?\u53f7(\u5339\u914d\u4e00\u4e2a\u5b57\u7b26)<\/strong><br \/>\n$redis-&gt;set(\u2018foo1\u2032,123);<br \/>\n$redis-&gt;set(\u2018foo2\u2032,456);<br \/>\n$redis-&gt;keys(\u2018foo*\u2019); \/\/\u8fd4\u56defoo1\u548cfoo2\u7684array<br \/>\n$redis-&gt;keys(\u2018f?o?\u2019);\u00a0 \/\/\u540c\u4e0a<\/p>\n<p><strong>\/\/randomkey \u968f\u673a\u8fd4\u56de\u4e00\u4e2akey<\/strong><br \/>\n$redis-&gt;randomkey(); \/\/\u53ef\u80fd\u662f\u8fd4\u56de \u2018foo1\u2032\u6216\u8005\u662f\u2019foo2\u2032\u53ca\u5176\u5b83\u4efb\u4f55\u4e00\u5b58\u5728redis\u7684key<\/p>\n<p><strong>\/\/rename\/renamenx \u5bf9key\u8fdb\u884c\u6539\u540d,\u6240\u4e0d\u540c\u7684\u662frenamenx\u4e0d\u5141\u8bb8\u6539\u6210\u5df2\u5b58\u5728\u7684key<\/strong><br \/>\n$redis-&gt;rename(\u2018str\u2019,&#8217;str2\u2032); \/\/\u628a\u539f\u5148\u547d\u540d\u4e3a\u2019str\u2019\u7684key\u6539\u6210\u4e86\u2019str2\u2032<\/p>\n<p><strong>\/\/expire \u8bbe\u7f6ekey-value\u7684\u65f6\u6548\u6027,ttl \u83b7\u53d6\u5269\u4f59\u6709\u6548\u671f,persist \u91cd\u65b0\u8bbe\u7f6e\u4e3a\u6c38\u4e45\u5b58\u50a8<\/strong><br \/>\n$redis-&gt;expire(\u2018foo\u2019, 1); \/\/\u8bbe\u7f6e\u6709\u6548\u671f\u4e3a1\u79d2<br \/>\n$redis-&gt;ttl(\u2018foo\u2019); \/\/\u8fd4\u56de\u6709\u6548\u671f\u503c1s<br \/>\n$redis-&gt;expire(\u2018foo\u2019); \/\/\u53d6\u6d88expire\u884c\u4e3a<\/p>\n<p><strong>\/\/dbsize \u8fd4\u56deredis\u5f53\u524d\u6570\u636e\u5e93\u7684\u8bb0\u5f55\u603b\u6570<\/strong><br \/>\n$redis-&gt;dbsize();<\/p>\n<p><strong>\/*<\/strong><br \/>\n<strong> \u961f\u5217\u64cd\u4f5c<\/strong><br \/>\n<strong> *\/<\/strong><\/p>\n<p><strong>\/\/rpush\/rpushx \u6709\u5e8f\u5217\u8868\u64cd\u4f5c,\u4ece\u961f\u5217\u540e\u63d2\u5165\u5143\u7d20<\/strong><br \/>\n\/\/lpush\/lpushx \u548crpush\/rpushx\u7684\u533a\u522b\u662f\u63d2\u5165\u5230\u961f\u5217\u7684\u5934\u90e8,\u540c\u4e0a,\u2019x&#8217;\u542b\u4e49\u662f\u53ea\u5bf9\u5df2\u5b58\u5728\u7684key\u8fdb\u884c\u64cd\u4f5c<br \/>\n$redis-&gt;rpush(\u2018fooList\u2019, \u2018bar1\u2032); \/\/\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\u7684\u957f\u5ea61<br \/>\n$redis-&gt;lpush(\u2018fooList\u2019, \u2018bar0\u2032); \/\/\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\u7684\u957f\u5ea62<br \/>\n$redis-&gt;rpushx(\u2018fooList\u2019, \u2018bar2\u2032); \/\/\u8fd4\u56de3,rpushx\u53ea\u5bf9\u5df2\u5b58\u5728\u7684\u961f\u5217\u505a\u6dfb\u52a0,\u5426\u5219\u8fd4\u56de0<br \/>\n<strong> \/\/llen\u8fd4\u56de\u5f53\u524d\u5217\u8868\u957f\u5ea6<\/strong><br \/>\n$redis-&gt;llen(\u2018fooList\u2019);\/\/3<\/p>\n<p><strong>\/\/lrange \u8fd4\u56de\u961f\u5217\u4e2d\u4e00\u4e2a\u533a\u95f4\u7684\u5143\u7d20<\/strong><br \/>\n$redis-&gt;lrange(\u2018fooList\u2019,0,1); \/\/\u8fd4\u56de\u6570\u7ec4\u5305\u542b\u7b2c0\u4e2a\u81f3\u7b2c1\u4e2a\u51712\u4e2a\u5143\u7d20<br \/>\n$redis-&gt;lrange(\u2018fooList\u2019,0,-1);\/\/\u8fd4\u56de\u7b2c0\u4e2a\u81f3\u5012\u6570\u7b2c\u4e00\u4e2a,\u76f8\u5f53\u4e8e\u8fd4\u56de\u6240\u6709\u5143\u7d20,\u6ce8\u610fredis\u4e2d\u5f88\u591a\u65f6\u5019\u4f1a\u7528\u5230\u8d1f\u6570,\u4e0b\u540c<\/p>\n<p><strong>\/\/lindex \u8fd4\u56de\u6307\u5b9a\u987a\u5e8f\u4f4d\u7f6e\u7684list\u5143\u7d20<\/strong><br \/>\n$redis-&gt;lindex(\u2018fooList\u2019,1); \/\/\u8fd4\u56de\u2019bar1\u2032<\/p>\n<p><strong>\/\/lset \u4fee\u6539\u961f\u5217\u4e2d\u6307\u5b9a\u4f4d\u7f6e\u7684value<\/strong><br \/>\n$redis-&gt;lset(\u2018fooList\u2019,1,\u2019123\u2032);\/\/\u4fee\u6539\u4f4d\u7f6e1\u7684\u5143\u7d20,\u8fd4\u56detrue<\/p>\n<p><strong>\/\/lrem \u5220\u9664\u961f\u5217\u4e2d\u5de6\u8d77\u6307\u5b9a\u6570\u91cf\u7684\u5b57\u7b26<\/strong><br \/>\n$redis-&gt;lrem(\u2018fooList\u2019,1,\u2019_&#8217;); \/\/\u5220\u9664\u961f\u5217\u4e2d\u5de6\u8d77(\u53f3\u8d77\u4f7f\u7528-1)1\u4e2a\u5b57\u7b26\u2019_'(\u82e5\u6709)<\/p>\n<p><strong>\/\/lpop\/rpop \u7c7b\u4f3c\u6808\u7ed3\u6784\u5730\u5f39\u51fa(\u5e76\u5220\u9664)\u6700\u5de6\u6216\u6700\u53f3\u7684\u4e00\u4e2a\u5143\u7d20<\/strong><br \/>\n$redis-&gt;lpop(\u2018fooList\u2019); \/\/\u2019bar0\u2032<br \/>\n$redis-&gt;rpop(\u2018fooList\u2019); \/\/\u2019bar2\u2032<\/p>\n<p><strong>\/\/ltrim \u961f\u5217\u4fee\u6539\uff0c\u4fdd\u7559\u5de6\u8fb9\u8d77\u82e5\u5e72\u5143\u7d20\uff0c\u5176\u4f59\u5220\u9664<\/strong><br \/>\n$redis-&gt;ltrim(\u2018fooList\u2019, 0,1); \/\/\u4fdd\u7559\u5de6\u8fb9\u8d77\u7b2c0\u4e2a\u81f3\u7b2c1\u4e2a\u5143\u7d20<\/p>\n<p><strong>\/\/rpoplpush \u4ece\u4e00\u4e2a\u961f\u5217\u4e2dpop\u51fa\u5143\u7d20\u5e76push\u5230\u53e6\u4e00\u4e2a\u961f\u5217<\/strong><br \/>\n$redis-&gt;rpush(\u2018list1\u2032,\u2019ab0\u2032);<br \/>\n$redis-&gt;rpush(\u2018list1\u2032,\u2019ab1\u2032);<br \/>\n$redis-&gt;rpush(\u2018list2\u2032,\u2019ab2\u2032);<br \/>\n$redis-&gt;rpush(\u2018list2\u2032,\u2019ab3\u2032);<br \/>\n$redis-&gt;rpoplpush(\u2018list1\u2032,\u2019list2\u2032);\/\/\u7ed3\u679clist1 =&gt;array(\u2018ab0\u2032),list2 =&gt;array(\u2018ab1\u2032,\u2019ab2\u2032,\u2019ab3\u2032)<br \/>\n$redis-&gt;rpoplpush(\u2018list2\u2032,\u2019list2\u2032);\/\/\u4e5f\u9002\u7528\u4e8e\u540c\u4e00\u4e2a\u961f\u5217,\u628a\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u79fb\u5230\u5934\u90e8list2 =&gt;array(\u2018ab3\u2032,\u2019ab1\u2032,\u2019ab2\u2032)<\/p>\n<p><strong>\/\/linsert \u5728\u961f\u5217\u7684\u4e2d\u95f4\u6307\u5b9a\u5143\u7d20\u524d\u6216\u540e\u63d2\u5165\u5143\u7d20<\/strong><br \/>\n$redis-&gt;linsert(\u2018list2\u2032, \u2018before\u2019,&#8217;ab1\u2032,\u2019123\u2032); \/\/\u8868\u793a\u5728\u5143\u7d20\u2019ab1\u2032\u4e4b\u524d\u63d2\u5165\u2019123\u2032<br \/>\n$redis-&gt;linsert(\u2018list2\u2032, \u2018after\u2019,&#8217;ab1\u2032,\u2019456\u2032);\u00a0\u00a0 \/\/\u8868\u793a\u5728\u5143\u7d20\u2019ab1\u2032\u4e4b\u540e\u63d2\u5165\u2019456\u2032<\/p>\n<p><strong>\/\/blpop\/brpop \u963b\u585e\u5e76\u7b49\u5f85\u4e00\u4e2a\u5217\u961f\u4e0d\u4e3a\u7a7a\u65f6\uff0c\u518dpop\u51fa\u6700\u5de6\u6216\u6700\u53f3\u7684\u4e00\u4e2a\u5143\u7d20\uff08\u8fd9\u4e2a\u529f\u80fd\u5728php\u4ee5\u5916\u53ef\u4ee5\u8bf4\u975e\u5e38\u597d\u7528\uff09<\/strong><br \/>\n\/\/brpoplpush \u540c\u6837\u662f\u963b\u585e\u5e76\u7b49\u5f85\u64cd\u4f5c\uff0c\u7ed3\u679c\u540crpoplpush\u4e00\u6837<br \/>\n$redis-&gt;blpop(\u2018list3\u2032,10); \/\/\u5982\u679clist3\u4e3a\u7a7a\u5219\u4e00\u76f4\u7b49\u5f85,\u76f4\u5230\u4e0d\u4e3a\u7a7a\u65f6\u5c06\u7b2c\u4e00\u5143\u7d20\u5f39\u51fa,10\u79d2\u540e\u8d85\u65f6<\/p>\n<p><strong>\/**<\/strong><br \/>\n<strong> set\u8868\u64cd\u4f5c<\/strong><br \/>\n<strong> *\/<\/strong><\/p>\n<p><strong>\/\/sadd \u589e\u52a0\u5143\u7d20,\u8fd4\u56detrue,\u91cd\u590d\u8fd4\u56defalse<\/strong><br \/>\n$redis-&gt;sadd(\u2018set1\u2032,\u2019ab\u2019);<br \/>\n$redis-&gt;sadd(\u2018set1\u2032,\u2019cd\u2019);<br \/>\n$redis-&gt;sadd(\u2018set1\u2032,\u2019ef\u2019);<\/p>\n<p><strong>\/\/srem \u79fb\u9664\u6307\u5b9a\u5143\u7d20<\/strong><br \/>\n$redis-&gt;srem(\u2018set1\u2032,\u2019cd\u2019); \/\/\u5220\u9664\u2019cd\u2019\u5143\u7d20<\/p>\n<p><strong>\/\/spop \u5f39\u51fa\u9996\u5143\u7d20<\/strong><br \/>\n$redis-&gt;spop(\u2018set1\u2032);<\/p>\n<p><strong>\/\/smove \u79fb\u52a8\u5f53\u524dset\u8868\u7684\u6307\u5b9a\u5143\u7d20\u5230\u53e6\u4e00\u4e2aset\u8868<\/strong><br \/>\n$redis-&gt;sadd(\u2018set2\u2032,\u2019123\u2032);<br \/>\n$redis-&gt;smove(\u2018set1\u2032,\u2019set2\u2032,\u2019ab\u2019);\/\/\u79fb\u52a8\u2019set1\u2032\u4e2d\u7684\u2019ab\u2019\u5230\u2019set2\u2032,\u8fd4\u56detrue or false<\/p>\n<p><strong>\/\/scard \u8fd4\u56de\u5f53\u524dset\u8868\u5143\u7d20\u4e2a\u6570<\/strong><br \/>\n$redis-&gt;scard(\u2018set2\u2032);\/\/2<\/p>\n<p><strong>\/\/sismember \u5224\u65ad\u5143\u7d20\u662f\u5426\u5c5e\u4e8e\u5f53\u524d\u8868<\/strong><br \/>\n$redis-&gt;sismember(\u2018set2\u2032,\u2019123\u2032); \/\/true or false<\/p>\n<p><strong>\/\/smembers \u8fd4\u56de\u5f53\u524d\u8868\u7684\u6240\u6709\u5143\u7d20<\/strong><br \/>\n$redis-&gt;smembers(\u2018set2\u2032); \/\/array(\u2019123\u2032,\u2019ab\u2019);<\/p>\n<p><strong>\/\/sinter\/sunion\/sdiff\u00a0 \u8fd4\u56de\u4e24\u4e2a\u8868\u4e2d\u5143\u7d20\u7684\u4ea4\u96c6\/\u5e76\u96c6\/\u8865\u96c6<\/strong><br \/>\n$redis-&gt;sadd(\u2018set1\u2032,\u2019ab\u2019);<br \/>\n$redis-&gt;sinter(\u2018set2\u2032,\u2019set1\u2032); \/\/\u8fd4\u56dearray(\u2018ab\u2019)<\/p>\n<p><strong>\/\/sinterstore\/sunionstore\/sdiffstore \u5c06\u4e24\u4e2a\u8868\u4ea4\u96c6\/\u5e76\u96c6\/\u8865\u96c6\u5143\u7d20copy\u5230\u7b2c\u4e09\u4e2a\u8868\u4e2d<\/strong><br \/>\n$redis-&gt;set(\u2018foo\u2019,0);<br \/>\n$redis-&gt;sinterstore(\u2018foo\u2019,&#8217;set1\u2032); \/\/\u8fd9\u8fb9\u7b49\u540c\u4e8e\u5c06\u2019set1\u2032\u7684\u5185\u5bb9copy\u5230\u2019foo\u2019\u4e2d\uff0c\u5e76\u5c06\u2019foo\u2019\u8f6c\u4e3aset\u8868<br \/>\n$redis-&gt;sinterstore(\u2018foo\u2019,array(\u2018set1\u2032,\u2019set2\u2032)); \/\/\u5c06\u2019set1\u2032\u548c\u2019set2\u2032\u4e2d\u76f8\u540c\u7684\u5143\u7d20copy\u5230\u2019foo\u2019\u8868\u4e2d,\u8986\u76d6\u2019foo\u2019\u539f\u6709\u5185\u5bb9<\/p>\n<p><strong>\/\/srandmember \u8fd4\u56de\u8868\u4e2d\u4e00\u4e2a\u968f\u673a\u5143\u7d20<\/strong><br \/>\n$redis-&gt;srandmember(\u2018set1\u2032);<\/p>\n<p><strong>\/**<\/strong><br \/>\n<strong> \u6709\u5e8fset\u8868\u64cd\u4f5c<\/strong><br \/>\n<strong> *\/<\/strong><\/p>\n<p><strong>\/\/sadd \u589e\u52a0\u5143\u7d20,\u5e76\u8bbe\u7f6e\u5e8f\u53f7,\u8fd4\u56detrue,\u91cd\u590d\u8fd4\u56defalse<\/strong><br \/>\n$redis-&gt;zadd(\u2018zset1\u2032,1,\u2019ab\u2019);<br \/>\n$redis-&gt;zadd(\u2018zset1\u2032,2,\u2019cd\u2019);<br \/>\n$redis-&gt;zadd(\u2018zset1\u2032,3,\u2019ef\u2019);<\/p>\n<p><strong>\/\/zincrby \u5bf9\u6307\u5b9a\u5143\u7d20\u7d22\u5f15\u503c\u7684\u589e\u51cf,\u6539\u53d8\u5143\u7d20\u6392\u5217\u6b21\u5e8f<\/strong><br \/>\n$redis-&gt;zincrby(\u2018zset1\u2032,10,\u2019ab\u2019);\/\/\u8fd4\u56de11<\/p>\n<p><strong>\/\/zrem \u79fb\u9664\u6307\u5b9a\u5143\u7d20<\/strong><br \/>\n$redis-&gt;zrem(\u2018zset1\u2032,\u2019ef\u2019); \/\/true or false<\/p>\n<p><strong>\/\/zrange \u6309\u4f4d\u7f6e\u6b21\u5e8f\u8fd4\u56de\u8868\u4e2d\u6307\u5b9a\u533a\u95f4\u7684\u5143\u7d20<\/strong><br \/>\n$redis-&gt;zrange(\u2018zset1\u2032,0,1); \/\/\u8fd4\u56de\u4f4d\u7f6e0\u548c1\u4e4b\u95f4(\u4e24\u4e2a)\u7684\u5143\u7d20<br \/>\n$redis-&gt;zrange(\u2018zset1\u2032,0,-1);\/\/\u8fd4\u56de\u4f4d\u7f6e0\u548c\u5012\u6570\u7b2c\u4e00\u4e2a\u5143\u7d20\u4e4b\u95f4\u7684\u5143\u7d20(\u76f8\u5f53\u4e8e\u6240\u6709\u5143\u7d20)<\/p>\n<p><strong>\/\/zrevrange \u540c\u4e0a,\u8fd4\u56de\u8868\u4e2d\u6307\u5b9a\u533a\u95f4\u7684\u5143\u7d20,\u6309\u6b21\u5e8f\u5012\u6392<\/strong><br \/>\n$redis-&gt;zrevrange(\u2018zset1\u2032,0,-1); \/\/\u5143\u7d20\u987a\u5e8f\u548czrange\u76f8\u53cd<\/p>\n<p><strong>\/\/zrangebyscore\/zrevrangebyscore \u6309\u987a\u5e8f\/\u964d\u5e8f\u8fd4\u56de\u8868\u4e2d\u6307\u5b9a\u7d22\u5f15\u533a\u95f4\u7684\u5143\u7d20<\/strong><br \/>\n$redis-&gt;zadd(\u2018zset1\u2032,3,\u2019ef\u2019);<br \/>\n$redis-&gt;zadd(\u2018zset1\u2032,5,\u2019gh\u2019);<br \/>\n$redis-&gt;zrangebyscore(\u2018zset1\u2032,2,9); \/\/\u8fd4\u56de\u7d22\u5f15\u503c2-9\u4e4b\u95f4\u7684\u5143\u7d20 array(\u2018ef\u2019,&#8217;gh\u2019)<br \/>\n\/\/\u53c2\u6570\u5f62\u5f0f<br \/>\n$redis-&gt;zrangebyscore(\u2018zset1\u2032,2,9,\u2019withscores\u2019); \/\/\u8fd4\u56de\u7d22\u5f15\u503c2-9\u4e4b\u95f4\u7684\u5143\u7d20\u5e76\u5305\u542b\u7d22\u5f15\u503c array(array(\u2018ef\u2019,3),array(\u2018gh\u2019,5))<br \/>\n$redis-&gt;zrangebyscore(\u2018zset1\u2032,2,9,array(\u2018withscores\u2019 =&gt;true,\u2019limit\u2019=&gt;array(1, 2))); \/\/\u8fd4\u56de\u7d22\u5f15\u503c2-9\u4e4b\u95f4\u7684\u5143\u7d20,\u2019withscores\u2019 =&gt;true\u8868\u793a\u5305\u542b\u7d22\u5f15\u503c; \u2018limit\u2019=&gt;array(1, 2),\u8868\u793a\u6700\u591a\u8fd4\u56de2\u6761,\u7ed3\u679c\u4e3aarray(array(\u2018ef\u2019,3),array(\u2018gh\u2019,5))<\/p>\n<p><strong>\/\/zunionstore\/zinterstore \u5c06\u591a\u4e2a\u8868\u7684\u5e76\u96c6\/\u4ea4\u96c6\u5b58\u5165\u53e6\u4e00\u4e2a\u8868\u4e2d<\/strong><br \/>\n$redis-&gt;zunionstore(\u2018zset3\u2032,array(\u2018zset1\u2032,\u2019zset2\u2032,\u2019zset0\u2032)); \/\/\u5c06\u2019zset1\u2032,\u2019zset2\u2032,\u2019zset0\u2032\u7684\u5e76\u96c6\u5b58\u5165\u2019zset3\u2032<br \/>\n\/\/\u5176\u5b83\u53c2\u6570<br \/>\n$redis-&gt;zunionstore(\u2018zset3\u2032,array(\u2018zset1\u2032,\u2019zset2\u2032),array(\u2018weights\u2019 =&gt; array(5,0)));\/\/weights\u53c2\u6570\u8868\u793a\u6743\u91cd\uff0c\u5176\u4e2d\u8868\u793a\u5e76\u96c6\u540e\u503c\u5927\u4e8e5\u7684\u5143\u7d20\u6392\u5728\u524d\uff0c\u5927\u4e8e0\u7684\u6392\u5728\u540e<br \/>\n$redis-&gt;zunionstore(\u2018zset3\u2032,array(\u2018zset1\u2032,\u2019zset2\u2032),array(\u2018aggregate\u2019 =&gt; \u2018max\u2019));\/\/\u2019aggregate\u2019 =&gt; \u2018max\u2019\u6216\u2019min\u2019\u8868\u793a\u5e76\u96c6\u540e\u76f8\u540c\u7684\u5143\u7d20\u662f\u53d6\u5927\u503c\u6216\u662f\u53d6\u5c0f\u503c<\/p>\n<p><strong>\/\/zcount \u7edf\u8ba1\u4e00\u4e2a\u7d22\u5f15\u533a\u95f4\u7684\u5143\u7d20\u4e2a\u6570<\/strong><br \/>\n$redis-&gt;zcount(\u2018zset1\u2032,3,5);\/\/2<br \/>\n$redis-&gt;zcount(\u2018zset1\u2032,\u2019(3\u2032,5)); \/\/\u2019(3\u2032\u8868\u793a\u7d22\u5f15\u503c\u57283-5\u4e4b\u95f4\u4f46\u4e0d\u542b3,\u540c\u7406\u4e5f\u53ef\u4ee5\u4f7f\u7528\u2019(5\u2032\u8868\u793a\u4e0a\u9650\u4e3a5\u4f46\u4e0d\u542b5<\/p>\n<p><strong>\/\/zcard \u7edf\u8ba1\u5143\u7d20\u4e2a\u6570<\/strong><br \/>\n$redis-&gt;zcard(\u2018zset1\u2032);\/\/4<\/p>\n<p><strong>\/\/zscore \u67e5\u8be2\u5143\u7d20\u7684\u7d22\u5f15<\/strong><br \/>\n$redis-&gt;zscore(\u2018zset1\u2032,\u2019ef\u2019);\/\/3<\/p>\n<p><strong>\/\/zremrangebyscore \u5220\u9664\u4e00\u4e2a\u7d22\u5f15\u533a\u95f4\u7684\u5143\u7d20<\/strong><br \/>\n$redis-&gt;zremrangebyscore(\u2018zset1\u2032,0,2); \/\/\u5220\u9664\u7d22\u5f15\u57280-2\u4e4b\u95f4\u7684\u5143\u7d20(\u2018ab\u2019,&#8217;cd\u2019),\u8fd4\u56de\u5220\u9664\u5143\u7d20\u4e2a\u65702<\/p>\n<p><strong>\/\/zrank\/zrevrank \u8fd4\u56de\u5143\u7d20\u6240\u5728\u8868\u987a\u5e8f\/\u964d\u5e8f\u7684\u4f4d\u7f6e(\u4e0d\u662f\u7d22\u5f15)<\/strong><br \/>\n$redis-&gt;zrank(\u2018zset1\u2032,\u2019ef\u2019);\/\/\u8fd4\u56de0,\u56e0\u4e3a\u5b83\u662f\u7b2c\u4e00\u4e2a\u5143\u7d20;zrevrank\u5219\u8fd4\u56de1(\u6700\u540e\u4e00\u4e2a)<\/p>\n<p><strong>\/\/zremrangebyrank \u5220\u9664\u8868\u4e2d\u6307\u5b9a\u4f4d\u7f6e\u533a\u95f4\u7684\u5143\u7d20<\/strong><br \/>\n$redis-&gt;zremrangebyrank(\u2018zset1\u2032,0,10); \/\/\u5220\u9664\u4f4d\u7f6e\u4e3a0-10\u7684\u5143\u7d20,\u8fd4\u56de\u5220\u9664\u7684\u5143\u7d20\u4e2a\u65702<\/p>\n<p><strong>\/**<\/strong><br \/>\n<strong> hash\u8868\u64cd\u4f5c<\/strong><br \/>\n<strong> *\/<\/strong><\/p>\n<p><strong>\/\/hset\/hget \u5b58\u53d6hash\u8868\u7684\u6570\u636e<\/strong><br \/>\n$redis-&gt;hset(\u2018hash1\u2032,\u2019key1\u2032,\u2019v1\u2032); \/\/\u5c06key\u4e3a\u2019key1\u2032 value\u4e3a\u2019v1\u2032\u7684\u5143\u7d20\u5b58\u5165hash1\u8868<br \/>\n$redis-&gt;hset(\u2018hash1\u2032,\u2019key2\u2032,\u2019v2\u2032);<br \/>\n$redis-&gt;hget(\u2018hash1\u2032,\u2019key1\u2032);\u00a0 \/\/\u53d6\u51fa\u8868\u2019hash1\u2032\u4e2d\u7684key \u2018key1\u2032\u7684\u503c,\u8fd4\u56de\u2019v1\u2032<\/p>\n<p><strong>\/\/hexists \u8fd4\u56dehash\u8868\u4e2d\u7684\u6307\u5b9akey\u662f\u5426\u5b58\u5728<\/strong><br \/>\n$redis-&gt;hexists (\u2018hash1\u2032,\u2019key1\u2032); \/\/true or false<\/p>\n<p><strong>\/\/hdel \u5220\u9664hash\u8868\u4e2d\u6307\u5b9akey\u7684\u5143\u7d20<\/strong><br \/>\n$redis-&gt;hdel(\u2018hash1\u2032,\u2019key2\u2032); \/\/true or false<\/p>\n<p><strong>\/\/hlen \u8fd4\u56dehash\u8868\u5143\u7d20\u4e2a\u6570<\/strong><br \/>\n$redis-&gt;hlen(\u2018hash1\u2032); \/\/1<\/p>\n<p><strong>\/\/hsetnx \u589e\u52a0\u4e00\u4e2a\u5143\u7d20,\u4f46\u4e0d\u80fd\u91cd\u590d<\/strong><br \/>\n$redis-&gt;hsetnx(\u2018hash1\u2032,\u2019key1\u2032,\u2019v2\u2032); \/\/false<br \/>\n$redis-&gt;hsetnx(\u2018hash1\u2032,\u2019key2\u2032,\u2019v2\u2032); \/\/true<\/p>\n<p><strong>\/\/hmset\/hmget \u5b58\u53d6\u591a\u4e2a\u5143\u7d20\u5230hash\u8868<\/strong><br \/>\n$redis-&gt;hmset(\u2018hash1\u2032,array(\u2018key3\u2032=&gt;\u2019v3\u2032,\u2019key4\u2032=&gt;\u2019v4\u2032));<br \/>\n$redis-&gt;hmget(\u2018hash1\u2032,array(\u2018key3\u2032,\u2019key4\u2032)); \/\/\u8fd4\u56de\u76f8\u5e94\u7684\u503c array(\u2018v3\u2032,\u2019v4\u2032)<\/p>\n<p><strong>\/\/hincrby \u5bf9\u6307\u5b9akey\u8fdb\u884c\u7d2f\u52a0<\/strong><br \/>\n$redis-&gt;hincrby(\u2018hash1\u2032,\u2019key5\u2032,3); \/\/\u8fd4\u56de3<br \/>\n$redis-&gt;hincrby(\u2018hash1\u2032,\u2019key5\u2032,10); \/\/\u8fd4\u56de13<\/p>\n<p><strong>\/\/hkeys \u8fd4\u56dehash\u8868\u4e2d\u7684\u6240\u6709key<\/strong><br \/>\n$redis-&gt;hkeys(\u2018hash1\u2032); \/\/\u8fd4\u56dearray(\u2018key1\u2032,\u2019key2\u2032,\u2019key3\u2032,\u2019key4\u2032,\u2019key5\u2032)<\/p>\n<p><strong>\/\/hvals \u8fd4\u56dehash\u8868\u4e2d\u7684\u6240\u6709value<\/strong><br \/>\n$redis-&gt;hvals(\u2018hash1\u2032); \/\/\u8fd4\u56dearray(\u2018v1\u2032,\u2019v2\u2032,\u2019v3\u2032,\u2019v4\u2032,13)<\/p>\n<p><strong>\/\/hgetall \u8fd4\u56de\u6574\u4e2ahash\u8868\u5143\u7d20<\/strong><br \/>\n$redis-&gt;hgetall(\u2018hash1\u2032); \/\/\u8fd4\u56dearray(\u2018key1\u2032=&gt;\u2019v1\u2032,\u2019key2\u2032=&gt;\u2019v2\u2032,\u2019key3\u2032=&gt;\u2019v3\u2032,\u2019key4\u2032=&gt;\u2019v4\u2032,\u2019key5\u2032=&gt;13)<\/p>\n<p><strong>\/**<\/strong><br \/>\n<strong> \u6392\u5e8f\u64cd\u4f5c<\/strong><br \/>\n<strong> *\/<\/strong><\/p>\n<p><strong>\/\/sort \u6392\u5e8f<\/strong><br \/>\n$redis-&gt;rpush(\u2018tab\u2019,3);<br \/>\n$redis-&gt;rpush(\u2018tab\u2019,2);<br \/>\n$redis-&gt;rpush(\u2018tab\u2019,17);<br \/>\n$redis-&gt;sort(\u2018tab\u2019);\u00a0 \/\/\u8fd4\u56dearray(2,3,17)<br \/>\n\/\/\u4f7f\u7528\u53c2\u6570,\u53ef\u7ec4\u5408\u4f7f\u7528 array(\u2018sort\u2019 =&gt; \u2018desc\u2019,&#8217;limit\u2019 =&gt; array(1, 2))<br \/>\n$redis-&gt;sort(\u2018tab\u2019,array(\u2018sort\u2019 =&gt; \u2018desc\u2019));\u00a0 \/\/\u964d\u5e8f\u6392\u5217,\u8fd4\u56dearray(17,3,2)<br \/>\n$redis-&gt;sort(\u2018tab\u2019,array(\u2018limit\u2019 =&gt; array(1, 2)));\u00a0 \/\/\u8fd4\u56de\u987a\u5e8f\u4f4d\u7f6e\u4e2d1\u7684\u5143\u7d202\u4e2a(\u8fd9\u91cc\u76842\u662f\u6307\u4e2a\u6570,\u800c\u4e0d\u662f\u4f4d\u7f6e),\u8fd4\u56dearray(3,17)<br \/>\n$redis-&gt;sort(\u2018tab\u2019,array(\u2018limit\u2019 =&gt; array(\u2018alpha\u2019 =&gt; true))); \/\/\u6309\u9996\u5b57\u7b26\u6392\u5e8f\u8fd4\u56dearray(17,2,3),\u56e0\u4e3a17\u7684\u9996\u5b57\u7b26\u662f\u20191\u2032\u6240\u4ee5\u6392\u9996\u4f4d\u7f6e<br \/>\n$redis-&gt;sort(\u2018tab\u2019,array(\u2018limit\u2019 =&gt; array(\u2018store\u2019 =&gt; \u2018ordered\u2019))); \/\/\u8868\u793a\u6c38\u4e45\u6027\u6392\u5e8f,\u8fd4\u56de\u5143\u7d20\u4e2a\u6570<br \/>\n$redis-&gt;sort(\u2018tab\u2019,array(\u2018limit\u2019 =&gt; array(\u2018get\u2019 =&gt; \u2018pre_*\u2019))); \/\/\u4f7f\u7528\u4e86\u901a\u914d\u7b26\u2019*&#8217;\u8fc7\u6ee4\u5143\u7d20,\u8868\u793a\u53ea\u8fd4\u56de\u4ee5\u2019pre_\u2019\u5f00\u5934\u7684\u5143\u7d20<\/p>\n<p><strong>\/**<\/strong><br \/>\n<strong> redis\u7ba1\u7406\u64cd\u4f5c<\/strong><br \/>\n<strong> *\/<\/strong><\/p>\n<p><strong>\/\/select \u6307\u5b9a\u8981\u64cd\u4f5c\u7684\u6570\u636e\u5e93<\/strong><br \/>\n$redis-&gt;select(\u2018mydb\u2019); \/\/\u6307\u5b9a\u4e3amydb,\u4e0d\u5b58\u5728\u5219\u521b\u5efa<\/p>\n<p><strong>\/\/flushdb \u6e05\u7a7a\u5f53\u524d\u5e93<\/strong><br \/>\n$redis-&gt;flushdb();<\/p>\n<p><strong>\/\/move \u79fb\u52a8\u5f53\u5e93\u7684\u5143\u7d20\u5230\u5176\u5b83\u5e93<\/strong><br \/>\n$redis-&gt;set(\u2018foo\u2019, \u2018bar\u2019);<br \/>\n$redis-&gt;move(\u2018foo\u2019, \u2018mydb2\u2032); \/\/\u82e5\u2019mydb2\u2032\u5e93\u5b58\u5728<\/p>\n<p><strong>\/\/info \u663e\u793a\u670d\u52a1\u5f53\u72b6\u6001\u4fe1\u606f<\/strong><br \/>\n$redis-&gt;info();<\/p>\n<p><strong>\/\/slaveof \u914d\u7f6e\u4ece\u670d\u52a1\u5668<\/strong><br \/>\n$redis-&gt;slaveof(\u2019127.0.0.1\u2032,80); \/\/\u914d\u7f6e127.0.0.1\u7aef\u53e380\u7684\u670d\u52a1\u5668\u4e3a\u4ece\u670d\u52a1\u5668<br \/>\n$redis-&gt;slaveof(); \/\/\u6e05\u9664\u4ece\u670d\u52a1\u5668<\/p>\n<p><strong>\/\/\u540c\u6b65\u4fdd\u5b58\u670d\u52a1\u5668\u6570\u636e\u5230\u78c1\u76d8<\/strong><br \/>\n$redis-&gt;save();<br \/>\n<strong>\/\/\u5f02\u6b65\u4fdd\u5b58\u670d\u52a1\u5668\u6570\u636e\u5230\u78c1\u76d8<\/strong><br \/>\n$redis-&gt;bgsave();<br \/>\n\/\/??<br \/>\n$redis-&gt;bgrewriteaof();<br \/>\n<strong>\/\/\u8fd4\u56de\u6700\u540e\u66f4\u65b0\u78c1\u76d8\u7684\u65f6\u95f4<\/strong><br \/>\n$redis-&gt;lastsave();<\/p>\n<p><strong>\/\/set\/get\u591a\u4e2akey-value<\/strong><br \/>\n$mkv = array(<br \/>\n\u2018usr:0001\u2032 =&gt; \u2018First user\u2019,<br \/>\n\u2018usr:0002\u2032 =&gt; \u2018Second user\u2019,<br \/>\n\u2018usr:0003\u2032 =&gt; \u2018Third user\u2019<br \/>\n);<br \/>\n$redis-&gt;mset($mkv); \/\/\u5b58\u50a8\u591a\u4e2akey\u5bf9\u5e94\u7684value<br \/>\n$retval = $redis-&gt;mget(array_keys($mkv)); \/\/\u83b7\u53d6\u591a\u4e2akey\u5bf9\u5e94\u7684value<br \/>\nprint_r($retval);<\/p>\n<p><strong>\/\/\u6279\u91cf\u64cd\u4f5c<\/strong><br \/>\n$replies = $redis-&gt;pipeline(function($pipe) {<br \/>\n$pipe-&gt;ping();<br \/>\n$pipe-&gt;flushdb();<br \/>\n$pipe-&gt;incrby(\u2018counter\u2019, 10); \/\/\u589e\u91cf\u64cd\u4f5c<br \/>\n$pipe-&gt;incrby(\u2018counter\u2019, 30);<br \/>\n$pipe-&gt;exists(\u2018counter\u2019);<br \/>\n$pipe-&gt;get(\u2018counter\u2019);<br \/>\n$pipe-&gt;mget(\u2018does_not_exist\u2019, \u2018counter\u2019);<br \/>\n});<br \/>\nprint_r($replies);<\/p>\n<p><strong>\/\/CAS,\u4e8b\u52a1\u6027\u64cd\u4f5c<\/strong><\/p>\n<p>function zpop($client, $zsetKey) {<br \/>\n$element = null;<br \/>\n$options = array(<br \/>\n\u2018cas\u2019\u00a0\u00a0 =&gt; true,\u00a0\u00a0\u00a0\u00a0 \/\/ Initialize with support for CAS operations<br \/>\n\u2018watch\u2019 =&gt; $zsetKey, \/\/ Key that needs to be WATCHed to detect changes<br \/>\n\u2018retry\u2019 =&gt; 3,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Number of retries on aborted transactions, after<br \/>\n\/\/ which the client bails out with an exception.<br \/>\n);<\/p>\n<p>$txReply = $client-&gt;multiExec($options, function($tx)<br \/>\nuse ($zsetKey, &amp;$element) {<br \/>\n@list($element) = $tx-&gt;zrange($zsetKey, 0, 0);<br \/>\nif (isset($element)) {<br \/>\n$tx-&gt;multi();\u00a0\u00a0\u00a0\u00a0 \/\/ With CAS, MULTI *must* be explicitly invoked.<br \/>\n$tx-&gt;zrem($zsetKey, $element);<br \/>\n}<br \/>\n});<br \/>\nreturn $element;<br \/>\n}<br \/>\n$zpopped = zpop($redis, \u2018zset\u2019);<br \/>\necho isset($zpopped) ? \u201cZPOPed $zpopped\u201d : \u201cNothing to ZPOP!\u201d, \u201c\\n\u201d;<\/p>\n<p><strong>\/\/\u5bf9\u5b58\u53d6\u7684key\u52a0\u524d\u7f00,\u5982: \u2018nrk:\u2019<\/strong><br \/>\n$redis-&gt;getProfile()-&gt;setPreprocessor(new KeyPrefixPreprocessor(\u2018nrk:\u2019));<\/p>\n<p><strong>\/\/\u5206\u5e03\u5f0f\u5b58\u50a8\u7684\u4e00\u4e9b\u65b9\u6cd5<\/strong><br \/>\n$multiple_servers = array(<br \/>\narray(<br \/>\n\u2018host\u2019\u00a0\u00a0\u00a0\u00a0 =&gt; \u2019127.0.0.1\u2032,<br \/>\n\u2018port\u2019\u00a0\u00a0\u00a0\u00a0 =&gt; 6379,<br \/>\n\u2018database\u2019 =&gt; 15,<br \/>\n\u2018alias\u2019\u00a0\u00a0\u00a0 =&gt; \u2018first\u2019,<br \/>\n),<br \/>\narray(<br \/>\n\u2018host\u2019\u00a0\u00a0\u00a0\u00a0 =&gt; \u2019127.0.0.1\u2032,<br \/>\n\u2018port\u2019\u00a0\u00a0\u00a0\u00a0 =&gt; 6380,<br \/>\n\u2018database\u2019 =&gt; 15,<br \/>\n\u2018alias\u2019\u00a0\u00a0\u00a0 =&gt; \u2018second\u2019,<br \/>\n),<br \/>\n);<\/p>\n<p>use Predis\\Distribution\\IDistributionStrategy;<\/p>\n<p>class NaiveDistributionStrategy implements IDistributionStrategy {<br \/>\nprivate $_nodes, $_nodesCount;<\/p>\n<p>public function __constructor() {<br \/>\n$this-&gt;_nodes = array();<br \/>\n$this-&gt;_nodesCount = 0;<br \/>\n}<\/p>\n<p>public function add($node, $weight = null) {<br \/>\n$this-&gt;_nodes[] = $node;<br \/>\n$this-&gt;_nodesCount++;<br \/>\n}<\/p>\n<p>public function remove($node) {<br \/>\n$this-&gt;_nodes = array_filter($this-&gt;_nodes, function($n) use($node) {<br \/>\nreturn $n !== $node;<br \/>\n});<br \/>\n$this-&gt;_nodesCount = count($this-&gt;_nodes);<br \/>\n}<\/p>\n<p>public function get($key) {<br \/>\n$count = $this-&gt;_nodesCount;<br \/>\nif ($count === 0) {<br \/>\nthrow new RuntimeException(\u2018No connections\u2019);<br \/>\n}<br \/>\nreturn $this-&gt;_nodes[$count &gt; 1 ? abs(crc32($key) % $count) : 0];<br \/>\n}<\/p>\n<p>public function generateKey($value) {<br \/>\nreturn crc32($value);<br \/>\n}<br \/>\n}<\/p>\n<p><strong>\/\/\u914d\u7f6e\u952e\u5206\u5e03\u7b56\u7565<\/strong><br \/>\n$options = array(<br \/>\n\u2018key_distribution\u2019 =&gt; new NaiveDistributionStrategy(),<br \/>\n);<\/p>\n<p>$redis = new Predis\\Client($multiple_servers, $options);<\/p>\n<p>for ($i = 0; $i set(\u201ckey:$i\u201d, str_pad($i, 4, \u20190\u2032, 0));<br \/>\n$redis-&gt;get(\u201ckey:$i\u201d);<br \/>\n}<\/p>\n<p>$server1 = $redis-&gt;getClientFor(\u2018first\u2019)-&gt;info();<br \/>\n$server2 = $redis-&gt;getClientFor(\u2018second\u2019)-&gt;info();<\/p>\n<p>printf(\u201cServer \u2018%s\u2019 has %d keys while server \u2018%s\u2019 has %d keys.\\n\u201d,<br \/>\n\u2018first\u2019, $server1[&#8216;db15&#8217;][&#8216;keys&#8217;], \u2018second\u2019, $server2[&#8216;db15&#8217;][&#8216;keys&#8217;]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/\u666e\u901aset\/get\u64cd\u4f5c $redis-&gt;set(\u2018libr&#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,5,18],"tags":[36,160,164,55],"class_list":["post-1006","post","type-post","status-publish","format-standard","hentry","category-NetOS","category-Note","category-Php","tag-php-2","tag-redis","tag-164","tag-55"],"_links":{"self":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/1006","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=1006"}],"version-history":[{"count":1,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/1006\/revisions"}],"predecessor-version":[{"id":1007,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/1006\/revisions\/1007"}],"wp:attachment":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1006"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1006"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1006"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}