{"id":6234,"date":"2024-07-04T20:52:58","date_gmt":"2024-07-04T12:52:58","guid":{"rendered":"https:\/\/t.n-years.com\/?p=6234"},"modified":"2024-07-04T20:53:13","modified_gmt":"2024-07-04T12:53:13","slug":"azure-%e6%8f%90%e4%be%9b-redis-%e5%92%8c-mysql-%e6%9c%8d%e5%8a%a1%e5%90%97","status":"publish","type":"post","link":"https:\/\/t.n-years.com\/?p=6234","title":{"rendered":"Azure \u63d0\u4f9b Redis \u548c MySQL \u670d\u52a1\u5417"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u662f\u7684\uff0cAzure \u63d0\u4f9b\u4e86\u6258\u7ba1\u7684 Redis \u548c MySQL \u670d\u52a1\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u4ecb\u7ecd\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Azure Cache for Redis<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Azure Cache for Redis<\/strong> \u662f\u4e00\u4e2a\u5b8c\u5168\u6258\u7ba1\u7684 Redis \u670d\u52a1\uff0c\u63d0\u4f9b\u9ad8\u541e\u5410\u91cf\u3001\u4f4e\u5ef6\u8fdf\u7684\u6570\u636e\u8bbf\u95ee\u3002<\/li>\n\n\n\n<li><strong>\u4f18\u70b9<\/strong>\uff1a<\/li>\n\n\n\n<li>\u5b8c\u5168\u6258\u7ba1\uff0c\u65e0\u9700\u7ba1\u7406\u57fa\u7840\u8bbe\u65bd\u3002<\/li>\n\n\n\n<li>\u652f\u6301\u9ad8\u53ef\u7528\u6027\u548c\u6570\u636e\u6301\u4e45\u6027\u3002<\/li>\n\n\n\n<li>\u591a\u79cd\u7f13\u5b58\u5927\u5c0f\u548c\u6027\u80fd\u9009\u9879\uff0c\u53ef\u6ee1\u8db3\u4e0d\u540c\u9700\u6c42\u3002<\/li>\n\n\n\n<li>\u652f\u6301\u96c6\u7fa4\u6a21\u5f0f\uff0c\u53ef\u4ee5\u6c34\u5e73\u6269\u5c55\u7f13\u5b58\u5bb9\u91cf\u3002<\/li>\n\n\n\n<li>\u63d0\u4f9b\u4e0e Azure \u5176\u4ed6\u670d\u52a1\u7684\u96c6\u6210\uff0c\u5982 Azure Functions\u3001Azure App Service \u7b49\u3002<\/li>\n\n\n\n<li><strong>\u5982\u4f55\u4f7f\u7528<\/strong>\uff1a<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5728 Azure \u95e8\u6237\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 Azure Cache for Redis \u5b9e\u4f8b\u3002<\/li>\n\n\n\n<li>\u914d\u7f6e\u5b9e\u4f8b\u7684\u5927\u5c0f\u3001\u5b9a\u4ef7\u5c42\u548c\u5176\u4ed6\u9009\u9879\u3002<\/li>\n\n\n\n<li>\u83b7\u53d6\u8fde\u63a5\u5b57\u7b26\u4e32\uff0c\u5c06\u5176\u96c6\u6210\u5230\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528 Redis \u8fdb\u884c\u7f13\u5b58\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Azure Database for MySQL<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Azure Database for MySQL<\/strong> \u662f\u4e00\u4e2a\u5b8c\u5168\u6258\u7ba1\u7684 MySQL \u6570\u636e\u5e93\u670d\u52a1\uff0c\u63d0\u4f9b\u4f01\u4e1a\u7ea7\u529f\u80fd\u3001\u6027\u80fd\u548c\u5b89\u5168\u6027\u3002<\/li>\n\n\n\n<li><strong>\u4f18\u70b9<\/strong>\uff1a<\/li>\n\n\n\n<li>\u5b8c\u5168\u6258\u7ba1\u7684 MySQL \u6570\u636e\u5e93\u670d\u52a1\uff0c\u652f\u6301\u81ea\u52a8\u66f4\u65b0\u3001\u5907\u4efd\u548c\u76d1\u63a7\u3002<\/li>\n\n\n\n<li>\u63d0\u4f9b\u9ad8\u53ef\u7528\u6027\u3001\u81ea\u52a8\u6545\u969c\u8f6c\u79fb\u548c\u533a\u57df\u590d\u5236\u3002<\/li>\n\n\n\n<li>\u591a\u79cd\u5b9a\u4ef7\u5c42\u548c\u914d\u7f6e\u9009\u9879\uff0c\u9002\u5e94\u4e0d\u540c\u7684\u6027\u80fd\u548c\u5b58\u50a8\u9700\u6c42\u3002<\/li>\n\n\n\n<li>\u652f\u6301\u7075\u6d3b\u7684\u7f29\u653e\u548c\u8c03\u6574\u6570\u636e\u5e93\u6027\u80fd\u3002<\/li>\n\n\n\n<li>\u63d0\u4f9b\u4e0e Azure \u5176\u4ed6\u670d\u52a1\u7684\u96c6\u6210\uff0c\u5982 Azure App Service\u3001Azure Kubernetes Service (AKS) \u7b49\u3002<\/li>\n\n\n\n<li><strong>\u5982\u4f55\u4f7f\u7528<\/strong>\uff1a<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5728 Azure \u95e8\u6237\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 Azure Database for MySQL \u5b9e\u4f8b\u3002<\/li>\n\n\n\n<li>\u914d\u7f6e\u5b9e\u4f8b\u7684\u8ba1\u7b97\u8d44\u6e90\u3001\u5b58\u50a8\u548c\u9ad8\u53ef\u7528\u6027\u9009\u9879\u3002<\/li>\n\n\n\n<li>\u83b7\u53d6\u8fde\u63a5\u5b57\u7b26\u4e32\uff0c\u5c06\u5176\u96c6\u6210\u5230\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4ee5\u4f7f\u7528 MySQL \u6570\u636e\u5e93\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u7efc\u5408\u6bd4\u8f83<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Azure Cache for Redis<\/strong>\uff1a<\/li>\n\n\n\n<li>\u9002\u7528\u4e8e\u9700\u8981\u9ad8\u541e\u5410\u91cf\u3001\u4f4e\u5ef6\u8fdf\u6570\u636e\u8bbf\u95ee\u7684\u5e94\u7528\u573a\u666f\u3002<\/li>\n\n\n\n<li>\u5e38\u7528\u4e8e\u7f13\u5b58\u3001\u4f1a\u8bdd\u5b58\u50a8\u3001\u5b9e\u65f6\u5206\u6790\u7b49\u9700\u8981\u5feb\u901f\u8bbf\u95ee\u6570\u636e\u7684\u573a\u666f\u3002<\/li>\n\n\n\n<li><strong>Azure Database for MySQL<\/strong>\uff1a<\/li>\n\n\n\n<li>\u9002\u7528\u4e8e\u5173\u7cfb\u578b\u6570\u636e\u5e93\u9700\u6c42\uff0c\u5305\u62ec\u4e8b\u52a1\u5904\u7406\u3001\u590d\u6742\u67e5\u8be2\u548c\u6570\u636e\u6301\u4e45\u6027\u3002<\/li>\n\n\n\n<li>\u5e38\u7528\u4e8e\u5e94\u7528\u7a0b\u5e8f\u7684\u6570\u636e\u5b58\u50a8\u3001\u62a5\u544a\u548c\u5206\u6790\u7b49\u573a\u666f\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u90e8\u7f72\u548c\u4f7f\u7528\u793a\u4f8b<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\u4f7f\u7528 Azure Cache for Redis<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u521b\u5efa Redis \u5b9e\u4f8b<\/strong>\uff1a<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u767b\u5f55\u5230 Azure \u95e8\u6237\u3002<\/li>\n\n\n\n<li>\u641c\u7d22\u5e76\u9009\u62e9\u201cAzure Cache for Redis\u201d\u3002<\/li>\n\n\n\n<li>\u70b9\u51fb\u201c\u6dfb\u52a0\u201d\uff0c\u586b\u5199\u5b9e\u4f8b\u7684\u57fa\u672c\u4fe1\u606f\uff08\u540d\u79f0\u3001\u8ba2\u9605\u3001\u8d44\u6e90\u7ec4\u3001\u4f4d\u7f6e\u3001\u5b9a\u4ef7\u5c42\u7b49\uff09\u3002<\/li>\n\n\n\n<li>\u70b9\u51fb\u201c\u521b\u5efa\u201d\u4ee5\u90e8\u7f72 Redis \u5b9e\u4f8b\u3002<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u83b7\u53d6\u8fde\u63a5\u5b57\u7b26\u4e32<\/strong>\uff1a<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u90e8\u7f72\u5b8c\u6210\u540e\uff0c\u8fdb\u5165\u5b9e\u4f8b\u6982\u89c8\u9875\u9762\u3002<\/li>\n\n\n\n<li>\u5728\u201c\u8bbe\u7f6e\u201d\u90e8\u5206\uff0c\u627e\u5230\u201c\u8bbf\u95ee\u5bc6\u94a5\u201d\uff0c\u83b7\u53d6\u8fde\u63a5\u5b57\u7b26\u4e32\u548c\u8bbf\u95ee\u5bc6\u94a5\u3002<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528 Redis<\/strong>\uff08Go \u793a\u4f8b\uff09\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   package main\n\n   import (\n       \"github.com\/go-redis\/redis\/v8\"\n       \"context\"\n       \"fmt\"\n   )\n\n   var ctx = context.Background()\n\n   func main() {\n       rdb := redis.NewClient(&amp;redis.Options{\n           Addr:     \"your-redis-instance.redis.cache.windows.net:6380\",\n           Password: \"your-access-key\",\n           DB:       0,\n       })\n\n       err := rdb.Set(ctx, \"key\", \"value\", 0).Err()\n       if err != nil {\n           panic(err)\n       }\n\n       val, err := rdb.Get(ctx, \"key\").Result()\n       if err != nil {\n           panic(err)\n       }\n       fmt.Println(\"key\", val)\n   }<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u4f7f\u7528 Azure Database for MySQL<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u521b\u5efa MySQL \u5b9e\u4f8b<\/strong>\uff1a<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u767b\u5f55\u5230 Azure \u95e8\u6237\u3002<\/li>\n\n\n\n<li>\u641c\u7d22\u5e76\u9009\u62e9\u201cAzure Database for MySQL\u201d\u3002<\/li>\n\n\n\n<li>\u70b9\u51fb\u201c\u6dfb\u52a0\u201d\uff0c\u586b\u5199\u5b9e\u4f8b\u7684\u57fa\u672c\u4fe1\u606f\uff08\u540d\u79f0\u3001\u8ba2\u9605\u3001\u8d44\u6e90\u7ec4\u3001\u4f4d\u7f6e\u3001\u5b9a\u4ef7\u5c42\u7b49\uff09\u3002<\/li>\n\n\n\n<li>\u70b9\u51fb\u201c\u521b\u5efa\u201d\u4ee5\u90e8\u7f72 MySQL \u5b9e\u4f8b\u3002<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u83b7\u53d6\u8fde\u63a5\u5b57\u7b26\u4e32<\/strong>\uff1a<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u90e8\u7f72\u5b8c\u6210\u540e\uff0c\u8fdb\u5165\u5b9e\u4f8b\u6982\u89c8\u9875\u9762\u3002<\/li>\n\n\n\n<li>\u5728\u201c\u8fde\u63a5\u5b57\u7b26\u4e32\u201d\u90e8\u5206\uff0c\u83b7\u53d6\u7528\u4e8e\u8fde\u63a5 MySQL \u6570\u636e\u5e93\u7684\u8fde\u63a5\u4fe1\u606f\u3002<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528 MySQL<\/strong>\uff08Go \u793a\u4f8b\uff09\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   package main\n\n   import (\n       \"database\/sql\"\n       \"fmt\"\n       _ \"github.com\/go-sql-driver\/mysql\"\n   )\n\n   func main() {\n       dsn := \"username:password@tcp(your-mysql-instance.mysql.database.azure.com:3306)\/database\"\n       db, err := sql.Open(\"mysql\", dsn)\n       if err != nil {\n           panic(err)\n       }\n       defer db.Close()\n\n       err = db.Ping()\n       if err != nil {\n           panic(err)\n       }\n       fmt.Println(\"Connected to MySQL database!\")\n\n       \/\/ Perform database operations here\n   }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7 Azure \u63d0\u4f9b\u7684\u6258\u7ba1\u670d\u52a1\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u5728\u4e91\u7aef\u90e8\u7f72\u548c\u7ba1\u7406 Redis \u548c MySQL\uff0c\u4ece\u800c\u4e13\u6ce8\u4e8e\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u548c\u4e1a\u52a1\u903b\u8f91\uff0c\u800c\u4e0d\u5fc5\u62c5\u5fc3\u5e95\u5c42\u57fa\u7840\u8bbe\u65bd\u7684\u7ef4\u62a4\u548c\u7ba1\u7406\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u662f\u7684\uff0cAzure \u63d0\u4f9b\u4e86\u6258\u7ba1\u7684 Redis \u548c MySQL \u670d\u52a1\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u4ecb\u7ecd\uff1a Azure Cache f&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/t.n-years.com\/?p=6234\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-6234","post","type-post","status-publish","format-standard","hentry","category-5"],"_links":{"self":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6234","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6234"}],"version-history":[{"count":1,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6234\/revisions"}],"predecessor-version":[{"id":6235,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6234\/revisions\/6235"}],"wp:attachment":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}