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

store.get is not a function error #34

Open
kamal-brill opened this issue Nov 29, 2022 · 0 comments
Open

store.get is not a function error #34

kamal-brill opened this issue Nov 29, 2022 · 0 comments

Comments

@kamal-brill
Copy link

kamal-brill commented Nov 29, 2022

I'm trying to connect to ElastiCache cluster and used the example code given in the readme, just passed the password in the redisOptions

It's throwing me the below error when trying to do caching.get()

TypeError: store.get is not a function
    at Object.get (C:\kamal\proj\node_modules\cache-manager\src\caching.ts:88:36)

Code used

import { Injectable, Scope } from '@nestjs/common';
const cacheManager = require('cache-manager');
const redisStore = require('cache-manager-ioredis');

@Injectable({ scope: Scope.DEFAULT })
export class CacheService {
  private cache;
  constructor() {
    cacheManager.caching({
      store: redisStore,
      clusterConfig: {
        nodes: [
          {
            port: 6379,
            host: 'clustercfg.some.elasticache.service.url.cache.amazonaws.com',
          },
        ],
        options: {
          maxRedirections: 16,
          redisOptions: {
            password: 'PASSWORD',
          },
        },
      },
    }).then(c => {
        this.cache = c;
    }).catch(err => {
        console.log(err);
        this.cache = null
    });
  }

  async get(key: string) {
    return this.cache.get(key);
  }

  set(key: string, value: any, ttl: number) {
    this.cache.set(key, value, { ttl });
    return this;
  }
}

Dependencies:

"cache-manager": "^5.1.3",
"cache-manager-ioredis": "^2.1.0"
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

1 participant