-
Notifications
You must be signed in to change notification settings - Fork 18
Custom responses list commands #273
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,3 +63,31 @@ extension BRPOP { | |
| /// * [Array]: The key from which the element was popped and the value of the popped element | ||
| public typealias Response = ListEntry? | ||
| } | ||
|
|
||
| /// Custom response type for LPOP and RPOP commands | ||
| /// Handles the different return types based on whether count parameter is provided | ||
| @_documentation(visibility: internal) | ||
| public struct ListPopResponse: RESPTokenDecodable, Sendable, Hashable { | ||
|
|
||
| private let token: RESPToken | ||
|
|
||
| public init(_ token: RESPToken) throws { | ||
| self.token = token | ||
| } | ||
|
|
||
| /// Gets the single element when count was not provided | ||
| /// - Returns: ByteBuffer if a single element was returned, nil otherwise | ||
| public func element() throws -> ByteBuffer? { | ||
| // Handle .null as it is expected when the key doesn't exist | ||
| if token.value == .null { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checking for null here shouldn't be needed, that has already been done because the LPOP/RPOP response is optional. Which means the function can return a non-optional value. It should be |
||
| return nil | ||
| } | ||
| return try ByteBuffer(token) | ||
| } | ||
|
|
||
| /// Gets the multiple elements when count was provided | ||
| /// - Returns: Array of ByteBuffer if multiple elements were returned, nil otherwise | ||
| public func elements() throws -> [ByteBuffer]? { | ||
| try [ByteBuffer]?(token) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't need to be optional |
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.