Skip to content

glide_sync.sync_commands.cluster_scan_cursor

ClusterScanCursor

Represents a cursor for cluster scan operations.

This class manages the state of a cluster scan cursor and automatically cleans up resources when the cursor is no longer needed.

Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/sync_commands/cluster_scan_cursor.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class ClusterScanCursor:
    """
    Represents a cursor for cluster scan operations.

    This class manages the state of a cluster scan cursor and automatically
    cleans up resources when the cursor is no longer needed.
    """

    def __init__(self, new_cursor: Optional[str] = None):
        """
        Create a new ClusterScanCursor instance.

        Args:
            new_cursor: Optional cursor string to initialize with. If None,
                       creates a cursor in the initial state.
        """
        _glide_ffi = _GlideFFI()
        self._ffi = _glide_ffi.ffi
        self._lib = _glide_ffi.lib

        self._cursor = new_cursor or "0"

    def get_cursor(self) -> str:
        """
        Get the current cursor string.

        Returns:
            str: The current cursor string
        """
        return self._cursor

    def is_finished(self) -> bool:
        """
        Check if the cluster scan is finished.

        Returns:
            bool: True if the scan is finished, False otherwise
        """
        return self._cursor == FINISHED_SCAN_CURSOR

    def __del__(self):
        """
        Clean up cluster scan cursor resources when the object is garbage collected.
        """
        try:
            if hasattr(self, "_cursor") and self._cursor:
                cursor_bytes = self._cursor.encode(ENCODING) + b"\0"
                cursor_buffer = self._ffi.from_buffer(cursor_bytes)

                self._lib.remove_cluster_scan_cursor(cursor_buffer)

        except Exception as e:
            Logger.log(
                Level.ERROR,
                "cluster_scan_cursor",
                f"Error during cluster scan cursor cleanup: {e}",
            )

get_cursor()

Get the current cursor string.

Returns:

Name Type Description
str str

The current cursor string

Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/sync_commands/cluster_scan_cursor.py
35
36
37
38
39
40
41
42
def get_cursor(self) -> str:
    """
    Get the current cursor string.

    Returns:
        str: The current cursor string
    """
    return self._cursor

is_finished()

Check if the cluster scan is finished.

Returns:

Name Type Description
bool bool

True if the scan is finished, False otherwise

Source code in doc-gen/valkey-glide/python/glide-sync/glide_sync/sync_commands/cluster_scan_cursor.py
44
45
46
47
48
49
50
51
def is_finished(self) -> bool:
    """
    Check if the cluster scan is finished.

    Returns:
        bool: True if the scan is finished, False otherwise
    """
    return self._cursor == FINISHED_SCAN_CURSOR