Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
yisraelU committed Aug 30, 2024
1 parent 8e31cad commit dcad2eb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
package dev.profunktor.redis4cats

import java.time.Instant
import io.lettuce.core.{ GeoArgs, ScanArgs => JScanArgs, ScriptOutputType => JScriptOutputType }

import io.lettuce.core.{ GeoArgs, ScriptOutputType => JScriptOutputType, ScanArgs => JScanArgs }

import scala.concurrent.duration.FiniteDuration

Expand Down Expand Up @@ -108,7 +109,7 @@ object effects {
def idleTime(idleTime: Long): RestoreArgs = copy(idleTime = Some(idleTime))
}

sealed abstract class ScanArgs(`match`: Option[String], count: Option[Long]) {
case class ScanArgs(`match`: Option[String], count: Option[Long]) {
def underlying: JScanArgs = {
val u = new JScanArgs
`match`.foreach(u.`match`)
Expand All @@ -117,9 +118,9 @@ object effects {
}
}
object ScanArgs {
def apply(`match`: String): ScanArgs = new ScanArgs(Some(`match`), None) {}
def apply(count: Long): ScanArgs = new ScanArgs(None, Some(count)) {}
def apply(`match`: String, count: Long): ScanArgs = new ScanArgs(Some(`match`), Some(count)) {}
def apply(`match`: String): ScanArgs = ScanArgs(Some(`match`), None)
def apply(count: Long): ScanArgs = ScanArgs(None, Some(count))
def apply(`match`: String, count: Long): ScanArgs = ScanArgs(Some(`match`), Some(count))
}

sealed trait FlushMode {
Expand Down Expand Up @@ -208,17 +209,14 @@ object effects {
case object Lt extends ExpireExistenceArg
}

// Models the core Redis Types as described in https://redis.io/docs/latest/develop/data-types/
// Caveat: BitSet, GeoSpatial etc... are implemented in terms of the core types , i.e. Geo is a Sorted Set etc..
sealed abstract class RedisType(val asString: String)
object RedisType {
def fromString(s: String): Option[RedisType] = s match {
case "string" => Some(String)
case "list" => Some(List)
case "set" => Some(Set)
case "zset" => Some(SortedSet)
case "hash" => Some(Hash)
case "stream" => Some(Stream)
case _ => None
}
val all = scala.List(String, List, Set, SortedSet, Hash, Stream)

def fromString(s: String): Option[RedisType] = all.find(_.asString == s)

case object String extends RedisType("string")

case object List extends RedisType("list")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,20 @@ trait TestScenarios { self: FunSuite =>
_ <- redis.del("k")
tpe <- redis.typeOf("k")
_ <- IO(assertEquals(tpe, None))
_ <- redis.set("k", "v")
tpe2 <- redis.typeOf("k")
_ <- redis.set("aV", "v")
tpe2 <- redis.typeOf("aV")
_ <- IO(assertEquals(tpe2, Some(RedisType.String)))
_ <- redis.del("k")
_ <- redis.setBit("bits", 0, 1)
bitSet <- redis.typeOf("bits")
_ <- IO(assertEquals(bitSet, Some(RedisType.String)))
_ <- redis.lPush("list", "v", "u")
list <- redis.typeOf("list")
_ <- IO(assertEquals(list, Some(RedisType.List)))
// geospatial
_ <- redis.geoAdd("geo", GeoLocation(Longitude(13.361389), Latitude(38.115556), "Palermo"))
geo <- redis.typeOf("geo")
_ <- IO(assertEquals(geo, Some(RedisType.SortedSet)))
_ <- redis.flushAll
} yield ()
}

Expand Down

0 comments on commit dcad2eb

Please sign in to comment.