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

Property 'getClient' does not exist on type 'Store' #14

Open
epozsh opened this issue Mar 31, 2020 · 5 comments
Open

Property 'getClient' does not exist on type 'Store' #14

epozsh opened this issue Mar 31, 2020 · 5 comments

Comments

@epozsh
Copy link

epozsh commented Mar 31, 2020

Getting this error with cache-manager with Typescript
when trying to const redisClient = redisCache.store.getClient()

@daphnesmit
Copy link

no update?

@xaphod
Copy link

xaphod commented Sep 6, 2022

looking at @types/cache-manager-redis-store the namespace that contains the store isn't exported.

@Heet1996
Copy link

I am still not able to getClient from store. Can someone suggest the workaround?

@bihongbin3027
Copy link

@Heet1996

@Module({
  imports: [
    // 连接redis
    CacheModule.registerAsync({
      isGlobal: true,
      inject: [ConfigService],
      useFactory: async (configService: ConfigService) => {
        const store = await redisStore({
          socket: {
            host: configService.get('REDIS_HOST'),
            port: +configService.get('REDIS_PORT'),
          },
          ttl: 60 * 30,
        });

        return {
          store: () => store,
        } as unknown as CacheStore;
      },
    }),
  ],
  providers: [RedisCacheService],
  exports: [RedisCacheService],
})

@loucadufault
Copy link

loucadufault commented Aug 23, 2023

The issue is that the usage example from the README: https://github.com/dabroek/node-cache-manager-redis-store/blob/04d04cb5e5a472a9f8eb78c59fa1f90eb6df5839/README.md#single-store) no longer works with the latest version of "node-cache-manager":

// not awaiting here is the first issue, since caching fn from node-cache-manager was updated in v5 to be async, see https://github.com/node-cache-manager/node-cache-manager#usage-examples
const redisCache = cacheManager.caching({
    store: await redisStore(config),
})

// redisCache.store returns an object like: { store: ... }, so can only access getClient on redisCache.store.store
const redisClient = redisCache.store.getClient()
// throws error: TypeError: Cannot read properties of undefined (reading 'getClient') 

dependencies:
"cache-manager": "^5.2.3"
"cache-manager-redis-store": "^3.0.1"

It's caused by a breaking change in v5 of node-cache-manager described here which makes passing in a store as is currently described in the README hit the else case in the caching fn: https://github.com/node-cache-manager/node-cache-manager/blob/d9f27d7fb74556f739df1487d1b622374886d675/src/caching.ts#L69, which sets the store property on the object returned by caching to the input { store: ... } object, hence the store.store.

Indeed, downgrading to:

"cache-manager": "4.1.0"
"cache-manager-redis-store": "2.0.0"
as mentioned here restores the behaviour in the README. I have noticed that even using "cache-manager-redis-store": "^3.0.0" works properly (e.g. can do await redisCache.store.get('foo') even though this was mentioned to be failing in the linked issue).

I've found that if using with "cache-manager": "^5.0.0", even though the call to caching can be done in a way that is compatible with new API, the wrap function stops working, so it is probably not a good idea to use.

Probably this package requires an update to be compatible with v5 (which from what I can see is not so likely jaredwray/cache-manager#236)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants