cpp_redis icon indicating copy to clipboard operation
cpp_redis copied to clipboard

evalsha command not working correctly.

Open IanHot opened this issue 7 years ago • 2 comments

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" "XFT_Scripts" ^[[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

IanHot avatar Mar 09 '18 09:03 IanHot

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

Cylix avatar Mar 11 '18 07:03 Cylix

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

IanHot avatar Mar 11 '18 09:03 IanHot