mirror of
https://github.com/seejohnrun/haste-server.git
synced 2024-11-01 03:21:21 +00:00
Fix config and redis settings
This commit is contained in:
parent
ced5c3eef4
commit
54f7b8744d
4 changed files with 13 additions and 24 deletions
|
@ -2,7 +2,7 @@
|
|||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
rootDir: './',
|
||||
rootDir: '../',
|
||||
testRegex: '\\.test\\.ts$',
|
||||
reporters: ['default']
|
||||
}
|
||||
|
|
|
@ -30,23 +30,18 @@ class RedisDocumentStore implements Store {
|
|||
connect = (options: RedisStoreConfig) => {
|
||||
winston.info('configuring redis')
|
||||
|
||||
const url = process.env.REDISTOGO_URL || options.url
|
||||
const host = options.host || '127.0.0.1'
|
||||
const port = options.port || 6379
|
||||
const url = process.env.REDISTOGO_URL || options.url || 'redis://redis:6379'
|
||||
const index = options.db || 0
|
||||
|
||||
if (url) {
|
||||
this.client = createClient({ url })
|
||||
this.client.connect()
|
||||
} else {
|
||||
this.client = createClient({
|
||||
url: `http://${host}:${port}`,
|
||||
database: index as number,
|
||||
username: options.username,
|
||||
password: options.password,
|
||||
})
|
||||
const config = {
|
||||
url,
|
||||
database: index as number,
|
||||
...(options.username ? { username: options.username } : {}),
|
||||
...(options.password ? { username: options.username } : {}),
|
||||
}
|
||||
|
||||
this.client = createClient(config)
|
||||
this.client.connect()
|
||||
|
||||
this.client.on('error', err => {
|
||||
winston.error('redis disconnected', err)
|
||||
})
|
||||
|
@ -54,9 +49,7 @@ class RedisDocumentStore implements Store {
|
|||
this.client
|
||||
.select(index as number)
|
||||
.then(() => {
|
||||
winston.info(
|
||||
`connected to redis on ${url || `${host}:${port}`}/${index}`,
|
||||
)
|
||||
winston.info(`connected to redis on ${url}/${index}`)
|
||||
})
|
||||
.catch(err => {
|
||||
winston.error(`error connecting to redis index ${index}`, {
|
||||
|
@ -85,7 +78,8 @@ class RedisDocumentStore implements Store {
|
|||
callback: Callback,
|
||||
skipExpire?: boolean | undefined,
|
||||
): void => {
|
||||
this.client?.set(key, data, this.getExpire(skipExpire))
|
||||
this.client
|
||||
?.set(key, data, this.getExpire(skipExpire))
|
||||
.then(() => {
|
||||
callback(true)
|
||||
})
|
||||
|
|
|
@ -52,8 +52,6 @@ export interface RethinkDbStoreConfig extends BaseStoreConfig {
|
|||
|
||||
export interface RedisStoreConfig extends BaseStoreConfig {
|
||||
url?: string
|
||||
host?: string
|
||||
port?: string
|
||||
db?: string
|
||||
user?: string
|
||||
username?: string | undefined
|
||||
|
|
|
@ -14,7 +14,6 @@ describe('Redis document store', () => {
|
|||
store = new RedisDocumentStore({
|
||||
expire: 10,
|
||||
type: 'redis',
|
||||
url: 'http://localhost:6666',
|
||||
})
|
||||
return store.set('hello1', 'world', async () => {
|
||||
const res = await store.client?.ttl('hello1')
|
||||
|
@ -26,7 +25,6 @@ describe('Redis document store', () => {
|
|||
store = new RedisDocumentStore({
|
||||
expire: 10,
|
||||
type: 'redis',
|
||||
url: 'http://localhost:6666',
|
||||
})
|
||||
|
||||
store.set(
|
||||
|
@ -43,7 +41,6 @@ describe('Redis document store', () => {
|
|||
it('should not set an expiration when expiration is off', async () => {
|
||||
store = new RedisDocumentStore({
|
||||
type: 'redis',
|
||||
url: 'http://localhost:6666',
|
||||
})
|
||||
|
||||
store.set('hello3', 'world', async () => {
|
||||
|
|
Loading…
Reference in a new issue