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

[548] Expose Redis operations via Redis trait #727

Merged

Conversation

m-kalai
Copy link
Contributor

@m-kalai m-kalai commented Jan 15, 2023

Resolves #548

  • getting rid of Redis environment dependency from all the API traits
  • mixing API traits in the Redis trait
  • getting rid of "accessors" from redis package object and fixing tests

@m-kalai m-kalai requested a review from a team as a code owner January 15, 2023 20:39
@mijicd
Copy link
Member

mijicd commented Jan 15, 2023

Am I missing something? This PR seems to contain only benchmarks.

@m-kalai
Copy link
Contributor Author

m-kalai commented Jan 15, 2023

@mijicd you scared me there a bit :) but i see all the changes, not just in the benchmark module

@mijicd
Copy link
Member

mijicd commented Jan 15, 2023

@mijicd you scared me there a bit :) but i see all the changes, not just in the benchmark module

I guess it's GitHub app issue. I'll check it out from laptop.

Copy link
Member

@mijicd mijicd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there :)

Comment on lines 33 to 38
private[redis] def run(in: In)(implicit executor: RedisExecutor, codec: BinaryCodec): ZIO[Any, RedisError, Out] =
executor
.execute(resp(in, codec))
.flatMap[Any, Throwable, Out](out => ZIO.attempt(output.unsafeDecode(out)(codec)))
.refineToOrDie[RedisError]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going with implicits, then:

  • let's keep the implicits alphabetically ordered
  • let's use an alias - IO[RedisError, Out] as return type (this is also applicable to the commands)
  • let's remove the other run

Otherwise, we can try passing codec and executor as constructor parameters here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't insist on implicits, it was just a way to get things done faster. I can make them "explicit" args or constructor params. Makes probably more sense as a constructor param as you suggested. Any particular order? Second argument list?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. It probably makes sense grouping it that, but I'm also fine if you place them in the same one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i made them constructor params in second argument list. Only complication was AskingCommand. I resolved it but not sure if it's the best way.

Comment on lines 5 to 9
trait CommandExecutor {
implicit def codec: BinaryCodec

implicit def executor: RedisExecutor
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename it somehow, as this is not really an executor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i was struggling with naming this one, considering those two methods were making Redis trait before this change. could it be something like RedisEnvironment or CommandExecutable. Any suggestion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Environment sounds good. They don't need to be implicit anymore either. The question remains: can we remove it completely?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think we can, unless we want to split command creation and execution. If we changed API traits to return RedisCommand and pushed invocation of run then we wouldn't need these dependencies on those traits. Or do you have some ideas?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not "expose" run. As mentioned below, 2nd parameter group is a bit too much as well, imo. On the other side, it makes sense if we restore implicits. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i mean't something like zio-dynamodb does, where you wrap command and arguments in some internal class which exposes method like

def execute: ZIO[RedisExecutor & BinaryCodec, RedisError, Out]

but that's different issue imho

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not bad. We might be able to combine it with returning somehow and make a nice "proxy", but let's leave it for the follow-up PR (if you're willing to dig into it :) ).

redis/src/main/scala/zio/redis/api/Lists.scala Outdated Show resolved Hide resolved
redis/src/test/scala/zio/redis/ClusterExecutorSpec.scala Outdated Show resolved Hide resolved
redis/src/test/scala/zio/redis/ClusterExecutorSpec.scala Outdated Show resolved Hide resolved
redis/src/test/scala/zio/redis/ConnectionSpec.scala Outdated Show resolved Hide resolved
redis/src/test/scala/zio/redis/ConnectionSpec.scala Outdated Show resolved Hide resolved
example/src/main/scala/example/contributorsCache.scala Outdated Show resolved Hide resolved
Copy link
Member

@mijicd mijicd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good to me. Two minor things and it's ready to go.


import zio.schema.codec.BinaryCodec

trait RedisEnvironment {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should make it package-private. After all, it is an implementation detail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, makes sense

Comment on lines 40 to 41
executor: RedisExecutor,
codec: BinaryCodec
Copy link
Member

@mijicd mijicd Jan 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this parameter group. Let's merge them in the first one (sorry 🙏 )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@mijicd
Copy link
Member

mijicd commented Jan 18, 2023

@m-kalai Please adjust the docs examples and it's ready to go.

@mijicd mijicd merged commit b0f8757 into zio:master Jan 18, 2023
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.

Introduce all Redis operations as type-safe methods of RedisExecutor trait
2 participants