-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change return type of CLIENT INFO and CLIENT LIST #813
Changes from 3 commits
befb097
8b8a53e
728938e
6853fc4
36c198c
91a956c
4f91b34
beecf21
1b1d18a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,40 +25,34 @@ trait Connection { | |
private[redis] final def asString: String = s"${ip.getHostAddress}:$port" | ||
} | ||
|
||
object Address { | ||
private[redis] final def fromString(addr: String): Option[Address] = | ||
addr.split(":").toList match { | ||
case ip :: port :: Nil => Some(new Address(InetAddress.getByName(ip), port.toInt)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. toIntOption |
||
case _ => None | ||
} | ||
} | ||
|
||
sealed case class ClientEvents(readable: Boolean = false, writable: Boolean = false) | ||
|
||
sealed trait ClientFlag | ||
|
||
object ClientFlag { | ||
case object ToBeClosedAsap extends ClientFlag | ||
|
||
case object Blocked extends ClientFlag | ||
|
||
case object ToBeClosedAfterReply extends ClientFlag | ||
|
||
case object WatchedKeysModified extends ClientFlag | ||
|
||
case object IsMaster extends ClientFlag | ||
|
||
case object MonitorMode extends ClientFlag | ||
|
||
case object PubSub extends ClientFlag | ||
|
||
case object ReadOnlyMode extends ClientFlag | ||
|
||
case object Replica extends ClientFlag | ||
|
||
case object Unblocked extends ClientFlag | ||
|
||
case object UnixDomainSocket extends ClientFlag | ||
|
||
case object MultiExecContext extends ClientFlag | ||
|
||
case object KeysTrackingEnabled extends ClientFlag | ||
|
||
case object Blocked extends ClientFlag | ||
case object BroadcastTrackingMode extends ClientFlag | ||
case object IsMaster extends ClientFlag | ||
case object KeysTrackingEnabled extends ClientFlag | ||
case object MonitorMode extends ClientFlag | ||
case object MultiExecContext extends ClientFlag | ||
case object PubSub extends ClientFlag | ||
case object ReadOnlyMode extends ClientFlag | ||
case object Replica extends ClientFlag | ||
case object ToBeClosedAfterReply extends ClientFlag | ||
case object ToBeClosedAsap extends ClientFlag | ||
case object TrackingTargetClientInvalid extends ClientFlag | ||
|
||
case object BroadcastTrackingMode extends ClientFlag | ||
case object Unblocked extends ClientFlag | ||
case object UnixDomainSocket extends ClientFlag | ||
case object WatchedKeysModified extends ClientFlag | ||
} | ||
|
||
sealed case class ClientInfo( | ||
|
@@ -87,6 +81,65 @@ trait Connection { | |
user: Option[String] = None | ||
) | ||
|
||
object ClientInfo { | ||
private[redis] final def from(line: String): ClientInfo = { | ||
def getFlags(flags: String): Set[ClientFlag] = { | ||
def clientFlag(cf: Char): Option[ClientFlag] = cf match { | ||
case 'A' => Some(ClientFlag.ToBeClosedAsap) | ||
case 'b' => Some(ClientFlag.Blocked) | ||
case 'B' => Some(ClientFlag.BroadcastTrackingMode) | ||
case 'c' => Some(ClientFlag.ToBeClosedAfterReply) | ||
case 'd' => Some(ClientFlag.WatchedKeysModified) | ||
case 'M' => Some(ClientFlag.IsMaster) | ||
case 'O' => Some(ClientFlag.MonitorMode) | ||
case 'P' => Some(ClientFlag.PubSub) | ||
case 'r' => Some(ClientFlag.ReadOnlyMode) | ||
case 'R' => Some(ClientFlag.TrackingTargetClientInvalid) | ||
case 'S' => Some(ClientFlag.Replica) | ||
case 't' => Some(ClientFlag.KeysTrackingEnabled) | ||
case 'u' => Some(ClientFlag.Unblocked) | ||
case 'U' => Some(ClientFlag.UnixDomainSocket) | ||
case 'x' => Some(ClientFlag.MultiExecContext) | ||
case _ => None | ||
} | ||
|
||
flags.foldLeft(Set.empty[ClientFlag])((fs, f) => fs ++ clientFlag(f)) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move these two functions to companion object. |
||
|
||
val data = line.trim.split(" ").map(_.split("=").toList).collect { case k :: v :: Nil => k -> v }.toMap | ||
val events = data("events") | ||
new ClientInfo( | ||
id = data("id").toLong, | ||
name = data.get("name"), | ||
address = data.get("addr").flatMap(Address.fromString), | ||
localAddress = data.get("laddr").flatMap(Address.fromString), | ||
fileDescriptor = data.get("fd").map(_.toLong), | ||
age = data.get("age").map(s => Duration.fromSeconds(s.toLong)), | ||
idle = data.get("idle").map(s => Duration.fromSeconds(s.toLong)), | ||
flags = data.get("flags").fold(Set.empty[ClientFlag])(getFlags), | ||
databaseId = data.get("id").map(_.toLong), | ||
subscriptions = data("sub").toInt, | ||
patternSubscriptions = data("psub").toInt, | ||
multiCommands = data("multi").toInt, | ||
queryBufferLength = data.get("qbuf").map(_.toInt), | ||
queryBufferFree = data.get("qbuf-free").map(_.toInt), | ||
outputListLength = data.get("oll").map(_.toInt), | ||
outputBufferMem = data.get("omem").map(_.toLong), | ||
events = ClientEvents(readable = events.contains("r"), writable = events.contains("w")), | ||
lastCommand = data.get("cmd"), | ||
argvMemory = data.get("argv-mem").map(_.toLong), | ||
totalMemory = data.get("total-mem").map(_.toLong), | ||
redirectionClientId = data.get("redir").map(_.toLong), | ||
user = data.get("user") | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Plenty of unsafe calls here. |
||
} | ||
|
||
private[redis] final def from(lines: Array[String]): ClientsInfo = | ||
lines.map(from).toList | ||
} | ||
|
||
type ClientsInfo = List[ClientInfo] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for this. |
||
|
||
sealed trait ClientKillFilter | ||
|
||
object ClientKillFilter { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename this to
ClientListOutput
. Also preferChunk
toList
, e.g.:You might be able to reuse
ClientInfoOutput
in its implementation, though it's not necessary.