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

Fix processing cluster response. #421

Conversation

Yury-Fridlyand
Copy link

  • function stats
  • function list
  • commands which return ClusterValue
  • fix corresponding tests
  • make glideRecordToRecord great again traverse and update data struct recursivly

Note: return type for updated functions weren't changed.

@@ -943,6 +999,8 @@ export class GlideClusterClient extends BaseClient {
/**
* Returns information about the functions and libraries.
*
* The command will be routed to a random node, unless `route` is provided.

Choose a reason for hiding this comment

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

Add @remakrs and move it right after @see

Copy link
Author

Choose a reason for hiding this comment

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

Other commands have the same - I'll update all of them in bulk later

Copy link
Author

Choose a reason for hiding this comment

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

I added a task reminder to do that when we will work on docs.

}

/**
* Returns information about the function that's currently running and information about the
* available execution engines.
*
* The command will be routed to all primary nodes, unless `route` is provided.

Choose a reason for hiding this comment

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

Add @remarks and move this line after @see line.

Copy link

@yipin-chen yipin-chen left a comment

Choose a reason for hiding this comment

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

LGTM, just minor comments

@@ -348,20 +348,63 @@ function convertGlideRecordForZSet(

/**
* @internal
* Downcast `GlideRecord` to `Record`. Use if you are 146% aware that `data` keys are always strings.
* Recursevly downcast `GlideRecord` to `Record`. Use if `data` keys are always strings.

Choose a reason for hiding this comment

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

Suggested change
* Recursevly downcast `GlideRecord` to `Record`. Use if `data` keys are always strings.
* Recursively downcast `GlideRecord` to `Record`. Use if `data` keys are always strings.

Choose a reason for hiding this comment

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

I don't understand that second part?

Copy link
Author

Choose a reason for hiding this comment

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

That will crash if a key is a Buffer. I use it in tests and while converting data for streams (stream IDs are strings)

Choose a reason for hiding this comment

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

Oh - because it's not safe.

Only use if the key attribute in `data` will always be if string type.  

Maybe specifically indicate that it should only be used for stream data containing stream ids?

*/
export function glideRecordToRecord<T>(
data: GlideRecord<T>,
): Record<string, T> {
const res: Record<string, T> = {};

for (const pair of data) {
res[pair.key as string] = pair.value;
let newVal = pair.value;

Choose a reason for hiding this comment

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

consider:

        const value = pair.value;
        let newVal = 
            isGlideRecord(value) ? glideRecordToRecord(value as GlideRecord<unknown>) as T :
            isGlideRecordArray(value) ? (value as GlideRecord<unknown>[]).map(glideRecordToRecord) as T :
            value;

Choose a reason for hiding this comment

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

you could also use a

const res = data.map(...)

Copy link
Author

@Yury-Fridlyand Yury-Fridlyand Sep 5, 2024

Choose a reason for hiding this comment

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

Let me avoid that. linter makes nested ternary operators unreadable

{ key: "bar", value: "baz" },
{ key: "foo", value: "bar" },

Choose a reason for hiding this comment

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

why did this get reversed?

Copy link
Author

Choose a reason for hiding this comment

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

A flaky test there, sometimes it receives elements reordered. Will fix it later.

Choose a reason for hiding this comment

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

ok...

@Yury-Fridlyand Yury-Fridlyand merged commit 6d832a4 into node/integ-valkey-293-return-record-with-glidestring Sep 5, 2024
6 of 8 checks passed
@Yury-Fridlyand Yury-Fridlyand deleted the node/return-record-with-glidestring-part-2 branch September 5, 2024 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants