Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
359 changes: 177 additions & 182 deletions modules/redis/src/main/scala/zio/redis/Input.scala

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private[redis] final class ClusterExecutor private (
}

for {
keyOpt <- ZIO.succeed(command.args.collectFirst { case key: RespCommandArgument.Key => key })
keyOpt <- ZIO.succeed(command.args.values.collectFirst { case key: RespCommandArgument.Key => key })
keySlot = keyOpt.fold(Slot.Default)(key => Slot((key.asCRC16 & (SlotsAmount - 1)).toLong))
result <- executeSafe(keySlot)
} yield result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package zio.redis.internal

import zio._
import zio.redis.Input.{CommandNameInput, Varargs}
import zio.redis._

private[redis] final class RedisCommand[-In, +Out] private (
Expand All @@ -33,7 +32,7 @@ private[redis] final class RedisCommand[-In, +Out] private (
.refineToOrDie[RedisError]

def resp(in: In): RespCommand =
Varargs(CommandNameInput).encode(name.split(" ")) ++ input.encode(in)
input.encode(in).buildCommand(RespCommandName(name))
}

private[redis] object RedisCommand {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,32 @@ package zio.redis.internal

import zio.Chunk

private[redis] final case class RespCommand(args: Chunk[RespCommandArgument]) extends AnyVal {
def ++(that: RespCommand): RespCommand = RespCommand(this.args ++ that.args)
private[redis] final case class RespCommand(name: RespCommandName, args: RespCommandArguments) {
def bulkStrings: Chunk[RespValue.BulkString] = name.bulkStrings ++ args.bulkStrings
}

private[redis] final case class RespCommandName(str: String) extends AnyVal {
def bulkStrings: Chunk[RespValue.BulkString] = Chunk.fromArray(str.split(" ").map(RespValue.bulkString))
}

private[redis] final case class RespCommandArguments(values: Chunk[RespCommandArgument]) extends AnyVal {
def ++(that: RespCommandArguments): RespCommandArguments = RespCommandArguments(this.values ++ that.values)
Comment thread
anovakovic01 marked this conversation as resolved.

def mapArguments(f: RespCommandArgument => RespCommandArgument): RespCommandArguments = RespCommandArguments(
Comment thread
anovakovic01 marked this conversation as resolved.
Outdated
values.map(f(_))
)

def buildCommand(name: RespCommandName): RespCommand = RespCommand(name, this)
Comment thread
anovakovic01 marked this conversation as resolved.
Outdated

def mapArguments(f: RespCommandArgument => RespCommandArgument): RespCommand = RespCommand(args.map(f(_)))
def bulkStrings: Chunk[RespValue.BulkString] = values.map(_.value)
}

private[redis] object RespCommand {
def empty: RespCommand = new RespCommand(Chunk.empty)
private[redis] object RespCommandArguments {
def empty: RespCommandArguments = new RespCommandArguments(Chunk.empty)

def apply(args: Chunk[RespCommandArgument]): RespCommand = new RespCommand(args)
def apply(args: Chunk[RespCommandArgument]): RespCommandArguments = new RespCommandArguments(args)

def apply(args: RespCommandArgument*): RespCommand = new RespCommand(Chunk.fromIterable(args))
def apply(args: RespCommandArgument*): RespCommandArguments = new RespCommandArguments(Chunk.fromIterable(args))

def apply(arg: RespCommandArgument): RespCommand = new RespCommand(Chunk.single(arg))
def apply(arg: RespCommandArgument): RespCommandArguments = new RespCommandArguments(Chunk.single(arg))
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ private[redis] sealed trait RespCommandArgument {
}

private[redis] object RespCommandArgument {

final case class CommandName(str: String) extends RespCommandArgument {
lazy val value: RespValue.BulkString = RespValue.bulkString(str)
}

final case class Literal(str: String) extends RespCommandArgument {
lazy val value: RespValue.BulkString = RespValue.bulkString(str)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private[redis] final class SingleNodeExecutor private (
def execute(command: RespCommand): IO[RedisError, RespValue] =
Promise
.make[RedisError, RespValue]
.flatMap(promise => requests.offer(Request(command.args.map(_.value), promise)) *> promise.await)
.flatMap(promise => requests.offer(Request(command.bulkStrings, promise)) *> promise.await)

/**
* Opens a connection to the server and launches send and receive operations. All failures are retried by opening a
Expand Down
Loading