@@ -87,6 +87,7 @@ func (l *RedisLocker) rollbackLocks(ctx context.Context, locked map[string]strin
8787 return nil
8888}
8989
90+ // ReleaseLock releases the locks for the given keys.
9091func (l * RedisLocker ) ReleaseLock (ctx context.Context , lockedKeys map [string ]string ) error {
9192 if len (lockedKeys ) == 0 {
9293 return nil
@@ -119,19 +120,24 @@ func (l *RedisLocker) ReleaseLock(ctx context.Context, lockedKeys map[string]str
119120 return nil
120121}
121122
123+ // GetLockedNodes returns the list of locked nodes.
122124func (l * RedisLocker ) GetLockedNodes (ctx context.Context ) ([]uint32 , error ) {
123- keys , err := l .client .Keys (ctx , "locked:*" ).Result ()
124- if err != nil {
125- return nil , err
126- }
127- nodes := make ([]uint32 , len (keys ))
128- for i , key := range keys {
125+ iter := l .client .Scan (ctx , 0 , "locked:*" , 0 ).Iterator ()
126+
127+ nodes := make ([]uint32 , 0 )
128+ for iter .Next (ctx ) {
129+ key := iter .Val ()
129130 nodeID := strings .Split (key , ":" )[1 ]
130131 value , parseErr := strconv .ParseUint (nodeID , 10 , 32 )
131132 if parseErr != nil {
132133 return nil , fmt .Errorf ("failed to parse locked node id from %s: %w" , key , parseErr )
133134 }
134- nodes [ i ] = uint32 (value )
135+ nodes = append ( nodes , uint32 (value ) )
135136 }
137+
138+ if err := iter .Err (); err != nil {
139+ return nil , err
140+ }
141+
136142 return nodes , nil
137143}
0 commit comments