-
Notifications
You must be signed in to change notification settings - Fork 64
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
Support GETEX and GETDEL #340
Changes from 1 commit
b302185
e964a67
ab4878d
86ad7d5
b0754ec
8b33a57
0bd581a
1e95a93
e167ec9
01fca43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -465,29 +465,33 @@ object Input { | |
Chunk.single(encodeString(data.stringify)) | ||
} | ||
|
||
case object GetExPersistInput extends Input[(String, Boolean)] { | ||
override private[redis] def encode(data: (String, Boolean)): Chunk[RespValue.BulkString] = | ||
if (data._2) Chunk(encodeString(data._1), encodeString("PERSIST")) else Chunk(encodeString(data._1)) | ||
} | ||
case object GetExInput extends Input[(String, Expire, Duration)] { | ||
override private[redis] def encode(data: (String, Expire, Duration)): Chunk[RespValue.BulkString] = | ||
case class GetExPersistInput[K: Schema]() extends Input[(K, Boolean)] { | ||
override private[redis] def encode(data: (K, Boolean))(implicit codec: Codec): Chunk[RespValue.BulkString] = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's remove |
||
if (data._2) Chunk(encodeBytes(data._1), encodeString("PERSIST")) else Chunk(encodeBytes(data._1)) | ||
} | ||
case class GetExInput[K: Schema]() extends Input[(K, Expire, Duration)] { | ||
override private[redis] def encode( | ||
data: (K, Expire, Duration) | ||
)(implicit codec: Codec): Chunk[RespValue.BulkString] = | ||
data match { | ||
case (key, Expire.SetExpireSeconds, duration) => | ||
Chunk(encodeString(key), encodeString("EX")) ++ DurationSecondsInput.encode(duration) | ||
Chunk(encodeBytes(key), encodeString("EX")) ++ DurationSecondsInput.encode(duration) | ||
case (key, Expire.SetExpireMilliseconds, duration) => | ||
Chunk(encodeString(key), encodeString("PX")) ++ DurationMillisecondsInput.encode(duration) | ||
case _ => Chunk(encodeString(data._1)) | ||
Chunk(encodeBytes(key), encodeString("PX")) ++ DurationMillisecondsInput.encode(duration) | ||
case _ => Chunk(encodeBytes(data._1)) | ||
} | ||
} | ||
|
||
case object GetExAtInput extends Input[(String, ExpiredAt, Instant)] { | ||
override private[redis] def encode(data: (String, ExpiredAt, Instant)): Chunk[RespValue.BulkString] = | ||
case class GetExAtInput[K: Schema]() extends Input[(K, ExpiredAt, Instant)] { | ||
override private[redis] def encode( | ||
data: (K, ExpiredAt, Instant) | ||
)(implicit codec: Codec): Chunk[RespValue.BulkString] = | ||
data match { | ||
case (key, ExpiredAt.SetExpireAtSeconds, instant) => | ||
Chunk(encodeString(key), encodeString("EXAT")) ++ TimeSecondsInput.encode(instant) | ||
Chunk(encodeBytes(key), encodeString("EXAT")) ++ TimeSecondsInput.encode(instant) | ||
case (key, ExpiredAt.SetExpireAtMilliseconds, instant) => | ||
Chunk(encodeString(key), encodeString("PXAT")) ++ TimeMillisecondsInput.encode(instant) | ||
case _ => Chunk(encodeString(data._1)) | ||
Chunk(encodeBytes(key), encodeString("PXAT")) ++ TimeMillisecondsInput.encode(instant) | ||
case _ => Chunk(encodeBytes(data._1)) | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1651,59 +1651,59 @@ trait StringsSpec extends BaseSpec { | |
key <- uuid | ||
value <- uuid | ||
_ <- pSetEx(key, 10.millis, value) | ||
exists <- getEx(key, true) | ||
exists <- getEx[String, String](key, true) | ||
_ <- ZIO.sleep(20.millis) | ||
res <- get(key) | ||
res <- get[String, String](key) | ||
} yield assert(res.isDefined)(equalTo(true)) && assert(exists)(equalTo(Some(value))) | ||
} @@ eventually, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a question why is this test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is because sleep is unreliable and subject to CPU and thread scheduling. 20ms is likely to cause failure. Here, it is similar to CAS. (guess) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah true, I forgot that we use the Live Clock in these tests. |
||
testM("not found value when set seconds ttl") { | ||
for { | ||
key <- uuid | ||
value <- uuid | ||
_ <- set(key, value) | ||
exists <- getEx(key, Expire.SetExpireSeconds, 1.second) | ||
exists <- getEx[String, String](key, Expire.SetExpireSeconds, 1.second) | ||
_ <- ZIO.sleep(1020.millis) | ||
res <- get(key) | ||
res <- get[String, String](key) | ||
} yield assert(res.isDefined)(equalTo(false)) && assert(exists)(equalTo(Some(value))) | ||
} @@ eventually, | ||
testM("not found value when set milliseconds ttl") { | ||
for { | ||
key <- uuid | ||
value <- uuid | ||
_ <- set(key, value) | ||
exists <- getEx(key, Expire.SetExpireMilliseconds, 10.millis) | ||
exists <- getEx[String, String](key, Expire.SetExpireMilliseconds, 10.millis) | ||
_ <- ZIO.sleep(20.millis) | ||
res <- get(key) | ||
res <- get[String, String](key) | ||
} yield assert(res.isDefined)(equalTo(false)) && assert(exists)(equalTo(Some(value))) | ||
} @@ eventually, | ||
testM("not found value when set seconds timestamp") { | ||
for { | ||
key <- uuid | ||
value <- uuid | ||
_ <- set(key, value) | ||
exists <- getExAt(key, ExpiredAt.SetExpireAtSeconds, Instant.now().plusMillis(10)) | ||
exists <- getEx[String, String](key, ExpiredAt.SetExpireAtSeconds, Instant.now().plusMillis(10)) | ||
_ <- ZIO.sleep(20.millis) | ||
res <- get(key) | ||
res <- get[String, String](key) | ||
} yield assert(res.isDefined)(equalTo(false)) && assert(exists)(equalTo(Some(value))) | ||
} @@ eventually, | ||
testM("not found value when set milliseconds timestamp") { | ||
for { | ||
key <- uuid | ||
value <- uuid | ||
_ <- set(key, value) | ||
exists <- getExAt(key, ExpiredAt.SetExpireAtMilliseconds, Instant.now().plusMillis(10)) | ||
exists <- getEx[String, String](key, ExpiredAt.SetExpireAtMilliseconds, Instant.now().plusMillis(10)) | ||
_ <- ZIO.sleep(20.millis) | ||
res <- get(key) | ||
res <- get[String, String](key) | ||
} yield assert(res.isDefined)(equalTo(false)) && assert(exists)(equalTo(Some(value))) | ||
} @@ eventually, | ||
testM("key not found") { | ||
for { | ||
key <- uuid | ||
value <- uuid | ||
_ <- set(key, value) | ||
res <- getExAt(value, ExpiredAt.SetExpireAtMilliseconds, Instant.now().plusMillis(10)) | ||
res2 <- getEx(value, Expire.SetExpireMilliseconds, 10.millis) | ||
res3 <- getEx(value, true) | ||
_ <- set[String, String](key, value) | ||
res <- getEx[String, String](value, ExpiredAt.SetExpireAtMilliseconds, Instant.now().plusMillis(10)) | ||
res2 <- getEx[String, String](value, Expire.SetExpireMilliseconds, 10.millis) | ||
res3 <- getEx[String, String](value, true) | ||
} yield assert(res)(equalTo(None)) && assert(res2)(equalTo(None)) && assert(res3)(equalTo(None)) | ||
} @@ eventually | ||
), | ||
|
@@ -1712,22 +1712,22 @@ trait StringsSpec extends BaseSpec { | |
for { | ||
key <- uuid | ||
_ <- sAdd(key, "a") | ||
res <- getDel(key).either | ||
res <- getDel[String, String](key).either | ||
} yield assert(res)(isLeft(isSubtype[WrongType](anything))) | ||
}, | ||
testM("key not exists") { | ||
for { | ||
key <- uuid | ||
res <- getDel(key) | ||
res <- getDel[String, String](key) | ||
} yield assert(res)(equalTo(None)) | ||
}, | ||
testM("get and remove key") { | ||
for { | ||
key <- uuid | ||
value <- uuid | ||
_ <- set(key, value) | ||
res <- getDel(key) | ||
notFound <- getDel(key) | ||
res <- getDel[String, String](key) | ||
notFound <- getDel[String, String](key) | ||
} yield assert(res)(equalTo(Some(value))) && assert(notFound)(equalTo(None)) | ||
} | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Case classes should be final.