vapor / redis

Vapor provider for RediStack
MIT License
458 stars 57 forks source link

Expose method on Redis objects to lease connections #191

Closed Mordil closed 2 years ago

Mordil commented 2 years ago

Adds a withBorrowedClient method on both Application.Redis and Request.Redis for being able to lease a RedisClient for a specified amount of time to execute commands serially with.

This allows for a custom execution of MULTI commands in the following way

request.redis.withBorrowedClient {
    return client
        .send(command: "MULTI")
        .flatMap { _ in client.send(command: "PING") }
        .flatMap { _ in client.send(command: "EXEC") }
}
// this is now an 'EventLoopFuture<RESPValue>' with the value being an array of RESPValue result of every queued command

This fixes #190

VaporBot commented 2 years ago

These changes are now available in 4.4.0