1. 程式人生 > 資料庫 >詳解Redis中key的命名規範和值的命名規範

詳解Redis中key的命名規範和值的命名規範

資料庫中得熱點資料key命名慣例

表名:主鍵名:主鍵值:欄位名
例如 user:id:0001:name
例如 user:id:0002:name
例如 order:id:s2002:price

上面的key對應的值則可以是

存放的方式 key value 優點
單獨的key:value形式 order:id:s2002:price 2000 方便簡單的操作,例如incr自增或自減
json格式 user:id:0001 {id:0001,name:"張三"} 方便一次性存和取資料,但是不方便更新資料

redis 快取 key常量命名規則示例

package com.awj.mall.restfulapi.common.consts;

public class CacheConsts {

  // 簡訊驗證碼型別
  /**
   * 登入
   */
  public static final String SMS_TYPE_LOGIN = "cache:api:sms_login_";
  /**
   * 重置密碼
   */
  public static final String SMS_TYPE_RESETPWD = "cache:api:sms_resetpwd_";
  /**
   * 重置手機號
   */
  public static final String SMS_TYPE_RESETPHONE = "cache:api:sms_resetphone_";
  /**
   * 註冊
   */
  public static final String SMS_TYPE_REG = "cache:api:sms_reg_";
  /**
   * 工單報備報備人校驗
   */
  public static final String SMS_TYPE_PROJECT = "cache:api:sms_project_";
  
  /**
   * 服務商申請
   */
  public static final String SMS_TYPE_SERVICE = "cache:api:sms_service_";
  /**
   * 繫結賬戶
   */
  public static final String SMS_TYPE_BIND_PAYACCOUNT = "cache:api:sms_bing_payaccount_";
  /**
   * 服務商接單後核銷碼簡訊訊息(消費者)
   */
  public static final String SMS_TYPE_SERVICE_HX = "cache:api:sms_service_hx_";


  /**
   * 重置密碼_token
   */
  public static final String SMS_TYPE_RESETPWD_TOKEN = "cache:api:sms_resetpwd:token_";
  /**
   * 重置密碼_手機號
   */
  public static final String SMS_TYPE_RESETPHONE_TOKEN = "cache:api:sms_resetphone:token_";

  //省市區商圈快取
  /**
   * 所有省市區
   */
  public static final String SYS_CITY_LIST = "cache:api:city_list";
  /**
   * 已開通區域包含商圈資訊
   */
  public static final String SYS_CITY_ESC_LIST = "cache:api:city_esc_list";
  /**
   * 所有已開通商圈
   */
  public static final String SYS_ESC_LIST = "cache:api:esc_list";

  public static final Integer SYS_CITY_LIST_EXPIRE_TIME_SECONDS = 60 * 60 * 24 * 15;

  /**
   * 驗證碼過期時間:5分鐘
   */
  public static final Integer CHECKCODE_EXPIRE_TIME_SECONDS = 5 * 60 * 1000;

  /**
   * 驗證碼在redis中的儲存時間:30分鐘
   */
  public static final Integer CHECKCODE_EXPIRE_TIME_SAVE_SECONDS = 30 * 60 * 1000;

  /**
   * 廣告類圖片
   */
  public static final String CACHE_IMAGE_RES_ADV = "cache:image_dir:" + SysConsts.IMAGE_RES_ADV;
  /**
   * 體驗服務中心相關圖片
   */
  public static final String CACHE_IMAGE_RES_ESC = "cache:image_dir:" + SysConsts.IMAGE_RES_ESC;
  /**
   * 品牌店鋪相關圖片
   */
  public static final String CACHE_IMAGE_RES_SHOP = "cache:image_dir:" + SysConsts.IMAGE_RES_SHOP;
  /**
   * 產品相關圖片
   */
  public static final String CACHE_IMAGE_RES_PRODUCT = "cache:image_dir:" + SysConsts.IMAGE_RES_PRODUCT;
  /**
   * 其他圖示/logo相關圖片
   */
  public static final String CACHE_IMAGE_RES_ICON = "cache:image_dir:" + SysConsts.IMAGE_RES_ICON;
  /**
   * 程式使用靜態檔案資源
   */
  public static final String CACHE_IMAGE_RES_STATIC = "cache:image_dir:" + SysConsts.IMAGE_RES_STATIC;

  /**
   * 商品分類儲存
   */
  public static final String CACHE_GOODS_CATE = "cache:goodscate";
  /**
   * 商品分類儲存過期時間
   */
  public static final Integer CACHE_GOODS_CATE_EXPIRE_TIME = 60 * 10;

  /**
   * 品牌儲存
   */
  public static final String CACHE_GOODS_BRAND = "cache:goodsbrand";


  /**
   * 平臺品牌儲存
   */
  public static final String CACHE_GOODS_BRAND_PLATFORM = "cache:goodsbrand:platform";

  /**
   * 商家品牌儲存
   */
  public static final String CACHE_GOODS_BRAND_SHOP = "cache:goodsbrand:shop";

  /**
   * 品牌儲存過期時間
   */
  public static final Integer CACHE_GOODS_BRAND_EXPIRE_TIME = 10 * 60;

  public static final String CACHE_P_USERINFO = "cache:piduserinfo";


  public static final String CACHE_ORDER_UN_PAY = "cache:order:unpay";
  public static final Long CACHE_ORDER_UN_PAY_EXPIRE_TIME = 24 * 60 * 60 * 1000L;


  public static final String CACHE_ORDER_COMMIT = "cache:commit:order:userid_";
  public static final Long CACHE_ORDER_COMMIT_EXPIRE_TIME = 3 * CACHE_ORDER_UN_PAY_EXPIRE_TIME;


  public static final String CACHE_WORKBENCH_UPDATE_MAX_INTEGRATL = "cache:workbeanch:updatemaxintegratl:userid_";

  public static final Long CACHE_SERVICE_EXPIRE_TIME = 30 * 24 * 60 * 60 * 1000L ;

  public static final Integer CACHE_P_USERINFO_EXPIRE_TIME = 30 * 60;


  public static final String CACHE_RANDOM_CATE_LIST = "cache:random_cate:list";


  public static final String CACHE_TAKE_ORDER = "cache:take_order:shop_";


  public static final String CACHE_SHOP_GOODS_PLUS_VOLUME = "cache:shop_goods:plusVolume";


  public static final String CACHE_SHOP_INFO_PLUS_VOLUME = "cache:shop_info:plusVolume";


  public static final String CACHE_SYS_TEMPLATE_CACHE = "cache:sms_template:";


  public static final String CACHE_TOKEN = "cache:token:";
  
  public static final String CACHE_SHOP_IMMEDIATELY_COMMIT = "cache:shop:immediately:commit:userid_";
  
  public static final Long CACHE_SHOP_IMMEDIATELY_COMMIT_EXPIRE_TIME = 10000L;


}

到此這篇關於詳解Redis中key的命名規範和值的命名規範的文章就介紹到這了,更多相關Redis key命名規範內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!