Skip to content

Commit 42afc15

Browse files
replace SortedSetDataType with ElementAndScore
Signed-off-by: James Xin <[email protected]>
1 parent 967f378 commit 42afc15

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

node/npm/glide/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ function initialize() {
192192
ReturnTypeJson,
193193
UniversalReturnTypeJson,
194194
Score,
195+
ElementAndScore,
195196
} = nativeBinding;
196197

197198
module.exports = {
@@ -342,6 +343,7 @@ function initialize() {
342343
ReturnTypeJson,
343344
UniversalReturnTypeJson,
344345
Score,
346+
ElementAndScore,
345347
};
346348

347349
globalObject = Object.assign(global, nativeBinding);

node/src/BaseClient.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,17 @@ export type StreamEntryDataType = Record<string, [GlideString, GlideString][]>;
352352
*/
353353
export type Score = number | "+inf" | "-inf";
354354

355+
/**
356+
* Data type which represents sorted sets data for input parameter of ZADD command,
357+
* including elements and their respective scores.
358+
*/
359+
export type ElementAndScore = {
360+
/** The sorted set element name. */
361+
element: GlideString;
362+
/** The element score. */
363+
score: Score;
364+
}[];
365+
355366
/**
356367
* @internal
357368
* Convert `GlideRecord<number>` recevied after resolving the value pointer into `SortedSetDataType`.
@@ -4024,10 +4035,7 @@ export class BaseClient {
40244035
*/
40254036
public async zadd(
40264037
key: GlideString,
4027-
membersAndScores:
4028-
| SortedSetDataType
4029-
| Record<string, number>
4030-
| Record<string, Score>,
4038+
membersAndScores: ElementAndScore | Record<string, Score>,
40314039
options?: ZAddOptions,
40324040
): Promise<number> {
40334041
return this.createWritePromise(

node/src/Commands.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
Score,
1515
ObjectType,
1616
SortedSetDataType,
17+
ElementAndScore,
1718
} from "./BaseClient";
1819
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
1920
import { GlideClient } from "./GlideClient";
@@ -1443,10 +1444,7 @@ export function convertElementsAndScores(
14431444
*/
14441445
export function createZAdd(
14451446
key: GlideString,
1446-
membersAndScores:
1447-
| SortedSetDataType
1448-
| Record<string, number>
1449-
| Record<string, Score>,
1447+
membersAndScores: ElementAndScore | Record<string, Score>,
14501448
options?: ZAddOptions,
14511449
incr = false,
14521450
): command_request.Command {

node/tests/SharedTests.ts

+7
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import {
5454
convertGlideRecordToRecord,
5555
parseInfoResponse,
5656
Score,
57+
ElementAndScore,
5758
} from "..";
5859
import { ValkeyCluster } from "../../utils/TestUtils";
5960
import { Client, GetAndSetRandomValue, getFirstResult } from "./TestUtilities";
@@ -4160,6 +4161,12 @@ export function runBaseTests(config: {
41604161
negInfMember: "-inf",
41614162
};
41624163
expect(await client.zadd(key, infMembersScores)).toEqual(2);
4164+
4165+
const infElementAndScore: ElementAndScore = [
4166+
{ element: "infMemberEAS", score: "+inf" },
4167+
{ element: "negInfMemberEAS", score: "-inf" },
4168+
];
4169+
expect(await client.zadd(key, infElementAndScore)).toEqual(2);
41634170
}, protocol);
41644171
},
41654172
config.timeout,

0 commit comments

Comments
 (0)