Socket
Socket
Sign inDemoInstall

@quantos/micro-request

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@quantos/micro-request - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

29

dist/redis_cache.js

@@ -19,18 +19,19 @@ "use strict";

let redisClient;
function initRedisClient() {
if (process.env.REDIS_PORT && process.env.REDIS_HOST) {
console.log('[@quantos/micro-request][Init redis client] Creating client on ' + process.env.REDIS_HOST + ':' + process.env.REDIS_PORT);
redisClient = redis_1.default.createClient(Number.parseInt(process.env.REDIS_PORT), process.env.REDIS_HOST, { enable_offline_queue: false });
redisClient.on('error', (error) => {
console.error('[@quantos/micro-request][Init redis client] ' + error);
redisClient = null;
setTimeout(() => initRedisClient(), 10000);
});
}
let _redisEnabled = false;
if (process.env.REDIS_PORT && process.env.REDIS_HOST) {
console.log('[@quantos/micro-request][Init redis client] Creating client on ' + process.env.REDIS_HOST + ':' + process.env.REDIS_PORT);
redisClient = redis_1.default.createClient(Number.parseInt(process.env.REDIS_PORT), process.env.REDIS_HOST, { enable_offline_queue: false });
redisClient.on('ready', () => {
_redisEnabled = true;
});
redisClient.on('error', (error) => {
console.error('[@quantos/micro-request][Init redis client] ' + error);
_redisEnabled = false;
redisClient = null;
});
}
initRedisClient();
class RedisCache {
static get(id, cachePrefix) {
return __awaiter(this, void 0, void 0, function* () {
if (!redisClient) {
if (!_redisEnabled) {
return null;

@@ -47,3 +48,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
if (!redisClient) {
if (!_redisEnabled) {
return null;

@@ -60,3 +61,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
if (!redisClient) {
if (!_redisEnabled) {
return;

@@ -63,0 +64,0 @@ }

{
"name": "@quantos/micro-request",
"version": "1.0.2",
"version": "1.0.3",
"description": "Quantos http client with cache, retry and fallback mechanism",

@@ -5,0 +5,0 @@ "author": "fabriziotognetto <info@quantos.it>",

@@ -7,15 +7,16 @@ import { RedisValueHelper } from '@quantos/redis-helper';

let redisClient: redis.RedisClient;
let _redisEnabled: boolean = false;
function initRedisClient(): void {
if (process.env.REDIS_PORT && process.env.REDIS_HOST) {
console.log('[@quantos/micro-request][Init redis client] Creating client on ' + process.env.REDIS_HOST + ':' + process.env.REDIS_PORT);
redisClient = redis.createClient(Number.parseInt(process.env.REDIS_PORT), process.env.REDIS_HOST, {enable_offline_queue: false});
redisClient.on('error', (error: any) => {
console.error('[@quantos/micro-request][Init redis client] ' + error);
redisClient = null;
setTimeout(() => initRedisClient(), 10000);
});
}
if (process.env.REDIS_PORT && process.env.REDIS_HOST) {
console.log('[@quantos/micro-request][Init redis client] Creating client on ' + process.env.REDIS_HOST + ':' + process.env.REDIS_PORT);
redisClient = redis.createClient(Number.parseInt(process.env.REDIS_PORT), process.env.REDIS_HOST, {enable_offline_queue: false});
redisClient.on('ready', () => {
_redisEnabled = true;
});
redisClient.on('error', (error: any) => {
console.error('[@quantos/micro-request][Init redis client] ' + error);
_redisEnabled = false;
redisClient = null;
});
}
initRedisClient();

@@ -25,3 +26,3 @@ export class RedisCache {

static async get<T>(id: any, cachePrefix?: string): Promise<T | null> {
if (!redisClient) { return null; }
if (!_redisEnabled) { return null; }
const cache = new RedisValueHelper<T>({ client: redisClient, prefix: cachePrefix });

@@ -33,3 +34,3 @@ const cached = await cache.getCached(`${id}`);

static async getMany<Y, T extends Entity<Y>>(ids: Y[], cachePrefix?: string): Promise<T[]> {
if (!redisClient) { return null; }
if (!_redisEnabled) { return null; }
const cache = new RedisValueHelper<T>({ client: redisClient, prefix: cachePrefix });

@@ -41,3 +42,3 @@ const cacheds = await cache.getCacheds(ids.map(String));

static async set<Y, T extends Entity<Y>>(id: Y, data: T, cachePrefix?: string): Promise<void> {
if (!redisClient) { return; }
if (!_redisEnabled) { return; }
const cache = new RedisValueHelper<T>({ client: redisClient, prefix: cachePrefix });

@@ -44,0 +45,0 @@ await cache.setCached(`${id}`, data);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc