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 keys API in test executor #194 #480

Merged
merged 4 commits into from
Nov 9, 2021

Conversation

anatolysergeev
Copy link
Collaborator

@anatolysergeev anatolysergeev commented Nov 9, 2021

This PR is continuation of PR #371
Some changes in the concept how we save expiration time, before there was an idea to have two separated stores for keys and expiration time, I do not very like that idea because it doesn't have good scale options. I decided to unite them in one key store where we save all information about our key: type, expiration time, etc.

@anatolysergeev anatolysergeev requested a review from a team as a code owner November 9, 2021 13:52
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.

A few remarks, other than that it looks great!

@@ -650,6 +660,193 @@ private[redis] final class TestExecutor private (
)
}

case api.Keys.Exists | api.Keys.Touch =>
val allkeys = input.map(_.asString)
Copy link
Member

Choose a reason for hiding this comment

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

This can be part of fold, e.g.:

STM.foldLefft(input)(0L) { case (acc, key) => 
  // key.asString
}

This pattern is repeated a few times so please adjust all occurrences.

val options = input.drop(1).map(_.asString)

val countIndex = options.indexOf("COUNT")
val count = Option.when(countIndex >= 0)(options(countIndex + 1).toInt)
Copy link
Member

Choose a reason for hiding this comment

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

I think that Option.when won't work in 2.12.


case api.Keys.Expire =>
val key = input(0).asString
val unixtime = now.plusSeconds(input(1).asLong)
Copy link
Member

Choose a reason for hiding this comment

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

This should be suspended, but since we don't have a proper solution for clock in stm, it can stay.

Comment on lines 1567 to 1568
_ <- if (newHash.isEmpty) delete(key)
else putHash(key, newHash)
Copy link
Member

Choose a reason for hiding this comment

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

You should be able to use ZIO.cond for all similar occurrences.

Comment on lines 3206 to 3208
case class KeyInfo(`type`: KeyType, expireAt: Option[Instant]) {
lazy val redisType: RedisType = KeyType.toRedisType(`type`)
}
Copy link
Member

Choose a reason for hiding this comment

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

Please make it final.

@mijicd mijicd merged commit 1329d00 into zio:master Nov 9, 2021
@anatolysergeev anatolysergeev deleted the keys-api-test-exec branch January 3, 2022 09:28
hcwilhelm pushed a commit to hcwilhelm/zio-redis that referenced this pull request Feb 18, 2025
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.

2 participants