Skip to content
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

Redis configuration provider #215

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

apemaia99
Copy link

@apemaia99 apemaia99 commented May 26, 2024

Redis

  • This PR aims to solve the impossibility to use the package without dependencies in unit test environments.
  • RedisFactory is a protocol that defines how to produce RedisClients.
  • RedisConfigurationFactory is an abstract factory that produce RedisConfigurations, and provides several methods that replaces all RedisConfiguration constructors. This breaks current APIs
  • An instance of redis now can be configured as following:
    • try app.redis(.one).use(.standalone(hostname: "an-hostname", port: 6379, pool: .init(connectionRetryTimeout: .milliseconds(100)))) like we already do in Fluent.
  • RedisConfiguration conforms to RedisFactory and actually creates RedisClients where previously were done in RedisStorage.LifeCycle.
  • RedisStorage now stores RedisClient instead of RedisConnectionPool.
    • the only way to use func withBorrowedConnection is by down casting RedisClient to RedisConnectionPool with as? operator or an error will be trowed.
  • The package expose also another product XCTRedis similarly to XCTFluent
  • Some file/folder & code refactor.

XCTRedis

This product allows to stub responses of redis, also for PubSub in order to test applications without conditions in production code to exclude redis. Writing code for test is not the way.

  • ArrayTestRedisClient is a stub class for storing & manipulating responses.
    • User shall interact with this class like XCTFluent ArrayTestDatabase
  • DummyRedis is the actual RedisClient stored in RedisStorage during tests.
    • These instances are as many as the eventLoops of our application.
    • Each instance peek responses from same ArrayTestRedisClient
  • RedisStub is the actual factory to be used in tests.
    • app.redis(.one).use(.stub(client: client))

Redis configuration provider + XCTRedis

R moved RedisStorage bootstrap implementation to RedisProvider concrete implementation
R added file for redisConnectionPool utils extension
… used from RedisStorage on bootstrap

F added computed property in order to retrieve factory based on current configuration
…eate new clients delegating creation to the factory

R redisStorage now holds a dictionary of RedisClient interfaces instead of RedisConnectionPool (that unfortunately is not an interface) .
    This allows mocking Vapor.Redis entirely.
    This has the cons that in some cases we should downcast in order to perform specific operations: pool.close on shutdown, withBorrowedConnection feature.
F added Application.Redis.Errors enum to hold errors
F added factory as additional optional parameter with default fallback on internal standard RedisProvider
F RedisConfiguration conforms to redisFactory
F added use method like other vapor services & removed redis.configuration
F added redisConfigurationFactory that allows to store a configuration for later client creation
F redisConfigurationFactory has a list of static method replacing old RedisConfiguration initializers, this is essential in order allow discovery on  redis.use(...)
R changed type on redisStorage
R separated content of redisStorage in multiple files and placed under its folder
F XCTRedis new product is exposed by redis package
F ArrayTestRedisClient is as base response provider
F DummyRedis as Fake Client to use in unit testing
F RedisStub is a common util in order to provide a fake client ready to use in test manipulating ArrayTestRedisClient
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant