Registry / gcp / google-cloud-redis

google-cloud-redis

JSON →
library2.22.0pypypi✓ verified 24d ago

Google Cloud Redis (also known as Memorystore for Redis) is a fully managed Redis service on Google Cloud Platform. This Python client library allows developers to programmatically create, manage, and interact with Redis instances, supporting operations like instance creation, deletion, and listing. The library is actively maintained by Google and receives frequent updates, typically aligning with broader Google Cloud client library releases.

pip install google-cloud-redis
INSTALL
IMPORT
SIG · GOOGLE-CLOUD-REDIS
G
google-cloud-redis
gcppythonv2.22.0
Install
6.1s avg
Import
1429ms
Disk
69MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.22.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 1.688s · 70.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 6.1s · import 1.170s · 69MB
69MB installed
● package 69MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CloudRedisClient
from google.cloud import redis_v1

This quickstart demonstrates how to initialize the Google Cloud Redis client and list existing Redis instances within a specified Google Cloud project and location. For authentication, ensure `GOOGLE_APPLICATION_CREDENTIALS` is set up (e.g., pointing to a service account key file, or rely on Application Default Credentials).

import os from google.cloud import redis_v1 # Your Google Cloud Project ID project_id = os.environ.get('GOOGLE_CLOUD_PROJECT', 'your-project-id') # The region where you want to list instances, e.g., 'us-central1' location = 'global' # Or a specific region like 'us-central1' def list_redis_instances(project_id: str, location: str): """Lists all Redis instances in a given project and location.""" client = redis_v1.CloudRedisClient() parent = f"projects/{project_id}/locations/{location}" try: # The `list_instances` method returns an iterable of Instance objects. instances = client.list_instances(parent=parent) if not instances: print(f"No Redis instances found in {location} for project {project_id}.") return print(f"Redis instances in {location} for project {project_id}:") for instance in instances: print(f" Name: {instance.name}") print(f" Host: {instance.host}") print(f" Port: {instance.port}") print(f" State: {instance.state.name}") print(f" Tier: {instance.tier.name}") print(f" Memory size (GB): {instance.memory_size_gb}") print(" ---") except Exception as e: print(f"Error listing Redis instances: {e}") if __name__ == "__main__": # Set GOOGLE_CLOUD_PROJECT environment variable or replace 'your-project-id' # Ensure GOOGLE_APPLICATION_CREDENTIALS is set up for authentication list_redis_instances(project_id, location)
Debug
Known issues
gotchaConnecting to a Memorystore for Redis instance from your application typically requires setting up Serverless VPC Access or VPC Network Peering. Direct public IP access is not usually available, and applications must be within the same VPC network or connected via a connector to access the Redis instance. Ensure your application's region aligns with your Redis instance's region for optimal connectivity and performance.
fix
Configure Serverless VPC Access for serverless environments (Cloud Functions, App Engine Standard) or VPC Network Peering for VM-based applications. Ensure client applications are deployed in the same region and VPC as the Redis instance, or have appropriate network connectivity configured.
affects: All
gotchaThis library (`google-cloud-redis`) is for *managing* Google Cloud Redis instances (creating, listing, deleting). To *interact with data* in a Redis instance (e.g., `GET`, `SET`, `HSET`), you need a separate Redis client library like `redis-py`.
fix
Install `redis` (or `redis-py`) using `pip install redis` to perform data operations. Use the host, port, and optional AUTH string obtained from the `google-cloud-redis` client to connect `redis-py`.
affects: All
breakingGoogle Cloud client libraries sometimes introduce breaking changes in major version releases. Always consult the changelog and release notes on the official GitHub repository or Google Cloud documentation when upgrading across major versions to understand API changes, parameter shifts, or behavioral modifications.
fix
Review the official release notes and migration guides for the specific major version you are upgrading to. Test your application thoroughly in a staging environment before deploying to production.
affects: Across major versions (e.g., from 1.x.x to 2.x.x)
gotchaEnabling Redis AUTH for your Memorystore instance provides an authentication token (UUID) for client connections. This enhances security but requires clients to explicitly authenticate. Furthermore, enabling in-transit encryption (TLS) is a critical best practice for securing data communication between your application and the Redis instance.
fix
When creating or updating an instance, enable AUTH and transit encryption. Retrieve the AUTH string via `gcloud redis instances get-auth-string` or the client library, and configure your `redis-py` client (or equivalent) to use this password and TLS when connecting. Ensure your client library supports TLS.
affects: All
gotchaMany Google Cloud operations, particularly instance creation or updates, are long-running operations (LROs). The client library returns an `Operation` object. You must explicitly call `.result()` on this object to wait for the operation to complete and retrieve its final status or result, or handle it asynchronously.
fix
Always handle the `Operation` object returned by methods like `create_instance` or `update_instance`. Use `operation.result()` for synchronous waiting or `operation.add_done_callback()` for asynchronous handling to ensure the operation has finished successfully or to catch errors.
affects: All
breakingThe Google Cloud client libraries require proper authentication to make API calls. The `DefaultCredentialsError` indicates that the application could not find Application Default Credentials (ADC). This is a common issue when running applications locally without `gcloud auth application-default login` or in environments (like Docker containers) without service account keys or ADC configured via environment variables (e.g., `GOOGLE_APPLICATION_CREDENTIALS`).
fix
Ensure your environment is correctly authenticated. For local development, run `gcloud auth application-default login`. For production environments, use service accounts attached to your compute resources (e.g., GKE, Cloud Run, Compute Engine) or provide service account credentials via the `GOOGLE_APPLICATION_CREDENTIALS` environment variable if running outside managed Google Cloud services.
affects: All
breakingThe `google-cloud-redis` client library (and most Google Cloud client libraries) requires authentication to interact with Google Cloud services. This error indicates that Application Default Credentials (ADC) or other authentication methods were not found, preventing the client from initializing and making API calls.
fix
Ensure proper authentication is configured for your environment. For local development, run `gcloud auth application-default login`. For deployed applications, configure a service account, enable Workload Identity, or ensure the underlying compute resource (e.g., GCE VM, Cloud Run, Cloud Functions) has the necessary IAM permissions and scopes.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'google.cloud.redis_v1'
The `google-cloud-redis` Python client library, or its specific API version module `redis_v1`, is not installed or not accessible in the current Python environment.
fix
Ensure the library is installed using pip: `pip install google-cloud-redis`
google.api_core.exceptions.PermissionDenied: 403 Permission denied
The authenticated Google Cloud identity (user or service account) lacks the necessary IAM permissions to perform the requested operation on the Redis instance or project.
fix
Grant the required IAM roles (e.g., `roles/redis.admin`, `roles/owner`) to the service account or user interacting with the Memorystore for Redis API.
google.api_core.exceptions.InvalidArgument: 400 The IP address range ... is already in use
During Redis instance creation, the specified IP address range for private services access conflicts with an existing allocated range in your VPC network, or the network peering is misconfigured.
fix
Choose a different, unallocated IP address range for your Redis instance, ensure the VPC network peering is correctly established, or let Memorystore automatically allocate a range.
google.api_core.exceptions.NotFound: 404 Not found
The Redis instance you are trying to access, update, or delete does not exist or its name/location is incorrect.
fix
Verify the Redis instance ID, project ID, and region/zone are correct, and ensure the instance actually exists in Google Cloud Memorystore for Redis.
Upgrade
Version history
2.22.0latest on PyPI · released Jun 22, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
26 hits · last 30 days
node
22
OpenAI (training)
2
Resources
google-cloud-redis — pip install google-cloud-redis · libregistry