Skip to Content
Node Cookbook - Third Edition
book

Node Cookbook - Third Edition

by Matteo Collina, David Mark Clements, Peter Elger, Mathias Buus Madsen
July 2017
Intermediate to advanced
656 pages
16h 1m
English
Packt Publishing
Content preview from Node Cookbook - Third Edition

How it works...

If both author and quote are specified via the command line, we go ahead and generate a random key prefixed with Quote:. So, each key will look something like Quote:0e3h6euk01vo. It's a common convention to prefix the Redis keys with names delimited by a colon as this helps us to identify keys when debugging.

We pass our key into client.hmset, a wrapper for the Redis HMSET command, which allows us to create multiple hashes.

Essentially, when called with params.author set to Steve Jobs and params.quote set to Stay hungry, stay foolish, the following command is sent to Redis and executed (where HASH is the string we generate with Math.random().toString(32).replace('.', '')):

HMSET Quotes:HASH author "Steve Jobs" quote "Stay ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Node Cookbook - Fourth Edition

Node Cookbook - Fourth Edition

Bethany Griggs
Your First Week With Node.js, 2nd Edition

Your First Week With Node.js, 2nd Edition

James Hibbard, Craig Buckler, Mark Brown, Nilson Jacques, James Kolce, Paul Orac, M. David Green, Florian Rappl

Publisher Resources

ISBN: 9781785880087Supplemental Content