type-cacheable icon indicating copy to clipboard operation
type-cacheable copied to clipboard

[BUG] CacheClear not working on Azure Redis

Open christianvanr opened this issue 4 years ago • 2 comments

Describe the bug type-cacheable CacheClear failure on method updateUserDetails due to client error: Cannot read property 'redis_version' of undefined when using @CacheClear

To Reproduce Steps to reproduce the behavior: When using the packages :

  • "@type-cacheable/core": "^9.1.0"
  • "@type-cacheable/redis-adapter": "^9.1.0 ,
  • "ioredis": "^4.19.4"
  • "redis": "^3.0.2",

and connecting to Azure Redis Cache, the following error appears (when debugging is enabled):

type-cacheable CacheClear failure on method ...... due to client error: Cannot read property 'redis_version' of undefined and the clearing the key is not working

Expected behavior The cachekey should be cleared

Additional context Analysis learns that this line of code in the index.js of the adapter introduces the exception

                    if (compareVersions(this.redisClient.**server_info**.redis_version, REDIS_VERSION_UNLINK_INTRODUCED) >= 0) {
                        this.redisClient.unlink(keyOrKeys, RedisAdapter.responseCallback(resolve, reject));
                    }

Debugger learns that in 'our' situation the property is not server_info but serverInfo , when replacing this property, everything works as expected again

christianvanr avatar Feb 04 '21 14:02 christianvanr

Hi @christianvanr, I am not sure what is happening here: https://github.com/NodeRedis/node-redis/blob/master/README.md#clientserver_info

According to the redis package and its corresponding types, this information comes through on client.server_info. Looking through the source of the library, I see the same. Do you have any more information on what could be causing this discrepancy?

joshuaslate avatar Feb 04 '21 23:02 joshuaslate

By changeing the adapter from @type-cacheable/redis-adapter to '@type-cacheable/ioredis-adapter' it is working (i didn't dive into the code, but maybe the check is not implemented there)/ If you still intrested in it : we are using : "redis": "^3.0.2", and "ioredis": "^4.19.4", (both are needed because we are using also other libraries, which are using redis)

christianvanr avatar Feb 05 '21 10:02 christianvanr

This should be working in the latest version of the redis-adapter.

joshuaslate avatar Sep 07 '22 22:09 joshuaslate