Skip to content

Instantly share code, notes, and snippets.

@arc279
Last active April 19, 2017 20:24
Show Gist options
  • Save arc279/7a9a74ade926f9b84f4ef0124d7d323b to your computer and use it in GitHub Desktop.
Save arc279/7a9a74ade926f9b84f4ef0124d7d323b to your computer and use it in GitHub Desktop.
redis lua update sample
redis.replicate_commands()
local cr = 0
local b = {}
while true do
local a = redis.call("SCAN", cr, "MATCH", "????", "COUNT", 10)
for i, v in ipairs(a[2]) do
local j = cjson.encode({v, v, v})
redis.call("SET", v, j)
b[v] = j
end
cr = a[1]
if cr == "0" then
break
end
end
return cjson.encode(b)
function redis_bulk() {
printf "*%d\r\n" "${#@}"
for x in "${@}"; do
printf "$%d\r\n%s\r\n" $(gecho -ne "$x" | wc -c) "$x"
done
}
for x in {1..100}; do
redis_bulk SET "$(printf "%04d" $x)" hoge$x
done | redis-cli --pipe
redis-cli --eval a.lua | jq .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment