Code files

This commit is contained in:
Akhil
2017-07-31 11:33:31 +05:30
parent 073a63ebdd
commit b9ae409ec0
801 changed files with 17535 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
const uuid = require('uuid')
const steed = require('steed')()
const redis = require('redis')
const client = redis.createClient()
const params = {
author: process.argv[2],
quote: process.argv[3]
}
if (params.author && params.quote) {
add(params)
list((err) => {
if (err) console.error(err)
client.quit()
})
return
}
if (params.author) {
list((err) => {
if (err) console.error(err)
client.quit()
})
return
}
client.quit()
function add ({author, quote}) {
const key = `Quotes: ${uuid()}`
client.hmset(key, {author, quote})
client.sadd(`Author: ${params.author}`, key)
}
function list (cb) {
client.smembers(`Author: ${params.author}`, (err, keys) => {
if (err) return cb(err)
steed.each(keys, (key, next) => {
client.hgetall(key, (err, {author, quote}) => {
if (err) return next(err)
console.log(`${author} ${quote} \n`)
next()
})
}, cb)
})
}