Skip to content

feat: can use existing Redis client in the watcher#59

Merged
nomeguy merged 5 commits intomasterfrom
copilot/add-clustered-watcher-support
Jan 14, 2026
Merged

feat: can use existing Redis client in the watcher#59
nomeguy merged 5 commits intomasterfrom
copilot/add-clustered-watcher-support

Conversation

Copy link
Contributor

Copilot AI commented Jan 13, 2026

Users with restricted access to connection details or centralized Redis clients cannot reuse existing client instances when creating watchers. The SubClient and PubClient fields in WatcherOptions were typed as *rds.Client, preventing use with cluster clients.

Changes

  • Type change: SubClient and PubClient in WatcherOptions now accept rds.UniversalClient instead of *rds.Client

    • Enables passing any client type: regular, cluster, sentinel, failover, ring
    • Backward compatible: *rds.Client implements rds.UniversalClient
  • Documentation: Added examples for using existing clients with both regular and cluster modes

Usage

// Create your own cluster client
clusterClient := redis.NewClusterClient(&redis.ClusterOptions{
    Addrs: []string{"localhost:7000", "localhost:7001", "localhost:7002"},
})

// Pass it to the watcher (empty addrs ignored when clients provided)
w, _ := rediswatcher.NewWatcherWithCluster("", rediswatcher.WatcherOptions{
    SubClient: clusterClient,
    PubClient: clusterClient,
    Channel:   "/casbin",
})

Works identically with NewWatcher() for regular clients.

Original prompt

This section details on the original issue you should resolve

<issue_title>No option to init new watcher (clustered) with redis client</issue_title>
<issue_description>Currently, there is no way to initialize a new watcher (in clustered mode) using an existing Redis client instance. The code expects Redis connection details like host, port, or options to internally create a new Redis client.

In my use case, I already have an active Redis client (due to restricted access to connection details or centralized Redis setup), and I need to reuse this client to create a clustered watcher.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@nomeguy nomeguy marked this pull request as ready for review January 13, 2026 18:06
Copilot AI and others added 4 commits January 13, 2026 18:10
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add option to initialize new watcher with existing Redis client Support initializing watcher with existing Redis client Jan 13, 2026
Copilot AI requested a review from nomeguy January 13, 2026 18:21
@nomeguy nomeguy changed the title Support initializing watcher with existing Redis client feat: support initializing watcher with existing Redis client Jan 14, 2026
@nomeguy nomeguy changed the title feat: support initializing watcher with existing Redis client feat: can use existing Redis client in the watcher Jan 14, 2026
@nomeguy nomeguy merged commit daa87e4 into master Jan 14, 2026
4 of 5 checks passed
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.

No option to init new watcher (clustered) with redis client

3 participants