package redis

import (
	
	
)
ScanIterator is used to incrementally iterate over a collection of elements. It's safe for concurrent use by multiple goroutines.
type ScanIterator struct {
	mu  sync.Mutex // protects Scanner and pos
	cmd *ScanCmd
	pos int
}
Err returns the last iterator error, if any.
func ( *ScanIterator) () error {
	.mu.Lock()
	 := .cmd.Err()
	.mu.Unlock()
	return 
}
Next advances the cursor and returns true if more values can be read.
func ( *ScanIterator) ( context.Context) bool {
	.mu.Lock()
	defer .mu.Unlock()
Instantly return on errors.
	if .cmd.Err() != nil {
		return false
	}
Advance cursor, check if we are still within range.
	if .pos < len(.cmd.page) {
		.pos++
		return true
	}

Return if there is no more data to fetch.
		if .cmd.cursor == 0 {
			return false
		}
Fetch next page.
		switch .cmd.args[0] {
		case "scan", "qscan":
			.cmd.args[1] = .cmd.cursor
		default:
			.cmd.args[2] = .cmd.cursor
		}

		 := .cmd.process(, .cmd)
		if  != nil {
			return false
		}

		.pos = 1
Redis can occasionally return empty page.
		if len(.cmd.page) > 0 {
			return true
		}
	}
}
Val returns the key/field at the current cursor position.
func ( *ScanIterator) () string {
	var  string
	.mu.Lock()
	if .cmd.Err() == nil && .pos > 0 && .pos <= len(.cmd.page) {
		 = .cmd.page[.pos-1]
	}
	.mu.Unlock()
	return