0
# Google Cloud Redis
1
2
Google Cloud Redis API client library provides Python bindings for managing Google Cloud Memorystore for Redis instances. This fully managed Redis service delivers extreme performance for applications running on Google Cloud without the operational burden of managing complex Redis deployments.
3
4
## Package Information
5
6
- **Package Name**: google-cloud-redis
7
- **Language**: Python
8
- **Installation**: `pip install google-cloud-redis`
9
- **API Service**: redis.googleapis.com
10
- **Library Type**: GAPIC Auto-generated
11
12
## Core Imports
13
14
```python
15
from google.cloud import redis
16
```
17
18
For specific API versions:
19
20
```python
21
from google.cloud import redis_v1
22
from google.cloud import redis_v1beta1
23
```
24
25
Direct client imports:
26
27
```python
28
from google.cloud.redis import CloudRedisClient, CloudRedisAsyncClient
29
```
30
31
For specific types and request/response classes:
32
33
```python
34
from google.cloud.redis import (
35
Instance,
36
InputConfig,
37
OutputConfig,
38
CreateInstanceRequest,
39
ListInstancesRequest
40
)
41
```
42
43
## Basic Usage
44
45
```python
46
from google.cloud.redis import CloudRedisClient
47
48
# Initialize the client
49
client = CloudRedisClient()
50
51
# List all Redis instances in a location
52
project_id = "your-project-id"
53
location = "us-central1"
54
parent = f"projects/{project_id}/locations/{location}"
55
56
instances = client.list_instances(parent=parent)
57
for instance in instances:
58
print(f"Instance: {instance.name}")
59
print(f"Host: {instance.host}:{instance.port}")
60
print(f"State: {instance.state}")
61
62
# Get details of a specific instance
63
instance_name = f"projects/{project_id}/locations/{location}/instances/my-redis"
64
instance = client.get_instance(name=instance_name)
65
print(f"Redis version: {instance.redis_version}")
66
print(f"Memory size: {instance.memory_size_gb}GB")
67
68
# Create a new Redis instance
69
from google.cloud.redis import Instance
70
71
new_instance = Instance(
72
display_name="My Redis Instance",
73
tier=Instance.Tier.STANDARD_HA,
74
memory_size_gb=1,
75
redis_version="REDIS_6_X"
76
)
77
78
operation = client.create_instance(
79
parent=parent,
80
instance_id="my-new-redis",
81
instance=new_instance
82
)
83
84
# Wait for the operation to complete
85
result = operation.result()
86
print(f"Created instance: {result.name}")
87
```
88
89
## Architecture
90
91
The google-cloud-redis client library is built on Google's API Client (GAPIC) framework, providing:
92
93
- **Client Classes**: Synchronous (`CloudRedisClient`) and asynchronous (`CloudRedisAsyncClient`) clients
94
- **Type System**: Protocol buffer-based request, response, and data types
95
- **Transport Layer**: Support for gRPC and REST transports with automatic retry and pagination
96
- **Operation Management**: Long-running operations for instance lifecycle management
97
- **Authentication**: Integration with Google Cloud authentication and service accounts
98
99
## Capabilities
100
101
### Redis Client Management
102
103
Core client functionality for authentication, configuration, and connection management to the Cloud Redis API.
104
105
```python { .api }
106
class CloudRedisClient:
107
def __init__(
108
self,
109
*,
110
credentials: Optional[Credentials] = None,
111
transport: Optional[Union[str, CloudRedisTransport]] = None,
112
client_options: Optional[ClientOptions] = None
113
) -> None: ...
114
115
class CloudRedisAsyncClient:
116
def __init__(
117
self,
118
*,
119
credentials: Optional[Credentials] = None,
120
transport: Optional[Union[str, CloudRedisTransport]] = None,
121
client_options: Optional[ClientOptions] = None
122
) -> None: ...
123
```
124
125
[Redis Client Management](./client-management.md)
126
127
### Instance Operations
128
129
Complete lifecycle management of Redis instances including creation, configuration updates, deletion, and status monitoring.
130
131
```python { .api }
132
def list_instances(
133
self,
134
*,
135
parent: str,
136
page_size: Optional[int] = None,
137
page_token: Optional[str] = None
138
) -> ListInstancesPager: ...
139
140
def get_instance(self, *, name: str) -> Instance: ...
141
142
def create_instance(
143
self,
144
*,
145
parent: str,
146
instance_id: str,
147
instance: Instance
148
) -> Operation: ...
149
150
def update_instance(
151
self,
152
*,
153
update_mask: FieldMask,
154
instance: Instance
155
) -> Operation: ...
156
157
def delete_instance(self, *, name: str) -> Operation: ...
158
```
159
160
[Instance Operations](./instance-operations.md)
161
162
### Data Management
163
164
Import and export functionality for moving data in and out of Redis instances using Google Cloud Storage.
165
166
```python { .api }
167
def import_instance(
168
self,
169
*,
170
name: str,
171
input_config: InputConfig
172
) -> Operation: ...
173
174
def export_instance(
175
self,
176
*,
177
name: str,
178
output_config: OutputConfig
179
) -> Operation: ...
180
```
181
182
[Data Management](./data-management.md)
183
184
### Maintenance and Operations
185
186
Advanced instance management including maintenance scheduling, failover operations, Redis version upgrades, and authentication.
187
188
```python { .api }
189
def upgrade_instance(
190
self,
191
*,
192
name: str,
193
redis_version: str
194
) -> Operation: ...
195
196
def failover_instance(
197
self,
198
*,
199
name: str,
200
data_protection_mode: FailoverInstanceRequest.DataProtectionMode = ...
201
) -> Operation: ...
202
203
def get_instance_auth_string(
204
self, *, name: str
205
) -> InstanceAuthString: ...
206
207
def reschedule_maintenance(
208
self,
209
*,
210
name: str,
211
reschedule_type: RescheduleMaintenanceRequest.RescheduleType,
212
schedule_time: Optional[Timestamp] = None
213
) -> Operation: ...
214
```
215
216
[Maintenance and Operations](./maintenance-operations.md)
217
218
## Core Types
219
220
### Instance
221
222
```python { .api }
223
class Instance:
224
name: str
225
display_name: str
226
labels: Dict[str, str]
227
location_id: str
228
alternative_location_id: str
229
redis_version: str
230
reserved_ip_range: str
231
secondary_ip_range: str
232
host: str
233
port: int
234
current_location_id: str
235
create_time: Timestamp
236
state: Instance.State
237
status_message: str
238
redis_configs: Dict[str, str]
239
tier: Instance.Tier
240
memory_size_gb: int
241
authorized_network: str
242
persistence_iam_identity: str
243
connect_mode: Instance.ConnectMode
244
auth_enabled: bool
245
server_ca_certs: List[TlsCertificate]
246
transit_encryption_mode: Instance.TransitEncryptionMode
247
maintenance_policy: MaintenancePolicy
248
maintenance_schedule: MaintenanceSchedule
249
replica_count: int
250
nodes: List[NodeInfo]
251
read_endpoint: str
252
read_endpoint_port: int
253
read_replicas_mode: Instance.ReadReplicasMode
254
customer_managed_key: str
255
persistence_config: PersistenceConfig
256
suspension_reasons: List[Instance.SuspensionReason]
257
maintenance_version: str
258
available_maintenance_versions: List[str]
259
260
class Instance.State(Enum):
261
STATE_UNSPECIFIED = 0
262
CREATING = 1
263
READY = 2
264
UPDATING = 3
265
DELETING = 4
266
REPAIRING = 5
267
MAINTENANCE = 6
268
IMPORTING = 8
269
FAILING_OVER = 9
270
271
class Instance.Tier(Enum):
272
TIER_UNSPECIFIED = 0
273
BASIC = 1
274
STANDARD_HA = 3
275
276
class Instance.ConnectMode(Enum):
277
CONNECT_MODE_UNSPECIFIED = 0
278
DIRECT_PEERING = 1
279
PRIVATE_SERVICE_ACCESS = 2
280
281
class Instance.TransitEncryptionMode(Enum):
282
TRANSIT_ENCRYPTION_MODE_UNSPECIFIED = 0
283
SERVER_AUTHENTICATION = 1
284
DISABLED = 2
285
286
class Instance.ReadReplicasMode(Enum):
287
READ_REPLICAS_MODE_UNSPECIFIED = 0
288
READ_REPLICAS_DISABLED = 1
289
READ_REPLICAS_ENABLED = 2
290
291
class Instance.SuspensionReason(Enum):
292
SUSPENSION_REASON_UNSPECIFIED = 0
293
CUSTOMER_MANAGED_KEY_ISSUE = 1
294
```
295
296
### Configuration Types
297
298
```python { .api }
299
class PersistenceConfig:
300
persistence_mode: PersistenceConfig.PersistenceMode
301
rdb_snapshot_period: PersistenceConfig.SnapshotPeriod
302
rdb_next_snapshot_time: Timestamp
303
rdb_snapshot_start_time: Timestamp
304
305
class PersistenceConfig.PersistenceMode(Enum):
306
PERSISTENCE_MODE_UNSPECIFIED = 0
307
DISABLED = 1
308
RDB = 2
309
310
class PersistenceConfig.SnapshotPeriod(Enum):
311
SNAPSHOT_PERIOD_UNSPECIFIED = 0
312
ONE_HOUR = 3
313
SIX_HOURS = 4
314
TWELVE_HOURS = 5
315
TWENTY_FOUR_HOURS = 6
316
317
class MaintenancePolicy:
318
create_time: Timestamp
319
update_time: Timestamp
320
description: str
321
weekly_maintenance_window: List[WeeklyMaintenanceWindow]
322
323
class WeeklyMaintenanceWindow:
324
day: DayOfWeek
325
start_time: TimeOfDay
326
duration: Duration
327
328
class MaintenanceSchedule:
329
start_time: Timestamp
330
end_time: Timestamp
331
can_reschedule: bool
332
schedule_deadline_time: Timestamp
333
```
334
335
## Notes
336
337
**API Method Parameters**: All client methods accept additional standard gRPC parameters (`retry`, `timeout`, `metadata`) that are omitted from the documentation for clarity. These parameters provide fine-grained control over request behavior and are documented in the Google API Client libraries documentation.