-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
transaction support #230
Comments
Hi @DeoLeung, I originally left out transaction support in Webdis because I wasn't sure exactly how to implement it, specifically what the best API would be. Most Webdis requests likely use a single command, doing things like "Transactions" in Redis use the Another approach I had considered was to send them as a JSON list of commands in a POST request, e.g. sending this as the request body: [
["MULTI"],
["SET", "foo", "1"],
["SET", "bar", "2"],
["EXEC"]
] The downside being that you'd have to structure the commands in a special format, which is not something that Webdis does anywhere else; the only "structured data" used in Webdis request is in its responses, where a request to There is an alternative though, and I know from user reports and questions that people do run
Here's an example where Webdis is used to execute the same "transaction" as above that's mutating both The Lua script can simply be: redis.call('SET', 'foo', '1');
redis.call('SET', 'bar', '2'); So we can remove spaces and put it all on one line, then encode the quotes and add it after $ echo -n 'http://127.0.0.1:7379/SCRIPT/LOAD/'"redis.call('SET','foo','1');redis.call('SET','bar','2');" | sed -e "s/'/%27/g"
http://127.0.0.1:7379/SCRIPT/LOAD/redis.call(%27SET%27,%27foo%27,%271%27);redis.call(%27SET%27,%27bar%27,%272%27); If you're building this command from a programming language, you just need to URL-encode the script, e.g. > encodeURIComponent("redis.call('SET','foo','1');redis.call('SET','bar','2');")
"redis.call('SET'%2C'foo'%2C'1')%3Bredis.call('SET'%2C'bar'%2C'2')%3B" Let's run our command by piping this encoded URL to $ echo -n 'http://127.0.0.1:7379/SCRIPT/LOAD/'"redis.call('SET','foo','1');redis.call('SET','bar','2');" | sed -e "s/'/%27/g" | xargs curl
{"SCRIPT":"61202b13748238bf45d58fd21c8ad16831f7a4c1"} This is our script hash; before running it let's first make sure $ curl http://127.0.0.1:7379/DEL/foo/bar
{"DEL":0} Then invoke the script with 0 parameters: $ curl http://127.0.0.1:7379/EVALSHA/61202b13748238bf45d58fd21c8ad16831f7a4c1/0
{"EVALSHA":null} And read back $ curl http://127.0.0.1:7379/MGET/foo/bar
{"MGET":["1","2"]} I hope the example helps! This should cover all use cases where |
Hi,
I see transaction support in TODO for a while, is there any plan for that?
thanks :)
The text was updated successfully, but these errors were encountered: