Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用python redis检查redis数据库中是否存在值_Python_Redis - Fatal编程技术网

如何使用python redis检查redis数据库中是否存在值

如何使用python redis检查redis数据库中是否存在值,python,redis,Python,Redis,以下是我的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) 它遇到以下错误消息: Internal Server Error: /get_user/ Traceback (most recent ca

以下是我的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)
它遇到以下错误消息:

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'
在py redis中,如何检查redis数据库中是否存在值。 原始查询会很有帮助。
请查看我的代码。

StrictRedis没有
HSET
功能,但它有
HSET
功能,用于设置Redis哈希中的字段。这就是你所犯错误的原因


要使用Redis py检查Redis中是否存在键,请使用
r=r.exists(“name”)

StricRedis没有
HSET
功能,但它有
HSET
功能用于设置Redis哈希中的字段。这就是你所犯错误的原因

要使用Redis py检查Redis中是否存在密钥,请使用
r=r.exists(“名称”)