Frage

I am trying to cache MySQL queries in my Cherrypy server.

I could not figure out how to solve the error when I was installing pylibmc, so I decided to use Redis-py.

Here I am trying a very simple example.

import redis
cache = redis.StrictRedis(host='localhost', port=8080, db=0)
       ...
       ...
cache.set('0', '1') # I also tested with other string keys, but failed with same error

and it's throwing the following error!

[05/May/2014:13:11:13] HTTP Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/cherrypy/_cprequest.py", line 656, in respond
    response.body = self.handler()
  File "/Library/Python/2.7/site-packages/cherrypy/lib/encoding.py", line 188, in __call__
    self.body = self.oldhandler(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/cherrypy/_cpdispatch.py", line 34, in __call__
    return self.callable(*self.args, **self.kwargs)
  File "server.py", line 92, in submit_data
    cache.set(str(idx), '1')#res)
  File "/Library/Python/2.7/site-packages/redis/client.py", line 897, in set
    return self.execute_command('SET', *pieces)
  File "/Library/Python/2.7/site-packages/redis/client.py", line 461, in execute_command
    return self.parse_response(connection, command_name, **options)
  File "/Library/Python/2.7/site-packages/redis/client.py", line 471, in parse_response
    response = connection.read_response()
  File "/Library/Python/2.7/site-packages/redis/connection.py", line 339, in read_response
    response = self._parser.read_response()
  File "/Library/Python/2.7/site-packages/redis/connection.py", line 118, in read_response
    (str(byte), str(response)))
InvalidResponse: Protocol Error: H, TTP/1.1 400 Bad Request

I could not figure out what was wrong, and my website runs without a problem on localhost at port 8080 when I am not using Redis.

War es hilfreich?

Lösung

Your webserver is running on port 8080, not your Redis server. Your Redis server is most likely running on port 6379, unless you changed your config for some reason. Right now you are trying to run Redis queries against your webserver, and that is not going to work. Make sure you are connecting to the correct Redis server address and port and then try again.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top