Skip to content

Commit 74bc2b1

Browse files
committed
Add babel transpiling to allow for more node versions
1 parent c0d2cb4 commit 74bc2b1

File tree

5 files changed

+107
-918
lines changed

5 files changed

+107
-918
lines changed

.babelrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"presets": [
3+
[
4+
"es2015",
5+
{
6+
"modules": false
7+
}
8+
]
9+
],
10+
"plugins": [
11+
"external-helpers"
12+
]
13+
}

dist/index.js

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,84 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
44

55
var Redis = _interopDefault(require('redis'));
66

7-
const redisStore = (...args) => {
8-
const redisCache = Redis.createClient(...args);
9-
const storeArgs = redisCache.options;
7+
var redisStore = function redisStore() {
8+
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
9+
args[_key] = arguments[_key];
10+
}
11+
12+
var redisCache = Redis.createClient.apply(Redis, args);
13+
var storeArgs = redisCache.options;
1014

1115
return {
1216
name: 'redis',
13-
getClient: () => redisCache,
14-
set: (key, value, options, cb) => (
15-
new Promise((resolve, reject) => {
17+
getClient: function getClient() {
18+
return redisCache;
19+
},
20+
set: function set(key, value, options, cb) {
21+
return new Promise(function (resolve, reject) {
1622
if (typeof options === 'function') {
1723
cb = options;
1824
options = {};
1925
}
2026
options = options || {};
2127

2228
if (!cb) {
23-
cb = (err, result) => (err ? reject(err) : resolve(result));
29+
cb = function cb(err, result) {
30+
return err ? reject(err) : resolve(result);
31+
};
2432
}
2533

26-
const ttl = (options.ttl || options.ttl === 0) ? options.ttl : storeArgs.ttl;
27-
const val = JSON.stringify(value) || '"undefined"';
34+
var ttl = options.ttl || options.ttl === 0 ? options.ttl : storeArgs.ttl;
35+
var val = JSON.stringify(value) || '"undefined"';
2836

2937
if (ttl) {
3038
redisCache.setex(key, ttl, val, handleResponse(cb));
3139
} else {
3240
redisCache.set(key, val, handleResponse(cb));
3341
}
34-
})
35-
),
36-
get: (key, options, cb) => (
37-
new Promise((resolve, reject) => {
42+
});
43+
},
44+
get: function get(key, options, cb) {
45+
return new Promise(function (resolve, reject) {
3846
if (typeof options === 'function') {
3947
cb = options;
4048
}
4149

4250
if (!cb) {
43-
cb = (err, result) => (err ? reject(err) : resolve(result));
51+
cb = function cb(err, result) {
52+
return err ? reject(err) : resolve(result);
53+
};
4454
}
4555

4656
redisCache.get(key, handleResponse(cb, { parse: true }));
47-
})
48-
),
49-
del: (key, options, cb) => {
57+
});
58+
},
59+
del: function del(key, options, cb) {
5060
if (typeof options === 'function') {
5161
cb = options;
5262
}
5363

5464
redisCache.del(key, handleResponse(cb));
5565
},
56-
reset: cb => redisCache.flushdb(handleResponse(cb)),
57-
keys: cb => redisCache.keys(handleResponse(cb)),
58-
ttl: (key, cb) => redisCache.ttl(key, handleResponse(cb)),
59-
isCacheableValue: args.isCacheableValue || (value => value !== undefined && value !== null),
66+
reset: function reset(cb) {
67+
return redisCache.flushdb(handleResponse(cb));
68+
},
69+
keys: function keys(cb) {
70+
return redisCache.keys(handleResponse(cb));
71+
},
72+
ttl: function ttl(key, cb) {
73+
return redisCache.ttl(key, handleResponse(cb));
74+
},
75+
isCacheableValue: args.isCacheableValue || function (value) {
76+
return value !== undefined && value !== null;
77+
}
6078
};
6179
};
6280

63-
function handleResponse(cb, opts = {}) {
64-
return (err, result) => {
81+
function handleResponse(cb) {
82+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
83+
84+
return function (err, result) {
6585
if (err) {
6686
return cb && cb(err);
6787
}
@@ -78,8 +98,10 @@ function handleResponse(cb, opts = {}) {
7898
};
7999
}
80100

81-
const methods = {
82-
create: (...args) => redisStore(...args),
101+
var methods = {
102+
create: function create() {
103+
return redisStore.apply(undefined, arguments);
104+
}
83105
};
84106

85107
module.exports = methods;

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,28 @@
22
"name": "cache-manager-redis-store",
33
"author": "Matthijs Dabroek <dabroek@gmail.com>",
44
"description": "Redis store for node-cache-manager module",
5-
"version": "1.0.1",
5+
"version": "1.1.0",
66
"license": "MIT",
77
"main": "dist/index.js",
88
"repository": {
99
"type": "git",
1010
"url": "https://github.com/dabroek/node-cache-manager-redis-store.git"
1111
},
1212
"scripts": {
13+
"prepublish": "npm prune",
1314
"test": "node test.js",
1415
"build": "rollup -c"
1516
},
1617
"dependencies": {
1718
"redis": "^2.7.1"
1819
},
1920
"devDependencies": {
20-
"rollup": "^0.41.6"
21+
"babel-plugin-external-helpers": "^6.22.0",
22+
"babel-preset-es2015": "^6.24.1",
23+
"rollup": "^0.41.6",
24+
"rollup-plugin-babel": "^2.7.1"
25+
},
26+
"engines": {
27+
"node": ">=4.2.0"
2128
}
2229
}

rollup.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
import babel from 'rollup-plugin-babel';
2+
13
export default {
24
entry: 'index.js',
35
format: 'cjs',
46
dest: 'dist/index.js',
7+
plugins: [
8+
babel({
9+
exclude: 'node_modules/**',
10+
}),
11+
],
512
};

0 commit comments

Comments
 (0)