redis.exceptions.connectionerror-

6gpjuf90  于 2021-06-09  发布在  Redis
关注(0)|答案(1)|浏览(630)

我已经写了一个程序,做多重处理,扫描,获取,并设置为redis。我们使用redis的原因是为了加快速度。
有人有什么建议吗。我试着在get语句周围放置一个retry循环(对于set也可以这样做),但是scan语句将更加棘手。是否有一些参数我扫描改变或增加,以避免这一点?
错误:

redis.exceptions.ConnectionError: Error 10048 connecting to 192.168.5.51:6379. Only one usage of each socket address (protocol/network address/port) is normally permitted.
  File "C:\Apps\ProcessData\redis\connection.py", line 1192, in get_connection
    connection.connect()
  File "C:\Apps\ProcessData\redis\connection.py", line 563, in connect
    raise ConnectionError(self._error_message(e))
  File "C:\Apps\ProcessData\redis\connection.py", line 563, in connect
    raise ConnectionError(self._error_message(e))

我认为错误的第二部分是:等待它再次发生以获得准确的文本:

Error 10048 connecting to 192.168.5.51:6379. Only one usage of each socket address (protocol/network address/port) is normally permitted.

对于redis获取的代码,我尝试以下方法:

redis_max_retries = 72
redis_retries = 0
redis_get_success = False
sleep_time_in_seconds = .1
while not redis_get_success and redis_retries < redis_max_retries:
    try:
       json_str = redis_obj.get(redis_key)
       redis_get_success = True
    except redis.exceptions.ConnectionError as e:
        redis_retries += 1
        time.sleep(sleep_time_in_seconds)

if not redis_get_success:
    print("redis_retries=", redis_retries, " on json_str = redis_obj.get(redis_key) in process_intervals" )
    sys.exit(0)

但我在扫描时也发现了错误,这看起来更难重试。

for keybatch in batcher(redis_obj.scan_iter(key_pattern), 1500):
        batch_counter += 1
        # print(batch_counter, "keybatch=", keybatch)

        for key in keybatch:
            if key is not None:
                #print("Trying key=", key)
                matching_keys_found += 1
                etc...
lstz6jyr

lstz6jyr1#

尝试连接到redislabs.com这样的在线redis托管站点,并使用文档进行连接,或者您可以尝试更改端口。错误是由端口或配置错误的redis服务器设置引起的。同样对于相同的端口和地址,每个套接字地址(协议/网络地址/端口)只允许使用一次?

相关问题