Browse Source

refactor(cache): 统一微信小程序缓存键分隔格式

- 为商城、相册及花材短链接缓存键增加冒号分隔符
- 统一商城海报缓存键的多维度命名格式
shizhongqi 2 days ago
parent
commit
83f8b191ea
1 changed files with 7 additions and 7 deletions
  1. 7 7
      app-hd/controllers/MainController.php

+ 7 - 7
app-hd/controllers/MainController.php

@@ -41,9 +41,9 @@ class MainController extends BaseController
             }
         }
 
-        $goodsShortUrl = 'wx_mini_goods_short_url' . $shopId;
-        $itemShortUrl = 'wx_mini_item_short_url' . $shopId;
-        $imageShortUrl = 'wx_mini_image_short_url' . $shopId;
+        $goodsShortUrl = 'wx_mini_goods_short_url:' . $shopId;
+        $itemShortUrl = 'wx_mini_item_short_url:' . $shopId;
+        $imageShortUrl = 'wx_mini_image_short_url:' . $shopId;
 
         $goodsUrl = Yii::$app->redis->executeCommand('GET', [$goodsShortUrl]);
         $imgUrl = Yii::$app->redis->executeCommand('GET', [$itemShortUrl]);
@@ -87,7 +87,7 @@ class MainController extends BaseController
 
         // ==================== 【性能优化】引入最终海报结果的 Redis 全局强缓存 ====================
         // 缓存键包含店员ID、门店ID、环境版本,保证多维度的唯一性
-        $posterCacheKey = "wx_mini_mall_poster_url_{$shopId}_{$adminId}_{$envVersion}";
+        $posterCacheKey = "wx_mini_mall_poster_url:{$shopId}:{$adminId}:{$envVersion}";
         $cachedPoster = Yii::$app->redis->executeCommand('GET', [$posterCacheKey]);
         if (!empty($cachedPoster)) {
             $respond = json_decode($cachedPoster, true);
@@ -121,7 +121,7 @@ class MainController extends BaseController
         if (getenv('YII_ENV') != 'production' && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
             $goodsLink = 'www.google.com';
         } else {
-            $goodsShortUrl = 'wx_mini_goods_short_url' . $shopId;
+            $goodsShortUrl = 'wx_mini_goods_short_url:' . $shopId;
             $goodsLink = Yii::$app->redis->executeCommand('GET', [$goodsShortUrl]);
             if (empty($goodsLink)) {
                 $goods = miniUtil::generateShortLink($merchant, 'pages/home/index?account=' . $shopId, '', $ptStyle);
@@ -168,7 +168,7 @@ class MainController extends BaseController
         if (getenv('YII_ENV') != 'production' && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
             $albumLink = 'www.google.com';
         } else {
-            $itemShortUrl = 'wx_mini_item_short_url' . $shopId;
+            $itemShortUrl = 'wx_mini_item_short_url:' . $shopId;
             $albumLink = Yii::$app->redis->executeCommand('GET', [$itemShortUrl]);
             if (empty($albumLink)) {
                 $image = miniUtil::generateShortLink($merchant, 'pages/home/mall?account=' . $shopId, '', $ptStyle);
@@ -235,7 +235,7 @@ class MainController extends BaseController
         if (getenv('YII_ENV') != 'production' && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) {
             $flowerLink = 'www.google.com';
         } else {
-            $imageShortUrl = 'wx_mini_image_short_url' . $shopId;
+            $imageShortUrl = 'wx_mini_image_short_url:' . $shopId;
             $flowerLink = Yii::$app->redis->executeCommand('GET', [$imageShortUrl]);
             if (empty($flowerLink)) {
                 $item = miniUtil::generateShortLink($merchant, 'pages/item/item?account=' . $shopId, '', $ptStyle);