You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-09 00:22:08 +03:00
fix GET
This commit is contained in:
@@ -1,19 +1,19 @@
|
|||||||
import { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
import testUtils, { GLOBAL } from '../test-utils';
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
import { transformArguments } from './GET';
|
import GET from './GET';
|
||||||
|
|
||||||
describe('GET', () => {
|
describe('GET', () => {
|
||||||
describe('transformArguments', () => {
|
describe('transformArguments', () => {
|
||||||
it('without options', () => {
|
it('without options', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
transformArguments('key'),
|
GET.transformArguments('key'),
|
||||||
['TS.GET', 'key']
|
['TS.GET', 'key']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('with LATEST', () => {
|
it('with LATEST', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
transformArguments('key', {
|
GET.transformArguments('key', {
|
||||||
LATEST: true
|
LATEST: true
|
||||||
}),
|
}),
|
||||||
['TS.GET', 'key', 'LATEST']
|
['TS.GET', 'key', 'LATEST']
|
||||||
|
@@ -1,20 +1,30 @@
|
|||||||
import { RedisCommandArguments } from '@redis/client/dist/lib/commands';
|
import { RedisArgument, TuplesReply, NumberReply, DoubleReply, Resp2Reply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||||
import { pushLatestArgument, SampleRawReply, SampleReply, transformSampleReply } from '.';
|
import { pushLatestArgument } from '.';
|
||||||
|
|
||||||
export const FIRST_KEY_INDEX = 1;
|
export interface TsGetOptions {
|
||||||
|
|
||||||
export const IS_READ_ONLY = true;
|
|
||||||
|
|
||||||
interface GetOptions {
|
|
||||||
LATEST?: boolean;
|
LATEST?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function transformArguments(key: string, options?: GetOptions): RedisCommandArguments {
|
export type TsGetReply = TuplesReply<[]> | TuplesReply<[NumberReply, DoubleReply]>;
|
||||||
|
|
||||||
|
export default {
|
||||||
|
FIRST_KEY_INDEX: 1,
|
||||||
|
IS_READ_ONLY: true,
|
||||||
|
transformArguments(key: RedisArgument, options?: TsGetOptions) {
|
||||||
return pushLatestArgument(['TS.GET', key], options?.LATEST);
|
return pushLatestArgument(['TS.GET', key], options?.LATEST);
|
||||||
}
|
},
|
||||||
|
transformReply: {
|
||||||
export function transformReply(reply: [] | SampleRawReply): null | SampleReply {
|
2(reply: Resp2Reply<TsGetReply>) {
|
||||||
if (reply.length === 0) return null;
|
return reply.length === 0 ? null : {
|
||||||
|
timestamp: reply[0],
|
||||||
return transformSampleReply(reply);
|
value: Number(reply[1])
|
||||||
}
|
};
|
||||||
|
},
|
||||||
|
3(reply: TsGetReply) {
|
||||||
|
return reply.length === 0 ? null : {
|
||||||
|
timestamp: reply[0],
|
||||||
|
value: reply[1]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} as const satisfies Command;
|
||||||
|
Reference in New Issue
Block a user