Skip to content

Instantly share code, notes, and snippets.

@lagondo
Created January 2, 2016 16:59
Show Gist options
  • Save lagondo/ffca9641512c778690af to your computer and use it in GitHub Desktop.
Save lagondo/ffca9641512c778690af to your computer and use it in GitHub Desktop.
redis rpc server client node.js
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)
})
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