Skip to content

Commit b8ae69c

Browse files
committed
Update setCahe for receive a instance of redis
1 parent fb32641 commit b8ae69c

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

src/index.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
'use strict';
22

3-
import redisUrl from 'redis-url';
43
import nodeGeocoder from 'node-geocoder';
54
import Promise from 'bluebird';
65

76
let client;
87

9-
const setCache = (uri) => {
10-
try {
11-
client = redisUrl.connect(uri);
12-
Promise.promisifyAll(Object.getPrototypeOf(client));
13-
} catch (err) {
14-
throw err;
15-
}
8+
const setCache = (instance) => {
9+
client = instance;
10+
Promise.promisifyAll(Object.getPrototypeOf(client));
1611
};
1712

1813
const getReverse = (lat, lng) => {
@@ -64,9 +59,7 @@ const getAddress = (loc) => {
6459
};
6560

6661
const clearCache = (lat, lng) => {
67-
if (client) {
68-
client.del(`geocoder:${lat}:${lng}`);
69-
}
62+
if (client) client.del(`geocoder:${lat}:${lng}`);
7063
};
7164

7265
module.exports = {

test/test.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
'use strict';
22

3-
import lib from '../lib';
43
import {expect} from 'chai';
4+
import redis from 'redis';
5+
import rg from '../lib';
56

67
describe('simple-reverse-geocoder', () => {
8+
before(() => {
9+
const client = redis.createClient();
10+
rg.setCache(client);
11+
});
12+
713
describe('getAddress', () => {
814
it('should return a valid address', (done) => {
915
const loc = {type: 'Point', coordinates: [-70.5171743, -33.3608387]};
10-
lib.setCache();
11-
lib.getAddress(loc).then(data => {
16+
rg.getAddress(loc).then(data => {
1217
expect(data).to.eql('Del Candil 665-701, Lo Barnechea');
1318
done();
1419
}).catch(err => {
@@ -17,8 +22,8 @@ describe('simple-reverse-geocoder', () => {
1722
});
1823
});
1924

20-
it('should return a valid address', (done) => {
21-
lib.getFromCache(-33.3608387, -70.5171743).then(reply => {
25+
it('should return a valid address from cache', (done) => {
26+
rg.getFromCache(-33.3608387, -70.5171743).then(reply => {
2227
expect(reply).to.eql('Del Candil 665-701, Lo Barnechea');
2328
done();
2429
}).catch(err => {
@@ -29,6 +34,6 @@ describe('simple-reverse-geocoder', () => {
2934
});
3035

3136
after(() => {
32-
lib.clearCache(-33.3608387, -70.5171743);
37+
rg.clearCache(-33.3608387, -70.5171743);
3338
});
3439
});

0 commit comments

Comments
 (0)