Python导入有密码的redis模块中的StrictRedis验证密码

在使用Python操作Redis时,若Redis服务器设置了密码,会出现'NOAUTH Authentication required.'的错误,需要进行身份验证。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

def create_app(config_name):
    setup_log(config_name)
    app = Flask(__name__)
    CORS(app)
    app.config.from_object(config[config_name])
    config[config_name].init_app(app)
    moment.init_app(app)
    db.init_app(app)
    # 初始化 redis 存储对象
    global redis_store
    redis_store = StrictRedis(host=config[config_name].REDIS_HOST, port=config[config_name].REDIS_PORT,decode_responses=True,password=config[config_name].REDIS_PASSWROD)
    # 开启csrf保护
    # CSRFProtect(app)
    # 设置session保存指定位置
    Session(app)
    configure_uploads(app, files)
    from .cloud import cloud as cloud_blueprint 
    。。。
    。。。蓝图略
    app.register_blueprint(device_blueprint, url_prefix='/device')
    env = os.getenv('FLASK_CONFIG')
    if env is None:
        app.config["SQLALCHEMY_ECHO"] = False
    socketio.init_app(app=app, async_mode=async_mode) 
    return app


class Config:
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'wangchihaiownseries'
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True
 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值