diff --git a/src/main/scala/zio/redis/Input.scala b/src/main/scala/zio/redis/Input.scala index 14af8f48accb7c655dee8cfddea4966579453b9f..99bfdcba041c61d550db817bc38bc3c25f860445 100644 --- a/src/main/scala/zio/redis/Input.scala +++ b/src/main/scala/zio/redis/Input.scala @@ -10,33 +10,43 @@ import scala.util.matching.Regex sealed trait Input[-A] object Input { - case object ByteInput extends Input[Chunk[Byte]] - case object DoubleInput extends Input[Double] - case object DurationInput extends Input[Duration] - case object LongInput extends Input[Long] - case object MatchInput extends Input[Regex] - case object UnitInput extends Input[Unit] - case object RangeInput extends Input[Range] - case object StringInput extends Input[String] - case object TimeInput extends Input[Instant] - case object SortedSetMemberScoreInput extends Input[options.MemberScore] - case object SortedSetUpdateInput extends Input[options.Updates] - case object SortedSetChangedInput extends Input[options.CH] - case object SortedSetIncrementInput extends Input[options.INCR] - case object SortedSetAggregateInput extends Input[options.Aggregate] - case object SortedSetLexRangeInput extends Input[options.LexRange] - case object SortedSetWithScoresInput extends Input[options.WithScores] - case object SortedSetLimitInput extends Input[options.Limit] - case object SortedSetScoreRangeInput extends Input[options.ScoreRange] - case object GeoCountInput extends Input[options.Count] - case object GeoLongLatInput extends Input[options.LongLat] - case object GeoOrderInput extends Input[options.Order] - case object GeoRadiusUnitInput extends Input[options.RadiusUnit] - case object GeoStoreInput extends Input[options.Store] - case object GeoStoreDistInput extends Input[options.StoreDist] - case object GeoWithCoordInput extends Input[options.WithCoord] - case object GeoWithDistInput extends Input[options.WithDist] - case object GeoWithHashInput extends Input[options.WithHash] + case object BoolInput extends Input[Boolean] + case object ByteInput extends Input[Chunk[Byte]] + case object DoubleInput extends Input[Double] + case object DurationInput extends Input[Duration] + case object LongInput extends Input[Long] + case object MatchInput extends Input[Regex] + case object UnitInput extends Input[Unit] + case object RangeInput extends Input[Range] + case object StringInput extends Input[String] + case object TimeInput extends Input[Instant] + case object SortedSetMemberScoreInput extends Input[options.MemberScore] + case object SortedSetUpdateInput extends Input[options.Updates] + case object SortedSetChangedInput extends Input[options.CH] + case object SortedSetIncrementInput extends Input[options.INCR] + case object SortedSetAggregateInput extends Input[options.Aggregate] + case object SortedSetLexRangeInput extends Input[options.LexRange] + case object SortedSetWithScoresInput extends Input[options.WithScores] + case object SortedSetLimitInput extends Input[options.Limit] + case object SortedSetScoreRangeInput extends Input[options.ScoreRange] + case object GeoCountInput extends Input[options.Count] + case object GeoLongLatInput extends Input[options.LongLat] + case object GeoOrderInput extends Input[options.Order] + case object GeoRadiusUnitInput extends Input[options.RadiusUnit] + case object GeoStoreInput extends Input[options.Store] + case object GeoStoreDistInput extends Input[options.StoreDist] + case object GeoWithCoordInput extends Input[options.WithCoord] + case object GeoWithDistInput extends Input[options.WithDist] + case object GeoWithHashInput extends Input[options.WithHash] + case object StringBitFieldGetInput extends Input[options.BitFieldGet] + case object StringBitFieldSetInput extends Input[options.BitFieldSet] + case object StringBitFieldIncrInput extends Input[options.BitFieldIncr] + case object StringBitFieldOverflowInput extends Input[options.BitFieldOverflow] + case object StringBitOperationInput extends Input[options.BitOperation] + case object StringBitPosRangeInput extends Input[options.BitPosRange] + case object StringExpirationInput extends Input[options.Expiration] + case object StringKeepTimeToLiveInput extends Input[options.KEEPTTL] + case object UpdatesInput extends Input[options.Updates] final case class OptionalInput[-A](a: Input[A]) extends Input[Option[A]] diff --git a/src/main/scala/zio/redis/api/SortedSets.scala b/src/main/scala/zio/redis/api/SortedSets.scala index 43fbe1324d067944ca25322dc059241234decdf8..92ca02a8756be2bde299b3faba0094093486a9d3 100644 --- a/src/main/scala/zio/redis/api/SortedSets.scala +++ b/src/main/scala/zio/redis/api/SortedSets.scala @@ -12,7 +12,7 @@ trait SortedSets { "ZADD", Tuple5( StringInput, - OptionalInput(SortedSetUpdateInput), + OptionalInput(UpdatesInput), OptionalInput(SortedSetChangedInput), OptionalInput(SortedSetIncrementInput), NonEmptyList(SortedSetMemberScoreInput) diff --git a/src/main/scala/zio/redis/api/Strings.scala b/src/main/scala/zio/redis/api/Strings.scala index 9e26c62405b3f74448b27c0ac2a7344096947f6b..9cacb07e821488d0c567c8f7ba87cc2d29421ef3 100644 --- a/src/main/scala/zio/redis/api/Strings.scala +++ b/src/main/scala/zio/redis/api/Strings.scala @@ -5,8 +5,31 @@ import zio.redis.Input._ import zio.redis.Output._ trait Strings { - final val append = Command("APPEND", Tuple2(StringInput, ByteInput), LongOutput) - final val bitcount = Command("BITCOUNT", Tuple2(StringInput, OptionalInput(RangeInput)), LongOutput) + final val append = Command("APPEND", Tuple2(StringInput, ByteInput), LongOutput) + final val bitcount = Command("BITCOUNT", Tuple2(StringInput, OptionalInput(RangeInput)), LongOutput) + final val bitfield = Command( + "BITFIELD", + Tuple5( + StringInput, + OptionalInput(NonEmptyList(StringBitFieldGetInput)), + OptionalInput(NonEmptyList(StringBitFieldSetInput)), + OptionalInput(NonEmptyList(StringBitFieldIncrInput)), + OptionalInput(NonEmptyList(StringBitFieldOverflowInput)) + ), + StreamOutput + ) + final val bitop = + Command( + "BITOP", + Tuple3( + StringBitOperationInput, + StringInput, + NonEmptyList(StringInput) + ), + LongOutput + ) + final val bitpos = + Command("BITPOS", Tuple3(StringInput, BoolInput, OptionalInput(StringBitPosRangeInput)), LongOutput) final val decr = Command("DECR", StringInput, LongOutput) final val decrby = Command("DECRBY", Tuple2(StringInput, LongInput), LongOutput) final val get = Command("GET", StringInput, ByteOutput) @@ -20,9 +43,20 @@ trait Strings { final val mset = Command("MSET", NonEmptyList(Tuple2(StringInput, ByteInput)), UnitOutput) final val msetnx = Command("MSETNX", NonEmptyList(Tuple2(StringInput, ByteInput)), BoolOutput) final val psetex = Command("PSETEX", Tuple3(StringInput, DurationInput, ByteInput), UnitOutput) - final val setbit = Command("SETBIT", Tuple3(StringInput, LongInput, ByteInput), ByteOutput) - final val setex = Command("SETEX", Tuple3(StringInput, DurationInput, ByteInput), UnitOutput) - final val setnx = Command("SETNX", Tuple2(StringInput, ByteInput), BoolOutput) - final val setrange = Command("SETRANGE", Tuple3(StringInput, LongInput, ByteInput), LongOutput) - final val strlen = Command("STRLEN", StringInput, LongOutput) + final val set = Command( + "SET", + Tuple5( + StringInput, + ByteInput, + OptionalInput(StringExpirationInput), + OptionalInput(UpdatesInput), + OptionalInput(StringKeepTimeToLiveInput) + ), + OptionalOutput(UnitOutput) + ) + final val setbit = Command("SETBIT", Tuple3(StringInput, LongInput, ByteInput), ByteOutput) + final val setex = Command("SETEX", Tuple3(StringInput, DurationInput, ByteInput), UnitOutput) + final val setnx = Command("SETNX", Tuple2(StringInput, ByteInput), BoolOutput) + final val setrange = Command("SETRANGE", Tuple3(StringInput, LongInput, ByteInput), LongOutput) + final val strlen = Command("STRLEN", StringInput, LongOutput) } diff --git a/src/main/scala/zio/redis/options/Shared.scala b/src/main/scala/zio/redis/options/Shared.scala new file mode 100644 index 0000000000000000000000000000000000000000..319f05148b1242c287e49a1bc90bcd4b5159eaa1 --- /dev/null +++ b/src/main/scala/zio/redis/options/Shared.scala @@ -0,0 +1,10 @@ +package zio.redis.options + +trait Shared { + sealed trait Updates + + object Updates { + case object XX extends Updates + case object NX extends Updates + } +} diff --git a/src/main/scala/zio/redis/options/SortedSets.scala b/src/main/scala/zio/redis/options/SortedSets.scala index dcb39c5d4c7d2d1ad0dc496ee377d2d496e2d96c..8b572eb3b1c22ca0913dc8275c26061e535b8dd7 100644 --- a/src/main/scala/zio/redis/options/SortedSets.scala +++ b/src/main/scala/zio/redis/options/SortedSets.scala @@ -46,13 +46,6 @@ trait SortedSets { case object WithScores type WithScores = WithScores.type - sealed trait Updates - - object Updates { - case object XX extends Updates - case object NX extends Updates - } - case object CH type CH = CH.type case object INCR diff --git a/src/main/scala/zio/redis/options/Strings.scala b/src/main/scala/zio/redis/options/Strings.scala new file mode 100644 index 0000000000000000000000000000000000000000..c5f105bd5c8214895470cdae618a6c56706f176c --- /dev/null +++ b/src/main/scala/zio/redis/options/Strings.scala @@ -0,0 +1,39 @@ +package zio.redis.options + +trait Strings { + + sealed trait BitFieldType + object BitFieldType { + sealed case class UnsignedInt(size: Int) extends BitFieldType + sealed case class SignedInt(size: Int) extends BitFieldType + } + + case class BitFieldGet(`type`: BitFieldType, offset: Int) + case class BitFieldSet(`type`: BitFieldType, offset: Int, value: BigInt) + case class BitFieldIncr(`type`: BitFieldType, offset: Int, increment: BigInt) + + sealed trait BitFieldOverflow + object BitFieldOverflow { + case object FAIL extends BitFieldOverflow + case object SAT extends BitFieldOverflow + case object WRAP extends BitFieldOverflow + } + + sealed trait BitOperation + object BitOperation { + case object AND extends BitOperation + case object OR extends BitOperation + case object XOR extends BitOperation + } + + case class BitPosRange(start: Long, end: Option[Long]) + + sealed trait Expiration + object Expiration { + sealed case class EX(seconds: Long) extends Expiration + sealed case class PX(milliSeconds: Long) extends Expiration + } + + case object KEEPTTL + type KEEPTTL = KEEPTTL.type +} diff --git a/src/main/scala/zio/redis/options/package.scala b/src/main/scala/zio/redis/options/package.scala index 9894b7a25a5620c7576fe8a297a37de3b7cdd01e..6bae5987dbb0ae85606afcd5e1f0a96935da4a4a 100644 --- a/src/main/scala/zio/redis/options/package.scala +++ b/src/main/scala/zio/redis/options/package.scala @@ -1,5 +1,3 @@ package zio.redis -package object options extends SortedSets with Geo { - // common options -} +package object options extends Geo with Shared with SortedSets with Strings