{"id":284,"date":"2018-04-11T21:40:01","date_gmt":"2018-04-11T13:40:01","guid":{"rendered":"https:\/\/www.myway5.com\/?p=284"},"modified":"2023-07-05T21:51:57","modified_gmt":"2023-07-05T13:51:57","slug":"redis-transaction-and-lock","status":"publish","type":"post","link":"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/","title":{"rendered":"redis\u4e2d\u7684\u4e8b\u52a1\u4e0e\u9501"},"content":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u662f\u6211\u5728\u67e5\u627e\u5982\u4f55\u5bf9redis\u4e2d\u7684\u503c\u505a\u539f\u5b50\u64cd\u4f5c\u65f6\u7684\u4e00\u7cfb\u5217\u7b14\u8bb0\uff0c\u867d\u7136\u6700\u521d\u7684\u76ee\u7684\u53ea\u662f\u7814\u7a76\u6709\u54ea\u4e9b\u65b9\u5f0f\u53ef\u4ee5\u5b9e\u73b0\u4e8b\u52a1(transaction)\u64cd\u4f5c\uff0c\u4f46\u662f\u540e\u6765\u7684\u5ef6\u4f38\u5f88\u591a\uff0c\u6240\u4ee5\u6211\u8ba4\u4e3a\u6709\u5fc5\u8981\u505a\u4e00\u4e9b\u7b14\u8bb0\u9632\u6b62\u5fd8\u8bb0\u3002<\/p>\n<h2>1.redis\u4e2d\u7684\u4e8b\u52a1<\/h2>\n<p>redis\u4e2d\u7684\u4e8b\u52a1\u5176\u5b9e\u5e76\u4e0d\u6ee1\u8db3\u6570\u636e\u5e93\u4e8b\u52a1\u7684\u56db\u4e2a\u7279\u6027\uff1a\u539f\u5b50\u6027\uff08Atomicity\uff09\u3001\u4e00\u81f4\u6027\uff08Consistency\uff09\u3001\u9694\u79bb\u578b\uff08Isolation\uff09\u3001\u6301\u4e45\u6027\uff08Durability\uff09\uff0c\u7b80\u79f0ACID\u3002redis\u53ea\u80fd\u5728\u4e00\u81f4\u6027\u548c\u9694\u79bb\u6027\u4e0a\u63d0\u4f9b\u4fdd\u8bc1\uff0c\u800c\u539f\u5b50\u6027\u548c\u6301\u4e45\u6027\u662f\u65e0\u6cd5\u4fdd\u8bc1\u7684\u3002\u56e0\u4e3aredis\u7684\u4e8b\u52a1\u64cd\u4f5c\u5982\u679c\u4e2d\u65ad\uff0c\u65e0\u6cd5\u56de\u6eda\uff0c\u6ee1\u8db3\u4e0d\u4e86\u539f\u5b50\u6027\uff0c\u5e76\u4e14redis\u7684\u6301\u4e45\u5316\u7b56\u7565\u6709\u5f88\u591a\u4e2d\uff0c\u6bd4\u5982\u5728\u7eaf\u5185\u5b58\u6a21\u5f0f\u4e0b\u662f\u65e0\u6cd5\u6301\u4e45\u5316\u6570\u636e\u5e93\u66f4\u6539\u7684\uff0c\u6ee1\u8db3\u4e0d\u4e86\u6301\u4e45\u6027\u3002<\/p>\n<p>\u6240\u4ee5\u4e0b\u9762\u9488\u5bf9\u4e0eredis\u4e8b\u52a1\u7684\u8ba8\u8bba\u90fd\u662f\u6709\u5c40\u9650\u6027\u7684\u3002\u4ec5\u4ec5\u662f\u6307\u5bf9redis\u6570\u636e\u8fdb\u884c\u64cd\u4f5c\u65f6\uff0c\u4e0d\u4f1a\u53d7\u5230\u5176\u4ed6\u5ba2\u6237\u7aef\u7684\u5e72\u6270\u3002\u4e3e\u4f8b\u6765\u8bf4\uff1a\u5ba2\u6237\u7aefA\u8bfb\u53d6keyA\uff0c\u4fee\u6539keyA\u4e2d\u95f4\uff0c\u4e0d\u4f1a\u53d7\u5230\u5ba2\u6237\u7aefB\u7684\u5f71\u54cd\u3002<\/p>\n<pre><code class=\"line-numbers\">    \/\/\u5ba2\u6237\u7aefA\u6267\u884c\u4ee5\u4e0b\u4ee3\u7801\n    \/\/\u83b7\u53d6user1\u7684\u6027\u522b\uff0c\u5982\u679c\u6027\u522b\u662f\u7537\uff0c\u5934\u50cf\u8bbe\u7f6e\u4e3a\u7537\u6027\u89d2\u8272\n    \/\/\u5426\u5219\u5934\u50cf\u8bbe\u7f6e\u4e3a\u5973\u6027\u89d2\u8272\n    <span class=\"katex math inline\">gender =<\/span>redis-&gt;get('user1_gender');\n    if(<span class=\"katex math inline\">gender === 'male'){<\/span>redis-&gt;set('user1_photo','male.png');\n    }else{\n        $redis-&gt;set('user1_photo','female.png');\n    }\n<\/code><\/pre>\n<pre><code class=\"line-numbers\">    \/\/\u5ba2\u6237\u7aefB\u6267\u884c\u4ee5\u4e0b\u4ee3\u7801\n    \/\/\u66f4\u6539user1\u7684\u6027\u522b\uff0c\u5982\u679c\u662f\u7537\u5219\u6539\u4e3a\u5973\uff0c\u5982\u679c\u662f\u5973\u5219\u6539\u4e3a\u7537\n    \/\/\u5e76\u6839\u636e\u6027\u522b\u8bbe\u7f6e\u5934\u50cf\n    <span class=\"katex math inline\">gender =<\/span>redis-&gt;get('user1_gender');\n    if(<span class=\"katex math inline\">gender === 'male'){<\/span>redis-&gt;set('user1_gender','female');\n        <span class=\"katex math inline\">redis-&gt;set('user1_photo','female.png');\n    }else{<\/span>redis-&gt;set('user1_gender','male');\n        $redis-&gt;set('user1_photo','male.png');\n    }\n\n<\/code><\/pre>\n<p>\u5982\u679c\u5ba2\u6237\u7aefA\u3001B\u540c\u65f6\u53ea\u6709\u4e00\u4e2a\u6267\u884c\uff0c\u90a3\u4e48\u6027\u522b\u548c\u5934\u50cf\u4e00\u5b9a\u662f\u5bf9\u5e94\u7684\u3002\u4f46\u662fA\u3001B\u540c\u65f6\u6267\u884c\uff0c\u5e76\u4e14\u6267\u884c\u987a\u5e8f\u5982\u4e0b:<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.myway5.com\/wp-content\/uploads\/2018\/03\/%E6%B7%B1%E5%BA%A6%E6%88%AA%E5%9B%BE_%E9%80%89%E6%8B%A9%E5%8C%BA%E5%9F%9F_20180308151942.png\" alt=\"\u65f6\u5e8f\u56fe\" \/><\/p>\n<p>\u90a3\u4e48\u6267\u884c\u7ed3\u679c\u5c31\u662fuser1\u6027\u522b\u4e3a\u5973\uff0c\u4f46\u5934\u50cf\u4e3a\u7537\u6027\u89d2\u8272\u3002<\/p>\n<p>\u6240\u4ee5\u9488\u5bf9\u4e8e\u8fd9\u79cd\u60c5\u51b5\uff0c\u6211\u4eec\u9700\u8981\u4e00\u5b9a\u7684\u63aa\u65bd\u53bb\u9884\u9632\u3002<\/p>\n<p>redis\u7684\u4e8b\u52a1\u5b9e\u73b0\u65b9\u5f0f\u6709\u591a\u79cd\u3002\u636e\u6211\u6240\u77e5\u6709\u4e09\u79cd\u65b9\u5f0f\uff1a<\/p>\n<ul>\n<li>1.<code>MULTI<\/code>\/<code>EXEC<\/code><\/li>\n<li>2.<code>WATCH<\/code>\/<code>UNWATCH<\/code><\/li>\n<li>3.lua\u811a\u672c<\/li>\n<\/ul>\n<h3>1.1 <code>MULTI<\/code>\/<code>EXEC<\/code><\/h3>\n<p><code>MULTI<\/code>\/<code>EXEC<\/code>\u662f\u6210\u5bf9\u51fa\u73b0\u7684\u6307\u4ee4\u3002\u5927\u5bb6\u90fd\u77e5\u9053\uff0credis\u6267\u884c\u6307\u4ee4\u662f\u5355\u7ebf\u7a0b\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4\u6240\u6709\u6307\u4ee4\u90fd\u5904\u4e8e\u4e00\u4e2a\u961f\u5217\uff0c\u4e00\u4e2a\u4e00\u4e2a\u6267\u884c\u3002<code>MULTI<\/code>\/<code>EXEC<\/code>\u53ef\u4ee5\u4fdd\u8bc1\u6240\u6709\u7684\u6307\u4ee4\u90fd\u4f1a\u88ab\u540c\u65f6\u653e\u677e\u5230redis\u4e2d\uff0c\u4e2d\u95f4\u4e0d\u4f1a\u63ba\u6742\u6765\u81ea\u5176\u4ed6\u5ba2\u6237\u7aef\u7684\u6307\u4ee4\u3002<\/p>\n<p>\u4f46\u662f\u8fd9\u4e2a\u9488\u5bf9\u4e8e\u4e0a\u8ff0\u60c5\u51b5\u5e76\u4e0d\u9002\u7528\u3002\u56e0\u4e3a\u6211\u4eec\u9700\u8981\u5728GET\u5230\u6570\u636e\u4e4b\u540e\uff0c\u624d\u80fd\u505a\u4e0b\u9762\u7684\u66f4\u65b0\u64cd\u4f5c\u3002<\/p>\n<h3>1.2 <code>WATCH<\/code>\/<code>UNWATCH<\/code><\/h3>\n<p>\u5728redis\u4e2d\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528watch\u6765\u76d1\u89c6\u4e00\u4e2a\u503c\u3002<\/p>\n<pre><code class=\"line-numbers\">redis&gt; WATCH name\nOK\n\nredis&gt; MULTI\nOK\n\nredis&gt; SET name peter\nQUEUED\n\nredis&gt; EXEC\n(nil)\n<\/code><\/pre>\n<p>\u6bd4\u5982\u8fd9\u6bb5\u4ee3\u7801\uff0c\u5728\u6211\u4eecWATCH name\u540e\uff0c\u5982\u679c\u53e6\u5916\u4e00\u4e2a\u5ba2\u6237\u7aef\u4fee\u6539\u4e86name\u7684\u503c\uff0c\u90a3\u4e48\u8fd9\u4e2a\u5ba2\u6237\u7aef\u518d\u6b21\u4fee\u6539name\u5219\u65e0\u6cd5\u6210\u529f\u3002\u8fd9\u5176\u5b9e\u5c31\u662f\u4e50\u89c2\u9501\u7684\u4e00\u79cd\u5b9e\u73b0\u3002\u5b83\u4fdd\u8bc1\u4e86\u4ee3\u7801\u7684\u6267\u884c\u7ed3\u679c\u4e0d\u4f1a\u9519\u4e71\u3002\u7528\u4e00\u5f00\u59cb\u7684\u4f8b\u5b50\u6765\u8bf4\uff0c\u5c31\u662f\u4e0d\u4f1a\u51fa\u73b0\u6027\u522b\u548c\u5934\u50cf\u4e0d\u5bf9\u5e94\u7684\u60c5\u51b5\u3002<\/p>\n<p>1.3 lua\u811a\u672c<br \/>\nredis\u4e2d\u53ef\u4ee5\u6267\u884clua\u811a\u672c\u6765\u5b8c\u6210\u4e8b\u52a1\u64cd\u4f5c\u3002lua\u811a\u672c\u548cMULTI\/EXEC\u5f88\u50cf\uff0c\u4e5f\u5c31\u662f\u8bf4\u5728lua\u811a\u672c\u6267\u884c\u7684\u8fc7\u7a0b\u4e2d\uff0credis\u662f\u4e0d\u6267\u884c\u5176\u4ed6\u5ba2\u6237\u7aef\u7684\u6307\u4ee4\u7684\u3002<\/p>\n<p>\u4f46\u662flua\u811a\u672c\u7684\u4e0d\u540c\u4e4b\u5904\u5728\u4e8e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528GET\u64cd\u4f5c\u6765\u83b7\u53d6\u6570\u636e\u5e76\u5224\u65ad\uff0c\u518d\u6267\u884c\u540e\u6765\u7684\u64cd\u4f5c\u3002<\/p>\n<h2>2.\u5728redis\u64cd\u4f5c\u4e2d\u4f7f\u7528\u9501<\/h2>\n<p>\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e2d\uff0c\u4e3a\u4e86\u9632\u6b62\u8d44\u6e90\u51fa\u73b0race condition\uff0c\u9700\u8981\u501f\u52a9\u9501\u6765\u4e92\u65a5\u7684\u8bbf\u95ee\u8d44\u6e90\u3002\u5728\u8fd9\u91cc\u4e5f\u662f\u4e00\u6837\u7684\uff0cuser1_gender\u5c31\u662f\u6211\u4eec\u8981\u4e92\u65a5\u8bbf\u95ee\u7684\u8d44\u6e90\u3002<\/p>\n<p>\u8fd8\u662f\u4e0a\u8ff0\u90a3\u4e2a\u4f8b\u5b50\uff0c\u5982\u679c\u6211\u4eec\u4f7f\u7528\u60b2\u89c2\u9501\uff0c\u53ea\u6709\u83b7\u5f97\u9501\u7684\u5ba2\u6237\u7aef\u624d\u80fd\u8bfb\u53d6\u548c\u4fee\u6539user1\u7684\u7684\u503c\uff0c\u4e5f\u53ef\u4ee5\u5f88\u597d\u7684\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\n<p>\u4f2a\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"line-numbers\">$can_lock = lock('user1_gender'); \/\/\u5f97\u5230\u9501\nif($can_lock){\n    do_something();\n    $release_lock('user1_gender');  \/\/\u91ca\u653e\u9501\n}\n<\/code><\/pre>\n<p>\u4e0d\u540c\u4e8e\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\u7684\u662f\uff0c\u6211\u4eec\u8fd9\u91cc\u7684\u9501\u7684\u8303\u56f4\u662f\u9488\u5bf9\u4e8e\u4e0d\u540c\u7684\u5ba2\u6237\u7aef\u3002\u56e0\u6b64\u6ca1\u6cd5\u4f7f\u7528\u57fa\u4e8e\u7cfb\u7edf\u7684\u3001\u6216\u8005\u57fa\u4e8e\u8bed\u8a00\u7684\u9501\uff0c\u800c\u662f\u5f97\u4f7f\u7528\u5206\u5e03\u5f0f\u7684\u9501\u3002\u8fd9\u6837\u7684\u5206\u5e03\u5f0f\u9501\u6211\u4eec\u540c\u6837\u53ef\u4ee5\u501f\u52a9\u4e8eredis\u6765\u5b9e\u73b0\u3002<\/p>\n<p>\u6574\u4e2a\u5206\u5e03\u5f0f\u9501\u7684\u5b9e\u73b0\u53ef\u4ee5\u6982\u62ec\u4e3a\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\uff1a<\/p>\n<ul>\n<li>\n<ol>\n<li>\u83b7\u5f97\u9501\u3002\u5f97\u5230\u8981\u9501\u7684\u8d44\u6e90\u7684\u552f\u4e00hash\uff1a<code>lockname<\/code>,\u4ee5\u53ca\u4e00\u4e2a\u968f\u673a\u5b57\u7b26\u4e32\uff1a<code>identifier<\/code>\uff0c\u8bbe\u7f6eexpire\uff1a20s,\u8fd9\u4e2aexpire\u5c31\u662f\u9501\u7684\u6709\u6548\u671f\uff0c\u5728\u6709\u6548\u671f\u540e\u9501\u4f1a\u81ea\u52a8\u91ca\u653e\uff0c\u9632\u6b62\u51fa\u73b0\u6b7b\u9501\u3002\u5728redis\u4e2d\u4f7f\u7528setnx(lockname,identifier,expire)\u3002\u8fd9\u53e5\u4ee3\u7801\u7684\u610f\u601d\u662f:\u5982\u679credis\u4e2d\u4e0d\u5b58\u5728lockname\uff0c\u5219\u5b58\u5165lockname\uff0c\u503c\u4e3aidentifier\uff0c\u8fc7\u671f\u65f6\u95f4\u662fexpire\u3002<\/li>\n<\/ol>\n<\/li>\n<li>\n<ol start=\"2\">\n<li>\u7b2c\u4e00\u6b65\u6211\u4eec\u5c31\u5f97\u5230\u4e86\u4e00\u4e2a\u9501\uff0c\u8fd9\u4e00\u6b65\u6211\u4eec\u5f00\u59cb\u6267\u884c\u83b7\u5f97\u9501\u4e4b\u540e\u7684\u4ee3\u7801<\/li>\n<\/ol>\n<\/li>\n<li>\n<ol start=\"3\">\n<li>\u91ca\u653e\u9501\u3002\u6211\u4eec\u6839\u636elockname\u6765\u4eceredis\u4e2d\u67e5\u627e\u3002\u5982\u679cget(lockname) <span class=\"text-highlighted-inline\" style=\"background-color: #fffd38;\"> identifier\uff0c\u5219\u8868\u793a\u6211\u4eec\u4ecd\u7136\u6301\u6709\u8fd9\u628a\u9501\uff0c\u4f7f\u7528delete(lockname)\u6765\u91ca\u653e\u9501\u3002\u5982\u679c\u4e0d\u7b49\u4e8e\uff0c\u8bf4\u660e\u6211\u4eec\u5df2\u7ecf\u4e0d\u6301\u6709\u8fd9\u628a\u9501\u4e86\uff0c\u5219\u4ec0\u4e48\u4e5f\u4e0d\u505a\u3002<\/span><\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<p>\u90a3\u4e48lock\u51fd\u6570\u53ef\u4ee5\u7528\u4ee5\u4e0b\u4ee3\u7801\u6765\u63cf\u8ff0:<\/p>\n<pre><code class=\"line-numbers\">function lock(<span class=\"katex math inline\">lockname,<\/span>identifier,<span class=\"katex math inline\">expire = 20){<\/span>acquire_timeout = 10;      \/\/\u82b1\u8d3910\u79d2\u53bb\u83b7\u5f97\u9501\uff0c\u5426\u5219\u5c31\u653e\u5f03\n    <span class=\"katex math inline\">end = time() +<\/span>acquire_timeout\n    while (time() &lt; <span class=\"katex math inline\">end){<\/span>can_lock = <span class=\"katex math inline\">redis-&gt;setnx(<\/span>lockname,<span class=\"katex math inline\">identifier,<\/span>expire);\n        if($can_lock){\n            return true;\n        }\n        sleep(0.1);\n    }\n\n    return false;\n}\n<\/code><\/pre>\n<pre><code class=\"line-numbers\">    function release_lock(<span class=\"katex math inline\">lockname,<\/span>identifier){\n        <span class=\"katex math inline\">redis-&gt;watch(<\/span>lockname);\n        try{\n            if(<span class=\"katex math inline\">redis-&gt;get(<\/span>lockname) === <span class=\"katex math inline\">identifier){\n                \/\/\u9501\u4ecd\u7136\u6301\u6709\uff0c\u91ca\u653e\u9501<\/span>redis-&gt;delete(<span class=\"katex math inline\">lockname);\n                return true;\n            }<\/span>redis-&gt;unwatch();\n        }catch(Exception $e){\n\n        }\n\n        return false;\n    }\n<\/code><\/pre>\n<p>\u8fd9\u6837\u6211\u4eec\u5c31\u5f88\u8f7b\u677e\u7684\u5f97\u5230\u4e86\u501f\u52a9\u4e8eredis\u5b9e\u73b0\u7684\u5206\u5e03\u5f0f\u9501\u3002\u4f46\u662f\u8fd9\u6837\u7684\u5b9e\u73b0\u65b9\u5f0f\u4f9d\u7136\u662f\u6709\u95ee\u9898\u7684\u3002<\/p>\n<p>\u95ee\u98981\uff1a\u5982\u679c\u5728\u67d0\u4e2a\u5ba2\u6237\u7aef\u83b7\u5f97\u9501\u540e\uff0credis\u4e3b\u670d\u52a1\u5668\u5b95\u673a\u4e86\uff0c\u90a3\u4e48\u5373\u4f7f\u6211\u4eec\u4f7f\u7528\u4e86\u4e3b\u4ece\u5907\u4efd\uff0c\u4ece\u5c5e\u670d\u52a1\u5668\u88ab\u63d0\u5347\u4e3a\u4e3b\u670d\u52a1\u5668\uff0c\u56e0\u4e3aredis\u5907\u4efd\u662f\u5f02\u6b65\u7684\u539f\u56e0\uff0c\u8fd9\u91cc\u7684\u9501\u662f\u6ca1\u6cd5\u53ca\u65f6\u540c\u6b65\u5230\u4ece\u5c5e\u670d\u52a1\u5668\u7684\u3002<\/p>\n<p>\u95ee\u98982\uff1a\u5982\u679c\u4e00\u4e2a\u5ba2\u6237\u7aef\u5728\u83b7\u5f97\u9501\u540e\uff0c\u6267\u884c\u7684\u64cd\u4f5c\u8d85\u8fc7\u4e86\u9501\u7684\u6709\u6548\u671f\uff0c\u9501\u88ab\u81ea\u52a8\u91ca\u653e\u4e86\u3002\u90a3\u4e48\u540e\u7eed\u7684\u64cd\u4f5c\u662f\u6ca1\u6cd5\u53d7\u5230\u9501\u7684\u4fdd\u62a4\u7684\u3002<\/p>\n<p>\u95ee\u98982\u7684\u89e3\u51b3\u65b9\u6848\u53ef\u4ee5\u662fwatch\uff0c\u5728\u83b7\u53d6\u9501\u540e\uff0c\u53ef\u4ee5\u7acb\u523bwatch\u8d44\u6e90\uff0c\u7136\u540e\u518d\u6267\u884c\u4f59\u4e0b\u64cd\u4f5c\u3002<\/p>\n<p>\u95ee\u98981\u7684\u89e3\u51b3\u65b9\u6848\u5219\u662f\u63a5\u4e0b\u6765\u8981\u4ecb\u7ecd\u7684redlock\u7b97\u6cd5<\/p>\n<h2>3.redlock<\/h2>\n<p>redlock\u7b97\u6cd5\u662fRedis\u7684\u4f5c\u8005antirez\u63d0\u51fa\u6765\u7684\u3002<br \/>\n\u53ef\u4ee5\u88ab\u6982\u8ff0\u4e3a\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\uff1a<\/p>\n<ul>\n<li>1.\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\uff08\u6beb\u79d2\u6570\uff09:start_time\u3002<\/p>\n<\/li>\n<li>\n<p>2.\u6309\u987a\u5e8f\u83b7\u5f97N\u4e2aRedis\u8282\u70b9\u7684\u9501\uff08\u4f7f\u7528\u76f8\u540c\u7684key\u548cidentifier\uff0c\u5e76\u8bbe\u7f6e\u521d\u59cb\u6709\u6548\u65f6\u95f4:init_validity_time\uff09\u3002\u5728\u83b7\u5f97\u6bcf\u4e2aredis\u7ed3\u70b9\u7684\u9501\u7684\u65f6\u5019\uff0c\u90fd\u8981\u8bbe\u7f6e\u4e00\u4e2atimeout\u53c2\u6570\uff0c\u8fd9\u4e2atimeout\u8981\u8fdc\u5c0f\u4e8e\u9501\u7684\u81ea\u52a8\u91ca\u653e\u65f6\u95f4\u3002\u4f8b\u5982\uff1a\u5982\u679c\u9501\u7684\u81ea\u52a8\u91ca\u653e\u65f6\u95f4\u662f10s\uff0ctimeout\u5e94\u8be5\u4e3a~5-55ms\uff08\u8fd8\u5f97\u89c6\u7f51\u7edc\u60c5\u51b5\u51b3\u5b9a\uff09\u3002\u8fd9\u6837\u53ef\u4ee5\u9632\u6b62\u5728\u83b7\u53d6\u9501\u65f6\uff0c\u8282\u70b9\u5b95\u673a\uff0c\u5bfc\u81f4\u8017\u65f6\u8fc7\u957f\u9501\u88ab\u91ca\u653e\u4e86\u3002\u5982\u679c\u83b7\u53d6\u9501\u5931\u8d25\u5219\u7acb\u523b\u83b7\u53d6\u4e0b\u4e00\u4e2aredis\u8282\u70b9\u7684\u9501<\/p>\n<\/li>\n<li>\n<p>3.client\u8ba1\u7b97\u4e3a\u4e86\u83b7\u53d6\u9501\u82b1\u4e86\u591a\u957f\u65f6\u95f4\uff1aused_time = current_time &#8211; start_time\u3002\u5f53\u4e14\u4ec5\u5f53client\u53ef\u4ee5\u83b7\u53d6\u5927\u591a\u6570\u5b9e\u4f8b\u7684\u65f6\u5019\uff08\u81f3\u5c11N \/ 2 + 1\u4e2a)\uff0c\u6240\u82b1\u8d39\u7684\u65f6\u95f4\u5c0f\u4e8e\u9501\u7684\u6709\u6548\u65f6\u95f4\uff0c\u624d\u8ba4\u4e3a\u83b7\u5f97\u4e86\u9501\u3002<\/p>\n<\/li>\n<li>\n<p>4.\u5982\u679c\u83b7\u5f97\u4e86\u9501\uff0c\u91cd\u65b0\u8ba1\u7b97\u9501\u7684\u6709\u6548\u65f6\u95f4:validity_time = init_validity_time &#8211; used_time<\/p>\n<\/li>\n<li>\n<p>5.\u5982\u679c\u9501\u83b7\u53d6\u5931\u8d25(\u65e0\u6cd5\u83b7\u53d6N\/2 + 1\u4e2a\u8282\u70b9\u7684\u9501\uff0c\u6216\u8005\u6709\u6548\u65f6\u95f4validity_time\u662f\u8d1f\u6570\uff09\uff0c\u5219\u91ca\u653e\u6240\u6709\u5b9e\u4f8b\u7684\u9501\uff08\u5373\u4f7f\u83b7\u5f97\u9501\u7684\u65f6\u5019\u5931\u8d25\u4e86\uff0c\u8fd9\u4e3b\u8981\u662f\u8003\u8651\u5230\u6709\u7684\u65f6\u5019\u9501\u83b7\u5f97\u6210\u529f\u4e86\uff0c\u4f46\u662f\u544a\u77e5\u5ba2\u6237\u7aef\u65f6\u7f51\u7edc\u5f02\u5e38\uff09\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u8fd9\u5f88\u597d\u7684\u89e3\u51b3\u4e86\u4e0a\u8ff0\u7684\u95ee\u98981\uff0c\u901a\u8fc7\u591a\u4e2aredis\u8282\u70b9\u4e86\u6765\u4fdd\u8bc1\u5206\u5e03\u5f0f\u9501\u670d\u52a1\u7684\u53ef\u9760\u6027\u3002<\/p>\n<h2>\u53c2\u8003\u6587\u7ae0<\/h2>\n<p><a href=\"https:\/\/redis.io\/topics\/distlock%20%E2%80%9CDistributed%20locks%20with%20Redis%E2%80%9D\">Distributed locks with Redis<\/a><\/p>\n<p><a href=\"https:\/\/mp.weixin.qq.com\/s\/JTsJCDuasgIJ0j95K8Ay8w\">\u57fa\u4e8eRedis\u7684\u5206\u5e03\u5f0f\u9501\u5230\u5e95\u5b89\u5168\u5417\uff08\u4e0a\uff09\uff1f<\/a><\/p>\n<p><a href=\"https:\/\/mp.weixin.qq.com\/s\/4CUe7OpM6y1kQRK8TOC_qQ\">\u57fa\u4e8eRedis\u7684\u5206\u5e03\u5f0f\u9501\u5230\u5e95\u5b89\u5168\u5417\uff08\u4e0b\uff09\uff1f<\/a><\/p>\n<p><a href=\"http:\/\/redisbook.readthedocs.io\/en\/latest\/feature\/transaction.html\">redis\u4e8b\u52a1<\/a><\/p>\n<p><a href=\"https:\/\/redislabs.com\/ebook\/part-2-core-concepts\/chapter-6-application-components-in-redis\/6-2-distributed-locking\/6-2-3-building-a-lock-in-redis\/\">6.2.3 Building a lock in Redis<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u662f\u6211\u5728\u67e5\u627e\u5982\u4f55\u5bf9redis\u4e2d\u7684\u503c\u505a\u539f\u5b50\u64cd\u4f5c\u65f6\u7684\u4e00\u7cfb\u5217\u7b14\u8bb0\uff0c\u867d\u7136\u6700\u521d\u7684\u76ee\u7684\u53ea\u662f\u7814\u7a76\u6709\u54ea\u4e9b\u65b9\u5f0f\u53ef\u4ee5\u5b9e\u73b0\u4e8b\u52a1 &hellip; <a href=\"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">redis\u4e2d\u7684\u4e8b\u52a1\u4e0e\u9501<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36,43],"tags":[46,45,17,44],"class_list":["post-284","post","type-post","status-publish","format-standard","hentry","category-php","category-redis","tag-distributed-lock","tag-lock","tag-redis","tag-transaction"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>redis\u4e2d\u7684\u4e8b\u52a1\u4e0e\u9501 - \u4e00\u53ea\u5b89\u9759\u7684\u732b<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"redis\u4e2d\u7684\u4e8b\u52a1\u4e0e\u9501 - \u4e00\u53ea\u5b89\u9759\u7684\u732b\" \/>\n<meta property=\"og:description\" content=\"\u8fd9\u7bc7\u6587\u7ae0\u662f\u6211\u5728\u67e5\u627e\u5982\u4f55\u5bf9redis\u4e2d\u7684\u503c\u505a\u539f\u5b50\u64cd\u4f5c\u65f6\u7684\u4e00\u7cfb\u5217\u7b14\u8bb0\uff0c\u867d\u7136\u6700\u521d\u7684\u76ee\u7684\u53ea\u662f\u7814\u7a76\u6709\u54ea\u4e9b\u65b9\u5f0f\u53ef\u4ee5\u5b9e\u73b0\u4e8b\u52a1 &hellip; \u7ee7\u7eed\u9605\u8bfbredis\u4e2d\u7684\u4e8b\u52a1\u4e0e\u9501\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/\" \/>\n<meta property=\"og:site_name\" content=\"\u4e00\u53ea\u5b89\u9759\u7684\u732b\" \/>\n<meta property=\"article:published_time\" content=\"2018-04-11T13:40:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-05T13:51:57+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.myway5.com\/wp-content\/uploads\/2018\/03\/%E6%B7%B1%E5%BA%A6%E6%88%AA%E5%9B%BE_%E9%80%89%E6%8B%A9%E5%8C%BA%E5%9F%9F_20180308151942.png\" \/>\n<meta name=\"author\" content=\"jiangpengfei\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"jiangpengfei\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/\"},\"author\":{\"name\":\"jiangpengfei\",\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685\"},\"headline\":\"redis\u4e2d\u7684\u4e8b\u52a1\u4e0e\u9501\",\"datePublished\":\"2018-04-11T13:40:01+00:00\",\"dateModified\":\"2023-07-05T13:51:57+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/\"},\"wordCount\":135,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685\"},\"image\":{\"@id\":\"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.myway5.com\/wp-content\/uploads\/2018\/03\/%E6%B7%B1%E5%BA%A6%E6%88%AA%E5%9B%BE_%E9%80%89%E6%8B%A9%E5%8C%BA%E5%9F%9F_20180308151942.png\",\"keywords\":[\"distributed-lock\",\"lock\",\"redis\",\"transaction\"],\"articleSection\":[\"php\",\"redis\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/\",\"url\":\"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/\",\"name\":\"redis\u4e2d\u7684\u4e8b\u52a1\u4e0e\u9501 - \u4e00\u53ea\u5b89\u9759\u7684\u732b\",\"isPartOf\":{\"@id\":\"https:\/\/www.myway5.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.myway5.com\/wp-content\/uploads\/2018\/03\/%E6%B7%B1%E5%BA%A6%E6%88%AA%E5%9B%BE_%E9%80%89%E6%8B%A9%E5%8C%BA%E5%9F%9F_20180308151942.png\",\"datePublished\":\"2018-04-11T13:40:01+00:00\",\"dateModified\":\"2023-07-05T13:51:57+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/#primaryimage\",\"url\":\"https:\/\/www.myway5.com\/wp-content\/uploads\/2018\/03\/%E6%B7%B1%E5%BA%A6%E6%88%AA%E5%9B%BE_%E9%80%89%E6%8B%A9%E5%8C%BA%E5%9F%9F_20180308151942.png\",\"contentUrl\":\"https:\/\/www.myway5.com\/wp-content\/uploads\/2018\/03\/%E6%B7%B1%E5%BA%A6%E6%88%AA%E5%9B%BE_%E9%80%89%E6%8B%A9%E5%8C%BA%E5%9F%9F_20180308151942.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.myway5.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"redis\u4e2d\u7684\u4e8b\u52a1\u4e0e\u9501\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.myway5.com\/#website\",\"url\":\"https:\/\/www.myway5.com\/\",\"name\":\"\u4e00\u53ea\u5b89\u9759\u7684\u732b\",\"description\":\"\u60f3\u5565\u5462\",\"publisher\":{\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.myway5.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685\",\"name\":\"jiangpengfei\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f8c7de757f6e0247412bcfd31b7c2271?s=96&d=monsterid&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f8c7de757f6e0247412bcfd31b7c2271?s=96&d=monsterid&r=g\",\"caption\":\"jiangpengfei\"},\"logo\":{\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/www.myway5.com\/index.php\/author\/joyme\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"redis\u4e2d\u7684\u4e8b\u52a1\u4e0e\u9501 - \u4e00\u53ea\u5b89\u9759\u7684\u732b","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/","og_locale":"zh_CN","og_type":"article","og_title":"redis\u4e2d\u7684\u4e8b\u52a1\u4e0e\u9501 - \u4e00\u53ea\u5b89\u9759\u7684\u732b","og_description":"\u8fd9\u7bc7\u6587\u7ae0\u662f\u6211\u5728\u67e5\u627e\u5982\u4f55\u5bf9redis\u4e2d\u7684\u503c\u505a\u539f\u5b50\u64cd\u4f5c\u65f6\u7684\u4e00\u7cfb\u5217\u7b14\u8bb0\uff0c\u867d\u7136\u6700\u521d\u7684\u76ee\u7684\u53ea\u662f\u7814\u7a76\u6709\u54ea\u4e9b\u65b9\u5f0f\u53ef\u4ee5\u5b9e\u73b0\u4e8b\u52a1 &hellip; \u7ee7\u7eed\u9605\u8bfbredis\u4e2d\u7684\u4e8b\u52a1\u4e0e\u9501","og_url":"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/","og_site_name":"\u4e00\u53ea\u5b89\u9759\u7684\u732b","article_published_time":"2018-04-11T13:40:01+00:00","article_modified_time":"2023-07-05T13:51:57+00:00","og_image":[{"url":"https:\/\/www.myway5.com\/wp-content\/uploads\/2018\/03\/%E6%B7%B1%E5%BA%A6%E6%88%AA%E5%9B%BE_%E9%80%89%E6%8B%A9%E5%8C%BA%E5%9F%9F_20180308151942.png","type":"","width":"","height":""}],"author":"jiangpengfei","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"jiangpengfei","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/#article","isPartOf":{"@id":"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/"},"author":{"name":"jiangpengfei","@id":"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685"},"headline":"redis\u4e2d\u7684\u4e8b\u52a1\u4e0e\u9501","datePublished":"2018-04-11T13:40:01+00:00","dateModified":"2023-07-05T13:51:57+00:00","mainEntityOfPage":{"@id":"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/"},"wordCount":135,"commentCount":0,"publisher":{"@id":"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685"},"image":{"@id":"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/#primaryimage"},"thumbnailUrl":"https:\/\/www.myway5.com\/wp-content\/uploads\/2018\/03\/%E6%B7%B1%E5%BA%A6%E6%88%AA%E5%9B%BE_%E9%80%89%E6%8B%A9%E5%8C%BA%E5%9F%9F_20180308151942.png","keywords":["distributed-lock","lock","redis","transaction"],"articleSection":["php","redis"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/","url":"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/","name":"redis\u4e2d\u7684\u4e8b\u52a1\u4e0e\u9501 - \u4e00\u53ea\u5b89\u9759\u7684\u732b","isPartOf":{"@id":"https:\/\/www.myway5.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/#primaryimage"},"image":{"@id":"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/#primaryimage"},"thumbnailUrl":"https:\/\/www.myway5.com\/wp-content\/uploads\/2018\/03\/%E6%B7%B1%E5%BA%A6%E6%88%AA%E5%9B%BE_%E9%80%89%E6%8B%A9%E5%8C%BA%E5%9F%9F_20180308151942.png","datePublished":"2018-04-11T13:40:01+00:00","dateModified":"2023-07-05T13:51:57+00:00","breadcrumb":{"@id":"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/"]}]},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/#primaryimage","url":"https:\/\/www.myway5.com\/wp-content\/uploads\/2018\/03\/%E6%B7%B1%E5%BA%A6%E6%88%AA%E5%9B%BE_%E9%80%89%E6%8B%A9%E5%8C%BA%E5%9F%9F_20180308151942.png","contentUrl":"https:\/\/www.myway5.com\/wp-content\/uploads\/2018\/03\/%E6%B7%B1%E5%BA%A6%E6%88%AA%E5%9B%BE_%E9%80%89%E6%8B%A9%E5%8C%BA%E5%9F%9F_20180308151942.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.myway5.com\/index.php\/2018\/04\/11\/redis-transaction-and-lock\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.myway5.com\/"},{"@type":"ListItem","position":2,"name":"redis\u4e2d\u7684\u4e8b\u52a1\u4e0e\u9501"}]},{"@type":"WebSite","@id":"https:\/\/www.myway5.com\/#website","url":"https:\/\/www.myway5.com\/","name":"\u4e00\u53ea\u5b89\u9759\u7684\u732b","description":"\u60f3\u5565\u5462","publisher":{"@id":"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.myway5.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685","name":"jiangpengfei","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.myway5.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/f8c7de757f6e0247412bcfd31b7c2271?s=96&d=monsterid&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f8c7de757f6e0247412bcfd31b7c2271?s=96&d=monsterid&r=g","caption":"jiangpengfei"},"logo":{"@id":"https:\/\/www.myway5.com\/#\/schema\/person\/image\/"},"url":"https:\/\/www.myway5.com\/index.php\/author\/joyme\/"}]}},"views":8016,"_links":{"self":[{"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/posts\/284","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/comments?post=284"}],"version-history":[{"count":2,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/posts\/284\/revisions"}],"predecessor-version":[{"id":1595,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/posts\/284\/revisions\/1595"}],"wp:attachment":[{"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/media?parent=284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/categories?post=284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/tags?post=284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}