From 7f9bef1fb99aa28639c7b4e34a2c0635facf5009 Mon Sep 17 00:00:00 2001 From: Ting-Wai To Date: Tue, 6 Nov 2018 23:23:31 -0800 Subject: [PATCH] [ioredis] Add types for Redis Streams commands --- types/ioredis/index.d.ts | 53 ++++++++++++++++++++++++++++++++++ types/ioredis/ioredis-tests.ts | 19 ++++++++++++ 2 files changed, 72 insertions(+) diff --git a/types/ioredis/index.d.ts b/types/ioredis/index.d.ts index 6f50ab0ee6..acd380e7db 100644 --- a/types/ioredis/index.d.ts +++ b/types/ioredis/index.d.ts @@ -9,6 +9,7 @@ // Francis Gulotta // Dmitry Motovilov // Oleg Repin +// Ting-Wai To // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -482,6 +483,32 @@ declare namespace IORedis { sscanStream(key: KeyType, options?: ScanStreamOption): NodeJS.EventEmitter; hscanStream(key: KeyType, options?: ScanStreamOption): NodeJS.EventEmitter; zscanStream(key: KeyType, options?: ScanStreamOption): NodeJS.EventEmitter; + + xack(key: KeyType, group: string, ...ids: string[]): any; + + xadd(key: KeyType, id: string, ...args: string[]): any; + + xclaim(key: KeyType, group: string, consumer: string, minIdleTime: number, ...args: any[]): any; + + xdel(key: KeyType, ...ids: string[]): any; + + xgroup(...args: any[]): any; + + xinfo(...args: any[]): any; + + xlen(key: KeyType): any; + + xpending(key: KeyType, group: string, ...args: any[]): any; + + xrange(key: KeyType, start: string, end: string, ...args: any[]): any; + + xread(...args: any[]): any; + + xreadgroup(groupOption: 'GROUP' | 'group', group: string, consumer: string, ...args: any[]): any; + + xrevrange(key: KeyType, end: string, start: string, ...args: any[]): any; + + xtrim(key: KeyType, maxLenOption: 'MAXLEN' | 'maxlen', ...args: any[]): any; } interface Pipeline { @@ -801,6 +828,32 @@ declare namespace IORedis { pfadd(key: KeyType, ...elements: string[]): Pipeline; pfcount(...keys: KeyType[]): Pipeline; + + xack(key: KeyType, group: string, ...ids: string[]): Pipeline; + + xadd(key: KeyType, id: string, ...args: string[]): Pipeline; + + xclaim(key: KeyType, group: string, consumer: string, minIdleTime: number, id: string, ...args: any[]): Pipeline; + + xdel(key: KeyType, ...ids: string[]): Pipeline; + + xgroup(...args: any[]): Pipeline; + + xinfo(...args: any[]): Pipeline; + + xlen(key: KeyType): Pipeline; + + xpending(key: KeyType, group: string, ...args: any[]): Pipeline; + + xrange(key: KeyType, start: string, end: string, ...args: any[]): Pipeline; + + xread(...args: any[]): Pipeline; + + xreadgroup(command: 'GROUP' | 'group', group: string, consumer: string, ...args: any[]): Pipeline; + + xrevrange(key: KeyType, end: string, start: string, ...args: any[]): Pipeline; + + xtrim(key: KeyType, strategy: 'MAXLEN' | 'maxlen', ...args: any[]): Pipeline; } interface NodeConfiguration { diff --git a/types/ioredis/ioredis-tests.ts b/types/ioredis/ioredis-tests.ts index 82b5ec4d12..df8e37aca8 100644 --- a/types/ioredis/ioredis-tests.ts +++ b/types/ioredis/ioredis-tests.ts @@ -173,3 +173,22 @@ new Redis.Cluster([{ host: 'localhost', port: 6379 }]); + +redis.xack('streamName', 'groupName', 'id'); +redis.xadd('streamName', '*', 'field', 'name'); +redis.xclaim('streamName', 'groupName', 'consumerName', 3600000, 'id'); +redis.xdel('streamName', 'id'); +redis.xgroup('CREATE', 'streamName', 'groupName', '$'); +redis.xgroup('SETUP', 'streamName', 'groupName', '$'); +redis.xgroup('DESTROY', 'streamName', 'groupName'); +redis.xgroup('DELCONSUMER', 'streamName', 'groupName', 'consumerName'); +redis.xinfo('CONSUMERS', 'streamName', 'groupName'); +redis.xinfo('GROUPS', 'streamName'); +redis.xinfo('STREAM', 'streamName'); +redis.xlen('streamName'); +redis.xpending('streamName', 'groupName', '-', '+', '10', 'consumerName'); +redis.xrange('streamName', '-', '+', 'COUNT', 1); +redis.xread('STREAMS', 'streamName', '0-0'); +redis.xreadgroup('GROUP', 'groupName', 'consumerName', 'STREAMS', 'streamName', '>'); +redis.xrevrange('streamName', '+', '-', 'COUNT', 1); +redis.xtrim('streamName', 'MAXLEN', '~', 1000);