这是我的Python代码:
def check(request):
import redis
R = redis.StrictRedis(host='127.0.0.1', port=6379, db=0)
R.set("name","srk")
r = R.HSET("name","srk")
print(r)
Run Code Online (Sandbox Code Playgroud)
它遇到错误并显示以下错误消息:
Internal Server Error: /get_user/
Traceback (most recent call last):
File "/home/soubhagya/.local/share/virtualenvs/pipenv-r-zifbiy/lib/python3.5/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/soubhagya/.local/share/virtualenvs/pipenv-r-zifbiy/lib/python3.5/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/soubhagya/.local/share/virtualenvs/pipenv-r-zifbiy/lib/python3.5/site-packages/django/core/handlers/base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/soubhagya/Desktop/Dev/rango/backend/access/views.py", line 103, in get_user
r = R.HSET("name","srk")
AttributeError: 'StrictRedis' object has no attribute 'HSET'
Run Code Online (Sandbox Code Playgroud)
在 py-redis 中,如何检查 redis 数据库中是否存在某个值。原始查询会很有帮助。请查看我的代码。
StrictRedis没有任何HSET
功能,但它确实具有hset
在Redis Hashes中设置字段的功能。这就是您收到错误的原因。
要使用 redis-py 检查 Redis 中是否存在密钥,请使用r = R.exists("name")
。
归档时间: |
|
查看次数: |
8086 次 |
最近记录: |