Created
January 2, 2016 16:59
-
-
Save lagondo/ffca9641512c778690af to your computer and use it in GitHub Desktop.
redis rpc server client node.js
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
const ioredis = require('ioredis') | |
const uuid = require('node-uuid') | |
const redis = new ioredis() | |
const request = { | |
id: uuid.v1(), | |
utterance: 'kuppi kahvia' | |
} | |
redis.rpush('parser', JSON.stringify(request)) | |
redis.brpop(request.id, 1, (err, reply) => { | |
console.log(reply) | |
}) |
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
const ioredis = require('ioredis') | |
const async = require('async') | |
const redis = new ioredis() | |
const blpop = (next) => { | |
redis.blpop('parser', 0, (err, arr) => { | |
const message = JSON.parse(arr[1]) | |
console.log(message) | |
redis.rpush(message.id, JSON.stringify({ hello: 'world'})) | |
redis.expire(message.id, 1) | |
next() | |
}) | |
} | |
const logError = (err) => { | |
console.error(err) | |
} | |
async.forever(blpop, logError) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment