Redis:无效的数据库索引

Redis:无效的数据库索引,redis,amazon-elasticache,Redis,Amazon Elasticache,我最近通过AWS启动了一个redis数据库,并想用一些初始的伪代码进行一些测试。在同一VPC内的EC2实例上运行代码时,我遇到了一个错误:redis.exceptions.ResponseError:invalid DB index 代码如下: import redis import pickle import zlib EXPIRATION_SECONDS = 600 r = redis.Redis(host='dse-inventory-orders.xxxxxx.xxxxxx.xxxxxx

我最近通过AWS启动了一个redis数据库,并想用一些初始的伪代码进行一些测试。在同一VPC内的EC2实例上运行代码时,我遇到了一个错误:
redis.exceptions.ResponseError:invalid DB index

代码如下:

import redis
import pickle
import zlib
EXPIRATION_SECONDS = 600
r = redis.Redis(host='dse-inventory-orders.xxxxxx.xxxxxx.xxxxxx.cache.amazonaws.com',
                port=6379, db='dse-inventory-orders')
r.set('foo', 'bar')
r.get('foo')

logger.info(f"r.get('foo'): {r.get('foo')}")
这是错误消息。你知道我做错了什么吗

Traceback (most recent call last):
File "/tmp/scripts/redis_test.py", line 25, in <module>
r.set('foo', 'bar')
File "/home/ec2-user/anaconda3/envs/solver_env/lib/python3.7/site-packages/redis/client.py", line 1801, in set
return self.execute_command('SET', *pieces)
File "/home/ec2-user/anaconda3/envs/solver_env/lib/python3.7/site-packages/redis/client.py", line 898, in execute_command
conn = self.connection or pool.get_connection(command_name, **options)
File "/home/ec2-user/anaconda3/envs/solver_env/lib/python3.7/site-packages/redis/connection.py", line 1192, in get_connection
connection.connect()
File "/home/ec2-user/anaconda3/envs/solver_env/lib/python3.7/site-packages/redis/connection.py", line 567, in connect
self.on_connect()
File "/home/ec2-user/anaconda3/envs/solver_env/lib/python3.7/site-packages/redis/connection.py", line 664, in on_connect
if nativestr(self.read_response()) != 'OK':
File "/home/ec2-user/anaconda3/envs/solver_env/lib/python3.7/site-packages/redis/connection.py", line 756, in read_response
raise response
redis.exceptions.ResponseError: invalid DB index
ERROR conda.cli.main_run:execute(39): Subprocess for 'conda run ['/bin/bash', '/usr/local/bin/fetch_and_run.sh', 'pythonRunnerCplex.sh', 's3://srdata-lab/ipredict_dev/dynamic_scheduling_engine/scripts/redis_test.py', 'redis_test.py']' command failed. Stderr was:
    
Traceback (most recent call last):
File "/tmp/scripts/redis_test.py", line 25, in <module>
r.set('foo', 'bar')
File "/home/ec2-user/anaconda3/envs/solver_env/lib/python3.7/site-packages/redis/client.py", line 1801, in set
return self.execute_command('SET', *pieces)
File "/home/ec2-user/anaconda3/envs/solver_env/lib/python3.7/site-packages/redis/client.py", line 898, in execute_command
conn = self.connection or pool.get_connection(command_name, **options)
File "/home/ec2-user/anaconda3/envs/solver_env/lib/python3.7/site-packages/redis/connection.py", line 1192, in get_connection
connection.connect()
File "/home/ec2-user/anaconda3/envs/solver_env/lib/python3.7/site-packages/redis/connection.py", line 567, in connect
self.on_connect()
File "/home/ec2-user/anaconda3/envs/solver_env/lib/python3.7/site-packages/redis/connection.py", line 664, in on_connect
if nativestr(self.read_response()) != 'OK':
File "/home/ec2-user/anaconda3/envs/solver_env/lib/python3.7/site-packages/redis/connection.py", line 756, in read_response
raise response
redis.exceptions.ResponseError: invalid DB index
回溯(最近一次呼叫最后一次):
文件“/tmp/scripts/redis_test.py”,第25行,在
r、 集合('foo','bar')
文件“/home/ec2 user/anaconda3/envs/solver_env/lib/python3.7/site packages/redis/client.py”,第1801行,在集合中
返回self.execute_命令('SET',*个)
文件“/home/ec2 user/anaconda3/envs/solver_env/lib/python3.7/site packages/redis/client.py”,第898行,在execute_命令中
conn=self.connection或pool.get\u connection(命令名,**选项)
文件“/home/ec2 user/anaconda3/envs/solver_env/lib/python3.7/site packages/redis/connection.py”,第1192行,在get_connection中
connection.connect()
文件“/home/ec2 user/anaconda3/envs/solver_env/lib/python3.7/site packages/redis/connection.py”,第567行,在connect中
self.on_connect()
文件“/home/ec2 user/anaconda3/envs/solver_env/lib/python3.7/site packages/redis/connection.py”,on_connect中第664行
如果nativestr(self.read_response())!='好的:
文件“/home/ec2 user/anaconda3/envs/solver_env/lib/python3.7/site packages/redis/connection.py”,第756行,在read_响应中
提出回应
redis.exceptions.ResponseError:无效的数据库索引
错误conda.cli.main_run:execute(39):'conda run['/bin/bash'、'/usr/local/bin/fetch_and_run.sh'、'pythonRunnerCplex.sh'、's3://srdata lab/ipredict_dev/dynamic_scheduling_engine/scripts/redis_test.py'、'redis_test.py']命令的子进程失败。Stderr是:
回溯(最近一次呼叫最后一次):
文件“/tmp/scripts/redis_test.py”,第25行,在
r、 集合('foo','bar')
文件“/home/ec2 user/anaconda3/envs/solver_env/lib/python3.7/site packages/redis/client.py”,第1801行,在集合中
返回self.execute_命令('SET',*个)
文件“/home/ec2 user/anaconda3/envs/solver_env/lib/python3.7/site packages/redis/client.py”,第898行,在execute_命令中
conn=self.connection或pool.get\u connection(命令名,**选项)
文件“/home/ec2 user/anaconda3/envs/solver_env/lib/python3.7/site packages/redis/connection.py”,第1192行,在get_connection中
connection.connect()
文件“/home/ec2 user/anaconda3/envs/solver_env/lib/python3.7/site packages/redis/connection.py”,第567行,在connect中
self.on_connect()
文件“/home/ec2 user/anaconda3/envs/solver_env/lib/python3.7/site packages/redis/connection.py”,on_connect中第664行
如果nativestr(self.read_response())!='好的:
文件“/home/ec2 user/anaconda3/envs/solver_env/lib/python3.7/site packages/redis/connection.py”,第756行,在read_响应中
提出回应
redis.exceptions.ResponseError:无效的数据库索引

建立连接时

redis.Redis(host='dse-inventory-orders.xxxxxx.xxxxxx.xxxxxx.cache.amazonaws.com',
                port=6379, db='dse-inventory-orders')
您使用
db
作为
dse库存订单
(字符串),但根据

选择具有指定的基于零的数字索引的Redis逻辑数据库。新连接始终使用数据库0


因此,将其替换为
0
,它将在建立连接时工作。

redis.Redis(host='dse-inventory-orders.xxxxxx.xxxxxx.xxxxxx.cache.amazonaws.com',
                port=6379, db='dse-inventory-orders')
您使用
db
作为
dse库存订单
(字符串),但根据

选择具有指定的基于零的数字索引的Redis逻辑数据库。新连接始终使用数据库0

因此,将其替换为
0
,它将起作用