Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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 get函数返回连接错误_Python_Python 2.7_Redis - Fatal编程技术网

Python Redis get函数返回连接错误

Python Redis get函数返回连接错误,python,python-2.7,redis,Python,Python 2.7,Redis,嘿,伙计们,我正在学习一门在线课程,我对Redis一点也不熟悉,所以我真的不知道发生了什么。似乎它引发了连接错误,但我不知道如何修复它。非常感谢你们 import redis if redis_client.get(news_digest) is None: num_of_news += 1 news['digest'] = news_digest 你需要先连接r=redis.redis(host='localhost',port=6379,db

嘿,伙计们,我正在学习一门在线课程,我对Redis一点也不熟悉,所以我真的不知道发生了什么。似乎它引发了连接错误,但我不知道如何修复它。非常感谢你们

import redis
if redis_client.get(news_digest) is None:
            num_of_news += 1
            news['digest'] = news_digest

你需要先连接
r=redis.redis(host='localhost',port=6379,db=0)
您是否在6379端口的本地主机上运行redis?如果没有,您应该…@MarkSetchell它有一行代码要连接。“redis_client=redis.StrictRedis(redis_主机,redis_端口)”@MarkSetchell谢谢!我通过使用brew安装redis解决了这个问题。。。。
if redis_client.get(news_digest) is None:
  File "/usr/local/lib/python2.7/site-packages/redis/client.py", line 1332, in get
    return self.execute_command('GET', name)
  File "/usr/local/lib/python2.7/site-packages/redis/client.py", line 836, in execute_command
    conn = self.connection or pool.get_connection(command_name, **options)
  File "/usr/local/lib/python2.7/site-packages/redis/connection.py", line 1073, in get_connection
    connection.connect()
  File "/usr/local/lib/python2.7/site-packages/redis/connection.py", line 544, in connect
    raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 61 connecting to localhost:6379. Connection refused.