# Redis

### Imports

{% tabs %}
{% tab title="Service" %}

```typescript
import { RedisService } from 'niro-health';
```

{% endtab %}

{% tab title="Module" %}

```typescript
import { RedisModule } from 'niro-health';
```

{% endtab %}

{% tab title="Interface" %}

```typescript
import type { IRedisService } from 'niro-health';
```

{% endtab %}
{% endtabs %}

### Environment Variables

Do you create variables an `.env` file.

<table><thead><tr><th width="291">name</th><th width="460">description</th></tr></thead><tbody><tr><td><code>REDIS_HOST</code></td><td><code>Host of the redis.</code></td></tr><tr><td><code>REDIS_PORT</code></td><td><code>Port of the redis.</code></td></tr><tr><td><code>REDIS_PASSWORD</code></td><td><code>Password of the redis.</code></td></tr></tbody></table>

Check the example file.

{% code title=".env" %}

```properties
REDIS_HOST=redis://localhost:6379
REDIS_PORT=6379
REDIS_PASSWORD=
```

{% endcode %}

### Method of Use

To use this module, you need to inject it into the desired service.

{% code overflow="wrap" %}

```typescript
import { Module } from '@nestjs/common';
import {
  AppHostService,
  PrismaService,
  ConfigurationService,
  ValidatorRegexpService,
  StringExService,
  DebugService,
} from 'niro-health';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  controllers: [AppController],
  providers: [
    AppService,
    {
      provide: 'IAppHostService',
      useClass: AppHostService,
    },
    {
      provide: 'IPrismaService',
      useClass: PrismaService,
    },
    {
      provide: 'IConfigurationService',
      useClass: ConfigurationService,
    },
    {
      provide: 'IValidatorRegexpService',
      useClass: ValidatorRegexpService,
    },
    {
      provide: 'IStringExService',
      useClass: StringExService,
    },
    {
      provide: 'IDebugService',
      useClass: DebugService,
    },
  ],
})
export class AppModule {}
```

{% endcode %}

Injecting the module into our service.

```typescript
import { Inject, Injectable } from '@nestjs/common';
import type { IAppHostService, IRedisService } from 'niro-health';

@Injectable()
export class AppService {
  constructor(
    @Inject('IAppHostService')
    private readonly appHostService: IAppHostService,
    @Inject('IRedisService')
    private readonly redisService: IRedisService,
  ) {}

  async enableShutdownHooks() {
    await this.redisService.enableShutdownHooks(this.appHostService.app);
  }
}
```

Modifying our <mark style="color:blue;">**`main.ts`**</mark>

{% code title="main.ts" %}

```typescript
import { NestFactory } from '@nestjs/core';
import { AppModule } from '@/app.module';
import { Logger } from '@nestjs/common';
import { AppHostModule, AppHostService } from 'niro-health';
import { AppModule } from './app.module';
import { AppService } from './app.service';

(async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    logger: new Logger('NestApplication', {
      timestamp: true,
    }),
    cors: true,
  });
  app.select(AppHostModule).get(AppHostService).setApp(app);
  app.select(AppModule).get(AppService).enableShutdownHooks();
})();
```

{% endcode %}

### With dependencies

You will need to inject the following interfaces.

<table><thead><tr><th width="308">Interface</th><th>Service</th></tr></thead><tbody><tr><td><code>AppHostService</code></td><td><a href="../app-host">Link to Service documentation</a></td></tr><tr><td><code>IConfigurationService</code></td><td><a href="../configuration">Link to Service documentation</a></td></tr><tr><td><code>IValidatorRegexpService</code></td><td><a href="../validator-regexp">Link to Service documentation</a></td></tr><tr><td><code>IStringExService</code></td><td><a href="../stringex">Link to Service documentation</a></td></tr><tr><td><code>IDebugService</code></td><td><a href="../debug">Link to Service documentation</a></td></tr></tbody></table>

### Properties

<table><thead><tr><th width="325">Property</th><th width="111.33333333333331" align="center">Scope</th><th>Description</th></tr></thead><tbody><tr><td><code>app</code></td><td align="center"><code>public</code></td><td><code>This is instance of application.</code></td></tr><tr><td><code>_client</code></td><td align="center"><code>private</code></td><td><code>This is the major component of ioredis. Use it to connect to a standalone Redis server or Sentinels.</code></td></tr><tr><td><code>_redisConfigurationFalsy</code></td><td align="center"><code>private</code></td><td><code>This is used to check if the environment variables from Redis are missing.</code></td></tr><tr><td><mark style="color:blue;"><strong>get</strong></mark> <code>redisConfigurationFalsy</code></td><td align="center"><code>public</code></td><td><code>Returns if environment variables from Redis are missing.</code></td></tr></tbody></table>

### Methods

<table><thead><tr><th width="316.3333333333333">Method</th><th width="114" align="center">Scope</th><th>Description</th></tr></thead><tbody><tr><td><code>keys</code></td><td align="center"><code>public</code></td><td><code>Get all keys that match a pattern.</code></td></tr><tr><td><code>save</code></td><td align="center"><code>public</code></td><td><code>It saves a key-value pair in the Redis database.</code></td></tr><tr><td><code>saveBuffer</code></td><td align="center"><code>public</code></td><td><code>It saves a key-value pair in the Redis database.</code></td></tr><tr><td><code>update</code></td><td align="center"><code>public</code></td><td><code>It update a key-value pair in the Redis database.</code></td></tr><tr><td><code>updateBuffer</code></td><td align="center"><code>public</code></td><td><code>It update a key-value pair in the Redis database.</code></td></tr><tr><td><code>findAll</code></td><td align="center"><code>public</code></td><td><code>It returns all the values in the Redis database.</code></td></tr><tr><td><code>findOne</code></td><td align="center"><code>public</code></td><td><code>It returns a value in the Redis database.</code></td></tr><tr><td><code>delete</code></td><td align="center"><code>public</code></td><td><code>It delete a key-value pair in the Redis database.</code></td></tr><tr><td><code>flushall</code></td><td align="center"><code>public</code></td><td><code>Delete all the keys of all the existing databases, not just the currently selected one.</code></td></tr><tr><td><code>shutdown</code></td><td align="center"><code>public</code></td><td><code>This method is used to shutdown application.</code></td></tr><tr><td><code>onApplicationShutdown</code></td><td align="center"><code>public</code></td><td><code>Application shutdown hook.</code></td></tr><tr><td><code>enableShutdownHooks</code></td><td align="center"><code>public</code></td><td><code>Enable shutdown hooks.</code></td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://guilhermesantos.gitbook.io/niro-health/modules/core/redis.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
