or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

index.mdredis-cache-operations.md

index.mddocs/

0

# Google Cloud NDB Redis Cache

1

2

Type stubs for Google Cloud NDB's Redis caching functionality. This package provides type annotations for the `RedisCache` class, which enables Redis-based global caching for Google Cloud NDB operations.

3

4

## Package Information

5

6

- **Package Name**: google-cloud-ndb

7

- **Package Type**: Type stub package (PEP 561)

8

- **Language**: Python

9

- **Installation**: `pip install google-cloud-ndb`

10

- **Redis Cache**: Part of the NDB global caching system

11

12

## Core Imports

13

14

```python

15

from google.cloud.ndb import RedisCache

16

```

17

18

Complete import for global cache types:

19

20

```python

21

from google.cloud.ndb import GlobalCache, RedisCache, MemcacheCache

22

```

23

24

## Basic Usage

25

26

```python

27

from google.cloud.ndb import RedisCache

28

import redis

29

30

# Create Redis client

31

redis_client = redis.Redis(host='localhost', port=6379, db=0)

32

33

# Create Redis cache for NDB operations

34

cache = RedisCache(redis_client, strict_read=True, strict_write=True)

35

36

# Use with NDB context (typical usage)

37

from google.cloud import ndb

38

39

client = ndb.Client()

40

with client.context(global_cache=cache):

41

# Your NDB operations will now use Redis caching

42

pass

43

```

44

45

## Architecture

46

47

The Google Cloud NDB Redis cache implementation provides a Redis-backed global cache for NDB operations:

48

49

- **GlobalCache Interface**: Abstract base class defining the caching contract

50

- **RedisCache Implementation**: Redis-specific implementation of global caching

51

- **Pipeline Support**: Efficient batch operations using Redis pipelines

52

- **Error Handling**: Transient error handling and strict read/write modes

53

- **Environment Configuration**: Support for configuration via environment variables

54

55

## Capabilities

56

57

### Redis Cache Implementation

58

59

Redis-backed global cache implementation for Google Cloud NDB with support for all standard cache operations.

60

61

```python { .api }

62

class RedisCache(GlobalCache):

63

transient_errors: Any

64

redis: Any

65

strict_read: Any

66

strict_write: Any

67

68

def __init__(self, redis, strict_read: bool = ..., strict_write: bool = ...) -> None: ...

69

70

@classmethod

71

def from_environment(cls, strict_read: bool = ..., strict_write: bool = ...) -> Self: ...

72

73

@property

74

def pipes(self): ...

75

76

def get(self, keys): ...

77

def set(self, items, expires: Incomplete | None = ...) -> None: ...

78

def delete(self, keys) -> None: ...

79

def watch(self, items) -> None: ...

80

def unwatch(self, keys) -> None: ...

81

def compare_and_swap(self, items, expires: Incomplete | None = ...) -> None: ...

82

def clear(self) -> None: ...

83

```

84

85

[Redis Cache Operations](./redis-cache-operations.md)

86

87

## Types

88

89

```python { .api }

90

import abc

91

from _typeshed import Incomplete

92

from typing import Any

93

from typing_extensions import Self

94

95

class GlobalCache(metaclass=abc.ABCMeta):

96

"""Abstract base class for global cache implementations."""

97

__metaclass__: Any

98

transient_errors: Any

99

strict_read: bool

100

strict_write: bool

101

102

@abc.abstractmethod

103

def get(self, keys): ...

104

105

@abc.abstractmethod

106

def set(self, items, expires: Incomplete | None = ...): ...

107

108

@abc.abstractmethod

109

def delete(self, keys): ...

110

111

@abc.abstractmethod

112

def watch(self, items): ...

113

114

@abc.abstractmethod

115

def unwatch(self, keys): ...

116

117

@abc.abstractmethod

118

def compare_and_swap(self, items, expires: Incomplete | None = ...): ...

119

120

@abc.abstractmethod

121

def clear(self): ...

122

123

class RedisCache(GlobalCache):

124

"""Redis implementation of GlobalCache for NDB operations."""

125

transient_errors: Any

126

redis: Any

127

strict_read: Any

128

strict_write: Any

129

130

def __init__(self, redis, strict_read: bool = ..., strict_write: bool = ...) -> None: ...

131

132

@classmethod

133

def from_environment(cls, strict_read: bool = ..., strict_write: bool = ...) -> Self: ...

134

```