-
Notifications
You must be signed in to change notification settings - Fork 0
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
b7f8ca2
commit e6594d9
Showing
1 changed file
with
62 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
# nestjs-redis-connector | ||
|
||
## introduction | ||
|
||
NestJS Redis Connector is a library that simplifies using Redis as a caching mechanism in your NestJS-based projects. This library provides an easy-to-use interface for connecting to a Redis server and interacting with it. | ||
|
||
|
||
## Installation | ||
|
||
|
||
YYou can install the NestJS Redis Connector package using npm or yarn: | ||
|
||
```bash | ||
npm install nestjs-redis-connector | ||
``` | ||
|
||
## Usage/Examples | ||
|
||
1. Import the `RedisConnectorModule` | ||
In your NestJS application, you need to import the `RedisConnectorModule` and register it with a connection configuration. This should be done in the application module, typically `app.module.ts`. | ||
|
||
```ts | ||
import { Module } from '@nestjs/common'; | ||
import { RedisConnectorModule } from 'nestjs-redis-connector'; | ||
|
||
@Module({ | ||
imports: [ | ||
RedisConnectorModule.register({ | ||
url: 'redis://localhost:6379', // Replace with your Redis server URL | ||
ttl: 0, // Set your default TTL (time-to-live) for cached data | ||
}), | ||
], | ||
}) | ||
export class AppModule {} | ||
``` | ||
|
||
2. Use `RedisClientService` | ||
Now that you have registered the `RedisConnectorModule`, you can use the `RedisClientService` in your `services` or `controllers` to interact with Redis. | ||
|
||
```ts | ||
import { Controller, Get } from '@nestjs/common'; | ||
import { RedisClientService } from 'nestjs-redis-connector'; | ||
|
||
@Controller('cache') | ||
export class CacheController { | ||
constructor(private readonly redisClient: RedisClientService) {} | ||
|
||
@Get(':key') | ||
async getCacheValue(@Param('key') key: string): Promise<string> { | ||
const cachedValue = await this.redisClient.getValue(key); | ||
return cachedValue; | ||
} | ||
} | ||
|
||
``` | ||
|
||
In the example above, we've created a `controller` that retrieves a cached value using the `getValue` method of the `RedisClientService`. You can customize your usage as per your application's requirements. | ||
## License | ||
|
||
This package is released under the [MIT License](https://choosealicense.com/licenses/mit/) | ||
|