Skip to content

Commit 8ce85b8

Browse files
authored
feat: redis migrations + redis tests (#26)
* feat: redis migrations + redis tests * fix: lint settings
1 parent 206ddd6 commit 8ce85b8

File tree

12 files changed

+126
-2
lines changed

12 files changed

+126
-2
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"extends": "makeomatic",
33
"rules": {
44
"semi": ["error", "never"],
5-
"quotes": ["error", "single", { "allowTemplateLiterals": true }]
5+
"quotes": ["error", "single", { "allowTemplateLiterals": true }],
6+
"no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 1, "maxBOF": 0 }]
67
}
78
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
async function createConstantKeys(service) {
2+
const { redis } = service
3+
const pipeline = redis.pipeline()
4+
pipeline.set('some.key')
5+
pipeline.sadd('some.set', 'value')
6+
pipeline.sadd('some.set', 'other value')
7+
8+
await pipeline.exec()
9+
}
10+
11+
module.exports = {
12+
min: 0,
13+
final: 1,
14+
script: createConstantKeys,
15+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
min: 1,
3+
final: 2,
4+
script: `${__dirname}/update-data.lua`,
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
redis.call('del', '{demo-app}some.key')
2+
redis.call('srem', '{demo-app}some.set', 'value')
3+
redis.call('sadd', '{demo-app}some.set', 'new value')

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@microfleet/transport-amqp": "^15.0.0",
1919
"@microfleet/validation": "^8.1.2",
2020
"common-errors": "^1.0.5",
21+
"ioredis": "^4.14.1",
2122
"ms-conf": "^5.0.2",
2223
"uuid": "^3.3.3"
2324
},

src/config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module.exports = {
2424
'http',
2525
'router',
2626
'amqp',
27+
'redisCluster',
2728
],
2829
app: {
2930
someSecret: {
@@ -46,6 +47,11 @@ module.exports = {
4647
directory: path.resolve(`${__dirname}/../migrations/knex`),
4748
},
4849
},
50+
redis: {
51+
options: {
52+
keyPrefix: '{demo-app}',
53+
},
54+
},
4955
amqp: {
5056
transport: {
5157
connection: {

src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class DemoApp extends Microfleet {
1414
this.addConnector(ConnectorsTypes.migration, async () => {
1515
await this.migrate('knex')
1616
}, 'knex-migration')
17+
18+
this.addConnector(ConnectorsTypes.migration, async () => {
19+
await this.migrate('redis', path.resolve(`${__dirname}/../migrations/redis`))
20+
}, 'redis-migration')
1721
}
1822
}
1923

test/config/test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ module.exports = {
77
},
88
},
99
},
10+
redis: {
11+
hosts: Array.from({ length: 5 }).map((_, i) => ({
12+
host: 'redis',
13+
port: 7000 + i,
14+
})),
15+
},
1016
knex: {
1117
debug: false,
1218
client: 'pg',

test/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ services:
1010
image: rabbitmq:3.8-alpine
1111
expose:
1212
- "5672"
13+
redis:
14+
image: grokzen/redis-cluster
1315
tester:
1416
expose:
1517
- "3000"

test/suites/amqp.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const rp = require('request-promise')
33
const DemoApp = require('../../src')
44

55
describe('#amqp action test', () => {
6-
// eslint-disable-next-line no-unused-vars
76
const query = rp.defaults({
87
baseUrl: 'http://0.0.0.0:3000/amqp',
98
method: 'POST',

0 commit comments

Comments
 (0)