您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

用于 Java 的 Redis 缓存库Redis Cache libraries for Java

概述Overview

Azure Redis 缓存是基于流行开源 Redis 缓存的安全分布式键值存储。Azure Redis Cache is a secure, distributed key-value store based on the popular open source Redis cache.

若要开始使用 Azure Redis 缓存,请参阅如何将 Azure Redis 缓存与 Java 配合使用To get started with Azure Redis Cache, see How to use Azure Redis Cache with Java.

客户端库Client library

使用开源 Jedis 客户端连接到 Azure Redis 缓存并在缓存中存储和检索值。Connect to Azure Redis Cache and store and retrieve values from the cache using the open-source Jedis client.

向 Maven pom.xml 文件中添加依赖项,以便在项目中使用客户端库。Add a dependency to your Maven pom.xml file to use the client library in your project.

<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>2.9.0</version>
    <type>jar</type>
</dependency>

示例Example

连接到 Azure Redis 并在缓存中插入字符串。Connect to Azure Redis and insert a string into the cache.

JedisShardInfo shardInfo = new JedisShardInfo("<name>.redis.cache.windows.net", 6380, useSsl);
    shardInfo.setPassword("<key>"); /* Use your access key. */
    Jedis jedis = new Jedis(shardInfo);
    jedis.set("foo", "bar");

管理 APIManagement API

使用管理 API 创建和缩放 Azure Redis 资源及管理访问密钥。Create and scale Azure Redis resources and manage access keys to with the management API.

<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-mgmt-redis</artifactId>
    <version>1.3.0</version>
</dependency>

示例Example

双节点标准层中创建新的 Azure Redis 缓存。Create a new Azure Redis Cache in the two-node standard tier.

RedisCache cache = azure.redisCaches().define(redisCacheName1)
    .withRegion(Region.US_CENTRAL)
    .withNewResourceGroup(rgName)
    .withStandardSku();

示例Samples

管理 Azure Redis 缓存Manage Azure Redis Cache

详细了解可在应用中使用的 Azure Redis 缓存示例 Java 代码Explore more sample Java code for Azure Redis Cache you can use in your apps.