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

zdppy_cache缓存框架升级,支持用户级别的缓存隔离,支持超级管理员管理普通用户的缓存

启动服务

import zdppy_api as api
import zdppy_cache

key1 = "admin"
key2 = "admin"

app = api.Api(routes=[
    *zdppy_cache.zdppy_api.cache(key1, key2, api)
])

if __name__ == '__main__':
    import zdppy_uvicorn

    zdppy_uvicorn.run(app, host="0.0.0.0", port=8888)

基于用户的缓存隔离

测试代码:

import req

# 用户1设置缓存
headers = {
    "key1": "zhangdapeng",
    "key2": "zhangdapeng520",
}
resp = req.post("http://127.0.0.1:8888/zdppy_cache", json={
    "key": "name",
    "value": "张三"
}, headers=headers)
print(resp.json())

resp = req.get("http://127.0.0.1:8888/zdppy_caches", json={}, headers=headers)
print(resp.json())

resp = req.get("http://127.0.0.1:8888/zdppy_cache", json={"key": "name"}, headers=headers)
print(resp.json())

# 用户2设置缓存
headers2 = {
    "key1": "zhangdapeng1",
    "key2": "zhangdapeng521",
}
resp = req.post("http://127.0.0.1:8888/zdppy_cache", json={
    "key": "name",
    "value": "张三333"
}, headers=headers2)
print(resp.json())
resp = req.get("http://127.0.0.1:8888/zdppy_cache", json={"key": "name"}, headers=headers2)
print(resp.json())
resp = req.get("http://127.0.0.1:8888/zdppy_cache", json={"key": "name"}, headers=headers)
print("用户1相同的key", resp.json())

不同的用户,相同的key,得到的是不同的值。
在这里插入图片描述

超级管理员可以管理普通用户的缓存

测试代码:

import req

# 用户1设置缓存
headers = {
    "key1": "zhangdapeng",
    "key2": "zhangdapeng520",
}
resp = req.post("http://127.0.0.1:8888/zdppy_cache", json={
    "key": "name",
    "value": "张三"
}, headers=headers)
print(resp.json())
resp = req.get("http://127.0.0.1:8888/zdppy_cache", json={"key": "name"}, headers=headers)
print(resp.json())

# 通过管理员获取用户缓存
headers2 = {
    "key1": "admin",
    "key2": "admin",
    "username": "zhangdapeng",  # 指定要操作的用户
}
resp = req.get("http://127.0.0.1:8888/zdppy_cache/manage", json={
    "key": "name",
}, headers=headers2)
print(resp.json())

# 通过管理员删除用户缓存
resp = req.delete("http://127.0.0.1:8888/zdppy_cache/manage", json={
    "key": "name",
}, headers=headers2)
print(resp.json())

# 用户自己查询缓存
resp = req.get("http://127.0.0.1:8888/zdppy_cache", json={"key": "name"}, headers=headers)
print(resp.json())

输出结果:
在这里插入图片描述


http://www.kler.cn/news/290415.html

相关文章:

  • 【MySql】面试问答:在使用mysql时,遇到分页查询慢的情况怎么处理?
  • 观测云核心技术解密:eBPF Tracing 实现原理
  • Java项目:137 springboot基于springboot的智能家居系统
  • 1. 深度学习基础:从神经网络到深度学习
  • CSS系列之浮动清除clear(三)
  • ztree搜索结果高亮变颜色(非highlight属性)
  • upload文件上传靶场
  • 在react中用three.js 渲染模型 在上面创建标签
  • 传统CV算法——基于opencv的答题卡识别判卷系统
  • 【大数据】Java与Python的无缝对接:探讨Java调用Python的方法与原理
  • <数据集>车辆识别数据集<目标检测>
  • 你必须知道的C语言问题(8)
  • Go 中间件学习
  • 【CanMV K230】边缘检测
  • 羊大师:白露养生经,羊奶不可少
  • docker实战基础一 (Docker基础命令)
  • 【云原生】Helm来管理Kubernetes集群的详细使用方法与综合应用实战
  • C++实现简易俄罗斯方块小游戏
  • Apache SeaTunnel Zeta 引擎源码解析(一)Server端的初始化
  • 心觉:如何填平想象和愿望之间的鸿沟?
  • Docker设置socks5代理
  • 大模型超详细解读汇总
  • 一个“改造”的工厂背后:中国电商的AI重构
  • 赛码网牛客在acm模式下利用node.js处理多行输入方法
  • 视频结构化从入门到精通——图像算法类型介绍
  • LuaJit分析(三)luajit字节码文件格式
  • 【C++】string的模拟实现
  • 1119 Pre- and Post-order Traversals
  • Django学习(二)
  • 基因对应身体的需求 平衡饮食的重要性 第四篇