Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

async-redis

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-redis - npm Package Compare versions

Comparing version 1.1.7 to 2.0.0

.env.example

24

examples/create-redis.js

@@ -1,11 +0,13 @@

const asyncRedis = require("../src");
/* eslint no-console: 0 */
const asyncRedis = require('../src');
const client = asyncRedis.createClient();
client.on("error", function (err) {
console.log("Error " + err);
client.on('error', (err) => {
console.log(`Error ${err}`);
});
let addToSet = async () => {
let key = 'exampleSet';
let values = [
const addToSet = async () => {
const key = 'exampleSet';
const values = [
'item_1',

@@ -17,12 +19,8 @@ 'item_2',

];
let promises = values.map((value) => {
return client.sadd(key, value);
});
const promises = values.map(value => client.sadd(key, value));
await Promise.all(promises);
return await client.smembers(key);
return client.smembers(key);
};
let flush = async () => {
return await client.flushall();
};
const flush = async () => client.flushall();

@@ -29,0 +27,0 @@ addToSet()

{
"private": false,
"version": "1.1.7",
"author": "Matthew Oaxaca",
"license": "MIT",
"version": "2.0.0",
"name": "async-redis",

@@ -11,14 +13,25 @@ "keywords": [

],
"author": "Matthew Oaxaca",
"license": "MIT",
"description": "Light wrapper over redis_node with first class async & promise support.",
"repository": {
"type": "git",
"url": "git://github.com/moaxaca/async-redis.git"
},
"bugs": {
"url": "https://github.com/moaxaca/async-redis/issues"
},
"main": "src/index.js",
"typings": "./index.d.ts",
"typings": "src/index.d.ts",
"engines": {
"node": ">=7.6.0"
},
"directories": {
"example": "examples",
"test": "test"
},
"scripts": {
"coveralls": "nyc yarn test && nyc report --reporter=text-lcov | coveralls",
"lint": "eslint --fix --ext .js, src",
"test": "mocha",
"lint": "eslint --fix --ext .js, .",
"test": "mocha test/**/*.spec.js --config test/setup.js --exit",
"test:integration": "mocha test/integration/*.spec.js --config test/setup.js --exit",
"test:unit": "mocha test/unit/*.spec.js --config test/setup.js --exit",
"version:patch": "npm version patch",

@@ -29,28 +42,15 @@ "version:minor": "npm version minor",

"dependencies": {
"redis": "^2.8.0",
"redis-commands": "^1.3.1"
"redis": "3.1.2"
},
"devDependencies": {
"chai": "^3.5.0",
"@types/node": "^15.6.1",
"@types/redis": "^2.8.28",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"coveralls": "^3.0.0",
"eslint": "^4.17.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.6.1",
"mocha": "^3.2.0",
"nyc": "^11.4.1"
},
"repository": {
"type": "git",
"url": "git://github.com/moaxaca/async-redis.git"
},
"bugs": {
"url": "https://github.com/moaxaca/async-redis/issues"
},
"directories": {
"example": "examples",
"test": "test"
"coveralls": "^3.1.0",
"dotenv": "^10.0.0",
"eslint": "^7.27.0",
"mocha": "^8.4.0",
"nyc": "^15.1.0"
}
}

@@ -11,3 +11,3 @@ Async Redis

Light weight wrapper over the node_redis library with first class async & promise support.
Light weight wrapper over the [node_redis](https://github.com/NodeRedis/node_redis) library with first class async & promise support.

@@ -14,0 +14,0 @@ ## Installation

@@ -1,35 +0,62 @@

/* eslint func-names: ["error", "as-needed"] */
const redis = require('redis');
const commands = require('redis-commands').list;
const objectDecorator = require('./object-decorator');
const objectPromisify = require('./object-promisify');
const redisCommands = require('./redis-commands');
const AsyncRedis = function (args) {
const client = Array.isArray(args) ? redis.createClient(...args) : redis.createClient(args);
return AsyncRedis.decorate(client);
const redisClients = new Map();
/**
* @return RedisClient
*/
const AsyncRedis = function (args=null) {
if (args) {
const serializedArgs = JSON.stringify(args);
if (!redisClients.has(serializedArgs)) {
redisClients.set(serializedArgs, Array.isArray(args) ? redis.createClient(...args) : redis.createClient(args));
}
this.setup(redisClients.get(serializedArgs));
}
};
/**
* @param {*} redisClient
* @returns void
*/
AsyncRedis.prototype.setup = function(redisClient) {
this.__redisClient = redisClient;
const commandConfigs = redisCommands(redisClient);
objectDecorator(redisClient, (name, method) => {
if (commandConfigs.commands.has(name)) {
objectPromisify(this, redisClient, name);
}
if (commandConfigs.queueCommands.has(name)) {
this[name] = (...args) => {
const multi = method.apply(redisClient, args);
return objectDecorator(multi, (multiName, multiMethod) => {
if (commandConfigs.multiCommands.has(multiName)) {
return objectPromisify(multi, multiMethod);
}
return multiMethod;
});
}
}
});
};
/**
* @param {...any} args
* @returns AsyncRedis
*/
AsyncRedis.createClient = (...args) => new AsyncRedis(args);
// this is the set of commands to NOT promisify
const commandsToSkipSet = new Set(['multi']);
// this is the set of commands to promisify
const commandSet = new Set(commands.filter(c => !commandsToSkipSet.has(c)));
/**
* @param {Redis} redisClient
* @returns AsyncRedis
*/
AsyncRedis.decorate = (redisClient) => {
const asyncClient = new AsyncRedis();
asyncClient.setup(redisClient);
return asyncClient;
};
AsyncRedis.decorate = redisClient => objectDecorator(redisClient, (name, method) => {
if (commandSet.has(name)) {
return (...args) => new Promise((resolve, reject) => {
args.push((error, ...results) => {
if (error) {
reject(error, ...results);
} else {
resolve(...results);
}
});
method.apply(redisClient, args);
});
}
return method;
});
module.exports = AsyncRedis;

@@ -7,10 +7,11 @@ /**

module.exports = (object, decorator) => {
/* eslint-disable */
for (const prop in object) {
if (typeof object[prop] === 'function') {
object[prop] = decorator(prop, object[prop]);
const returned = decorator(prop, object[prop]);
if (typeof returned === 'function') {
object[prop] = returned;
}
}
}
/* eslint-enable */
return object;
};
const { assert } = require('chai');
const { RedisClient } = require('redis');
const AsyncRedis = require('../../src');
const getTestRedisConfig = require('../util/getTestRedisConfig');
describe('AsyncRedis.createClient', function () {
const options = {
host: '127.0.0.1',
port: 6379,
};
describe('AsyncRedis.createClient', () => {
const options = getTestRedisConfig();
const url = `redis://${options.host}:${options.port}`;

@@ -14,3 +12,3 @@

const asyncRedisClient = new AsyncRedis(options);
assert.instanceOf(asyncRedisClient, RedisClient);
assert.instanceOf(asyncRedisClient, AsyncRedis);
});

@@ -20,3 +18,3 @@

const asyncRedisClient = AsyncRedis.createClient(url);
assert.instanceOf(asyncRedisClient, RedisClient);
assert.instanceOf(asyncRedisClient, AsyncRedis);
});

@@ -26,4 +24,4 @@

const asyncRedisClient = AsyncRedis.createClient(options);
assert.instanceOf(asyncRedisClient, RedisClient);
assert.instanceOf(asyncRedisClient, AsyncRedis);
});
});
const { assert } = require('chai');
const redis = require('redis');
const redisCommands = require('redis-commands');
const AsyncRedis = require('../../src');
const getRedisCommands = require('../../src/redis-commands');
const getTestRedisConfig = require('../util/getTestRedisConfig');
describe('AsyncRedis.decorate', function () {
const client = redis.createClient();
const asyncRedisClient = AsyncRedis.decorate(client);
describe('AsyncRedis.decorate', () => {
const options = getTestRedisConfig();
const redisClient = redis.createClient(options);
const asyncRedisClient = AsyncRedis.decorate(redisClient);
it('should have decorated every command', async () => {
const commands = redisCommands.list;
commands.forEach(command => {
const commands = getRedisCommands(redisClient).commands;
commands.forEach((command) => {
assert.isFunction(asyncRedisClient[command], `redis.${command} isn't decorated`);

@@ -14,0 +17,0 @@ });

@@ -0,1 +1,2 @@

require('dotenv').config();
const chai = require('chai');

@@ -2,0 +3,0 @@ const chaiAsPromise = require('chai-as-promised');

Sorry, the diff of this file is not supported yet

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