-
Notifications
You must be signed in to change notification settings - Fork 13
Custom function and script responses #216
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
9e05b31
0a1d78c
fd17b80
bdb9314
66e672a
4b20b33
d697201
3a7c242
c47a685
cffbb55
c8a0abf
57b71f3
d7dd137
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 |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// | ||
// This source file is part of the valkey-swift project | ||
// Copyright (c) 2025 the valkey-swift project authors | ||
// | ||
// See LICENSE.txt for license information | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// This file is autogenerated by ValkeyCommandsBuilder | ||
|
||
import NIOCore | ||
|
||
extension FUNCTION { | ||
public typealias LOADResponse = String | ||
} | ||
|
||
extension FUNCTION.LIST { | ||
public typealias Response = [ResponseElement] | ||
public struct ResponseElement: RESPTokenDecodable, Sendable { | ||
public struct Function: RESPTokenDecodable, Sendable { | ||
public let name: String | ||
public let description: String? | ||
public let flags: [String] | ||
|
||
public init(fromRESP token: RESPToken) throws { | ||
let map = try [String: RESPToken](fromRESP: token) | ||
guard let name = map["name"] else { throw RESPDecodeError.missingToken(key: "name", token: token) } | ||
guard let description = map["description"] else { throw RESPDecodeError.missingToken(key: "description", token: token) } | ||
guard let flags = map["flags"] else { throw RESPDecodeError.missingToken(key: "flags", token: token) } | ||
self.name = try String(fromRESP: name) | ||
self.description = try String?(fromRESP: description) | ||
self.flags = try [String](fromRESP: flags) | ||
} | ||
} | ||
public let libraryName: String | ||
public let engine: String | ||
public let functions: [Function] | ||
public let libraryCode: String? | ||
|
||
public init(fromRESP token: RESPToken) throws { | ||
let map = try [String: RESPToken](fromRESP: token) | ||
guard let libraryName = map["library_name"] else { throw RESPDecodeError.missingToken(key: "library_name", token: token) } | ||
guard let engine = map["engine"] else { throw RESPDecodeError.missingToken(key: "engine", token: token) } | ||
guard let functions = map["functions"] else { throw RESPDecodeError.missingToken(key: "functions", token: token) } | ||
let libraryCode = map["library_code"] | ||
self.libraryName = try String(fromRESP: libraryName) | ||
self.engine = try String(fromRESP: engine) | ||
self.functions = try [Function](fromRESP: functions) | ||
self.libraryCode = try libraryCode.map { try String(fromRESP: $0) } | ||
} | ||
} | ||
} | ||
|
||
extension FUNCTION.LOAD { | ||
public typealias Response = FUNCTION.LOADResponse | ||
} | ||
|
||
extension FUNCTION.STATS { | ||
public struct Response: RESPTokenDecodable, Sendable { | ||
|
||
public struct Script: RESPTokenDecodable, Sendable { | ||
public let name: String | ||
public let command: [ByteBuffer] | ||
public let durationInMilliseconds: Double | ||
|
||
public init(fromRESP token: RESPToken) throws { | ||
let map = try [String: RESPToken](fromRESP: token) | ||
guard let name = map["name"] else { throw RESPDecodeError.missingToken(key: "name", token: token) } | ||
guard let command = map["command"] else { throw RESPDecodeError.missingToken(key: "command", token: token) } | ||
guard let duration = map["duration_ms"] else { throw RESPDecodeError.missingToken(key: "duration_ms", token: token) } | ||
self.name = try .init(fromRESP: name) | ||
self.command = try .init(fromRESP: command) | ||
self.durationInMilliseconds = try Double(fromRESP: duration) | ||
} | ||
} | ||
public struct Engine: RESPTokenDecodable, Sendable { | ||
public let libraryCount: Int | ||
public let functionCount: Int | ||
|
||
public init(fromRESP token: RESPToken) throws { | ||
let map = try [String: RESPToken](fromRESP: token) | ||
guard let libraryCount = map["libraries_count"] else { throw RESPDecodeError.missingToken(key: "libraries_count", token: token) } | ||
guard let functionCount = map["functions_count"] else { throw RESPDecodeError.missingToken(key: "functions_count", token: token) } | ||
self.libraryCount = try .init(fromRESP: libraryCount) | ||
self.functionCount = try .init(fromRESP: functionCount) | ||
} | ||
} | ||
public let runningScript: Script | ||
public let engines: [String: Engine] | ||
public init(fromRESP token: RESPToken) throws { | ||
let map = try [String: RESPToken](fromRESP: token) | ||
guard let runningScript = map["running_script"] else { throw RESPDecodeError.missingToken(key: "running_script", token: token) } | ||
guard let engines = map["engines"] else { throw RESPDecodeError.missingToken(key: "engines", token: token) } | ||
self.runningScript = try .init(fromRESP: runningScript) | ||
self.engines = try .init(fromRESP: engines) | ||
} | ||
} | ||
} | ||
|
||
extension SCRIPT { | ||
public typealias LOADResponse = String | ||
public typealias EXISTSResponse = [Int] | ||
public typealias SHOWResponse = String | ||
} | ||
|
||
extension SCRIPT.LOAD { | ||
public typealias Response = SCRIPT.LOADResponse | ||
} | ||
|
||
extension SCRIPT.EXISTS { | ||
public typealias Response = SCRIPT.EXISTSResponse | ||
} | ||
|
||
extension SCRIPT.SHOW { | ||
public typealias Response = SCRIPT.SHOWResponse | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,8 +111,6 @@ public enum FUNCTION { | |
/// Returns information about all libraries. | ||
@_documentation(visibility: internal) | ||
public struct LIST: ValkeyCommand { | ||
public typealias Response = RESPToken.Array | ||
|
||
@inlinable public static var name: String { "FUNCTION LIST" } | ||
|
||
public var libraryNamePattern: String? | ||
|
@@ -131,8 +129,6 @@ public enum FUNCTION { | |
/// Creates a library. | ||
@_documentation(visibility: internal) | ||
public struct LOAD<FunctionCode: RESPStringRenderable>: ValkeyCommand { | ||
public typealias Response = ByteBuffer | ||
|
||
@inlinable public static var name: String { "FUNCTION LOAD" } | ||
|
||
public var replace: Bool | ||
|
@@ -186,8 +182,6 @@ public enum FUNCTION { | |
/// Returns information about a function during execution. | ||
@_documentation(visibility: internal) | ||
public struct STATS: ValkeyCommand { | ||
public typealias Response = RESPToken.Map | ||
|
||
@inlinable public static var name: String { "FUNCTION STATS" } | ||
|
||
@inlinable public init() { | ||
|
@@ -239,8 +233,6 @@ public enum SCRIPT { | |
/// Determines whether server-side Lua scripts exist in the script cache. | ||
@_documentation(visibility: internal) | ||
public struct EXISTS<Sha1: RESPStringRenderable>: ValkeyCommand { | ||
public typealias Response = RESPToken.Array | ||
|
||
@inlinable public static var name: String { "SCRIPT EXISTS" } | ||
|
||
public var sha1s: [Sha1] | ||
|
@@ -316,8 +308,6 @@ public enum SCRIPT { | |
/// Loads a server-side Lua script to the script cache. | ||
@_documentation(visibility: internal) | ||
public struct LOAD<Script: RESPStringRenderable>: ValkeyCommand { | ||
public typealias Response = ByteBuffer | ||
|
||
@inlinable public static var name: String { "SCRIPT LOAD" } | ||
|
||
public var script: Script | ||
|
@@ -334,8 +324,6 @@ public enum SCRIPT { | |
/// Show server-side Lua script in the script cache. | ||
@_documentation(visibility: internal) | ||
public struct SHOW<Sha1: RESPStringRenderable>: ValkeyCommand { | ||
public typealias Response = ByteBuffer | ||
|
||
@inlinable public static var name: String { "SCRIPT SHOW" } | ||
|
||
public var sha1: Sha1 | ||
|
@@ -621,7 +609,7 @@ extension ValkeyClientProtocol { | |
/// - Complexity: O(N) where N is the number of functions | ||
@inlinable | ||
@discardableResult | ||
public func functionList(libraryNamePattern: String? = nil, withcode: Bool = false) async throws -> RESPToken.Array { | ||
public func functionList(libraryNamePattern: String? = nil, withcode: Bool = false) async throws -> FUNCTION.LIST.Response { | ||
try await execute(FUNCTION.LIST(libraryNamePattern: libraryNamePattern, withcode: withcode)) | ||
} | ||
|
||
|
@@ -633,7 +621,10 @@ extension ValkeyClientProtocol { | |
/// - Response: [String]: The library name that was loaded | ||
@inlinable | ||
@discardableResult | ||
public func functionLoad<FunctionCode: RESPStringRenderable>(replace: Bool = false, functionCode: FunctionCode) async throws -> ByteBuffer { | ||
public func functionLoad<FunctionCode: RESPStringRenderable>( | ||
replace: Bool = false, | ||
functionCode: FunctionCode | ||
) async throws -> FUNCTION.LOADResponse { | ||
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. To ensure consistency in readability, should we call it 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. The reason I do this is to avoid the generic parameter that comes with |
||
try await execute(FUNCTION.LOAD(replace: replace, functionCode: functionCode)) | ||
} | ||
|
||
|
@@ -657,7 +648,7 @@ extension ValkeyClientProtocol { | |
/// - Complexity: O(1) | ||
@inlinable | ||
@discardableResult | ||
public func functionStats() async throws -> RESPToken.Map { | ||
public func functionStats() async throws -> FUNCTION.STATS.Response { | ||
try await execute(FUNCTION.STATS()) | ||
} | ||
|
||
|
@@ -679,7 +670,7 @@ extension ValkeyClientProtocol { | |
/// - Response: [Array]: An array of integers that correspond to the specified SHA1 digest arguments. | ||
@inlinable | ||
@discardableResult | ||
public func scriptExists<Sha1: RESPStringRenderable>(sha1s: [Sha1]) async throws -> RESPToken.Array { | ||
public func scriptExists<Sha1: RESPStringRenderable>(sha1s: [Sha1]) async throws -> SCRIPT.EXISTSResponse { | ||
try await execute(SCRIPT.EXISTS(sha1s: sha1s)) | ||
} | ||
|
||
|
@@ -725,7 +716,7 @@ extension ValkeyClientProtocol { | |
/// - Response: [String]: The SHA1 digest of the script added into the script cache | ||
@inlinable | ||
@discardableResult | ||
public func scriptLoad<Script: RESPStringRenderable>(script: Script) async throws -> ByteBuffer { | ||
public func scriptLoad<Script: RESPStringRenderable>(script: Script) async throws -> SCRIPT.LOADResponse { | ||
try await execute(SCRIPT.LOAD(script: script)) | ||
} | ||
|
||
|
@@ -737,7 +728,7 @@ extension ValkeyClientProtocol { | |
/// - Response: [String]: Lua script if sha1 hash exists in script cache. | ||
@inlinable | ||
@discardableResult | ||
public func scriptShow<Sha1: RESPStringRenderable>(sha1: Sha1) async throws -> ByteBuffer { | ||
public func scriptShow<Sha1: RESPStringRenderable>(sha1: Sha1) async throws -> SCRIPT.SHOWResponse { | ||
try await execute(SCRIPT.SHOW(sha1: sha1)) | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.