Skip to content

chore: add npm run repl with a connected client - #3566

Merged
nkaradzhov merged 2 commits into
redis:masterfrom
nkaradzhov:chore/repl-script
Oct 31, 2026
Merged

nkaradzhov merged 2 commits into
redis:masterfrom
nkaradzhov:chore/repl-script

Conversation

@nkaradzhov

@nkaradzhov nkaradzhov commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Adds npm run repl, which opens a Node REPL with a connected client ready to use. This makes it quick to try commands against a local server while developing.

npm run repl                                  # localhost:6379
npm run repl -- --host 10.0.0.5 --port 7000   # or -h / -p
REDIS_URL=redis://localhost:6380 npm run repl
  • --host and --port are optional; a missing one falls back to localhost / 6379. Flags take priority over REDIS_URL.
  • If the first connection fails, the script prints the reason and exits instead of retrying forever. After that, the client's normal reconnects apply.
  • .exit or Ctrl+D closes the client.
  • The script uses the built packages, so run npm run build after source changes.

Checklist

  • Does npm test pass with this change (including linting)? — lint passes; npm test not run, as this adds a dev script only and no library code
  • Is the new or changed code fully tested? — no automated tests; checked flag parsing by hand
  • Is a documentation update included? — not needed; no API change

Note

Low Risk
Dev-only script and package.json entry; no runtime library or API changes.

Overview
Adds npm run repl, a dev workflow that starts a Node REPL with a pre-connected client so you can try Redis commands interactively (e.g. await client.ping()).

Connection targets localhost:6379 by default, REDIS_URL, or --host / --port (flags override the env var; partial flags fall back to localhost/6379). The script fails fast on the initial connect error, then uses the client’s normal reconnect behavior; exiting the REPL destroys the client. It imports the workspace redis package, so a npm run build is needed after library changes.

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

Opens a Node REPL with a connected `client` in scope. Takes optional
--host/--port flags, or REDIS_URL. Exits if the first connect fails.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-31T15:33:53.423098Z 69ee000 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 69ee000e14

ℹ️ 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 scripts/repl.mjs
});

const url = host || port
? `redis://${host ?? 'localhost'}:${port ?? 6379}`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Bracket IPv6 host literals before forming the URL

When the new host flag is given a bare IPv6 literal such as --host ::1, this builds redis://::1:6379; RedisClient.parseURL() passes that to the WHATWG URL parser, which throws ERR_INVALID_URL, even though the client supports bracketed IPv6 Redis URLs. Detect and bracket IPv6 literals or pass host and port as socket options directly.

Useful? React with 👍 / 👎.

Comment thread scripts/repl.mjs
await client.connect();
client.off('error', onConnectError);
client.on('error', err => console.error('Redis client error:', reason(err)));
console.log(`Connected to ${url}. Use \`client\`, e.g. await client.ping()`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Redact credentials before echoing REDIS_URL

When REDIS_URL contains credentials such as redis://user:secret@host, this success message and the connection-error message interpolate the unmodified URL, exposing the password in terminal scrollback or captured output. Preserve the raw URL for createClient, but print a separately redacted display URL.

Useful? React with 👍 / 👎.

Comment thread scripts/repl.mjs Outdated
const server = repl.start('redis> ');
server.context.client = client;
server.on('exit', async () => {
await client.close();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Force-close pending commands when exiting the REPL

If a user leaves a blocking command such as client.blPop('k', 0) outstanding and then uses .exit or Ctrl-D, RedisClient.close() deliberately leaves the socket open until the command queue drains, so this await never reaches process.exit() and the REPL hangs. Exit cleanup should call the idempotent client.destroy() or otherwise force-cancel outstanding commands.

Useful? React with 👍 / 👎.

@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.

Stale Bugbot comment from a previous run.

Comment thread scripts/repl.mjs

const url = host || port
? `redis://${host ?? 'localhost'}:${port ?? 6379}`
: process.env.REDIS_URL ?? 'redis://localhost:6379';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

IPv6 hosts build invalid Redis URLs

Low Severity

--host is interpolated into a redis:// URL without bracketing IPv6 literals. createClient then runs that string through parseURL, which uses the WHATWG URL parser and throws Invalid URL instead of connecting.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 69ee000. Configure here.

@nkaradzhov
nkaradzhov merged commit 21edadc into redis:master Oct 31, 2026
14 checks passed

@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 high effort and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

Reviewed by Cursor Bugbot for commit c3e36dd. Configure here.

Comment thread scripts/repl.mjs

const url = host || port
? `redis://${host ?? 'localhost'}:${port ?? 6379}`
: process.env.REDIS_URL ?? 'redis://localhost:6379';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

IPv6 hosts produce invalid URLs

Low Severity

Flag-based URL construction interpolates --host directly into a redis:// URL. An IPv6 literal is a valid host value but is not bracketed, so createClient rejects the URL as invalid instead of connecting.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c3e36dd. Configure here.

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