Skip to content

Commit 890dabf

Browse files
committed
fix(iterator): remove unnecessary mutex
1 parent 52af8ba commit 890dabf

File tree

1 file changed

+1
-12
lines changed

1 file changed

+1
-12
lines changed

iterator.go

+1-12
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,21 @@ package redis
22

33
import (
44
"context"
5-
"sync"
65
)
76

87
// ScanIterator is used to incrementally iterate over a collection of elements.
9-
// It's safe for concurrent use by multiple goroutines.
108
type ScanIterator struct {
11-
mu sync.Mutex // protects Scanner and pos
129
cmd *ScanCmd
1310
pos int
1411
}
1512

1613
// Err returns the last iterator error, if any.
1714
func (it *ScanIterator) Err() error {
18-
it.mu.Lock()
19-
err := it.cmd.Err()
20-
it.mu.Unlock()
21-
return err
15+
return it.cmd.Err()
2216
}
2317

2418
// Next advances the cursor and returns true if more values can be read.
2519
func (it *ScanIterator) Next(ctx context.Context) bool {
26-
it.mu.Lock()
27-
defer it.mu.Unlock()
28-
2920
// Instantly return on errors.
3021
if it.cmd.Err() != nil {
3122
return false
@@ -68,10 +59,8 @@ func (it *ScanIterator) Next(ctx context.Context) bool {
6859
// Val returns the key/field at the current cursor position.
6960
func (it *ScanIterator) Val() string {
7061
var v string
71-
it.mu.Lock()
7262
if it.cmd.Err() == nil && it.pos > 0 && it.pos <= len(it.cmd.page) {
7363
v = it.cmd.page[it.pos-1]
7464
}
75-
it.mu.Unlock()
7665
return v
7766
}

0 commit comments

Comments
 (0)