Skip to content

[BUG] ioredis-adapter ignores hashKey decorator and always uses set / get #1281

@herebebogans

Description

@herebebogans

Not sure if this is a bug or expected behaviour

From my testing with both redis adapters it seems that ioredis-adapter always use string key type regardless of hashKey decorator

Simple example to reproduce

type User = {
  name: string;
  id: number;
};

export class Users {
  static userCacheKey = (args: any) => args[0];

  @Cacheable({
    cacheKey: 'users'
  })
  listUsers(): Promise<User[]> {
    return Promise.resolve([
      { name: 'John Doe', id: 100 },
      { name: 'Jane Smith', id: 200 }
    ]);
  }

  @Cacheable({
    cacheKey: Users.userCacheKey,
    hashKey: 'user',
  })
  getUser(id: number): Promise<User> {
    return this.listUsers().then((users) => users.find((u) => u.id === id)!);
  }
}

When monitoring with redis adapter enabled with above for
await Users.getUser(100);

"HGETALL" "user:100"
"GET" "users"
"SET" "users" "[{\"name\":\"John Doe\",\"id\":100},{\"name\":\"Jane Smith\",\"id\":200}]"
"HSET" "user:100" "name" "\"John Doe\"" "id" "100"

when monitoring with ioredis adapter enabled

"get" "user:100"
"get" "users"
"set" "users" "[{\"name\":\"John Doe\",\"id\":100},{\"name\":\"Jane Smith\",\"id\":200}]"
"set" "user:100" "{\"name\":\"John Doe\",\"id\":100}"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions