未验证 提交 b40713b3 编写于 作者: J Justin Heyes-Jones 提交者: GitHub

Update Scan api to return Long instead of String (#211)

上级 35252724
......@@ -110,16 +110,16 @@ object Output {
}
case object ScanOutput extends Output[(String, Chunk[String])] {
case object ScanOutput extends Output[(Long, Chunk[String])] {
override protected def tryDecode(respValue: RespValue): (String, Chunk[String]) =
override protected def tryDecode(respValue: RespValue): (Long, Chunk[String]) =
respValue match {
case RespValue.ArrayValues(cursor @ RespValue.BulkString(_), RespValue.Array(items)) =>
val strings = items.map {
case s @ RespValue.BulkString(_) => s.asString
case other => s"$other is not a bulk string"
}
(cursor.asString, strings)
(cursor.asString.toLong, strings)
case other =>
throw ProtocolError(s"$other isn't scan output")
}
......
......@@ -36,7 +36,7 @@ trait Hashes {
b: Option[Regex] = None,
c: Option[Long] = None,
d: Option[String] = None
): ZIO[RedisExecutor, RedisError, (String, Chunk[String])] = HScan.run((a, b, c, d))
): ZIO[RedisExecutor, RedisError, (Long, Chunk[String])] = HScan.run((a, b, c, d))
final def hSet(a: String, b: (String, String), bs: (String, String)*): ZIO[RedisExecutor, RedisError, Long] =
HSet.run((a, (b, bs.toList)))
......
......@@ -68,7 +68,7 @@ trait Keys {
b: Option[Regex] = None,
c: Option[Long] = None,
d: Option[String] = None
): ZIO[RedisExecutor, RedisError, (String, Chunk[String])] = Scan.run((a, b, c, d))
): ZIO[RedisExecutor, RedisError, (Long, Chunk[String])] = Scan.run((a, b, c, d))
final def touch(a: String, as: String*): ZIO[RedisExecutor, RedisError, Long] = Touch.run((a, as.toList))
......
......@@ -145,14 +145,14 @@ trait Sets {
* @param cursor Cursor to use for this iteration of scan
* @param regex Glob-style pattern that filters which elements are returned
* @param count Count of elements. Roughly this number will be returned by Redis if possible
* @return Returns the items for this iteration or nothing when you reach the end
* @return Returns the next cursor, and items for this iteration or nothing when you reach the end, as a tuple
*/
final def sScan(
key: String,
cursor: Long,
regex: Option[Regex] = None,
count: Option[Count] = None
): ZIO[RedisExecutor, RedisError, (String, Chunk[String])] = SScan.run((key, cursor, regex, count))
): ZIO[RedisExecutor, RedisError, (Long, Chunk[String])] = SScan.run((key, cursor, regex, count))
/**
* Add multiple sets
......
......@@ -325,7 +325,7 @@ trait SortedSets {
cursor: Long,
regex: Option[Regex] = None,
count: Option[Count] = None
): ZIO[RedisExecutor, RedisError, (String, Chunk[String])] = ZScan.run((key, cursor, regex, count))
): ZIO[RedisExecutor, RedisError, (Long, Chunk[String])] = ZScan.run((key, cursor, regex, count))
/**
* Get the score associated with the given member in a sorted set.
......
......@@ -84,7 +84,7 @@ trait KeysSpec extends BaseSpec {
_ <- set(key, value)
scan <- scan(0L)
(next, elements) = scan
} yield assert(next)(isNonEmptyString) && assert(elements)(isNonEmpty)
} yield assert(next)(isGreaterThan(0L)) && assert(elements)(isNonEmpty)
},
testM("fetch random key") {
for {
......
......@@ -138,7 +138,7 @@ object OutputSpec extends BaseSpec {
val input = respArrayVals(respBulkString("5"), respArray("foo", "bar"))
for {
res <- Task(ScanOutput.unsafeDecode(input))
} yield assert(res)(equalTo("5" -> Chunk("foo", "bar")))
} yield assert(res)(equalTo(5L -> Chunk("foo", "bar")))
}
),
suite("string")(
......
......@@ -738,7 +738,7 @@ trait SetsSpec extends BaseSpec {
_ <- sAdd(key, "a", "b", "c")
scan <- sScan(key, 0L)
(cursor, members) = scan
} yield assert(cursor)(isNonEmptyString) &&
} yield assert(cursor)(isZero) &&
assert(members)(isNonEmpty)
},
testM("empty set") {
......@@ -746,7 +746,7 @@ trait SetsSpec extends BaseSpec {
key <- uuid
scan <- sScan(key, 0L)
(cursor, members) = scan
} yield assert(cursor)(equalTo("0")) &&
} yield assert(cursor)(isZero) &&
assert(members)(isEmpty)
},
testM("with match over non-empty set") {
......@@ -755,16 +755,28 @@ trait SetsSpec extends BaseSpec {
_ <- sAdd(key, "one", "two", "three")
scan <- sScan(key, 0L, Some("t[a-z]*".r))
(cursor, members) = scan
} yield assert(cursor)(isNonEmptyString) &&
} yield assert(cursor)(isZero) &&
assert(members)(isNonEmpty)
},
testM("with count over non-empty set with two iterations") {
for {
key <- uuid
_ <- sAdd(key, "a", "b", "c", "d", "e")
scan <- sScan(key, 0L, count = Some(Count(3L)))
(cursor, members) = scan
scan2 <- sScan(key, cursor, count = Some(Count(3L)))
(cursor2, members2) = scan2
} yield assert(cursor)(isGreaterThan(0L)) &&
assert(members)(isNonEmpty) &&
assert(cursor2)(isZero)
},
testM("with count over non-empty set") {
for {
key <- uuid
_ <- sAdd(key, "a", "b", "c", "d", "e")
scan <- sScan(key, 0L, count = Some(Count(3L)))
(cursor, members) = scan
} yield assert(cursor)(isNonEmptyString) &&
} yield assert(cursor)(isGreaterThan(0L)) &&
assert(members)(isNonEmpty)
},
testM("error when not set") {
......
......@@ -794,14 +794,14 @@ trait SortedSetsSpec extends BaseSpec {
_ <- zAdd(key)(MemberScore(1d, "atest"), MemberScore(2d, "btest"), MemberScore(3d, "ctest"))
scan <- zScan(key, 0L)
(cursor, members) = scan
} yield assert(cursor)(isNonEmptyString) && assert(members)(isNonEmpty)
} yield assert(cursor)(isZero) && assert(members)(isNonEmpty)
},
testM("empty set") {
for {
key <- uuid
scan <- zScan(key, 0L)
(cursor, members) = scan
} yield assert(cursor)(equalTo("0")) && assert(members)(isEmpty)
} yield assert(cursor)(isZero) && assert(members)(isEmpty)
},
testM("with match over non-empty set") {
for {
......@@ -809,7 +809,7 @@ trait SortedSetsSpec extends BaseSpec {
_ <- zAdd(key)(MemberScore(1d, "one"), MemberScore(2d, "two"), MemberScore(3d, "three"))
scan <- zScan(key, 0L, Some("t[a-z]*".r))
(cursor, members) = scan
} yield assert(cursor)(isNonEmptyString) && assert(members)(isNonEmpty)
} yield assert(cursor)(isZero) && assert(members)(isNonEmpty)
},
testM("with count over non-empty set") {
for {
......@@ -823,7 +823,7 @@ trait SortedSetsSpec extends BaseSpec {
)
scan <- zScan(key, 0L, None, Some(Count(3L)))
(cursor, members) = scan
} yield assert(cursor)(isNonEmptyString) && assert(members)(isNonEmpty)
} yield assert(cursor)(isZero) && assert(members)(isNonEmpty)
},
testM("match with count over non-empty set") {
for {
......@@ -837,7 +837,7 @@ trait SortedSetsSpec extends BaseSpec {
)
scan <- zScan(key, 0L, Some("t[a-z]*".r), Some(Count(3L)))
(cursor, members) = scan
} yield assert(cursor)(isNonEmptyString) && assert(members)(isNonEmpty)
} yield assert(cursor)(isZero) && assert(members)(isNonEmpty)
},
testM("error when not set") {
for {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册