-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
edac18d
commit 854f9e0
Showing
7 changed files
with
64 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
export const redisConfig = { | ||
export function getRedisConfig() { | ||
return { | ||
host: process.env.REDIS_HOST || '127.0.0.1', | ||
port: Number(process.env.REDIS_PORT) || 6379, | ||
port: Number(process.env.REDIS_PORT) || 3308, | ||
password: process.env.REDIS_PASSWORD || undefined, | ||
db: Number(process.env.REDIS_DB) || 0, | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { RedisController } from './redis.controller'; | ||
|
||
describe('RedisController', () => { | ||
let controller: RedisController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [RedisController], | ||
}).compile(); | ||
|
||
controller = module.get<RedisController>(RedisController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Controller, Get, Post, Delete, Param, Body } from '@nestjs/common'; | ||
import { RedisRepository } from './redis.repository'; | ||
|
||
@Controller('redis') | ||
export class RedisController { | ||
constructor(private readonly redisRepository: RedisRepository) {} | ||
|
||
@Get(':key') | ||
async getValue(@Param('key') key: string): Promise<string | null> { | ||
return await this.redisRepository.get(key); | ||
} | ||
|
||
@Post() | ||
async setValue( | ||
@Body() body: { key: string; value: string; ttl?: number }, | ||
): Promise<string> { | ||
const { key, value, ttl } = body; | ||
return await this.redisRepository.set(key, value, ttl); | ||
} | ||
@Delete(':key') | ||
async deleteKey(@Param('key') key: string): Promise<number> { | ||
return await this.redisRepository.delete(key); | ||
} | ||
|
||
@Get(':key/exists') | ||
async checkExists(@Param('key') key: string): Promise<boolean> { | ||
const result = await this.redisRepository.exists(key); | ||
return result === 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters