Skip to content

Releases: vapor/redis

Allow customizing encoding and decoding of RedisCache values

17 Feb 20:34
e955843
Compare
Choose a tag to compare
This patch was authored and released by @gwynne.

It is now possible to specify a custom Encoder and Decoder to use in place of JSONEncoder and JSONDecoder for storing and retrieving values cached in Redis via the Cache interface.

Add support for `async`/`await`

26 Oct 16:39
50d6cea
Compare
Choose a tag to compare
This patch was authored and released by @0xTim.

Add async APIs for Redis

Expose method on Redis objects to lease connections

30 Sep 06:45
e114520
Compare
Choose a tag to compare
This patch was authored and released by @Mordil.

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

Add support for Vapor `Cache` protocol expiration time

12 Apr 13:00
47bb678
Compare
Choose a tag to compare
This patch was authored by @madsodgaard and released by @0xTim.

Adds support for setting an expiration time when using Redis as the Vapor cache via app.caches.use(.redis). See v4.44.0 for more info.

This PR also fixes #187 by adding a function to set an expiration time when setting a key to JSON:

app.redis.setex("user", toJSON: User(name: "mads"), expirationInSeconds: 10)

Add cache protocol

21 Feb 20:13
8037b6f
Compare
Choose a tag to compare
This patch was authored and released by @tanner0101.

Add Redis implementation for Vapor's new cache protocol: vapor/vapor#2558

// Use redis as application cache
app.caches.use(.redis)

Use passed-in eventloop when acquiring RedisConnectionPool

04 Feb 20:55
f65588b
Compare
Choose a tag to compare
This patch was authored and released by @siemensikkema.

Use the passed-in eventloop when acquiring RedisConnectionPool to prevent triggering a precondition related to ending up in a wrong eventloop (fixes #180, replaces: #183).

Support for Multiple Redis instances

27 Jan 07:36
bdd8285
Compare
Choose a tag to compare
This patch was authored by @danramteke and released by @Mordil. #120

Usage

Assuming a redis1 ID has been defined,

extension RedisID {
    static var redis1: RedisID {
        RedisID("redis1")
    }
}

The Redis configuration in configure.swift can look like this:

    app.redis.configuration = try RedisConfiguration(url: Environment.get("REDIS_URL")!)
    app.redis(.redis1).configuration = try RedisConfiguration(url: Environment.get("REDIS_URL_1")!)
    app.redis(.redis2).configuration = try RedisConfiguration(url: Environment.get("REDIS_URL_2")!)

and then the routes in routes.swift can look like this:

    app.get("redis") { req in
        req.redis.get("name").map { respValue in
            return respValue.string ?? "name not found in default Redis"
        }
    }

    app.get("redis1") { req in
        req.redis(.redis1).get("name").map { respValue in
            return respValue.string ?? "name not found in Redis 1"
        }
    }

Default Redis

All previous syntax is still supported. If the redis property is used rather than the redis(_:) method, it will always refer to the default RedisID.

Redis 4.0.0

09 Dec 07:14
00fdd68
Compare
Choose a tag to compare

Change Sessions driver to be generic

09 Dec 07:11
00fdd68
Compare
Choose a tag to compare
Pre-release
This patch was co-authored by @Mordil and @gwynne and released by @Mordil.

This changes the RedisSessionsDriver to be generic over the RedisSessionsDelegate to drop the performance overhead of the delegate existential.

In general, no one should see a breaking change unless you were passing a RedisSessionsDelegate as an existential - as you will see the "RedisSessionsDelegate cannot be passed to a generic context" message

Change semantics of Redis sessions with key and ID generation

27 Nov 23:21
a03b581
Compare
Choose a tag to compare
This patch was authored and released by @Mordil.

This addresses some semantic issues with the original implementation of SessionDriver for Redis in #175.

Two important changes were made to RedisSessionsDelegate:

  1. makeNewID does not prefix the ID with vrs- anymore
  2. A new makeKey(for:) optional method has been added to the protocol to convert an ID to a RediStack.RedisKey to customize how the id is represented as a key.
    • The default implementation adds the vrs- prefix.

In addition, the protocol has seen two quality of life (breaking) changes to the required protocol methods:

  1. Their argument labels have been updated to read a bit nicer at call sites, and the RedisKey is now passed instead of a SessionID
    • redis(_:storeData:forID:) -> redis(_:store:with:)
    • redis(_:fetchDataForID:) -> redis(_:fetchDataFor:)
  2. They have been marked @inlinable in the protocol definition. To take advantage of potential inlining, make sure you also mark your conformances with @inlinable.