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

Redis: store.set is not a function (cache-manager-ioredis-yet) #596

Closed
Drunkenpilot opened this issue Sep 21, 2023 · 2 comments
Closed

Redis: store.set is not a function (cache-manager-ioredis-yet) #596

Drunkenpilot opened this issue Sep 21, 2023 · 2 comments
Labels

Comments

@Drunkenpilot
Copy link

Describe the bug
Can't set value when use redis.
Tried both cache-manager-ioredis-yet and cache-manager-redis-yet.
Error message:

store.set is not a function
    at Object.set (/node_modules/cache-manager/dist/caching.js:48:45)
     redis_version:6.0.20

    "cache-manager": "^5.2.3",
    "cache-manager-ioredis-yet": "^1.2.2",
    "cache-manager-redis-yet": "^4.1.2",

How To Reproduce (best to provide workable code or tests!)

  const cacheManager = require('cache-manager');
  const { redisStore } = require('cache-manager-ioredis-yet');

 const redisCache = await cacheManager.caching({
    store: await redisStore({
      host: 'localhost', // default value
      username: "default",
      port: 6379, // default value
      password: 'XXXX',
      db: 0,
      ttl: 60 * 1000 /*milliseconds*/
    }),
  });

  redisCache.set('foo', 'bar', 5 * 1000)

@pkkasu
Copy link

pkkasu commented Sep 24, 2023

Having same issue with Mongoose, any update ?

@Drunkenpilot
Copy link
Author

Find the source of issue:
Codes should be like this when use custom stores

  /**
   * @CacheManager
   * @Redis
   */ 
const cacheManager = require('cache-manager');

const { redisStore } = require('cache-manager-ioredis-yet');
const store = await redisStore({
      host: 'localhost', // default value
      username: "default",
      port: 6379, // default value
      password: 'XXXX',
      db: 0,
      ttl: 60 * 1000 /*milliseconds*/
 })

const redisCache = await cacheManager.caching(store);

 /**
   * @CacheManager
   * @FS
   */
 const cacheManager = require('cache-manager');

 const FsStore = require('cache-manager-fs');
 const store = FsStore.create({
       path: 'diskcache',          //path for cached files
       ttl: 60 * 60,               //time to life in seconds
      maxsize: 1000 * 1000 * 1000,    // max size in bytes on disk
       zip: true,                  //zip files to save diskspace (default: false)
       preventfill: true
    })
 
const diskCache = await cacheManager.caching(store);

 await diskCache.set('key', 'value');
 console.log(await diskCache.get('key')); //"value"

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

No branches or pull requests

2 participants