RediStack icon indicating copy to clipboard operation
RediStack copied to clipboard

fix: bugs in zpopmin/zpopmax;

Open iwecon opened this issue 2 months ago • 1 comments

Details: #135

Because zadd defaults to (RESPValue, Double), scoreIsFirst is set to false by default.

zadd function:

@inlinable
public func zadd<Value: RESPValueConvertible>(
    _ elements: [(element: Value, score: Double)],
    to key: RedisKey,
    inserting insertBehavior: RedisZaddInsertBehavior = .allElements,
    returning returnBehavior: RedisZaddReturnBehavior = .insertedElementsCount
) -> EventLoopFuture<Int> {
    var args: [RESPValue] = [.init(from: key)]

    args.append(convertingContentsOf: [insertBehavior.string, returnBehavior.string].compactMap({ $0 }))
    args.add(contentsOf: elements, overestimatedCountBeingAdded: elements.count * 2) { (array, next) in
        array.append(.init(bulk: next.score.description))
        array.append(next.element.convertedToRESPValue())
    }

    return self.send(command: "ZADD", with: args)
        .tryConverting()
}

iwecon avatar Dec 08 '25 19:12 iwecon