smlamont
smlamont

Reputation: 13

Getting Redis to run in Python on Cloud9

I have seen examples getting Redis to run on Python on Cloud9, but I keep hitting a fundamental error.

Just running:

import os
import redis
#r = redis.Redis()

Yields module and socket errors as follows:

Traceback (most recent call last):

File "/home/ubuntu/workspace/redis-trial.py", line 5, in <module> from redis.client import Redis, StrictRedis                                                                                                                                                                                                          
File "/usr/local/lib/python2.7/dist-packages/redis/__init__.py", line 1, in <module> from redis.client import Redis, StrictRedis                                                                                                                                                                                                         
File "/usr/local/lib/python2.7/dist-packages/redis/client.py", line 10, in <module> from redis.connection import (ConnectionPool, UnixDomainSocketConnection,                                            
File "/usr/local/lib/python2.7/dist-packages/redis/connection.py", line 6, in <module> import socket                                                                                                                                                                                                                                       
File "/home/ubuntu/workspace/socket.py", line 5, in <module> s = socket.socket() # Create a socket object                                                                                                                                                                                             TypeError: 'module' object is not callable

(Yes, I know I commented out the r = redis.Redis(), but I get the same problem regardless whether I leave it in).

I have tried other configurations such as:

r = redis.Redis(host='localhost', port=6379, db=0, password=None, socket_timeout=None, connection_pool=None, charset='utf-8', errors='strict', unix_socket_path=None)

But it keeps crapping out -- looks like at the initial import.

I have Redis-cli running on the server. Running redis-cli ping yields the correct PONG response.

Ideas?

Upvotes: 1

Views: 469

Answers (2)

To install redis-py, simply: $ sudo pip install redis

import redis, os
r_server = redis.Redis(host=os.getenv("IP", "0.0.0.0"), port=6379)

r_server.set('test_key', 'test_value')
print "test_key: " + r_server.get('test_key')

Upvotes: 1

Daniel Roseman
Daniel Roseman

Reputation: 599926

You have a local file called socket.py which is shadowing the standard library socket module. Rename your file.

Upvotes: 0

Related Questions