Skip to content

fix(client): cache subsequent clients #2963

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 3 commits into from
May 14, 2025

Conversation

nkaradzhov
Copy link
Collaborator

@nkaradzhov nkaradzhov commented May 14, 2025

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

Copy link
Member

@bobymicroby bobymicroby left a comment

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
11 checks passed
@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
# for free to join this conversation on GitHub. Already have an account? # 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