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
The original app.redis.configuration = RedisConfiguation(...) syntax is still supported. It refers to the default Redis ID
The routes in routes.swift still look like
app.get("redis") { req in
req.redis.get("name").map { respValue in
return respValue.string ?? "name not found in Redis"
}
}
I added a RedisStorage class that works similarly to the Databases class in Fluent. It holds on to the Redis configurations and connection pools. Just like what's on master, there is a connection pool per EventLoop. But now, a RedisID is also used.
The Application.Redis and Request.Redis structs still exist, and they get their Redis connection pool from app.redisStorage, which is an instance of RedisStorage
Hello, excited for my second PR to this repo. <3 https://github.com/vapor/redis/pull/120
I discovered there wasn't support for multiple Redis instances, while upgrading my app from Vapor 3 to Vapor 4. This PR addresses this.
Usage
Assuming a
redis1
ID has been defined,The Redis configuration in
configure.swift
can look like this:and then the routes in
routes.swift
can look like this:Default Redis
The original
app.redis.configuration = RedisConfiguation(...)
syntax is still supported. It refers to thedefault
Redis IDThe routes in
routes.swift
still look likeSample App
A sample app is available at https://github.com/danramteke/study-redis-multiple
Arch
I added a
RedisStorage
class that works similarly to theDatabases
class inFluent
. It holds on to the Redis configurations and connection pools. Just like what's on master, there is a connection pool perEventLoop
. But now, aRedisID
is also used.The
Application.Redis
andRequest.Redis
structs still exist, and they get their Redis connection pool fromapp.redisStorage
, which is an instance ofRedisStorage