Closed rqb500 closed 2 years ago
There're two problems with your code:
auto mset_with_ttl_script = "( // <-------- you missed a *R*
local len = #KEYS
if (len == 0 or len + 1 ~= #ARGV) then return 0 end
local ttl = tonumber(ARGV[len + 1])
if (not ttl or ttl <= 0) then return 0 end
for i = 1, len do redis.call("SET", KEYS[i], ARGV[i], "EX", ttl) end
return 1
)";
It should be: auto mset_with_ttl_script = R"(your script here)";
redis.eval<long long>(mset_with_ttl_script, keys.begin(), keys.end(),
vals.begin(), vals.end()); // <--------- this should be args
You should pass args
instead of vals
to eval
.
Regards
thanks, thats help much
Describe the problem I encountered a compilation problem when I started using redis plus plus.I downloaded and installed redis plus plus with vcpkg, but when running the sample code, the compiler prompts me the following error:
Severity Code Description Project File Line Suppression State Error C2679 binary '<<': no operator found which takes a right-hand operand of type 'std::optional' (or there is no acceptable conversion) redistest E:\123\vcpkg\vcpkg\installed\x64-windows\include\sw\redis++\command_args.h 158
problem code: ` auto redis = Redis("tcp://127.0.0.1:6379"); auto mset_with_ttl_script = "(\ local len = #KEYS\ if (len == 0 or len + 1 ~= #ARGV) then return 0 end\ local ttl = tonumber(ARGV[len + 1])\ if (not ttl or ttl <= 0) then return 0 end\ for i = 1, len do redis.call(\"SET\", KEYS[i], ARGV[i], \"EX\", ttl) end\ return 1\ )";
what should i do for correct using redis-plus-plus
Environment: