You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.5 KiB
65 lines
1.5 KiB
import { createClient } from 'redis';
|
|
|
|
const client = createClient({
|
|
password: process.env.REDIS_PWD,
|
|
socket: {
|
|
host: 'redis-11789.c329.us-east4-1.gce.redns.redis-cloud.com',
|
|
port: 11789
|
|
}
|
|
});
|
|
|
|
await client.connect();
|
|
console.log('connected');
|
|
|
|
//await client.set('foo', 'bar');
|
|
//const value = await client.get('foo');
|
|
//console.log(value) // returns 'bar'
|
|
|
|
//await client.hSet('viv', {
|
|
//name: 'Vivienne',
|
|
//age: 6
|
|
//})
|
|
//const viv = await client.hGetAll('viv');
|
|
//const vivAge = await client.hGet('viv', 'age');
|
|
//console.log(viv);
|
|
//console.log(vivAge);
|
|
|
|
//await client.json.set('matt', '$', {
|
|
//name:'Matt',
|
|
//age: 43,
|
|
//daughter: {
|
|
//name: 'Viv',
|
|
//age: 6
|
|
//}
|
|
//})
|
|
//const animal = await client.json.get('animal', '$')
|
|
//console.log(animal);
|
|
|
|
|
|
|
|
import pg from 'pg'
|
|
const { Client } = pg
|
|
const pgClient = new Client({
|
|
database:'lepr_stack'
|
|
})
|
|
await pgClient.connect()
|
|
|
|
const results = await pgClient.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 fluffy = {
|
|
id: results.rows[0].id,
|
|
name:results.rows[0].name,
|
|
species:results.rows[0].species,
|
|
age: results.rows[0].age,
|
|
owner: {
|
|
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 client.json.set('fluffy', '$', fluffy)
|
|
await pgClient.end()
|
|
await client.disconnect();
|
|
|