Skip to content

Commit d0aed8a

Browse files
author
Hans Kristian Flaatten
committed
feat(api): Redis database wrapper
0 parents  commit d0aed8a

8 files changed

+257
-0
lines changed

.eslintrc

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# vi:syntax=json
2+
{
3+
"extends": "airbnb-base",
4+
"env": {
5+
"mocha": true,
6+
"node": true
7+
},
8+
"parserOptions": {
9+
"ecmaVersion": 6,
10+
"sourceType": "script",
11+
"ecmaFeatures": {
12+
"modules": false
13+
}
14+
},
15+
"rules": {
16+
"strict": [2, "global"]
17+
}
18+
}

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Den Norske Turistforening (DNT), Hans Kristian Flaatten
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# @turbasen/db-redis
2+
3+
[![Build status](https://app.wercker.com/status/5030e064047a362f5b19495b974190b7/s "wercker status")](https://app.wercker.com/project/bykey/5030e064047a362f5b19495b974190b7)
4+
[![Codacy grade](https://img.shields.io/codacy/grade/f1b04663349647a9bb7765a296c7caca.svg "Codacy grade")](https://www.codacy.com/app/Turbasen/db-redis)
5+
[![Codacy coverage](https://img.shields.io/codacy/coverage/f1b04663349647a9bb7765a296c7caca.svg "Codacy coverage")](https://www.codacy.com/app/Turbasen/db-redis)
6+
[![NPM downloads](https://img.shields.io/npm/dm/@turbasen/db-redis.svg "NPM downloads")](https://www.npmjs.com/package/@turbasen/db-redis)
7+
[![NPM version](https://img.shields.io/npm/v/@turbasen/db-redis.svg "NPM version")](https://www.npmjs.com/package/@turbasen/db-redis)
8+
[![Node version](https://img.shields.io/node/v/@turbasen/db-redis.svg "Node version")](https://www.npmjs.com/package/@turbasen/db-redis)
9+
[![Dependency status](https://img.shields.io/david/Turbasen/db-redis.svg "Dependency status")](https://david-dm.org/Turbasen/db-redis)
10+
11+
Internal Redis wrapper for Nasjonal Turbase API.
12+
13+
## Getting started
14+
15+
Download [Docker for Mac or Windows](https://www.docker.com/products/docker).
16+
17+
Run in this directory:
18+
19+
```
20+
$ docker-compose up
21+
```
22+
23+
Docker is now watching for changes and will run the test suite automatically.
24+
25+
## Usage
26+
27+
Connects automatically to Redis using the following configurations:
28+
29+
* `REDIS_PORT_6379_TCP_ADDR` and `REDIS_PORT_6379_TCP_PORT`
30+
* Default to `redis` and `6379`
31+
32+
```js
33+
const redis = require('redis');
34+
```
35+
36+
## [MIT lisenced](https://github.com/Turbasen/db-redis/blob/master/LICENSE)

docker-compose.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: '2'
2+
3+
services:
4+
redis:
5+
image: redis:3
6+
7+
node:
8+
image: node:argon
9+
working_dir: /usr/src/app
10+
volumes:
11+
- .:/usr/src/app
12+
links:
13+
- redis
14+
depends_on:
15+
- redis
16+
environment:
17+
- NODE_ENV=development
18+
- NPM_CONFIG_LOGLEVEL=silent
19+
- NPM_CONFIG_PROGRESS=false
20+
- NPM_CONFIG_SPIN=false
21+
command: npm run test:watch

index.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
const Redis = require('ioredis');
4+
5+
const addr = process.env.REDIS_PORT_6379_TCP_ADDR || 'redis';
6+
const port = process.env.REDIS_PORT_6379_TCP_PORT || '6379';
7+
8+
module.exports = new Redis(port, addr);

package.json

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"name": "@turbasen/db-redis",
3+
"version": null,
4+
"description": "Internal Redis wrapper for Nasjonal Turbase API",
5+
"main": "index.js",
6+
"files": [
7+
"index.js"
8+
],
9+
"scripts": {
10+
"codacy-coverage": "codacy-coverage",
11+
"cover": "istanbul cover --report lcovonly ./node_modules/.bin/_mocha -- -R spec test.js",
12+
"grunt:watch": "grunt watch",
13+
"lint": "eslint index.js test.js",
14+
"nsp": "nsp check",
15+
"semantic-release": "semantic-release",
16+
"test": "mocha -R tap -b --check-leaks test.js",
17+
"test:watch": "mocha -R progress -b --check-leaks -w test.js",
18+
"greenkeeper-postpublish": "greenkeeper-postpublish"
19+
},
20+
"repository": {
21+
"type": "git",
22+
"url": "git+https://github.com/Turbasen/db-redis.git"
23+
},
24+
"keywords": [
25+
"nasjonal turbase",
26+
"turbasen",
27+
"db",
28+
"redis"
29+
],
30+
"author": "Hans Kristian Flaatten <[email protected]>",
31+
"license": "MIT",
32+
"bugs": {
33+
"url": "https://github.com/Turbasen/db-redis/issues"
34+
},
35+
"homepage": "https://github.com/Turbasen/db-redis#readme",
36+
"dependencies": {
37+
"ioredis": "^2.2.0"
38+
},
39+
"devDependencies": {
40+
"codacy-coverage": "^1.1.3",
41+
"eslint": "^2.13.1",
42+
"eslint-config-airbnb-base": "^3.0.1",
43+
"eslint-plugin-import": "^1.10.0",
44+
"greenkeeper-postpublish": "^1.0.0",
45+
"istanbul": "^0.4.4",
46+
"mocha": "^2.5.3",
47+
"nsp": "^2.5.0",
48+
"semantic-release": "^4.3.5"
49+
},
50+
"engines": {
51+
"node": ">=4.0.0"
52+
}
53+
}

test.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
3+
const redis = require('.');
4+
const assert = require('assert');
5+
const Ioredis = require('ioredis');
6+
7+
describe('redis', () => {
8+
it('returns Redis instance', () => {
9+
assert(redis instanceof Ioredis);
10+
});
11+
12+
it('is connected to the database', done => {
13+
redis.info((err, info) => {
14+
assert.ifError(err);
15+
assert.equal(typeof info, 'string');
16+
done();
17+
});
18+
});
19+
20+
it('connects via REDIS_PORT_6379_TCP_* environment variables', () => {
21+
process.env.REDIS_PORT_6379_TCP_ADDR = 'redis';
22+
process.env.REDIS_PORT_6379_TCP_PORT = '6379';
23+
24+
delete require.cache[require.resolve('.')];
25+
const redisOverEnv = require('.'); // eslint-disable-line global-require
26+
assert(redisOverEnv instanceof Ioredis);
27+
28+
delete process.env.MONGO_PORT_27017_TCP_ADDR;
29+
delete process.env.MONGO_PORT_27017_TCP_PORT;
30+
});
31+
});

wercker.yml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
box: node:argon
2+
3+
build:
4+
services:
5+
- mongo:3.0
6+
- redis:3
7+
8+
steps:
9+
- script:
10+
name: wait for MongoDB to start
11+
code: |
12+
apt-get update --no-install-recommends -y
13+
apt-get install --no-install-recommends -y netcat
14+
while ! nc -q 1 $MONGO_PORT_27017_TCP_ADDR $MONGO_PORT_27017_TCP_PORT </dev/null; do sleep 3; done
15+
16+
- script:
17+
name: echo nodejs information
18+
code: |
19+
echo "node version $(node -v) running"
20+
echo "npm version $(npm -v) running"
21+
22+
- npm-install
23+
24+
- script:
25+
name: lint
26+
code: npm run lint
27+
28+
- npm-test
29+
30+
- script:
31+
name: test coverage
32+
code: |
33+
npm run cover
34+
cat ./coverage/lcov.info | npm run codacy-coverage
35+
36+
- script:
37+
name: node security project
38+
code: |
39+
npm run nsp
40+
41+
after-steps:
42+
- turistforeningen/slack-notifier:
43+
url: $SLACK_WEBHOOK_URL
44+
45+
npm:
46+
steps:
47+
# Rebuild node_modules to fix broken symlinks
48+
# https://github.com/wercker/docs/issues/310
49+
- script:
50+
name: npm rebuild
51+
code: npm rebuild
52+
53+
- script:
54+
name: semantic release pre
55+
code: npm run semantic-release -- pre
56+
57+
- turistforeningen/npm-publish
58+
59+
- script:
60+
name: semantic release post
61+
code: npm run semantic-release -- post
62+
63+
- script:
64+
name: greenkeeper postpublish
65+
code: npm run greenkeeper-postpublish
66+
67+
after-steps:
68+
- turistforeningen/slack-notifier:
69+
url: $SLACK_WEBHOOK_URL

0 commit comments

Comments
 (0)