-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,168 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
modules/redis/src/main/scala/zio/redis/RedisSubscription.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2021 John A. De Goes and the ZIO contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package zio.redis | ||
|
||
import zio._ | ||
import zio.redis.internal.SubscriptionExecutor | ||
|
||
trait RedisSubscription extends api.Subscription | ||
|
||
object RedisSubscription { | ||
lazy val local: ZLayer[CodecSupplier, RedisError.IOError, RedisSubscription] = | ||
SubscriptionExecutor.local >>> makeLayer | ||
|
||
lazy val singleNode: ZLayer[CodecSupplier & RedisConfig, RedisError.IOError, RedisSubscription] = | ||
SubscriptionExecutor.layer >>> makeLayer | ||
|
||
private def makeLayer: URLayer[CodecSupplier & SubscriptionExecutor, RedisSubscription] = | ||
ZLayer.fromFunction(Live.apply _) | ||
|
||
private final case class Live(codecSupplier: CodecSupplier, executor: SubscriptionExecutor) extends RedisSubscription | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
modules/redis/src/main/scala/zio/redis/api/Publishing.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright 2021 John A. De Goes and the ZIO contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package zio.redis.api | ||
|
||
import zio.redis.Input._ | ||
import zio.redis.Output._ | ||
import zio.redis._ | ||
import zio.redis.internal.{RedisCommand, RedisEnvironment} | ||
import zio.schema.Schema | ||
import zio.{Chunk, IO} | ||
|
||
trait Publishing extends RedisEnvironment { | ||
import Publishing._ | ||
|
||
/** | ||
* Posts a message to the given channel. | ||
* | ||
* @param channel | ||
* Target channel name for publishing messages. | ||
* @param message | ||
* The value of the message to be published to the channel. | ||
* @return | ||
* Returns the number of clients that received the message. | ||
*/ | ||
final def publish[A: Schema](channel: String, message: A): IO[RedisError, Long] = { | ||
val command = RedisCommand(Publish, Tuple2(StringInput, ArbitraryKeyInput[A]()), LongOutput, executor) | ||
command.run((channel, message)) | ||
} | ||
|
||
/** | ||
* Lists the currently active channel that has one or more subscribers (excluding clients subscribed to patterns). | ||
* | ||
* @param pattern | ||
* Pattern to get matching channels. | ||
* @return | ||
* Returns a list of active channels matching the specified pattern. | ||
*/ | ||
final def pubSubChannels(pattern: String): IO[RedisError, Chunk[String]] = { | ||
val command = RedisCommand(PubSubChannels, StringInput, ChunkOutput(MultiStringOutput), executor) | ||
command.run(pattern) | ||
} | ||
|
||
/** | ||
* The number of unique patterns that are subscribed to by clients. | ||
* | ||
* @return | ||
* Returns the number of patterns all the clients are subscribed to. | ||
*/ | ||
final def pubSubNumPat: IO[RedisError, Long] = { | ||
val command = RedisCommand(PubSubNumPat, NoInput, LongOutput, executor) | ||
command.run(()) | ||
} | ||
|
||
/** | ||
* The number of subscribers (exclusive of clients subscribed to patterns) for the specified channels. | ||
* | ||
* @param channel | ||
* Channel name to get the number of subscribers. | ||
* @param channels | ||
* Channel names to get the number of subscribers. | ||
* @return | ||
* Returns a map of channel and number of subscribers for channel. | ||
*/ | ||
final def pubSubNumSub(channel: String, channels: String*): IO[RedisError, Map[String, Long]] = { | ||
val command = RedisCommand(PubSubNumSub, NonEmptyList(StringInput), NumSubResponseOutput, executor) | ||
command.run((channel, channels.toList)) | ||
} | ||
} | ||
|
||
private[redis] object Publishing { | ||
final val Publish = "PUBLISH" | ||
final val PubSubChannels = "PUBSUB CHANNELS" | ||
final val PubSubNumPat = "PUBSUB NUMPAT" | ||
final val PubSubNumSub = "PUBSUB NUMSUB" | ||
} |
Oops, something went wrong.