Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Sato committed Jan 30, 2018
1 parent 8154bd7 commit 28ca4e0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 24 deletions.
9 changes: 4 additions & 5 deletions redisCacheModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ function redisCacheModule(config){
self.backgroundRefreshIntervalCheck = (typeof config.backgroundRefreshIntervalCheck === 'boolean') ? config.backgroundRefreshIntervalCheck : true;
self.backgroundRefreshInterval = config.backgroundRefreshInterval || 60000;
self.backgroundRefreshMinTtl = config.backgroundRefreshMinTtl || 70000;
self.JSON = config.JSON || Object.create(JSON);
self.logJsonParseFailures = config.logJsonParseFailures || false;
self.nameSpace = config.nameSpace || '';

Expand Down Expand Up @@ -148,7 +147,7 @@ function redisCacheModule(config){
log(false, 'Attempting to get key:', {key: cacheKey});
self.db.get(cacheKey, function(err, result){
try {
result = self.JSON.parse(result);
result = JSON.parse(result);
} catch (err) {
if(self.logJsonParseFailures) {
log(true, 'Error parsing JSON, err:', err);
Expand Down Expand Up @@ -178,7 +177,7 @@ function redisCacheModule(config){
for(var i = 0; i < response.length; i++){
if(response[i] !== null){
try {
response[i] = self.JSON.parse(response[i]);
response[i] = JSON.parse(response[i]);
} catch (err) {
if(self.logJsonParseFailures) {
log(true, 'Error parsing JSON, err:', err);
Expand Down Expand Up @@ -216,7 +215,7 @@ function redisCacheModule(config){
var exp = (expiration * 1000) + Date.now();
if(typeof value === 'object'){
try {
value = self.JSON.stringify(value);
value = JSON.stringify(value);
} catch (err) {
if(self.logJsonParseFailures) {
log(true, 'Error converting to JSON, err:', err);
Expand Down Expand Up @@ -268,7 +267,7 @@ function redisCacheModule(config){
value = value.cacheValue;
}
try {
value = self.JSON.stringify(value);
value = JSON.stringify(value);
} catch (err) {
if(self.logJsonParseFailures) {
log(true, 'Error converting to JSON, err:', err);
Expand Down
19 changes: 0 additions & 19 deletions test/server/redis-cache-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,26 +155,7 @@ describe('redisCacheModule Tests', function () {

}, 1500);
});
it('Using custom JSON interface should parse JSON to custom object', function (done) {
this.timeout(5000);

redisCache.logJsonParseFailures = true;
redisCache.JSON.parse = function (text) {
const obj = JSON.parse(text);
if (obj.type === 'Buffer') {
return Buffer.from(obj);
} else {
return obj;
}
};

const buffer = Buffer.from([0x00, 0x61, 0x00, 0x62, 0x00, 0x63])
redisCache.set('bffr', buffer);
redisCache.get('bffr', function (err, response) {
expect(response).toEqual(buffer);
done();
});
});
it('should retry connecting when retries is less than 5 times', function() {
var mockOptions = {
attempt: 5,
Expand Down

0 comments on commit 28ca4e0

Please sign in to comment.