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

persistence

Package Overview
Dependencies
Maintainers
3
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

persistence - npm Package Compare versions

Comparing version 0.4.0 to 1.0.0

test/failover_on_crash.test.js

31

lib/list.js

@@ -48,5 +48,6 @@ var Persistence = require('./persistence.js'),

var calculateStartOffset = function(from, start, end, size) {
var startOffset = 0; //default is from the start
// if from is not specified, read all
var calculateStartOffset = function(start, end, size, from) {
var startOffset = 0; //default is to read the whole list
// if from is not provided, it is an attempt to read the whole list
if(!from && from !== 0) return 0;

@@ -58,3 +59,4 @@

// buffer for any newly added members in queue; hence -100.
// -ve values based on offset from the end.
// -ve values are based on offset from the end.
// -1 - (end - from) will cover any skipped ids and over-read.
startOffset = -1 - (end - from) - 100;

@@ -67,6 +69,6 @@ return startOffset;

var redis = Persistence.redis();
var startOffset = calculateStartOffset(from, start, end, size);
var startOffset = calculateStartOffset(start, end, size, from);
if(startOffset === null) {
callback('sync-error');
if(callback) callback('sync-error');
return;

@@ -88,12 +90,6 @@ }

callback(null, parsed);
if(callback) callback(null, parsed);
});
};
var logError = function(error) {
if(error) {
logging.error(error);
}
};
// push an entry into a list; with expiration, trimming etc set

@@ -110,10 +106,10 @@ // stamps an auto incrementing id (blocks if id is not available

entry.id = value;
multi.publish(list.name, JSON.stringify(entry), logError);
multi.publish(list.name, JSON.stringify(entry), Persistence.handler);
if(list.maxLength > 0) {
multi.rpush(list.name, JSON.stringify(entry), logError);
multi.rpush(list.name, JSON.stringify(entry), Persistence.handler);
}
if(list.expiry) {
multi.expire(list.name, list.expiry, logError);
multi.expire(list.name, list.expiry, Persistence.handler);
} else {

@@ -125,3 +121,3 @@ logging.warn('resource created without ttl :', list.name);

if(list.maxLength) {
multi.ltrim(list.name, -list.maxLength, -1, logError);
multi.ltrim(list.name, -list.maxLength, -1, Persistence.handler);
}

@@ -135,3 +131,2 @@

//If blocked, continue
List.prototype.unblock = function() {

@@ -138,0 +133,0 @@ this.idGen.unblock();

@@ -187,3 +187,6 @@ var logging = require('minilog')('persistence'),

if (err) {
logging.error(err);
logging.error({ error: err.toString() });
if (err.toString().test(/READONLY/)) {
throw new Error(err);
}
}

@@ -190,0 +193,0 @@ };

{
"name": "persistence",
"version": "0.4.0",
"version": "1.0.0",
"description": "An abstraction library for redis and sentinel connection management",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -1,4 +0,14 @@

persistence
===========
## persistence
An abstraction library for redis and sentinel connection management
## Copyright and license
Copyright 2014 Zendesk
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

@@ -7,2 +7,13 @@ var Persistence = require('../lib/persistence.js');

Persistence.setConfig(configuration);
function Dummy () { }
Dummy.prototype.toString = function() {
return this;
}
Dummy.prototype.test = function(pattern) {
return pattern == '/READONLY/'
}
process.on('message', function(message) {

@@ -12,4 +23,11 @@ if(message === 'connect') {

process.send('connected');
setInterval(function() {
Persistence.persistHash('xyz', 'f', 1);
}, 1000);
});
}
else if (message === 'test_error')
{
Persistence.handler(new Dummy());
}
});

@@ -101,2 +101,3 @@ var assert = require('assert'),

});
it('should reuse existing connection', function(done) {

@@ -103,0 +104,0 @@ var config = JSON.parse(JSON.stringify(configuration));

var assert = require('assert'),
ConnectionHelper = require('../lib/connection_helper.js'),
SentinelHelper = require('simple_sentinel'),
client;
SentinelHelper = require('simple_sentinel');

@@ -34,3 +32,2 @@ describe('A sentinel-connected persistence', function() {

this.timeout(10000);
process.env.noverbose=!process.env.verbose;
SentinelHelper.start(helperConfig);

@@ -40,4 +37,4 @@ connect(done);

after(function() {
this.timeout(10000);
child.kill();
process.env.noverbose=!process.env.verbose;
SentinelHelper.stop(helperConfig);

@@ -47,3 +44,3 @@ });

it('should die if master fails, but able to restart with new master', function(done) {
this.timeout(10000);
this.timeout(30000);
child.on('exit', function() {

@@ -57,5 +54,6 @@ setTimeout(function() {

});
//Kill master
SentinelHelper.stop({ redis: { ports: [ 16379 ] } });
// Cause underlying redis to fail over
require('child_process').exec('redis-cli -p 26379 sentinel failover mymaster');
});
});

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