你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

用于 Python 的 Azure Redis 缓存库Azure Redis Cache libraries for Python

概述Overview

Azure Redis 缓存基于流行的开源 Redis 项目。Azure Redis Cache is based on the popular open source Redis project. 使用它可以访问 Microsoft 管理的、可从 Azure 应用访问的安全专用 Redis 实例。It gives you access to a secure, dedicated Redis instance, managed by Microsoft and accessible from your Azure apps.

Redis 是一种高级键值存储,其中键可包含数据结构,例如字符串、哈希、列表、集和排序集。Redis is an advanced key-value store, where keys can contain data structures such as strings, hashes, lists, sets, and sorted sets. Redis 支持针对这些数据类型的一组原子操作。Redis supports a set of atomic operations on these data types.

详细了解 Azure Redis 缓存Learn more about Azure Redis Cache.

管理 APIManagement API

使用 Redis 管理 API 在订阅中创建和管理 Redis 资源。Create and manage your Redis resources in your subscription with the Redis management API.

pip install redis
pip install azure-mgmt-redis

示例Example

以下示例创建新的 Redis 缓存:The following example creates a new Redis cache:

from azure.mgmt.redis import RedisManagementClient
from azure.mgmt.redis.models import Sku, RedisCreateOrUpdateParameters

redis_client = RedisManagementClient(
    credentials,
    subscription_id
)
group_name = 'myresourcegroup'
cache_name = 'mycachename'
redis_cache = redis_client.redis.create_or_update(
    group_name,
    cache_name,
    RedisCreateOrUpdateParameters(
        sku = Sku(name = 'Basic', family = 'C', capacity = '1'),
        location = "East US"
    )
)
# redis_cache is a RedisResourceWithAccessKey instance