Skip to content

add publishing to core#1079

Open
yisraelU wants to merge 6 commits intoprofunktor:series/3.xfrom
yisraelU:publish
Open

add publishing to core#1079
yisraelU wants to merge 6 commits intoprofunktor:series/3.xfrom
yisraelU:publish

Conversation

@yisraelU
Copy link
Copy Markdown
Collaborator

@yisraelU yisraelU commented Dec 25, 2025

closes #1049

  • This is a big change, which breaks binary compatibility, as it moves publishing and pubsub stats out of the streams module into the effects module.

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 effects module and provides a standard implementation. The pubsub feature available in the streaming module , makes use of that implementation too

@yisraelU yisraelU requested a review from gvolpe December 29, 2025 21:18
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))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be cleaner/safer to share a deferred/queue between the main fiber and subscribing fiber

@yisraelU yisraelU changed the base branch from series/2.x to series/3.x January 2, 2026 04:34
@yisraelU
Copy link
Copy Markdown
Collaborator Author

yisraelU commented Jan 2, 2026

@Mergifyio rebase!

@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Jan 2, 2026

rebase !

❌ Base branch update has failed

Details

Git reported the following error:

Rebasing (1/7)
Auto-merging modules/effects/src/main/scala/dev/profunktor/redis4cats/commands.scala
Auto-merging modules/effects/src/main/scala/dev/profunktor/redis4cats/redis.scala
Auto-merging modules/tests/src/test/scala/dev/profunktor/redis4cats/Redis4CatsFunSuite.scala
CONFLICT (content): Merge conflict in modules/tests/src/test/scala/dev/profunktor/redis4cats/Redis4CatsFunSuite.scala
Auto-merging site/docs/effects/index.md
error: could not apply a6465ff... add publishing to core
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply a6465ff... add publishing to core

@yisraelU
Copy link
Copy Markdown
Collaborator Author

yisraelU commented Jan 2, 2026

@Mergifyio rebase!

@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Jan 2, 2026

rebase !

✅ Branch has been successfully rebased

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Publishing requires a separate connection

2 participants