Created
May 19, 2015 00:31
-
-
Save ismaelga/3fa7529376202a776a66 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmacro defredis_script(name, script) do | |
script_sha = :crypto.hash(:sha, script) | |
quote bind_quoted: [script_sha: script_sha, name: name, script: script] do | |
def unquote(name)(client, keys \\ [], argv \\ []) do | |
query_args = [length(keys)] ++ keys ++ argv | |
case Exredis.query client, ["EVALSHA", unquote(script_sha)] ++ query_args do | |
<<"NOSCRIPT", _ :: binary>> -> | |
Exredis.query client, ["EVAL", unquote(script)] ++ query_args | |
reply -> reply | |
end | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmacro defredis_script(name, script) do | |
quote do | |
@script_sha :crypto.hash(:sha, unquote(script)) | |
def unquote(name)(client, keys \\ [], argv \\ []) do | |
query_args = [length(keys)] ++ keys ++ argv | |
case Exredis.query client, ["EVALSHA", @script_sha] ++ query_args do | |
<<"NOSCRIPT", _ :: binary>> -> | |
Exredis.query client, ["EVAL", unquote(script)] ++ query_args | |
reply -> reply | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment