dexdagr8
dexdagr8

Reputation: 337

NestJs Cache Manager issue

I'm having trouble when trying to use cache-manager by NestJS, the problem is the value always return true,

const isSet = await this.cacheManager.store.getClient().set(key, value, 'EX', ttl, 'NX')
console.log("isSet => " + isSet)

if(isSet === true) {
  try {
      //do smth
  } catch(err) {
     console.log("err => " + err)
     throw err;
  } finally {
    //await this.cacheManager.del(key);
  }
}

my question is, when using redis-cli, when i repeatedly do

set key val ex ttl nx

if not exists, it returns OK, but when exists it returns nil.

enter image description here

Why does cache-manager keep returning true?

Depedency Version

"cache-manager": "^3.6.0",
"cache-manager-redis-store": "^2.0.0",

Upvotes: 1

Views: 1817

Answers (1)

Ali Reza Riahi
Ali Reza Riahi

Reputation: 206

you can try it:

const isSet = await this.cacheManager.store.getClient().set(key, value, 'EX', ttl, 'NX');
const actualValue = await this.cacheManager.store.getClient().get(key);

if(actualValue === value) {
  try {
    //do smth
  } catch(err) {
    console.log("err => " + err);
    throw err;
  } finally {
    //await this.cacheManager.del(key);
  }
}

Upvotes: 1

Related Questions