You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Checked with the following commands: strLen, hLen, hStrLen, but likely other len-returning commands may suffer from the same issue.
Actual behavior
All the commands above have return values of type Option[Long].
However, neither of them under any condition returns None.
Consider an example (expand):
importcats.effect.std.Consoleimportcats.effect.*importdev.profunktor.redis4cats.*importdev.profunktor.redis4cats.effect.Log.Stdout.givenobjectXLenAppextendsIOApp.Simple:overridedefrun:IO[Unit] =Redis[IO]
.utf8(redisHost)
.use: (redis: RedisCommands[IO, String, String]) =>for// INIT: make sure the DB is empty.
_ <- redis.flushAll
//// STRLEN command example//// Call STRLEN for a nonexistent key.
strlen1 <- redis.strLen("string-key")
_ <-Console[IO].println(
s"""string result #1 (key does not exist): | len: $strlen1
|""".stripMargin
)
// Set the key to an empty string.
_ <- redis.set("string-key", "")
strlen2 <- redis.strLen("string-key")
_ <-Console[IO].println(
s"""string result #2 (key is set to an empty string): | len: $strlen2
|""".stripMargin
)
//// HLEN and HSTRLEN example//// Call HLEN and HSTRLEN for a nonexistent hash entity.
hlen1 <- redis.hLen("hash-key")
hstrlenA1 <- redis.hStrLen("hash-key", "hash-field-a")
_ <-Console[IO].println(
s"""hash result #1 (hash does not exist): | hlen: $hlen1
| hstrlenA: $hstrlenA1
|""".stripMargin
)
// Create a new hash entity "hash-key" by setting "hash-field-a" to an empty value.// Note: "hash-field-b" still does not exist.
_ <- redis.hSet("hash-key", "hash-field-a", "")
hlen2 <- redis.hLen("hash-key")
hstrlenA2 <- redis.hStrLen("hash-key", "hash-field-a")
hstrlenB2 <- redis.hStrLen("hash-key", "hash-field-b")
_ <-Console[IO].println(
s"""hash result #2 (hash contains the 'hash-field-a' field only set to an empty string): | hlen: $hlen2
| hstrlenA: $hstrlenA2
| hstrlenB: $hstrlenB2
|""".stripMargin
)
//yield ()
end for
The example above emits the following output (expand):
string result #1 (key does not exist):
len: Some(0)
string result #2 (key is set to an empty string):
len: Some(0)
hash result #1 (hash does not exist):
hlen: Some(0)
hstrlenA: Some(0)
hash result #2 (hash contains the 'hash-field-a' field only set to an empty string):
hlen: Some(1)
hstrlenA: Some(0)
hstrlenB: Some(0)
Notice that in all the cases return values from *Len commands are Some(...) and neverNone.
Expected behavior:
Either of two, actually:
The commands should return None if a key they are asked about does not exist (preferrable, but...).
If the former behavior is unfeasible, then their return value type is supposed to be just Long rather than Option[Long].
More details
According to both - the upstream library source code and Redis docs, p.2 might be the only feasible option though.
/** * Get the length of the value stored in a key. * * @param key the key. * @return Long integer-reply the length of the string at {@code key}, or {@code 0} when {@code key} does not exist. */RedisFuture<Long> strlen(Kkey);
Integer reply: the length of the string stored at key, or 0 when the key
Note, neither of them mentions anything about Nil or Null or anything that could support the None return value. Therefore, most likely Option does not make any sense out there.
The text was updated successfully, but these errors were encountered:
Checked with the following commands:
strLen
,hLen
,hStrLen
, but likely other len-returning commands may suffer from the same issue.Actual behavior
All the commands above have return values of type
Option[Long]
.However, neither of them under any condition returns
None
.Consider an example (expand):
The example above emits the following output (expand):
Notice that in all the cases return values from
*Len
commands areSome(...)
and neverNone
.Expected behavior:
Either of two, actually:
None
if a key they are asked about does not exist (preferrable, but...).Long
rather thanOption[Long]
.More details
According to both - the upstream library source code and Redis docs, p.2 might be the only feasible option though.
Here is an API definition for
strlen
in Lettuce:And here is API docs in Redis:
Note, neither of them mentions anything about Nil or Null or anything that could support the
None
return value. Therefore, most likelyOption
does not make any sense out there.The text was updated successfully, but these errors were encountered: