Cylix / cpp_redis

C++11 Lightweight Redis client: async, thread-safe, no dependency, pipelining, multi-platform - NO LONGER MAINTAINED - Please check https://github.com/cpp-redis/cpp_redis
MIT License
1.25k stars 554 forks source link

evalsha command not working correctly. #169

Open IanHot opened 6 years ago

IanHot commented 6 years ago

I am using cpp_redis with tacopie. I am trying to use the EVALSHA command with scripts already loaded in Redis. When I use the evalscript it is converting the SHA1 bytes into hex where they are not printable. If I "MONITOR" redis is see the following: - +1520583946.165641 [0 192.168.1.45:63106] "HGETALL" "_XFTScripts" ^[[21~^[[23~+1520585064.352591 [0 192.168.1.45:63106] "EVALSHA" "\xfa\x91\xc1Dr;X\x95\xbf\x04+\xcf6'\x13\tx\x13f" "0"

I have the equivalent code in C# and if I run and 'MONITOR' it I get the following: - +1520586386.865007 [0 192.168.1.45:63534] "HGETALL" "_XFT_Scripts" +1520586391.261374 [0 192.168.1.45:63534] "EVALSHA" "fa91c144723b5895bf042bcf362713097813665f" "0"

Note the first command reads the set of script SHA1s in both cases

How do I fix this? I am using CPP_Redis version 4.3.0 and Tacopie 3.2.0 built with VS 2017 Should I be directing this to the Tacopie issues area? Thanks

Cylix commented 6 years ago

Hi @IanHot,

I checked quickly on the cpp_redis code to see if we have some particular handling on the sha1 parameter of the cpp_redis::client::evalsha function, but we simply forward the parameter as any other parameters for all the other functions (including the EVALSHA command itself).

Would you mind sharing a small code snippet that would help me to understand how you are using the cpp_redis library (which functions and parameters)? Typically, are you just forwarding the return value of HGETALL to EVALSHA or are you doing something else?

Thanks

IanHot commented 6 years ago

Thanks for getting back. Here is the code snippet

            std::unordered_map<XRG_Action, std::string> mScripts;
        // Get LuaScriptMap
        auto  rep = mClient.hgetall("_XFT_Scripts");
        mClient.commit();
        auto r = rep.get();
        auto records = r.as_array();
        for (uint32_t i = 0; i < records.size(); ++i)
        {
            XRG_Action act;
            string sEnum = records[i].as_string();
            act = ToEnum(Sys_GetConfig)
                : ToEnum(Sys_GetQueues)
                : ToEnum(Clt_Connect)
                : ToEnum(Clt_Disconnect)
                : ToEnum(Clt_Submit)
                : ToEnum(Clt_Collect)
                : XRG_Action::Agt_Connect;
            mScripts[act] = records[++i].as_string();
        }
        rep = mClient.evalsha(mScripts[Sys_GetQueues], 0, vector<string>(), vector<string>());

As you can see I simply use one of the strings I get back from the "HGETALL".

regards