Chapter 7: initial samples

This commit is contained in:
Beth Griggs
2020-05-16 14:33:26 +01:00
parent bcf782f7dc
commit adb2130b38
140 changed files with 1777 additions and 1960 deletions
+34
View File
@@ -0,0 +1,34 @@
const redis = require('redis')
const client = redis.createClient()
const task = process.argv[2]
client.on('error', (err) => {
console.log("Error:", err)
})
if (!task) {
listTasks()
} else {
addTask(task)
}
function addTask(task) {
const key = `Task: ${Math.random().toString(32).replace('.', '')}`
client.hmset(key, {
task
})
listTasks()
}
function listTasks() {
client.keys('Task:*', (err, keys) => {
if (err) throw err
keys.forEach(key => {
client.hgetall(key, (err, task) => {
if (err) throw err
console.log(task)
})
})
client.quit()
})
}