add publishing to core#1079
Conversation
| if (cluster) conn.clusterSync else conn.sync.widen | ||
|
|
||
| private[redis4cats] val pubSubStatsImpl: F[algebra.PubSubStats[F, K]] = | ||
| conn.async.map(c => new dev.profunktor.redis4cats.effect.LivePubSubStats[F, K, V](c)) |
There was a problem hiding this comment.
I think it might make sense for the pubsub api to depend on RedisCommands, rather than have an intermediate LivePubSubStats abstraction. The streams impl already does that, see here.
There was a problem hiding this comment.
RedisCommands would give access to all Redis commands , which is unsafe for a pubsub connection as once the connection is in "Subscribe" mode , redis will not respect the standard RESP
There was a problem hiding this comment.
True, and this is also the same for the streams, which provides a nice fs2 abstraction over the commands. It doesn’t call those extra commands. However, subscribe is different as it changes the connection state, whereas xread can be used on connection sharing the other commands.
| * Note: This trait does NOT include subscribe functionality. For full pub/sub with subscriptions, see the streams | ||
| * module's PubSubCommands. | ||
| */ | ||
| trait PublishAndStats[F[_], K, V] extends Publish[F, K, V] with PubSubStats[F, K] |
There was a problem hiding this comment.
Wondering if a single trait is fine here, though I like the break out of stats since Redis namespaces the stats with "pubsub" which is different the the publish commands
There was a problem hiding this comment.
Redis puts publish under pubsub too https://redis.io/docs/latest/commands/publish/ , hence I grouped it together , but I'm ok with either way
There was a problem hiding this comment.
Yea it’s fine, was more so curious your thoughts
| for { | ||
| // Start subscriber in background | ||
| fiber <- pubSub.subscribe(channel).compile.drain.start | ||
| _ <- IO.sleep(200.millis) // Wait for subscription to be established |
There was a problem hiding this comment.
Might be cleaner/safer to share a deferred/queue between the main fiber and subscribing fiber
|
@Mergifyio rebase! |
❌ Base branch update has failedDetailsGit reported the following error: |
|
@Mergifyio rebase! |
✅ Branch has been successfully rebased |
closes #1049
Background - Redis has a pubsub feature that when activated changes the Connection from a standard connection to a "PubSub" connection. A "PubSub" connection cannot run standard Redis commands nor does it obey the RESP semantics of Req->Reply. To this end Publishing and Stats were implemented in a separate module.
Problem - This is too limiting as , publishing itself (not subscribe) and stats are standard Redis commands and should be accessible within the standard Redis Connection.
Solution - This pr creates moves the abstract publish and stats traits to the
effectsmodule and provides a standard implementation. Thepubsubfeature available in thestreamingmodule , makes use of that implementation too