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