当前位置: 首页 > news >正文

使用redis设置店铺状态

 知识点:

将前端传过来的status(0,1)通过redis对象以key,values值的形式存放在redis中。

#设置店铺状态

redisTemplate.opsForValue().set(KEY,status);

#获取店铺状态

Integer  status = (Integer) redisTemplate.opsForValue().get(KEY);

#设置一个静态常量

 public final static String KEY="SHOP_STATUS";

package com.sky.controller.admin;

import com.sky.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController("adminShopController")
@RequestMapping("/admin/shop")
public class ShopController {

    public final static String KEY="SHOP_STATUS";

    @Autowired
    private RedisTemplate redisTemplate;


    @PutMapping("/{status}")
    public Result setStatus(@PathVariable Integer status){
        log.info("设置店铺的营业状态为:{}",status == 1 ? "营业中":"大洋中");
        redisTemplate.opsForValue().set(KEY,status);
        return Result.success();
    }

    @GetMapping("/status")
    public Result<Integer> getStatus(){
        Integer  status = (Integer) redisTemplate.opsForValue().get(KEY);
        log.info("获取店铺的状态:{}",status == 1 ? "营业中":"大洋中");
        return Result.success(status);
    }
}

http://www.dtcms.com/a/91484.html

相关文章:

  • 【ESP32-C2】基于 esptool 完成 Secure Boot V2 和 Flash 加密 Development 模式的完整指令序列
  • 遥控器钥匙学习---通过uds指令
  • How to share files with Linux mint 22 via samba in Windows
  • spring - 十二种事务失效场景
  • python虚拟环境安装opus(windows)
  • 大模型重点1 【综述-文字版】
  • 深度解析提示词工程:让AI成为你的超级助手(2025实战指南)
  • CI/CD(四) docker-compose 安装harbor
  • WebGPU 是比 WASM 更好的选择吗? (Is WebGPU a Better Choice Than WASM? )
  • 鸿蒙开发之背景图片的使用
  • mongoShake数据迁移
  • 什么是Vue.js
  • 网管软件Zabbix3.4.8 使用笔记 - 更改记录保留的时间 20250325
  • 【Ai】--- 可视化 DeepSeek-r1 接入 Open WebUI(超详细)
  • 深入理解数据类型、建表与数据库引擎
  • K8S——PaaS平台pod调度机制
  • Rust从入门到精通之进阶篇:16.智能指针
  • 选素数--线性筛
  • 网络基础-路由器和交换机工作配置
  • Redis--redis客户端
  • NodeJs之fs模块
  • Gunicorn部署指南:核心参数详解与实践
  • (UI自动化测试web端)第二篇:元素定位的方法_css定位之ID选择器
  • 【Spring AI】基于专属知识库的RAG智能问答小程序开发——功能优化:用户鉴权主体功能开发
  • 从输入 URL 到页面加载完成,发生了什么?
  • sql结尾加刷题
  • 【LeetCode 题解】算法:4.寻找两个正序数组的中位数
  • Spring WebSecurityCustomizer 的作用
  • Resume全栈项目(一)(.NET)
  • wokwi arduino mega 2560 - 键盘与LCD显示