{"id":4415,"date":"2019-07-15T17:50:43","date_gmt":"2019-07-15T09:50:43","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=4415"},"modified":"2019-07-15T17:50:43","modified_gmt":"2019-07-15T09:50:43","slug":"%e9%98%bf%e9%87%8c%e7%9a%84-redis-%e8%bf%9e%e7%8e%af%e7%82%ae%e9%9d%a2%e8%af%95%e9%a2%98%ef%bc%8c%e7%9c%8b%e7%9a%84%e8%b5%84%e6%96%99%e4%b8%80%e4%b8%aa%e4%b9%9f%e6%b2%a1%e7%94%a8%e4%b8%8a","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=4415","title":{"rendered":"\u963f\u91cc\u7684 Redis \u8fde\u73af\u70ae\u9762\u8bd5\u9898\uff0c\u770b\u7684\u8d44\u6599\u4e00\u4e2a\u4e5f\u6ca1\u7528\u4e0a"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Redis \u8fd9\u7c7b\u5f00\u6e90\u7684 Key-Value \u6570\u636e\u5e93\u88ab\u8d8a\u6765\u8d8a\u591a\u7684\u516c\u53f8\u6240\u91c7\u7528\uff0c\u4e8e\u662f\u4e4e\uff0cRedis \u5df2\u7ecf\u662f\u6210\u4e86\u9762\u8bd5\u5fc5\u95ee\u7684\u6280\u672f\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6628\u5929\uff0c\u6211\u5728\u5916\u4e70\u83dc\u671f\u95f4\uff0c\u6709\u7f51\u53cb\u79c1\u4fe1\u6211\uff0c\u8bf4\u4e0a\u5468\u9762\u8bd5\u963f\u91cc\uff0c\u9762\u4e86 Redis \u7684\u77e5\u8bc6\uff0c\u547d\u4ee4\u4e4b\u7c7b\u7684\u4e00\u4e2a\u4e5f\u6ca1\u95ee\uff0c\u53ea\u95ee\u4e86 Redis \u7684\u5bc6\u7801\u914d\u7f6e\u548c Jedis \u5bf9\u914d\u7f6e\u6587\u4ef6\u7684\u52a0\u89e3\u5bc6\u5904\u7406\u3002\u4ed6\u5f53\u573a\u61f5\u5708\u4e86\uff0c\u9762\u8bd5\u4e4b\u524d\u770b\u4e86\u5f88\u591a Redis \u7684\u77e5\u8bc6\uff0c\u4e00\u4e2a\u4e5f\u6ca1\u95ee\u5230\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1g50nqbweb8j20ve0hk1ci.jpg\" alt=\"\" \/><figcaption>Redis \u8fde\u73af\u70ae\u9762\u8bd5\u9898<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u4eca\u5929\uff0c\u6211\u4eec\u5c31\u4e00\u8d77\u6765\u8bf4\u8bf4\uff0cRedis \u7684\u5bc6\u7801\u8ba4\u8bc1\u914d\u7f6e\u548c Jedis \u7684\u5bf9\u914d\u7f6e\u7684\u52a0\u5bc6\u5bc6\u7801\u7684\u5904\u7406\uff01<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u516c\u53f8\u8d8a\u5927\uff0c\u5b89\u5168\u6027\u8981\u6c42\u8d8a\u9ad8\u3002\u4e3a\u4e86\u4e0d\u8ba9\u4f60\u7684\u6570\u636e\u88f8\u5954\uff0c\u6240\u4ee5\uff0c\u5b89\u5168\u8ba4\u8bc1\u5f88\u6709\u5fc5\u8981\u3002Redis \u7684\u5bc6\u7801\u914d\u7f6e\u6709\u4e24\u79cd\u65b9\u6848\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u76f4\u63a5\u5728 redis.conf \u4e2d\u914d\u7f6e\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1g50nyj01pxj20u00hiwhl.jpg\" alt=\"\" \/><figcaption>Redis \u914d\u7f6e\u5bc6\u7801<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u6bd4\u5982\uff0c\u6211\u7684 redis.conf \u5728 \/usr\/local\/etc\/redis.conf \u4f4d\u7f6e\uff0c\u90a3\u4e48\u6211\u5c31\u7f16\u8f91\u8fd9\u4e2a\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u627e\u5230 #requirepass foobared \u8fd9\u4e00\u884c\uff0c\u53bb\u6389\u524d\u9762\u7684 # \u53f7\u3002\u8bbe\u7f6e\u5bc6\u7801\u4e3a\uff1axttblog\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>requirepass xttblog<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4fdd\u5b58\u6587\u4ef6\uff0c\u7136\u540e\u91cd\u542f Redis\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew services restart redis<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u9664\u4e86\uff0c\u8fd9\u4e00\u79cd\u914d\u7f6e\u5bc6\u7801\u7684\u65b9\u6cd5\uff0c\u8fd8\u6709\u4e00\u79cd\u901a\u8fc7\u547d\u4ee4\u7684\u5f62\u5f0f\u4fee\u6539\u5bc6\u7801\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u901a\u8fc7 config set requirepass \u547d\u4ee4\uff0c\u914d\u7f6e\u4fee\u6539\u5bc6\u7801\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>redis-cli -h 127.0.0.1 -p 6379 -a xttblog<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fde\u63a5\u4e0a\u4e86\u4e4b\u540e\uff0c\u914d\u7f6e\u6216\u4fee\u6539\u65b0\u5bc6\u7801\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>config set requirepass xttblog_new_password<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7136\u540e\uff0c\u65e0\u9700\u91cd\u542f\uff0c\u4e4b\u540e\u7684\u65b0\u94fe\u63a5\u90fd\u5fc5\u987b\u901a\u8fc7\u65b0\u5bc6\u7801\u624d\u80fd\u624d\u80fd\u5b8c\u6210\u8ba4\u8bc1\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u662f\u8fd9\u79cd\u65b9\u5f0f\u6709\u4e00\u4e2a\u95ee\u9898\uff0c\u90a3\u5c31\u662f\uff0c\u5f53\u670d\u52a1\u91cd\u542f\u4e4b\u540e\uff0c\u65b0\u5bc6\u7801\u5c31\u5931\u6548\u4e86\uff0c\u8ba4\u8bc1\u5bc6\u7801\u53c8\u88ab\u91cd\u7f6e\u6210\u4e86\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u5bc6\u7801\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4e00\u65e6\u4f60\u914d\u7f6e\u4e86\u5bc6\u7801\u3002\u90a3\u4e48\u4f60\u8fde\u63a5\u7684 Jedis\uff0c\u96c6\u7fa4\u4e2d\u7684 slave \u90fd\u9700\u8981\u914d\u7f6e\u5bc6\u7801\uff0c\u5426\u5219\u5c31\u65e0\u6cd5\u6b63\u5e38\u4f7f\u7528\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u914d\u7f6e\u5bc6\u7801\u540e\uff0cJedis \u7684\u4f7f\u7528\u5c31\u975e\u5e38\u7b80\u5355\u4e86\u3002\u53ea\u9700\u8981\u5728 yml \u4e2d\uff0c\u914d\u7f6e\u5bc6\u7801\u8ba4\u8bc1\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>spring:\n    redis:\n        host: 127.0.0.1\n        port: 6379\n        password: xttblog_new_password\n        database: 8<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u662f\uff0c\u53ea\u8fd9\u6837\u8fd8\u4e0d\u884c\uff0c\u8fd8\u9700\u8981\u628a\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u5185\u5bb9\u7ed9\u52a0\u5bc6\u4e86\u3002\u7136\u540e\u5728 JedisPool \u4e2d\uff0c\u5bf9\u8981\u4f7f\u7528\u7684\u5bc6\u7801\u8fdb\u884c\u89e3\u5bc6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Bean\npublic JedisPool pool(JedisPoolConfig config, JedisProperties jedisProperties) {\n    return new JedisPool(config, jedisProperties.getHost(), jedisProperties.getPort(), 5000,\n            decryptPwd(jedisProperties.getPassword()), jedisProperties.getDatabase());\n}\nprivate String decryptPwd(String pwd){\n    \/\/\u7701\u7565\u89e3\u5bc6\u4ee3\u7801\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u9664\u6b64\u4e4b\u5916\uff0c\u5927\u5bb6\u90fd\u77e5\u9053\u963f\u91cc\u9762\u8bd5\u7684\u5957\u8def\u3002\u5149\u4f1a\u8fd9\u4e9b\u8fd8\u4e0d\u884c\uff0c\u6bd4\u5982\uff0c\u5bf9\u65b9\u7ee7\u7eed\u5957\u8def\u4f60\uff0c\u539f\u751f Redis \u901a\u8fc7 config get \u547d\u4ee4\u53ef\u80fd\u83b7\u53d6\u5230\u670d\u52a1\u7aef\u654f\u611f\u4fe1\u606f\u3002\u9488\u5bf9\u8fd9\u79cd\u60c5\u51b5\uff0c\u5982\u4f55\u89e3\u51b3\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u4f55\u68c0\u9a8c\/\u6821\u9a8c\u5bc6\u7801\u8bbe\u7f6e\u7684\u590d\u6742\u5ea6\uff1f\u5982\u4f55\u9632\u6b62 Redis \u8ba4\u8bc1\u7684\u66b4\u529b\u7834\u89e3\uff1f\u5982\u4f55\u9650\u5236\u8bbf\u95ee\u7684 IP \u8303\u56f4\uff1f\u767b\u5f55\u8ba4\u8bc1\u65f6\uff0c\u80fd\u5426\u8bb0\u5f55\u65e5\u5fd7\uff1f\u600e\u4e48\u8bb0\u5f55\uff1f\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u660e\u6587\u5bc6\u7801\u5982\u4f55\u52a0\u5bc6\u5904\u7406\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0a\uff0c\u5e0c\u671b\u5927\u5bb6\u5bf9\u6709\u6240\u5e2e\u52a9\u3002\u77e5\u9053\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u8d76\u7d27\u5145\u7535\u5427\uff01<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=4415\">\u963f\u91cc\u7684 Redis \u8fde\u73af\u70ae\u9762\u8bd5\u9898\uff0c\u770b\u7684\u8d44\u6599\u4e00\u4e2a\u4e5f\u6ca1\u7528\u4e0a<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>Redis \u8fd9\u7c7b\u5f00\u6e90\u7684 Key-Value \u6570\u636e\u5e93\u88ab\u8d8a\u6765\u8d8a\u591a\u7684\u516c\u53f8\u6240\u91c7\u7528\uff0c\u4e8e\u662f\u4e4e\uff0cRedis \u5df2\u7ecf\u662f\u6210\u4e86\u9762\u8bd5\u5fc5 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[669,1876,1879,1877,410],"class_list":["post-4415","post","type-post","status-publish","format-standard","hentry","category-java","tag-redis","tag-redis-hgetall-","tag-redis-hgetall","tag-410"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4415"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4415\/revisions"}],"predecessor-version":[{"id":4416,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4415\/revisions\/4416"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}