Created
October 26, 2009 21:45
-
-
Save nrk/219077 to your computer and use it in GitHub Desktop.
Pipelining commands in redis-lua
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
| * PONG | |
| * true | |
| * 0 | |
| * 10 | |
| * 40 | |
| * 1 | |
| * 40 | |
| * {2=40} |
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
| require 'luarocks.require' | |
| require 'redis' | |
| require 'base' | |
| local redis = Redis.connect("192.168.1.205", 6379) | |
| -- all the commands inside of a pipeline are sent to the server | |
| -- in one go, thus avoiding chatty sessions with redis. | |
| local replies = redis:pipeline(function() | |
| ping() | |
| flush_database() | |
| exists('counter') | |
| increment_by('counter', 10) | |
| increment_by('counter', 30) | |
| exists('counter') | |
| get('counter') | |
| get_multiple('does_not_exist', 'counter') | |
| end) | |
| for _, reply in pairs(replies) do | |
| print('*', reply) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment