Use Redis from Node.js Module #63 Flashcards
How is Redis Installed?
npm intit -y (add “type”: “module” to your package.json file) Then: npm install redis
How is the redis object created?
const redis = require(“redis”)
OR
import redis from ‘redis’
Next the client needs to get set up, how to do this?
const client = redis.createClient( )
How are values stored ?
client.set( “keyname”, “value” )
How are keys returned using JavaScript in Redis?
.get( ) method
client.get( “name”, ( err, res ) => {
console.log( res )//’Flavio”
} )
Async functions are not allowed so we use callbacks. Res = Result which is being logged
How can we delete a key?
client.del( “names” )
If we need to create a regular list how is that done?
client.lpush.( ‘names’, ‘Flavio’)
creates a list and adds Flavio to the top of that list
What if we wanted to create a list and push the new entry to the bottom?
client.rpush( ‘rname’, ‘roger’ )