Use Redis from Node.js Module #63 Flashcards

1
Q

How is Redis Installed?

A

npm intit -y (add “type”: “module” to your package.json file) Then: npm install redis

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How is the redis object created?

A

const redis = require(“redis”)

OR

import redis from ‘redis’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Next the client needs to get set up, how to do this?

A

const client = redis.createClient( )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How are values stored ?

A

client.set( “keyname”, “value” )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How are keys returned using JavaScript in Redis?

A

.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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How can we delete a key?

A

client.del( “names” )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

If we need to create a regular list how is that done?

A

client.lpush.( ‘names’, ‘Flavio’)

creates a list and adds Flavio to the top of that list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What if we wanted to create a list and push the new entry to the bottom?

A

client.rpush( ‘rname’, ‘roger’ )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly