Skip to content
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

Broadcast commands in the Cluster client #2431

Open
24 tasks
uglide opened this issue Feb 27, 2023 · 5 comments
Open
24 tasks

Broadcast commands in the Cluster client #2431

uglide opened this issue Feb 27, 2023 · 5 comments

Comments

@uglide
Copy link
Contributor

uglide commented Feb 27, 2023

Motivation

The Cluster client should provide overrides for specific Redis Core and module commands to make them easy to use with OS Cluster API.

import { createCluster } from 'redis';

const cluster = createCluster({
    rootNodes: [
        // ...
    ]
});

cluster.on('error', (err) => console.log('Redis Cluster Error', err));

await cluster.connect();

await cluster.json.set('doc1', '$', {
    name: 'Alice',
    age: 32,
    coins: 100,
    email: '[email protected]'
})

await cluster.json.set('doc2', '$', {
    name: 'Bob',
    age: 23,
    coins: 15,
    email: '[email protected]'
})

// Both mget commands should return all documents from cluster
console.log(await cluster.json.mGet(['doc1', 'doc2'], '$..name'))
console.log(await cluster.json.mGet(['doc2', 'doc1'], '$..name'))

Basic Code Example

No response

@uglide uglide added the feature label Feb 27, 2023
@leibale
Copy link
Collaborator

leibale commented Feb 27, 2023

@uglide
Copy link
Contributor Author

uglide commented Feb 27, 2023

@leibale JSON.MGET is a different beast compared to MGET. We don't know the key of documents where the path return us any results. That's why it's helpful to have a high-level wrapper that merges results from all primaries.

@leibale
Copy link
Collaborator

leibale commented Feb 27, 2023

Then we need a wrapper like in Graph... executing client.ft.search (or any other command) should be as close as possible to the redis-cli version (with some "type mapping"). "Automagically" running multiple commands when the user executed only one feels wrong.

@chayim @itamarhaber @guyroyse @simonprickett WDUT?

@itamarhaber
Copy link
Member

Idk about the implementation, but I'm just saying that where a command should run is a part of the command's docs and modules should use the same API: https://redis.io/docs/reference/command-tips/#request_policy

@leibale
Copy link
Collaborator

leibale commented Feb 27, 2023

so something like

const REQUEST_POLICIES = {
  ...
};

const RESPONSE_POLICES = {
  ...
};

// will default to the policy defined in redis
cluster.ping();

// can be overridden
cluster.withPolicy({
  request: ...,
  response: ...
}).ping();

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

No branches or pull requests

3 participants