django 开发使用redis遇到的问题

django 开发使用redis遇到的问题

1、redis.exceptions.DataError: Invalid input of type: ‘dict’. Convert to a bytes, string, int or float first.

参考博客:https://www.cnblogs.com/hanfe1/p/12634473.html

用python向redis写入数据报错

出错原因:python使用的redis模块版本过高

解决方案:

对python中的redis模块进行降级

pip3 install -U redis==2.10.6 #将当前版本降级到2.10.6

2、Redis (error) NOAUTH Authentication required.

参考开发文档:https://docs.djangoproject.com/zh-hans/2.1/topics/cache/

出错原因:服务端的redis配置了密码,python校验出错

解决方案:

在options中添加password参数

CACHES = {
     
    "verify_code": {
       # 验证码
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://127.0.0.1:6379/2",

        "OPTIONS": {
     
            "PASSWORD": "yourpassword",
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
        }
    },
}

3、redis.exceptions.ResponseError: value is not an integer or out of range

参考博客:https://www.cnblogs.com/lucky-heng/p/11135287.html

出错原因:

3.0的客户端已经废弃了Redis这个类,将之前的StrictRedis类改名为Redis,这样在使用SETEX方法时,参数的顺序已经变了(name, time, value),不再是之前的(name, value,time)

解决方案:

第一种,按照3.x中的规定修改setex函数的参数顺序,第二种,换回2.x,当然还是推荐第一种办法。

你可能感兴趣的:(python,redis,django)