Skip to content

Commit 4fb4c68

Browse files
committed
added reactive cache refresh
1 parent 3397b6f commit 4fb4c68

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

command.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4378,7 +4378,6 @@ func (c *cmdsInfoCache) Get(ctx context.Context) (map[string]*CommandInfo, error
43784378
return c.cmds, err
43794379
}
43804380

4381-
// TODO: Call it on client reconnect
43824381
func (c *cmdsInfoCache) Refresh() {
43834382
c.refreshLock.Lock()
43844383
defer c.refreshLock.Unlock()

osscluster.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -859,15 +859,19 @@ func (c *clusterState) slotNodes(slot int) []*clusterNode {
859859
//------------------------------------------------------------------------------
860860

861861
type clusterStateHolder struct {
862-
load func(ctx context.Context) (*clusterState, error)
863-
864-
state atomic.Value
865-
reloading uint32 // atomic
862+
load func(ctx context.Context) (*clusterState, error)
863+
commandsCacheRefresh func()
864+
state atomic.Value
865+
reloading uint32 // atomic
866866
}
867867

868-
func newClusterStateHolder(fn func(ctx context.Context) (*clusterState, error)) *clusterStateHolder {
868+
func newClusterStateHolder(
869+
load func(ctx context.Context) (*clusterState, error),
870+
commandsCacheRefresh func(),
871+
) *clusterStateHolder {
869872
return &clusterStateHolder{
870-
load: fn,
873+
load: load,
874+
commandsCacheRefresh: commandsCacheRefresh,
871875
}
872876
}
873877

@@ -876,6 +880,7 @@ func (c *clusterStateHolder) Reload(ctx context.Context) (*clusterState, error)
876880
if err != nil {
877881
return nil, err
878882
}
883+
c.commandsCacheRefresh()
879884
c.state.Store(state)
880885
return state, nil
881886
}
@@ -940,9 +945,9 @@ func NewClusterClient(opt *ClusterOptions) *ClusterClient {
940945
nodes: newClusterNodes(opt),
941946
}
942947

943-
c.state = newClusterStateHolder(c.loadState)
944-
// TODO: execute on handshake, should be called again on reconnect
945948
c.cmdsInfoCache = newCmdsInfoCache(c.cmdsInfo)
949+
950+
c.state = newClusterStateHolder(c.loadState, c.cmdsInfoCache.Refresh)
946951
c.cmdable = c.Process
947952
c.initHooks(hooks{
948953
dial: nil,

0 commit comments

Comments
 (0)