详解Redis中key的命名规范和值的命名规范
程序员文章站
2022-04-23 20:25:24
数据库中得热点数据key命名惯例 表名:主键名:主键值:字段名 例如 user:id:0001:name...
数据库中得热点数据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命名规范内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!