nrk (owner)

Revisions

gist: 219077 Download_button fork
public
Description:
Pipelining commands in redis-lua
Public Clone URL: git://gist.github.com/219077.git
Embed All Files: show embed
output.txt #
1
2
3
4
5
6
7
8
* PONG
* true
* 0
* 10
* 40
* 1
* 40
* {2=40}
redis-pipeline.lua #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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