Skip to content

Receiver must be an instance of class RedisCluster #2967

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

Closed
Rimantovas opened this issue May 20, 2025 · 1 comment · Fixed by #2971
Closed

Receiver must be an instance of class RedisCluster #2967

Rimantovas opened this issue May 20, 2025 · 1 comment · Fixed by #2971
Assignees
Labels

Comments

@Rimantovas
Copy link

Description

When using RedisJSON commands, getting error: "Receiver must be an instance of class RedisCluster". Simple operations like get or set work fine.

RedisJSON module is enabled on my Redis cluster. Commands work fine on Go services using go-redis.

Redis is instantied as such:

this.redisCluster = createCluster({
      rootNodes: [
        {
          url: `redis://${configService.get<string>('REDIS_HOST')}:${configService.get<string>('REDIS_PORT')}`,
        },
      ],
      defaults: {
        socket: {
          connectTimeout: 15000, // 15 seconds
          keepAlive: true, // Keep-alive every 5 seconds
          reconnectStrategy: (retries) => {
            const delay = Math.min(retries * 100, 3000); // Max 3 second delay between retries
            console.warn(
              `Redis connection retry attempt: ${retries}, retrying in ${delay}ms`,
            );
            return delay;
          },
        },
      },
    });

Node.js Version

20

Redis Server Version

7.4.2

Node Redis Version

5.0.1

Platform

Linux and macOS

Logs

TypeError: Receiver must be an instance of class RedisCluster
2025-05-20T12:26:35.981+03:00    at Object.get (/home/node/node_modules/.pnpm/@[email protected]/node_modules/@redis/client/dist/lib/cluster/index.js:29:31)
@Rimantovas Rimantovas added the Bug label May 20, 2025
@Rimantovas
Copy link
Author

Follow up.

Found a fix for now. Need to bind redisCluster client to json get command.

async jsonGet<T>(key: string, field?: string): Promise<T | null> {
    const jsonGet = this.redisCluster.json.get.bind(this.redisCluster);
    const value = await jsonGet(key, { path: field ?? '$' });
    if (value) {
      try {
        return JSON.parse(value as string) as T;
      } catch (error) {
        return value as T;
      }
    }
    return null;
  }

@nkaradzhov nkaradzhov self-assigned this May 20, 2025
nkaradzhov added a commit to nkaradzhov/node-redis that referenced this issue May 21, 2025
Private class fields (e.g., #execute) cause runtime errors when accessed from contexts where `this` is not the exact instance, triggering “Receiver must be an instance of class RedisCluster”.

fixes redis#2967
nkaradzhov added a commit that referenced this issue May 22, 2025
Private class fields (e.g., #execute) cause runtime errors when accessed from contexts where `this` is not the exact instance, triggering “Receiver must be an instance of class RedisCluster”.

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

Successfully merging a pull request may close this issue.

2 participants