1
1
const q = require ( 'q' )
2
2
const EventEmitter = require ( 'events' ) . EventEmitter
3
3
const { MongoClient, ObjectId } = require ( 'mongodb' )
4
- const Redis = require ( 'redis ' )
4
+ const Redis = require ( 'ioredis ' )
5
5
const fs = require ( 'fs' )
6
6
7
7
const DATABASE_VERSION = 9
@@ -26,9 +26,14 @@ module.exports = function (config) {
26
26
delete config . mongo . port
27
27
delete config . mongo . database
28
28
29
- const redis = Redis . createClient ( config . redis )
30
- const pub = Redis . createClient ( config . redis )
31
- const sub = Redis . createClient ( config . redis )
29
+ if ( config . redis . namespace ) {
30
+ config . redis . keyPrefix = `${ config . redis . namespace } :`
31
+ delete config . redis . namespace
32
+ }
33
+
34
+ const redis = new Redis ( config . redis )
35
+ const pub = new Redis ( config . redis )
36
+ const sub = new Redis ( config . redis )
32
37
33
38
const mongo = q . ninvoke ( MongoClient , 'connect' , uri , Object . assign ( { promiseLibrary : Promise , useUnifiedTopology : true } , config . mongo ) )
34
39
. then ( client => client . db ( ) )
@@ -78,10 +83,10 @@ module.exports = function (config) {
78
83
if ( v === '^[WE]d*5[NS]d*5$' ) {
79
84
query . $regex = v . replace ( / \] d \* / g, ']\\d*' )
80
85
81
- // https://github.com/screeps/backend-local/blob/7520c8c7e6a443ad955d25e064dbd151a909d8cb/lib/cronjobs.js#L393
82
- // https://github.com/screeps/backend-local/blob/7520c8c7e6a443ad955d25e064dbd151a909d8cb/lib/strongholds.js#L132
83
- //
84
- // ignore properly escaped sector regex queries
86
+ // https://github.com/screeps/backend-local/blob/7520c8c7e6a443ad955d25e064dbd151a909d8cb/lib/cronjobs.js#L393
87
+ // https://github.com/screeps/backend-local/blob/7520c8c7e6a443ad955d25e064dbd151a909d8cb/lib/strongholds.js#L132
88
+ //
89
+ // ignore properly escaped sector regex queries
85
90
} else if ( v . match ( / \^ [ E W ] \d * \\ d [ N S ] \d * \\ d \$ / g) === null && v . match ( / \^ \[ [ E W ] { 2 } \] \\ d \* 5 \[ [ N S ] { 2 } \] \\ d \* 5 \$ / g) === null ) {
86
91
// default regex escape fix for loki regex queries to work with mongo regex queries
87
92
query . $regex = v . replace ( / \\ { 1 , 2 } / g, '\\\\' )
0 commit comments