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

Implement transactions API #156

Open
5 tasks
mijicd opened this issue Nov 20, 2020 · 6 comments · May be fixed by #733
Open
5 tasks

Implement transactions API #156

mijicd opened this issue Nov 20, 2020 · 6 comments · May be fixed by #733
Assignees
Labels
enhancement New feature or request zio-hackathon ZIO Hackathon 2020
Milestone

Comments

@mijicd
Copy link
Member

mijicd commented Nov 20, 2020

Extracted from this comment authored by @regis-leray.

Commands

  • DISCARD Discard all commands issued after MULTI
  • EXEC Execute all commands issued after MULTI
  • MULTI Mark the start of a transaction block
  • UNWATCH Forget about all watched keys
  • WATCH key [key ...] Watch the given keys to determine execution of the MULTI/EXEC block

Tips

  • Define the API in zio.redis.api.
  • Command-specific options should be defined in zio.redis.options.
  • Additional inputs and outputs can be defined in zio.redis.Input and zio.redis.Output, respectively.
  • Redis API evolves, therefore the commands listed above might be slightly changed. Double check the official docs before starting with implementation.
  • Use telnet to understand command protocol details.
  • Write inputs and outputs tests in zio.redis.InputSpec and zio.redis.OutputSpec, respectively.
  • Write integration tests by expanding the zio.redis.ApiSpec.
  • If you feel that the pull request size is growing out of control, feel free to split it but make sure to link this issue in each of the related PRs.
@mijicd mijicd added the enhancement New feature or request label Nov 20, 2020
@mijicd mijicd self-assigned this Nov 20, 2020
@mijicd mijicd added the zio-hackathon ZIO Hackathon 2020 label Nov 20, 2020
@mijicd
Copy link
Member Author

mijicd commented Feb 15, 2021

Redis transaction API consists of two groups of commands:

  • transactions (MULTI, EXEC, DISCARD)
  • optimistic locking (WATCH, UNWATCH)

The latter can be (relatively) easily implemented via the existing primitives, while the former requires more attention.

There are a few things to keep in mind:

  • "group" transaction commands
  • handle intermediate results
  • consider having a separate connection for blocking operations (this is a general thing to evaluate, and we can and should deal with it later)

With that in mind, here's the rough idea for a primitive that we could use to represent transactions:

sealed trait RedisTransaction[+Out] {
  def commit: ZIO[RedisExecutor, RedisError, Out]
  // zip operators
} 

object RedisTransaction {
  final case class Single[In, Out](command: RedisCommand[In, Out], in: In) extends RedisTransaction[Out]

  final case class Zip[A, B](left: RedisTransaction[A], right: RedisTransaction[B]) extends RedisTransaction[(A, B)]

  final case class ZipLeft[A, B](left: RedisTransaction[A], right: RedisTransaction[B]) extends RedisTransaction[A]

  final case class ZipRight[A, B](left: RedisTransaction[A], right: RedisTransaction[B]) extends RedisTransaction[B]
}

Note that this API forces user to be explicit about transaction boundaries. Internally, its "interpreter" would take care of all protocol details, e.g., calling commit would build a MULTI ... EXEC block at one point.

@anovakovic01 please take a look and let me know if you have any questions about it. Also, don't take this design as absolute truth - as said, it's just a rough idea.

@anovakovic01
Copy link
Member

@mijicd Thanks for the instructions. I think that I've understood the base idea. Draft PR will be sent as soon as I sketch something.

@barthorre
Copy link
Contributor

Anyone still working on this?

@mijicd
Copy link
Member Author

mijicd commented Aug 20, 2021

@anovakovic01 is, he can share the current state, and perhaps you could pair up.

@barthorre
Copy link
Contributor

Would be happy to assist where I can!

@anovakovic01
Copy link
Member

anovakovic01 commented Aug 29, 2021

@barthorre Sorry for waiting for an update this long. I'm still working on this one, should send a draft PR soon. It should introduce a single abstraction that will unify both transactions and the regular commands. When API is defined we'll need to update the executor to be able to process transactions. Help will be needed on that part.

@anovakovic01 anovakovic01 linked a pull request Jan 21, 2023 that will close this issue
@mijicd mijicd added this to the 0.3.0 milestone Apr 6, 2023
@mijicd mijicd modified the milestones: 0.3.0, 0.4.0 May 8, 2023
@mijicd mijicd modified the milestones: 0.4.0, 2.0.0 Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request zio-hackathon ZIO Hackathon 2020
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants