-1
我正嘗試使用Redis的燒瓶來跟蹤所有在線用戶。我使用Redis代替全局字典的原因是,我可以爲會話設置超時。使用Redis跟蹤Flask中的在線用戶
否則我將不得不運行一個線程來定期刪除用戶,如果他們已經登錄超過10分鐘。
我按照這裏的代碼在我的燒瓶項目中包含Redis http://flask.pocoo.org/snippets/71/ 我在視圖中創建了redis對象,並且在視圖中也包含了輔助函數。但是我得到這個堆棧跟蹤,當我在打電話的get_online_users p.sunion(...)()函數
return self.wsgi_app(environ, start_response)
File "/Users/sahilshah/.virtualenvs/venv/lib/python2.7/site-
packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/sahilshah/.virtualenvs/venv/lib/python2.7/site-
packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/sahilshah/.virtualenvs/venv/lib/python2.7/site-
packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/Users/sahilshah/.virtualenvs/venv/lib/python2.7/site-
packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/sahilshah/.virtualenvs/venv/lib/python2.7/site-
packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/sahilshah/.virtualenvs/venv/lib/python2.7/site-
packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/sahilshah/.virtualenvs/venv/lib/python2.7/site
packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/sahilshah/Documents/2015 Spring Classes/CIS
350/studybuddy/sahil/app/views.py", line 23, in signin
online_users = get_online_users()
File "/Users/sahilshah/Documents/2015 Spring Classes/CIS
350/studybuddy/sahil/app/views.py", line 102, in get_online_users
for x in minutes])
File "/Users/sahilshah/.virtualenvs/venv/lib/python2.7/site-
packages/redis/client.py", line 1543, in sunion
return self.execute_command('SUNION', *args)
File "/Users/sahilshah/.virtualenvs/venv/lib/python2.7/site-
packages/redis/client.py", line 570, in execute_command
connection.send_command(*args)
File "/Users/sahilshah/.virtualenvs/venv/lib/python2.7/site-
packages/redis/connection.py", line 556, in send_command
self.send_packed_command(self.pack_command(*args))
File "/Users/sahilshah/.virtualenvs/venv/lib/python2.7/site-
packages/redis/connection.py", line 532, in send_packed_command
self.connect()
File "/Users/sahilshah/.virtualenvs/venv/lib/python2.7/site
packages/redis/connection.py", line 436, in connect
raise ConnectionError(self._error_message(e))
ConnectionError: Error 61 connecting to localhost:6379. Connection refused.
你需要運行redis :) – Jared
你是什麼意思運行redis? – sahibeast
Redis是一個服務器。它需要運行才能讓您的應用連接到它。 – dirn