Skip to content

fix(client): cache subsequent clients - #2963

Merged
nkaradzhov merged 3 commits into
redis:masterfrom
nkaradzhov:slow-create-client
May 14, 2025
Merged

fix(client): cache subsequent clients#2963
nkaradzhov merged 3 commits into
redis:masterfrom
nkaradzhov:slow-create-client

Conversation

@nkaradzhov

@nkaradzhov nkaradzhov commented May 14, 2025

Copy link
Copy Markdown
Collaborator

we dont need to recreate a client if
its config hasnt changed

fixes #2954

Description

Describe your pull request here


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)?

we dont need to recreate a client if
its config hasnt changed

fixes redis#2954
@nkaradzhov

Copy link
Copy Markdown
Collaborator Author

using the following test script we can see reasonable numbers

import { createClient, createClientPool, createCluster } from './packages/client'


const n = 200
const start1 = performance.now();
for (let i = 0; i < n; i++) {
  createClient();
}
console.log(`createClient(${n})`, performance.now() - start1);

const start2 = performance.now();
for (let i = 0; i < n; i++) {
  createClientPool();
}
console.log(`createClientPool(${n})`, performance.now() - start2);

const start3 = performance.now();
for (let i = 0; i < n; i++) {
 createCluster()
}
console.log(`createCluster(${n})`, performance.now() - start3);

@bobymicroby bobymicroby left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@nkaradzhov
nkaradzhov merged commit 6f961bd into redis:master May 14, 2025
@nkaradzhov
nkaradzhov deleted the slow-create-client branch May 15, 2025 07:51
florian-schunk pushed a commit to florian-schunk/node-redis that referenced this pull request Jun 18, 2025
* fix(client): cache subsequent clients

we dont need to recreate a client if
its config hasnt changed

fixes redis#2954

* handle circular structures

* make cache generic
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.

createClient in v5 is much slower than in v4

2 participants