当前位置:网站首页>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
边栏推荐
- Mature threads should know how to refuse
- Fetch request - simple record
- minio安装部署及使用
- Cabasicanimation pause \ enterprise action
- 物业小区高校水电抄表充值管理系统
- Wechat e-book reading applet graduation project (6) opening defense ppt
- The author of surging issued the pressure test results
- 简历书写注意事项
- Autojs learning-2048 small game automation
- Common errors in golang compilation
猜你喜欢

百度地图技术概述,及基本API与WebApi的应用开发

OSPF路由控制,防环相关知识

物业小区高校水电抄表充值管理系统

Eureka,拿捏日千万级访问量妥妥的!
![[Huang ah code] Introduction to MySQL - 5. Database tips: a single column group by will, and multiple columns?](/img/4d/552c4251779705a6dfd4ceb59c4261.png)
[Huang ah code] Introduction to MySQL - 5. Database tips: a single column group by will, and multiple columns?

Thesis research NLP

iptables防止nmap扫描以及binlog详解

donet framework4. X==windows form application new project, through system Data. SqlClient connects to sqlserver to query

T+0变T+1!快赎金额降至1万!又有银行调整现金理财产品申赎规则

Mature threads should know how to refuse
随机推荐
Avplayer adds playback progress monitoring
Software testing - Advanced
rotoc-gen-go: unable to determine Go import path for **. proto
VirtualLab基础实验教程-7.偏振(3)
CAD视频课程推荐 b站
Fetch request - simple record
异或和加密方式的解密的复现
ospf防环
使用Everything清理垃圾文件
priority_ Introduction and use of queue
Distributed notes (02) - redis of distributed cache (brief description of uses, features, high availability solutions redis cluster, tweetproxy, CODIS)
Week 2022/7/16
MySQL中判断和向下取整的使用场景和用法
MySQL InnoDB transaction related records
DNS原理及解析过程
物业小区高校水电抄表充值管理系统
LeetCode之最大正方形(暴力求解和动态规划求解)
删除文件 unable to find or create trash dirctory
MySQL表的查询进阶
Cannot find module ‘process‘ or its corresponding type declarations.