Skip to content

refactor(client): remove type cast in cluster slots by propagating options generics - #3380

Open
Piyush0049 wants to merge 4 commits into
redis:masterfrom
Piyush0049:refactor/cluster-slots-type-cast
Open

refactor(client): remove type cast in cluster slots by propagating options generics#3380
Piyush0049 wants to merge 4 commits into
redis:masterfrom
Piyush0049:refactor/cluster-slots-type-cast

Conversation

@Piyush0049

@Piyush0049 Piyush0049 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Description

This pull request improves type safety across the @redis/client cluster subsystem by resolving a maintainer technical debt comment (// TODO: find a way to avoid type casting) in cluster-slots.ts.

Background

Previously, RedisClusterClientOptions omitted keyof ClusterCommander, which inadvertently stripped configuration options like RESP from cluster option types. This forced internal node discovery in cluster-slots.ts to use an unsafe as RedisClientOptions<M, F, S, RESP, {}> type cast to bypass TypeScript compiler errors.

Key Changes

  1. Preserved Configuration Options: Updated RedisClusterClientOptions to exclude command execution methods while retaining configuration properties (RESP).
  2. Propagated Options Generics: Extended RedisClusterClientOptions with <M, F, S, RESP, TYPE_MAPPING> and updated RedisClusterOptions properties (rootNodes, defaults) to pass generics recursively down the topology hierarchy.
  3. Clean Overloads and Typed Discovery: Replaced options as RedisClientOptions in cluster-slots.ts with a strongly typed object literal clientOptions: RedisClientOptions<M, F, S, RESP, {}> and simplified #clientOptionsDefaults with standard TypeScript function overloads.

Checklist

  • Does npm test pass with this change (including linting)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?

Note

Low Risk
Mostly compile-time typing; small behavioral alignment in how RESP is passed into factory-created clients and cluster node connections.

Overview
Improves type safety for cluster and standalone client factories by threading M, F, S, RESP, and TYPE_MAPPING through RedisClusterClientOptions, rootNodes, defaults, and internal cluster-slots helpers.

RedisClusterClientOptions is now generic and omits only cluster command surface from ClusterCommander, so options like RESP stay on node/discovery option types instead of being stripped. Topology discovery in #getShards builds an explicit RedisClientOptions object and drops the previous as RedisClientOptions cast; #clientOptionsDefaults gains overloads for clearer typing.

Runtime wiring: standalone RedisClient.factory merges config?.RESP into proxied client options; cluster node creation uses #clientFactory<TYPE_MAPPING> and relies on merged defaults for RESP instead of passing RESP again on each node. RedisCluster.create forwards factory generics explicitly.

Reviewed by Cursor Bugbot for commit 8c5ea72. Bugbot is set up for automated code reviews on this repo. Configure here.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bbaa97c667

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/client/lib/cluster/index.ts Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit e704f69. Configure here.

Comment thread packages/client/lib/cluster/cluster-slots.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c11eef7fd2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/client/lib/cluster/index.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant