Skip to content

Commit

Permalink
Merge pull request #1386 from gkorland/patch-1
Browse files Browse the repository at this point in the history
add a simple streams example
  • Loading branch information
stockholmux committed Nov 12, 2018
2 parents 23ef1e7 + 96fdc77 commit 49a635d
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions examples/streams.js
@@ -0,0 +1,47 @@
'use strict';

var redis = require('redis');
var client1 = redis.createClient();
var client2 = redis.createClient();
var client3 = redis.createClient();

client1.xadd('mystream', '*', 'field1', 'm1', function (err) {
if(err){
return console.error(err);
}
client1.xgroup('CREATE', 'mystream', 'mygroup', '$', function (err) {
if(err){
return console.error(err);
}
});

client2.xreadgroup('GROUP', 'mygroup', 'consumer', 'Block', 1000,
'STREAMS', 'mystream', '>', function (err, stream) {
if(err){
return console.error(err);
}
console.log('client2 ' + stream);
});

client3.xreadgroup('GROUP', 'mygroup', 'consumer', 'Block', 1000,
'STREAMS', 'mystream', '>', function (err, stream) {
if(err){
return console.error(err);
}
console.log('client3 ' + stream);
});


client1.xadd('mystream', '*', 'field1', 'm2', function (err) {
if(err){
return console.error(err);
}
});

client1.xadd('mystream', '*', 'field1', 'm3', function (err) {
if(err){
return console.error(err);
}
});

});

0 comments on commit 49a635d

Please sign in to comment.