redis cluster调用时返回结果不一致

问题描述:使用emqx_resource调用redis7 cluster的FCALL xxxFunction时,有的能执行成功,有的执行失败提示no_connection.

emqx版本:开源版v5.3.0
运行环境:Windows10 x64
操作步骤:

  1. 搭建redis7 集群并加载lua脚本(脚本中有save_user_msg,save_user_msg2两个函数,只有函数名不一样,参数和函数体一样,代码已上传
  2. 启动emqx console
  3. 进入配置文件所在目录,加载配置文件,建立redis的连接
cd("C:\\Users\\tt\\Desktop").
{ok,Raw}=hocon:load("emqx_redis_cluster.conf",#{format=>ridchmap}).
{_,#{config:=Config}}=emqx_config:check_config(emqx_redis,Raw).
emqx_resource:create(emqx_redis,emqx_redis,emqx_redis, Config).

配置文件如下

config{
  pool_size=8
  redis_type=cluster
  servers="127.0.0.1:6380,127.0.0.1:6381,127.0.0.1:6382"
}

  1. 执行命令,结果却不一致
    以下命令返回 {ok,undefined}
emqx_resource:simple_sync_query(emqx_redis, {cmd, [<<"FCALL">>, <<"save_user_msg">>, 1, <<"Username">>, <<"Mid">>, <<"Msg_Binary">>, 1]}).

以下命令返回 {error,no_connection}

emqx_resource:simple_sync_query(emqx_redis, {cmd, [<<"FCALL">>, <<"save_user_msg2">>, 1, <<"Username">>, <<"Mid">>, <<"Msg_Binary">>, 1]}).

你的redis没问题吗?

刚使用python实现调用redis cluster的FCALL,确认两个函数调用都能成功。

import asyncio
import datetime

import aioredis_cluster


async def init():
    redis = await aioredis_cluster.create_redis_cluster([
        ("localhost", 6380),
        ("localhost", 6381),
        ("localhost", 6382),
        ("localhost", 6383),
        ("localhost", 6384),
        ("localhost", 6385),
    ])
    return redis


async def close(redis):
    await redis.wait_closed()

async def run():
    redis = await init()
    ret = await redis.execute(b"FCALL", "save_user_msg", 1, 'Username', 'Mid', 'Msg_Binary')
    ret2 = await redis.execute(b"FCALL", "save_user_msg2", 1, 'Username', 'Mid', 'Msg_Binary')
    await redis.wait_closed()


if __name__ == '__main__':
    loops = asyncio.get_event_loop()
    loops.run_until_complete(asyncio.wait([run()]))