-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
ποΈ Implement streams commands #86
Conversation
Thanks @Terkwood! I'll review this PR in the coming days. |
tests/stream_test.ts
Outdated
|
||
let created = await client.xgroup_create(key, groupName, "$", true); | ||
assertEquals(created, "OK"); | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to use assertThrowsAsync
.
try { | |
await assertThrowsAsync(async () => { | |
await client.xgroup_create( | |
key, | |
groupName, | |
0, | |
true | |
); | |
}, Error, "-BUSYERR"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Altered, but for now the Error
type and exact error message are left undefined
. The message text contains a bunch of whitespace and a newline and is a little tricky to match. Haven't tracked down the Error class yet. I can come back to this if it's a sticking point...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AssertionError: Expected error to be instance of "Error", but got "Error".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, got the message part matching, at least!
@@ -286,6 +313,352 @@ export type RedisCommands = { | |||
srem(key: string, ...members: string[]): Promise<Integer>; | |||
sunion(...keys: string[]): Promise<BulkString[]>; | |||
sunionstore(destination: string, ...keys: string[]): Promise<Integer>; | |||
// Stream | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice documents!
|
||
export interface XMessage { | ||
xid: XId; | ||
field_values: Map<string, string>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, it's hard to decide whether Map
or Record
is better... π€
Looks good to me overall, but a few things need to be fixed. |
Thanks for the fast review! I will be able to respond on Thursday or Friday! The comments look straightforward. I don't have a strong opinion on Record vs Map for the return type from the xread and xreadgroup methods, but my ultimate rationale was that iterating thru Maps seems a bit less clunky: https://stackoverflow.com/questions/16174182/typescript-looping-through-a-dictionary But for accessing individual fields, Record (dictionary I'm happy to use either choice. |
Co-authored-by: uki00a <uki00a@gmail.com>
...but leaves the error type and message undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for submitting the changes!
There is just one thing to fix.
Please check it.
@Terkwood Let's merge this PR for now! |
Merged, thanks a lot @Terkwood! |
Woohoo! Thanks, my pleasure! |
Released in v0.11.0! |
So cool!! Thanks! |
Add stream commands
This change set resolves #36. π’
API design π¨
We gladly welcome feedback on the design. You can read the method defs in
command.ts
to see the most up-to-date version of the command inputs & outputsStrongly Typed Message IDs
We implemented strong types for stream entry IDs:
We made an effort to ensure flexibility in the command interfaces. For instance, in
xadd
, you may also pass simple numbers, or paired numbers[1000,10]
, or the special string"*"
.Methods which return
XId
s will always return the exact form, so that you can deconstruct them with minimal pain.See
XId
and the related types instreams.ts
for details.Return type for XREAD π
We offer an
interface
for the XREAD reply type which is hopefully less annoying to use than the Redis default array type. Please note that we return field_value pairs as aMap
.Allow input of record objects in XADD
In
xadd
, we chose to allow input of arbitraryRecord<string | number,string | number>
objects, as well asMap<string | number,string | number>
.β This allows greater flexibility for input, but may end up being a little confusing since the field_value outputs of
xread
andxreadgroup
are alwaysMap<string,string>
. βCommands to implement and test
docs and sanity checks
We made an effort to verify that argument names match the canonical names exposed by Redis. One exception is references to
ID
in Redis docs, which we callxid: XId
in order to match the parsed, typed flavor of data. Minimal command form should be included in each doc string.The JsDoc approach isn't very nice since only typescript export statements can trigger deno doc, but at least these docs are available to developers via their editors.
special reply types to model
Some hints for reply types https://github.com/Terkwood/redis-rs/blob/0d126f54d6970b931594bf677b09a368af70617d/src/streams.rs#L231
Additional requirements
isNumber
areas are saneAlways Remember
deno lint
(see chore: pass "deno lint"Β #98 for inspiration). The CI will enforce this anyway.deno fmt --check
. The CI will enforce this also.