Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict'
/* eslint-env mocha */
/* eslint-disable no-new */
/* global BigInt */
const assert = require('assert')
const util = require('util')
const Buffer = require('buffer').Buffer
const Parser = require('..')
const errors = require('redis-errors')
const ReplyError = errors.ReplyError
const ParserError = errors.ParserError
const RedisError = errors.RedisError
const hasBigIntSupport = !/^v[0-9]\./.test(process.version)
// Mock the not needed return functions
function returnReply (data) { console.log(data); throw new Error('failed') }
function returnError (err) { console.log(err); throw new Error('failed') }
function pushReply (data) { console.log(data); throw new Error('failed') }
function returnFatalError (err) { console.log(JSON.stringify(err.buffer.slice(err.offset).toString())); throw err }
function getBigInt (input, sign) {
if (hasBigIntSupport) {
return input === '-' ? -BigInt(sign) : BigInt(input)
}
return input === '-' ? input + sign : ('' + input)
}
'use strict'
/* eslint-env mocha */
/* eslint-disable no-new */
/* global BigInt */
const assert = require('assert')
const util = require('util')
const Buffer = require('buffer').Buffer
const Parser = require('..')
const errors = require('redis-errors')
const ReplyError = errors.ReplyError
const ParserError = errors.ParserError
const RedisError = errors.RedisError
const hasBigIntSupport = !/^v[0-9]\./.test(process.version)
// Mock the not needed return functions
function returnReply (data) { console.log(data); throw new Error('failed') }
function returnError (err) { console.log(err); throw new Error('failed') }
function pushReply (data) { console.log(data); throw new Error('failed') }
function returnFatalError (err) { console.log(JSON.stringify(err.buffer.slice(err.offset).toString())); throw err }
function getBigInt (input, sign) {
if (hasBigIntSupport) {
return input === '-' ? -BigInt(sign) : BigInt(input)
}
return input === '-' ? input + sign : ('' + input)
}
'use strict'
/* eslint-env mocha */
/* eslint-disable no-new */
const assert = require('assert')
const util = require('util')
const Buffer = require('buffer').Buffer
const JavascriptParser = require('../')
const HiredisParser = require('./hiredis')
const errors = require('redis-errors')
const ReplyError = errors.ReplyError
const ParserError = errors.ParserError
const RedisError = errors.RedisError
const parsers = [HiredisParser, JavascriptParser]
// Mock the not needed return functions
function returnReply () { throw new Error('failed') }
function returnError () { throw new Error('failed') }
function returnFatalError (err) { throw err }
describe('parsers', function () {
describe('general parser functionality', function () {
it('fail for missing options argument', function () {
assert.throws(function () {
new JavascriptParser()
}, function (err) {
assert(err instanceof TypeError)
'use strict'
/* eslint-env mocha */
/* eslint-disable no-new */
const assert = require('assert')
const util = require('util')
const Buffer = require('buffer').Buffer
const JavascriptParser = require('../')
const HiredisParser = require('./hiredis')
const errors = require('redis-errors')
const ReplyError = errors.ReplyError
const ParserError = errors.ParserError
const RedisError = errors.RedisError
const parsers = [HiredisParser, JavascriptParser]
// Mock the not needed return functions
function returnReply () { throw new Error('failed') }
function returnError () { throw new Error('failed') }
function returnFatalError (err) { throw err }
describe('parsers', function () {
describe('general parser functionality', function () {
it('fail for missing options argument', function () {
assert.throws(function () {
new JavascriptParser()
}, function (err) {
assert(err instanceof TypeError)
return true
'use strict'
const hiredis = require('hiredis')
const errors = require('redis-errors')
const ReplyError = errors.ReplyError
const ParserError = errors.ParserError
/**
* Parse data
* @param parser
* @returns {*}
*/
function parseData (parser, data) {
try {
return parser.reader.get()
} catch (err) {
// Protocol errors land here
// Reset the parser. Otherwise new commands can't be processed properly
parser.reader = new hiredis.Reader(parser.options)
parser.returnFatalError(new ParserError(err.message, JSON.stringify(data), -1))
}
'use strict'
const hiredis = require('hiredis')
const errors = require('redis-errors')
const ReplyError = errors.ReplyError
const ParserError = errors.ParserError
/**
* Parse data
* @param parser
* @returns {*}
*/
function parseData (parser, data) {
try {
return parser.reader.get()
} catch (err) {
// Protocol errors land here
// Reset the parser. Otherwise new commands can't be processed properly
parser.reader = new hiredis.Reader(parser.options)
parser.returnFatalError(new ParserError(err.message, JSON.stringify(data), -1))
}
}
export { default as Cluster } from "./cluster";
export { default as Command } from "./command";
export { default as ScanStream } from "./ScanStream";
export { default as Pipeline } from "./pipeline";
export { default as AbstractConnector } from "./connectors/AbstractConnector";
export {
default as SentinelConnector,
SentinelIterator
} from "./connectors/SentinelConnector";
// Type Exports
export { ISentinelAddress } from "./connectors/SentinelConnector";
export { IRedisOptions } from "./redis/RedisOptions";
// No TS typings
export const ReplyError = require("redis-errors").ReplyError;
const PromiseContainer = require("./promiseContainer");
Object.defineProperty(exports, "Promise", {
get() {
return PromiseContainer.get();
},
set(lib) {
PromiseContainer.set(lib);
}
});
export function print(err: Error | null, reply?: any) {
if (err) {
console.log("Error: " + err);
} else {
console.log("Reply: " + reply);
function tryConnection(random?: boolean, asking?: string) {
if (_this.status === "end") {
command.reject(new AbortError("Cluster is ended."));
return;
}
let redis;
if (_this.status === "ready" || command.name === "cluster") {
if (node && node.redis) {
redis = node.redis;
} else if (
Command.checkFlag("ENTER_SUBSCRIBER_MODE", command.name) ||
Command.checkFlag("EXIT_SUBSCRIBER_MODE", command.name)
) {
redis = _this.subscriber.getInstance();
if (!redis) {
command.reject(new AbortError("No subscriber for the cluster"));
return;
}
} else {
function tryConnection(random?: boolean, asking?: string) {
if (_this.status === "end") {
command.reject(new AbortError("Cluster is ended."));
return;
}
let redis;
if (_this.status === "ready" || command.name === "cluster") {
if (node && node.redis) {
redis = node.redis;
} else if (
Command.checkFlag("ENTER_SUBSCRIBER_MODE", command.name) ||
Command.checkFlag("EXIT_SUBSCRIBER_MODE", command.name)
) {
redis = _this.subscriber.getInstance();
if (!redis) {
command.reject(new AbortError("No subscriber for the cluster"));
return;
}
} else {
if (!random) {
if (typeof targetSlot === "number" && _this.slots[targetSlot]) {
const nodeKeys = _this.slots[targetSlot];
if (typeof to === "function") {
const nodes = nodeKeys.map(function(key) {
return _this.connectionPool.getInstanceByKey(key);
});
redis = to(nodes, command);
if (Array.isArray(redis)) {
redis = sample(redis);
}
if (!redis) {
redis = nodes[0];
function tryConnection(random, asking) {
if (_this.status === 'end') {
command.reject(new AbortError('Cluster is ended.'));
return;
}
var redis;
if (_this.status === 'ready' || (command.name === 'cluster')) {
if (node && node.redis) {
redis = node.redis;
} else if (Command.checkFlag('ENTER_SUBSCRIBER_MODE', command.name) ||
Command.checkFlag('EXIT_SUBSCRIBER_MODE', command.name)) {
redis = _this.subscriber.getInstance();
if (!redis) {
command.reject(new AbortError('No subscriber for the cluster'));
return;
}
} else {
if (!random) {
if (typeof targetSlot === 'number' && _this.slots[targetSlot]) {