GCP Memorystore IAM Authentication
使用 IAM 驗證將 LiteLLM 的 Redis 快取連線到 GCP Memorystore,讓 proxy 以服務帳戶進行驗證, 且您的設定中不會有 Redis 密碼。
資訊
目前僅支援 Redis 叢集的 Redis IAM 驗證。關於 AWS ElastiCache 和 Valkey,請參閱 AWS ElastiCache IAM Authentication。關於 Azure Cache for Redis 和 Azure Managed Redis,請參閱 Azure Redis Entra ID Authentication。
uv add google-cloud-iam
- 在 config.yaml 中設定
- 在 .env 中設定
適用於具備 GCP IAM 的 Redis 叢集:
litellm_settings:
cache: True
cache_params:
type: redis
redis_startup_nodes:
[{ "host": "10.128.0.2", "port": 6379 }, { "host": "10.128.0.2", "port": 11008 }]
gcp_service_account: "projects/-/serviceAccounts/your-sa@project.iam.gserviceaccount.com"
ssl: true
ssl_cert_reqs: null
ssl_check_hostname: false
您可以在 .env 中設定 GCP IAM Redis 驗證:
適用於 Redis 叢集:
REDIS_CLUSTER_NODES='[{"host": "10.128.0.2", "port": 6379}, {"host": "10.128.0.2", "port": 11008}]'
REDIS_GCP_SERVICE_ACCOUNT="projects/-/serviceAccounts/your-sa@project.iam.gserviceaccount.com"
REDIS_GCP_SSL_CA_CERTS="./server-ca.pem"
REDIS_SSL="True"
REDIS_SSL_CERT_REQS="None"
REDIS_SSL_CHECK_HOSTNAME="False"
GCP 驗證設定
請確認您的 GCP 憑證已設定:
# Option 1: Service account key file
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account-key.json"
# Option 2: If running on GCP compute instance with service account attached
# No additional setup needed
在 proxy 執行後,請使用
/cache/ping 確認連線。關於 Redis
快取的其他所有內容,包括叢集拓撲與 TLS,請參閱 Redis and Valkey。