redis接口用于获取配置文件中的缓存数据库别名,并进行存取。代码如下:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
路径 : ys_redis.py
标题 : 云软redis接口
创建 : 2022-04-13 12:52
更新 : 2022-04-13 12:52
编写 : 陈倚云
"""
VERSION = (4, 11, 0)
__version__ = '.'.join(map(str, VERSION))
"""
1 存入redis数据
conn = get_redis_connection('sms_codes')
ret = conn.set('name', 'Chengl')
2 获取redis数据
conn = get_redis_connection('sms_codes')
name = bytes(conn.get('name')).decode()
"""
def get_redis_connection(alias='default', write=True):
"""
获取redis接口
"""
from django.core.cache import caches
cache = caches[alias]
if not hasattr(cache, "client"):
raise NotImplementedError("settings.py中alias访问错误")
if not hasattr(cache.client, "get_client"):
raise NotImplementedError("settings.py中alias访问错误")
return cache.client.get_client(write)
原创文章,作者:bd101bd101,如若转载,请注明出处:https://blog.ytso.com/tech/bigdata/244820.html