[mw_shl_code=python,true]from rediscluster import StrictRedisCluster
import time
def redis_cluster():
redis_nodes = [{'host':'192.168.188.88','port':7001},
{'host':'192.168.188.88','port':7002},
{'host':'192.168.188.89','port':7003},
{'host':'192.168.188.89','port':7004},
{'host':'192.168.188.143','port':7005},
{'host':'192.168.188.143','port':7006}
]
try:
redisconn = StrictRedisCluster(startup_nodes = redis_nodes,decode_responses=True, password='abc')
except Exception as e:
print("connect error: %s"%e)
redis_cluster()
# sys.exit(1)
# redisconn.set('name','kk')
print("name is", redisconn.get('name'))
i = 0
while True:
i = i +1
print(i)
redis_cluster()
time.sleep(0.5)[/mw_shl_code]
代码如上,在执行的时候报错:
[mw_shl_code=applescript,true]Traceback (most recent call last):
File "<ipython-input-14-ec6a84dd9f89>", line 1, in <module>
runfile('C:/Users/shuangyu/Documents/redis.py', wdir='C:/Users/shuangyu/Documents')
File "C:\Users\shuangyu\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile
execfile(filename, namespace)
File "C:\Users\shuangyu\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/shuangyu/Documents/redis.py", line 8, in <module>
from rediscluster import StrictRedisCluster
File "C:\Users\shuangyu\Anaconda3\lib\site-packages\rediscluster\__init__.py", line 7, in <module>
from .client import StrictRedisCluster, RedisCluster
File "C:\Users\shuangyu\Anaconda3\lib\site-packages\rediscluster\client.py", line 10, in <module>
from .connection import ClusterConnectionPool, ClusterReadOnlyConnectionPool
File "C:\Users\shuangyu\Anaconda3\lib\site-packages\rediscluster\connection.py", line 11, in <module>
from .nodemanager import NodeManager
File "C:\Users\shuangyu\Anaconda3\lib\site-packages\rediscluster\nodemanager.py", line 8, in <module>
from .exceptions import RedisClusterException
File "C:\Users\shuangyu\Anaconda3\lib\site-packages\rediscluster\exceptions.py", line 3, in <module>
from redis.exceptions import (
File "C:\Users\shuangyu\Documents\redis.py", line 8, in <module>
from rediscluster import StrictRedisCluster
ImportError: cannot import name 'StrictRedisCluster'[/mw_shl_code]
redis-py-cluster 模块重新安装过,还是不行。
目前的情况是spyder中和在cmd下运行都报同样的错误,但将代码输入ipython中则可以正常执行。不太清楚这个是什么问题,烦请知道的大大指点下!谢谢!
|