{"id":864,"date":"2022-01-02T14:18:00","date_gmt":"2022-01-02T14:18:00","guid":{"rendered":"https:\/\/262235.xyz\/?p=864"},"modified":"2022-01-02T14:18:00","modified_gmt":"2022-01-02T14:18:00","slug":"864","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2022\/01\/02\/864\/","title":{"rendered":"Python \u5217\u8868 list \u8f6c\u5b57\u7b26\u4e32\u4fdd\u5b58\u4e24\u79cd\u65b9\u6cd5: json\u5217\u8868\u4e92\u8f6c\uff0cjoin\u7ec4\u5408\u5b57\u7b26\u4e32\u548csplit\u8f6c\u5217\u8868"},"content":{"rendered":"<h2>Python \u5217\u8868 list \u8f6c\u5b57\u7b26\u4e32\u4fdd\u5b58\u4e24\u79cd\u65b9\u6cd5: json\u5217\u8868\u4e92\u8f6c\uff0cjoin\u7ec4\u5408\u5b57\u7b26\u4e32\u548csplit\u8f6c\u5217\u8868<\/h2>\n<p>redis\u662f\u4e00\u4e2akey-value\u5b58\u50a8\u7cfb\u7edf\u3002\u548cMemcached\u7c7b\u4f3c\uff0c\u5b83\u652f\u6301\u5b58\u50a8\u7684value\u7c7b\u578b\u76f8\u5bf9\u66f4\u591a\uff0c\u5305\u62ecstring(\u5b57\u7b26\u4e32)\u3001list(\u94fe\u8868)\u3001set(\u96c6\u5408)\u3001zset(sorted set --\u6709\u5e8f\u96c6\u5408)\u548chash\uff08\u54c8\u5e0c\u7c7b\u578b\uff09\u3002<br \/>\u4e3a\u4e86\u628aPython\u7a0b\u5e8f\u4e2d\u6570\u636e\u4fdd\u5b58\u5230Redis\u6570\u636e\u5e93\u4e2d\uff0c\u628a\u4e00\u884c\u6570\u636e(list)\u8f6c\u6362\u6210\u5b57\u7b26\u4e32\u4fdd\u5b58\uff0c\u8c03\u7528\u7684\u65f6\u5019\u4e5f\u80fd\u8fd8\u539f\u6765\u6570\u636e\u7ed3\u6784\u3002<\/p>\n<h2>\u60f3\u5230\u4e86\u4e24\u79cd\u65b9\u6cd5:<\/h2>\n<h3>\u5217\u8868list\u548cjson\u4e92\u8f6c<\/h3>\n<pre><code>import json\nlst = ['45.11.188.188', '22', '45.11.188.188', '40000', '\u5927\u6bdb4.5\u6bdb\u9e21']\njsn = json.dumps(lst)\nprint(jsn)\n\nl = json.loads(jsn)\nprint(l)<\/code><\/pre>\n<h3>\u4f7f\u7528join\u7ec4\u5408\u5217\u8868list\u8f6c\u5b57\u7b26\u4e32 \u548c\u4f7f\u7528split\u5b57\u7b26\u4e32\u8f6c\u5217\u8868list<\/h3>\n<pre><code>ls = ['45.11.188.188', '22', '45.11.188.188', '40000', '\u5927\u6bdb4.5\u6bdb\u9e21']\nstr = '|'.join(ls)\nprint(str)\n\nnls = str.split('|')\nprint(nls)<\/code><\/pre>\n<h3>Python \u5217\u8868\u6570\u636e\u8f6cjson\u4fdd\u5b58Redis\u548c\u8c03\u7528\u6570\u636e\u5b9e\u9a8c<\/h3>\n<pre><code>import json, redis\npool = redis.ConnectionPool(host='\u4e3b\u673a\u540d', port=6379, db=0, password='\u5bc6\u7801')\nr = redis.Redis(connection_pool=pool)\n\nlst = ['45.11.188.188', '22', '45.11.188.188', '40000', '\u5927\u6bdb4.5\u6bdb\u9e21']\nstr = json.dumps(lst)\nr.set('string', str)\n\nlist_json = r.get('string')\nvps_info = json.loads(list_json)\nprint(vps_info, '\nIP:',vps_info[0])<\/code><\/pre>\n<ul>\n<li>\n<p>\u8f93\u51fa<\/p>\n<p>['45.11.188.188', '22', '45.11.188.188', '40000', '\u5927\u6bdb4.5\u6bdb\u9e21']<br \/>  IP: 45.11.188.188<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Python \u5217\u8868 list \u8f6c\u5b57\u7b26\u4e32\u4fdd\u5b58\u4e24\u79cd\u65b9\u6cd5: json\u5217\u8868\u4e92\u8f6c\uff0cjoin\u7ec4\u5408\u5b57\u7b26\u4e32\u548cspli [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[45],"class_list":["post-864","post","type-post","status-publish","format-standard","hentry","category-learn","tag-python"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/864","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/comments?post=864"}],"version-history":[{"count":0,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/864\/revisions"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=864"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=864"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=864"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}