Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 5, 2025

The redis_client package only supported a singleton pattern via SetConfig()/GetRDB(), preventing applications from creating multiple independent Redis clients (e.g., separate clients for cache, sessions, queues).

Changes

  • Added NewRDB(Config) - Factory function to create independent Redis client instances
  • Added NewCache(CacheConfig) - Factory function to create independent cache instances with custom configurations (local cache size, TTL, refresh channel)
  • Deprecated singleton pattern - SetConfig()/GetRDB()/GetCache() remain for backward compatibility
  • Fixed cache invalidation bug - Subscriber now uses cache key from message payload instead of comparing with channel name

Example

// Create multiple independent clients
primaryRDB := redis_client.NewRDB(redis_client.Config{
    Urls:     []string{"primary:6379"},
    Password: "secret1",
})

sessionRDB := redis_client.NewRDB(redis_client.Config{
    Urls:     []string{"session:6379"},
    Password: "secret2",
})

// Create independent cache instances with custom configs
primaryCache := redis_client.NewCache(redis_client.CacheConfig{
    Redis:               primaryRDB,
    RefreshEventChannel: "primary:refresh",
    LocalCacheSize:      2000,
    LocalCacheTTL:       2 * time.Minute,
})

sessionCache := redis_client.NewCache(redis_client.CacheConfig{
    Redis:               sessionRDB,
    RefreshEventChannel: "session:refresh",
})

The factory pattern aligns with other modules in go-webmods (gorm_client, mongo_client, object_storage) and maintains full backward compatibility.

Original prompt

This section details on the original issue you should resolve

<issue_title>Support creating multiple clients in redis_client</issue_title>
<issue_description></issue_description>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits November 5, 2025 05:05
Co-authored-by: slhmy <31381093+slhmy@users.noreply.github.com>
…el name

Co-authored-by: slhmy <31381093+slhmy@users.noreply.github.com>
Co-authored-by: slhmy <31381093+slhmy@users.noreply.github.com>
Copilot AI changed the title [WIP] Support creating multiple clients in redis_client Add factory pattern to redis_client for multiple client instances Nov 5, 2025
Copilot AI requested a review from slhmy November 5, 2025 05:10
@slhmy slhmy marked this pull request as ready for review November 5, 2025 06:01
@slhmy slhmy merged commit ae9e3be into main Nov 5, 2025
1 check 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.

Support creating multiple clients in redis_client

2 participants