Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module '"@liaoliaots/nestjs-redis"' has no exported member 'InjectRedis' #553

Open
maheshupasani opened this issue Oct 10, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@maheshupasani
Copy link

maheshupasani commented Oct 10, 2024

After upgrading version 9 to version 10, existing code is not working and the decorators are removed in new version 10.
A clear and concise description of what the bug is.

src/databases/redis.service.ts:1:10 - error TS2305: Module '"@liaoliaots/nestjs-redis"' has no exported member 'InjectRedis'.
1 import { InjectRedis } from '@liaoliaots/nestjs-redis';
~~~~~~~~~~~

export class RedisService {
constructor(@InjectRedis() private readonly redisClient: Redis) { }
}

Steps to reproduce

Below is implementation that is working in v9.
src/databases/redis.service.ts:1:10 - error TS2305: Module '"@liaoliaots/nestjs-redis"' has no exported member 'InjectRedis'.
1 import { InjectRedis } from '@liaoliaots/nestjs-redis';
~~~~~~~~~~~

export class RedisService {
constructor(@InjectRedis() private readonly redisClient: Redis) { }
}

Expected behavior

It should work after upgrading it to v10 from v9

Environment

  • OS: [e.g. Arch Linux]
  • Other details that you think may affect.

Additional context

Add any other context about the problem here.

@maheshupasani maheshupasani added the bug Something isn't working label Oct 10, 2024
@maheshupasani maheshupasani changed the title InjectRedis and CacheModule has no exported member Module '"@liaoliaots/nestjs-redis"' has no exported member 'InjectRedis' Oct 10, 2024
@Scalahansolo
Copy link

Read the v10 update release notes. InjectRedis was removed.

@liaoliaots
Copy link
Owner

liaoliaots commented Dec 14, 2024

InjectRedis has some issues which would lead to inconsistent behavior in production environments, so it has been removed for now.

@kameshpal
Copy link

what is the alternate approach to mitigate in v10 ?

@Stanback
Copy link

Stanback commented Feb 6, 2025

@kameshpal As far as I know you would replace something like this:

import { Redis } from 'ioredis';

// ...

  constructor(
    // ...

    @InjectRedis()
    private readonly redis: Redis,

   // ...
) {

with this:

import { RedisService } from '@liaoliaots/nestjs-redis';

// ...

  constructor(
    // ...

    private readonly redisService: RedisService, // Or ClusterService depending on your situation

   // ...
) {

Then update your usage:

// Instead of this:

this.redis.setnx(...) // or whatever operation you want

// You'll do this:

this.redisService.getOrThrow().setnx(...) // there's also a getOrNil(), in either case, it's up to you to figure out error handling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants