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

DSL-style builder for Kedis #2

Open
solonovamax opened this issue Jan 9, 2025 · 1 comment
Open

DSL-style builder for Kedis #2

solonovamax opened this issue Jan 9, 2025 · 1 comment

Comments

@solonovamax
Copy link

Currently, when creating a KedisClient, it is required that you use a clunky KedisConfiguration class, which leads to the following:

KedisClient(
configuration = KedisConfiguration(
endpoint = KedisConfiguration.Endpoint.HostPort(
host = "127.0.0.1",
port = 6379,
),
authentication = KedisConfiguration.Authentication.NoAutoAuth,
connectionTimeoutMillis = 250,
keepAlive = true,
),
)

If instead a DSL-style builder were offered, that would be amazing.

For example, the above code could be rewritten as something along the lines of

KedisClient.builder {
    hostAndPort("127.0.0.1", 6379)
    noAuthentication()
    connectionTimeoutMillis = 250
    keepAlive = true
}
@domgew
Copy link
Owner

domgew commented Jan 29, 2025

The "clunky" configuration class has the benefit of using a full parameter set and sealed polymorphism which are a way of compile-time verification, so that you cannot forget or misconfigure anything (assuming the data is correct) as opposed to runtime errors with a builder. Additionally, it is easier to inject the configuration instance when using dependency injection.

I however am not opposed to giving the user a choice and I see the aesthetic appeal of the DSL approach - but rather as an addition than a replacement.

Feel free to open a pull request with the desired interface and implementation. It could for example, be an additional overload of the invoke operator function on the KedisClient's companion object or a builder extension function as you described - both constructing the configuration class and calling the original operator I would suggest.

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

No branches or pull requests

2 participants