当前位置:网站首页>py3 redis通用调用
py3 redis通用调用
2022-07-17 04:34:00 【小小的木头人】
记录一个python通用的调用类
# -*- coding: utf-8 -*-
import redis
import json
from config import OFFICIAL_APIS
class Redis_read_write:
@staticmethod
def get_redis():
""" 获取 Redis 的连接 """
r = redis.Redis(host=OFFICIAL_APIS['redis_ip'], port=OFFICIAL_APIS['redis_port'], username=None, password=None,
db=0)
return r
# set_data(key_name, access_token, ex=7100)
@staticmethod
def set_data(name, value, **kwargs):
# 将数据存入redis缓存
r = Redis_read_write.get_redis()
value = json.dumps(value)
r.set(name, value, **kwargs)
# get_data(key_name)
@staticmethod
def get_data(name):
# 取出key为name的值
r = Redis_read_write.get_redis()
value = r.get(name)
if value:
value = json.loads(value)
return value
边栏推荐
- Wechat e-book reading applet graduation project (6) opening defense ppt
- AutoJs学习-实现极乐净土
- priority_ Introduction and use of queue
- 使用kaggle跑李宏毅机器学习作业
- Touchid and faceid~1
- 探索:制药厂系统网络时钟同步(NTP时间同步服务器)
- 对于每一个 Provider 实例都会维护多个连接
- 万文多图之Word高效插入参考文献
- [Unity] Input.gettouch[index]的index
- Autojs learning-2048 small game automation
猜你喜欢
MySql 一行变多行(根据特定符号分割)
Eureka,拿捏日千万级访问量妥妥的!
LeetCode之最大正方形(暴力求解和动态规划求解)
[ruoyi Vue plus] learning notes 30 - redisson (VI) bounded blocking queue (redisson source code + Lua script)
实时BI(四)低成本的数据准实时处理思路
CAD video course recommendation station B
使用小丸工具箱进行极限视频压缩
PyTorch Image Models(timm)库
‘ionic‘ 不是内部或外部命令,也不是可运行的程序或批处理文件。
T + 0 to t + 1! The quick redemption amount is reduced to 10000! Another bank adjusted the rules for the application and redemption of cash wealth management products
随机推荐
树状数组:[JXOI2017]加法 题解
实时BI(四)低成本的数据准实时处理思路
SQL interface switching cannot obtain focus
By voting for the destruction of STI by Dao, seektiger is truly community driven
C# List 集合对象去重 Linq去重 带时间去重
Golang reverse slice code example
基于JIRA7.9.2定制修改
STM32 - timer series (II) general timer
百度地图技术概述,及基本API与WebApi的应用开发
Impersonate the server for requests
Eas (energy aware scheduling) green energy-saving scheduler
VB.NET插件开发- 提取文件
Phthon3 install mysqldb error problem solving reason: image not found
Mature threads should know how to refuse
LeetCode之最大正方形(暴力求解和动态规划求解)
Intensive reading series of papers
使用Everything清理垃圾文件
64. Minimum path sum: given an M x n grid containing non negative integers, please find a path from the upper left corner to the lower right corner, so that the sum of the numbers on the path is the m
Simulation Implementation of library function
Optimization and configuration of OSPF