1.0.8 • Published 1 year ago

pg-x-redis v1.0.8

Weekly downloads
-
License
-
Repository
github
Last release
1 year ago

PG x Redis

PG x Redis utilizes Redis, RedisJSON and RediSearch to speed up PostgreSQL Queries by caching Data into Redis and Selecting Redis Data over PostgreSQL Data.

Prerequisites

To use this Package, your Server needs Redis, RedisJSON, RediSearch and PostgreSQL.

Getting started

import RedisXpSQL from 'PG-x-Redis';

const DataBase = new RedisXpSQL(
  { // Postgres Config
    database: 'DataBase Name',
    user: 'DataBase User',
    password: 'DataBase Password',
    port: 5432,
    host: 'DataBase Host',
  },
  { // Redis Config
    password: 'DataBase Password',
    host: 'DataBase Host',
    name: 'DataBase Alias',
  },
);

await DataBase.init();

This Package only supports simple Queries and 4 types of Actions Notice: Only use this Packages query() Function on PostgreSQL Tables with defined Primary Keys. It uses Primary Keys to save Data in Redis as it is a KeyValue Storage. Package does not support IN, NOT IN and BETWEEN Conditions yet

Supported Action Types

INSERT

await DataBase.query(
    `INSERT INTO userinfo (firstname, lastname, email, age) VALUES ($1, $2, $3, $4);`,
    [ 'John', 'Doe', 'JohnDoe@mail.com', 24],
);
// Response > [{ firstname: 'John', lastname: 'Doe', email: 'JohnDoe@mail.com', age: 24 }]

UPDATE

await DataBase.query(
    `UPDATE userinfo SET age = $1 WHERE firstname = $2 AND lastname = $3;`,
    [ 25, 'John', 'Doe' ],
);
// Response > [{ 'John', 'Doe',  'JohnDoe@mail.com', 25 }]

SELECT

await DataBase.query(
    `SELECT * FROM userinfo WHERE age = $1`,
    [ 25 ],
);
// Response > [{ 'John', 'Doe',  'JohnDoe@mail.com', 25 }]

DELETE

await DataBase.query(
    `DELETE FROM userinfo WHERE email = $1`,
    [ 'JohnDoe@mail.com' ],
);
// Response > [{ 'John', 'Doe',  'JohnDoe@mail.com', 25 }]

Query Replacements

Replacements can only be passed in Array Form for pg Data Sanitization

Redis Client

DataBase.redis
DataBase.redis.json.get('Key')
DataBase.redis.ft.search('Index Key', 'Redis Query')
// etc...

PostgreSQL Client

DataBase.postgres
DataBase.postgres.query(`PSQL Query`, [ 'SQL Options' ])
// etc...

! Warning ! for raw Interactions with Redis and PostgreSQL Clients

Changed Data will not be cached

Contributing

I will happily accept your pull request if it:

  • looks reasonable
  • does not break backwards compatibility
1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago