mirror of
https://github.com/hanzokv/go.git
synced 2026-09-24 00:31:51 +00:00
* [maintnotif] Cluster specific handlers (#3613) * maint notification handlers for cluster messages * unrelax all conns * trigger ci on feature branches * feat(maintnotif): lazy cluster topology reload (#3614) * lazy cluster topology reload * fix discrepancies between options structs * Update osscluster_lazy_reload_test.go Co-authored-by: Copilot <[email protected]> * Update osscluster.go Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]> * feat(e2e): mock maintnotif e2e tests (#3639) * lazy cluster topology reload * fix discrepancies between options structs * Update osscluster_lazy_reload_test.go Co-authored-by: Copilot <[email protected]> * Update osscluster.go Co-authored-by: Copilot <[email protected]> * wip fault with mock proxy * make lint happy * fix linter issues * faster tests with mocks * linter once again * add complex node test * add ci e2e * use correct redis container * e2e fix --------- Co-authored-by: Copilot <[email protected]> * fix(retry): Add retry mechanism for NOREPLICAS error (#3647) * fix(queuedNewConn): protect against nil context (#3649) * fix(maintnotif): fix smigrated parser and add cluster state reload interval option (#3663) * fix SMIGRATED parsing * fix smigrated parser * add ClusterStateReloadInterval to ClusterOptions * fix tests * set default cluster reload interval to 10s * chore(lint): format * feat(smigrated): new format & remember original host:port (#3697) * lazy cluster topology reload * fix discrepancies between options structs * Update osscluster_lazy_reload_test.go Co-authored-by: Copilot <[email protected]> * Update osscluster.go Co-authored-by: Copilot <[email protected]> * wip fault with mock proxy * make lint happy * fix linter issues * faster tests with mocks * linter once again * add complex node test * add ci e2e * use correct redis container * e2e fix * additional e2e tests * fix data race * fix random shard picker * fix e2e tests * fix for empty endpoint * fix case when semaphore is full, but still need to check idle * scenario tests * create database from config * wip * feat(client): store original addrs for later use * fix(notif): change smigrated notification * fix(lint): fix linter * fix(smigrated): use array * fix(e2e): wip * Update options.go Co-authored-by: Copilot <[email protected]> * Update redis.go Co-authored-by: Copilot <[email protected]> * fix(notif): if the conn has no original addr, trigger reload with first target * chore(e2e): wip cluster e2e * chore(e2e): fix nil pointer from e2e tests * chore(e2e): fix tests and reports * chore(e2e): proper logging in e2e * chore(e2e): add pubsub in the tests as well * chore(e2e): mockproxy fixes * chore(e2e): mockproxy fixes * chore(e2e): mockproxy fixes * chore(e2e): mockproxy fixes v3 * stop background routines * fix(e2e): tests --------- Co-authored-by: Copilot <[email protected]> * chore(docs): add example app (#3651) * chore(lint): fmt * chore(docs): improve docs * chore(docs): update features.md * chore(github): remove example * chore(maintnotif): rename option and address pr comments * fix(e2e): command runner should use client timeout * chore(e2e): refactor tests * fix(e2e): set default timeout to 90m * fix(e2e): skip tests if proxy cannot be started --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: ofekshenawa <[email protected]> Co-authored-by: Elena Kolevska <[email protected]>
119 lines
3.8 KiB
Go
119 lines
3.8 KiB
Go
package redis
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net"
|
|
"time"
|
|
|
|
"github.com/redis/go-redis/v9/internal/interfaces"
|
|
"github.com/redis/go-redis/v9/push"
|
|
)
|
|
|
|
// ErrInvalidCommand is returned when an invalid command is passed to ExecuteCommand.
|
|
var ErrInvalidCommand = errors.New("invalid command type")
|
|
|
|
// ErrInvalidPool is returned when the pool type is not supported.
|
|
var ErrInvalidPool = errors.New("invalid pool type")
|
|
|
|
// newClientAdapter creates a new client adapter for regular Redis clients.
|
|
func newClientAdapter(client *baseClient) interfaces.ClientInterface {
|
|
return &clientAdapter{client: client}
|
|
}
|
|
|
|
// clientAdapter adapts a Redis client to implement interfaces.ClientInterface.
|
|
type clientAdapter struct {
|
|
client *baseClient
|
|
}
|
|
|
|
// GetOptions returns the client options.
|
|
func (ca *clientAdapter) GetOptions() interfaces.OptionsInterface {
|
|
return &optionsAdapter{options: ca.client.opt}
|
|
}
|
|
|
|
// GetPushProcessor returns the client's push notification processor.
|
|
func (ca *clientAdapter) GetPushProcessor() interfaces.NotificationProcessor {
|
|
return &pushProcessorAdapter{processor: ca.client.pushProcessor}
|
|
}
|
|
|
|
// optionsAdapter adapts Redis options to implement interfaces.OptionsInterface.
|
|
type optionsAdapter struct {
|
|
options *Options
|
|
}
|
|
|
|
// GetReadTimeout returns the read timeout.
|
|
func (oa *optionsAdapter) GetReadTimeout() time.Duration {
|
|
return oa.options.ReadTimeout
|
|
}
|
|
|
|
// GetWriteTimeout returns the write timeout.
|
|
func (oa *optionsAdapter) GetWriteTimeout() time.Duration {
|
|
return oa.options.WriteTimeout
|
|
}
|
|
|
|
// GetNetwork returns the network type.
|
|
func (oa *optionsAdapter) GetNetwork() string {
|
|
return oa.options.Network
|
|
}
|
|
|
|
// GetAddr returns the connection address.
|
|
func (oa *optionsAdapter) GetAddr() string {
|
|
return oa.options.Addr
|
|
}
|
|
|
|
// GetNodeAddress returns the address of the Redis node as reported by the server.
|
|
// For cluster clients, this is the endpoint from CLUSTER SLOTS before any transformation.
|
|
// For standalone clients, this defaults to Addr.
|
|
func (oa *optionsAdapter) GetNodeAddress() string {
|
|
return oa.options.NodeAddress
|
|
}
|
|
|
|
// IsTLSEnabled returns true if TLS is enabled.
|
|
func (oa *optionsAdapter) IsTLSEnabled() bool {
|
|
return oa.options.TLSConfig != nil
|
|
}
|
|
|
|
// GetProtocol returns the protocol version.
|
|
func (oa *optionsAdapter) GetProtocol() int {
|
|
return oa.options.Protocol
|
|
}
|
|
|
|
// GetPoolSize returns the connection pool size.
|
|
func (oa *optionsAdapter) GetPoolSize() int {
|
|
return oa.options.PoolSize
|
|
}
|
|
|
|
// NewDialer returns a new dialer function for the connection.
|
|
func (oa *optionsAdapter) NewDialer() func(context.Context) (net.Conn, error) {
|
|
baseDialer := oa.options.NewDialer()
|
|
return func(ctx context.Context) (net.Conn, error) {
|
|
// Extract network and address from the options
|
|
network := oa.options.Network
|
|
addr := oa.options.Addr
|
|
return baseDialer(ctx, network, addr)
|
|
}
|
|
}
|
|
|
|
// pushProcessorAdapter adapts a push.NotificationProcessor to implement interfaces.NotificationProcessor.
|
|
type pushProcessorAdapter struct {
|
|
processor push.NotificationProcessor
|
|
}
|
|
|
|
// RegisterHandler registers a handler for a specific push notification name.
|
|
func (ppa *pushProcessorAdapter) RegisterHandler(pushNotificationName string, handler interface{}, protected bool) error {
|
|
if pushHandler, ok := handler.(push.NotificationHandler); ok {
|
|
return ppa.processor.RegisterHandler(pushNotificationName, pushHandler, protected)
|
|
}
|
|
return errors.New("handler must implement push.NotificationHandler")
|
|
}
|
|
|
|
// UnregisterHandler removes a handler for a specific push notification name.
|
|
func (ppa *pushProcessorAdapter) UnregisterHandler(pushNotificationName string) error {
|
|
return ppa.processor.UnregisterHandler(pushNotificationName)
|
|
}
|
|
|
|
// GetHandler returns the handler for a specific push notification name.
|
|
func (ppa *pushProcessorAdapter) GetHandler(pushNotificationName string) interface{} {
|
|
return ppa.processor.GetHandler(pushNotificationName)
|
|
}
|