parent
f2b3acd1d0
commit
0853fb6f34
@ -1,64 +1,51 @@
|
|||||||
import { createClient } from 'redis';
|
import { createClient } from 'redis';
|
||||||
|
import pg from 'pg'
|
||||||
|
const connectRedis = async ()=>{
|
||||||
|
const redis = createClient({
|
||||||
|
password: process.env.REDIS_PWD,
|
||||||
|
socket: {
|
||||||
|
host: 'redis-11789.c329.us-east4-1.gce.redns.redis-cloud.com',
|
||||||
|
port: 11789
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await redis.connect();
|
||||||
|
console.log('connected to redis');
|
||||||
|
return redis
|
||||||
|
}
|
||||||
|
|
||||||
const redis = createClient({
|
const redis = await connectRedis()
|
||||||
password: process.env.REDIS_PWD,
|
|
||||||
socket: {
|
|
||||||
host: 'redis-11789.c329.us-east4-1.gce.redns.redis-cloud.com',
|
|
||||||
port: 11789
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await redis.connect();
|
|
||||||
console.log('connected');
|
|
||||||
|
|
||||||
//await redis.set('foo', 'bar');
|
|
||||||
//const value = await redis.get('foo');
|
|
||||||
//console.log(value) // returns 'bar'
|
|
||||||
|
|
||||||
//await redis.hSet('viv', {
|
|
||||||
//name: 'Vivienne',
|
|
||||||
//age: 6
|
|
||||||
//})
|
|
||||||
//const viv = await redis.hGetAll('viv');
|
|
||||||
//const vivAge = await redis.hGet('viv', 'age');
|
|
||||||
//console.log(viv);
|
|
||||||
//console.log(vivAge);
|
|
||||||
|
|
||||||
//await redis.json.set('matt', '$', {
|
|
||||||
//name:'Matt',
|
|
||||||
//age: 43,
|
|
||||||
//daughter: {
|
|
||||||
//name: 'Viv',
|
|
||||||
//age: 6
|
|
||||||
//}
|
|
||||||
//})
|
|
||||||
//const animal = await redis.json.get('animal', '$')
|
|
||||||
//console.log(animal);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import pg from 'pg'
|
const connectPostgres = async ()=>{
|
||||||
const { Client } = pg
|
const { Client } = pg
|
||||||
const postgres = new Client({
|
const postgres = new Client({
|
||||||
database:'lepr_stack'
|
database:'lepr_stack'
|
||||||
})
|
})
|
||||||
await postgres.connect()
|
await postgres.connect()
|
||||||
|
console.log('connected to pg');
|
||||||
|
return postgres
|
||||||
|
}
|
||||||
|
|
||||||
const results = await postgres.query('SELECT pets.*, people.first_name, people.last_name, people.age AS owner_age FROM pets JOIN people ON pets.owner_id = pets.id')
|
const postgres = await connectPostgres()
|
||||||
const fluffy = {
|
|
||||||
id: results.rows[0].id,
|
const runExample = async ()=>{
|
||||||
name:results.rows[0].name,
|
const results = await postgres.query('SELECT pets.*, people.first_name, people.last_name, people.age AS owner_age FROM pets JOIN people ON pets.owner_id = pets.id')
|
||||||
species:results.rows[0].species,
|
const fluffy = {
|
||||||
age: results.rows[0].age,
|
id: results.rows[0].id,
|
||||||
owner: {
|
name:results.rows[0].name,
|
||||||
id:results.rows[0].owner_id,
|
species:results.rows[0].species,
|
||||||
first_name:results.rows[0].first_name,
|
age: results.rows[0].age,
|
||||||
last_name:results.rows[0].last_name,
|
owner: {
|
||||||
age:results.rows[0].owner_age
|
id:results.rows[0].owner_id,
|
||||||
|
first_name:results.rows[0].first_name,
|
||||||
|
last_name:results.rows[0].last_name,
|
||||||
|
age:results.rows[0].owner_age
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
console.log(fluffy);
|
||||||
|
await redis.json.set('fluffy', '$', fluffy)
|
||||||
}
|
}
|
||||||
console.log(fluffy);
|
|
||||||
await redis.json.set('fluffy', '$', fluffy)
|
await runExample()
|
||||||
await postgres.end()
|
await postgres.end()
|
||||||
await redis.disconnect();
|
await redis.disconnect();
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in new issue