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 */
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'
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);
'use strict'
const Buffer = require('buffer').Buffer
const StringDecoder = require('string_decoder').StringDecoder
const decoder = new StringDecoder()
const errors = require('redis-errors')
const ReplyError = errors.ReplyError
const ParserError = errors.ParserError
var bufferPool = Buffer.allocUnsafe(32 * 1024)
var bufferOffset = 0
var interval = null
var counter = 0
var notDecreased = 0
/**
* Used for integer numbers only
* @param {JavascriptRedisParser} parser
* @returns {undefined|number}
*/
function parseSimpleNumbers (parser) {
const length = parser.buffer.length - 1
var offset = parser.offset
var number = 0
'use strict'
const Buffer = require('buffer').Buffer
const StringDecoder = require('string_decoder').StringDecoder
const decoder = new StringDecoder()
const errors = require('redis-errors')
const ReplyError = errors.ReplyError
const ParserError = errors.ParserError
var bufferPool = Buffer.allocUnsafe(32 * 1024)
var bufferOffset = 0
var interval = null
var counter = 0
var notDecreased = 0
/**
* Used for integer numbers only
* @param {JavascriptRedisParser} parser
* @returns {undefined|number}
*/
function parseSimpleNumbers (parser) {
const length = parser.buffer.length - 1
var offset = parser.offset
var number = 0
'use strict';
exports = module.exports = require('./redis');
exports.ReplyError = require('redis-errors').ReplyError;
exports.Cluster = require('./cluster').default;
exports.Command = require('./command').default;
exports.ScanStream = require('./ScanStream').default;
exports.Pipeline = require('./pipeline');
var PromiseContainer = require('./promiseContainer');
Object.defineProperty(exports, 'Promise', {
get: function() {
return PromiseContainer.get();
},
set: function(lib) {
PromiseContainer.set(lib);
}
});
exports.print = function (err, reply) {