“用于 Redis 的 Azure 缓存”示例Azure Cache for Redis samples

本主题提供 Azure Redis 缓存示例列表,包括连接到缓存、从缓存读取数据和将数据写入缓存,以及使用 ASP.NET Azure Redis 缓存提供程序等方案。This topic provides a list of Azure Cache for Redis samples, covering scenarios such as connecting to a cache, reading and writing data to and from a cache, and using the ASP.NET Azure Cache for Redis providers. 有些示例是可下载的项目,有些示例提供了分步指南并包含代码片段但没有链接到可下载的项目。Some of the samples are downloadable projects, and some provide step-by-step guidance and include code snippets but do not link to a downloadable project.

Hello world 示例Hello world samples

本部分中的示例显示了使用各种语言和 Redis 客户端连接到 Azure Redis 缓存实例、从缓存中读取数据以及向其中写入数据方面的基础知识。The samples in this section show the basics of connecting to an Azure Cache for Redis instance and reading and writing data to the cache using a variety of languages and Redis clients.

Hello world 示例展示了如何使用 StackExchange.Redis .NET 客户端执行不同的缓存操作。The Hello world sample shows how to perform various cache operations using the StackExchange.Redis .NET client.

此示例演示如何:This sample shows how to:

  • 使用不同的连接选项Use various connection options
  • 使用同步和异步操作与缓存相互读取和写入对象Read and write objects to and from the cache using synchronous and asynchronous operations
  • 使用 Redis MGET/MSET 命令返回指定键的值Use Redis MGET/MSET commands to return values of specified keys
  • 执行 Redis 事务操作Perform Redis transactional operations
  • 处理 Redis 列表和排序集Work with Redis lists and sorted sets
  • 使用 JsonConvert 序列化程序存储.NET 对象Store .NET objects using JsonConvert serializers
  • 使用 Redis 集实现标记Use Redis sets to implement tagging
  • 使用 Redis 群集Work with Redis Cluster

有关详细信息,请参阅 GitHub 上的 StackExchange.Redis;有关更多的使用方案,请参阅 StackExchange.Redis.Tests 单元测试。For more information, see the StackExchange.Redis documentation on GitHub, and for more usage scenarios see the StackExchange.Redis.Tests unit tests.

如何将 Azure Redis 缓存与 Python 配合使用展示了如何使用 Python 和 redis-py 客户端开始使用 Azure Redis 缓存。How to use Azure Cache for Redis with Python shows how to get started with Azure Cache for Redis using Python and the redis-py client.

在缓存中处理 .NET 对象演示了如何对 .NET 对象进行序列化,以便可以将它写入到 Azure Redis 缓存实例以及从中读取它。Work with .NET objects in the cache shows you one way to serialize .NET objects so you can write them to and read them from an Azure Cache for Redis instance.

将 Azure Redis 缓存用作 ASP.NET SignalR 的横向扩展基架Use Azure Cache for Redis as a Scale out Backplane for ASP.NET SignalR

将 Azure Redis 缓存用作 ASP.NET SignalR 的横向扩展基架示例演示如何将 Azure Redis 缓存用作 SignalR 基架。The Use Azure Cache for Redis as a Scale out Backplane for ASP.NET SignalR sample demonstrates how you can use Azure Cache for Redis as a SignalR backplane. 有关基架的更多信息,请参阅 采用 Redis 的 SignalR 扩展For more information about backplane, see SignalR Scaleout with Redis.

Azure Redis 缓存客户查询示例Azure Cache for Redis customer query sample

此示例对从缓存访问数据与从持久存储访问数据时的性能进行了比较。This sample demonstrates compares performance between accessing data from a cache and accessing data from persistence storage. 此示例有两个项目。This sample has two projects.

ASP.NET 会话状态和输出缓存ASP.NET Session State and Output Caching

使用 Azure Redis 缓存存储 ASP.NET SessionState 和 OutputCache示例演示如何使用 Azure Redis 缓存通过为 Redis 使用 SessionState 和 OutputCache 提供程序来存储 ASP.NET 会话和输出缓存。The Use Azure Cache for Redis to store ASP.NET SessionState and OutputCache sample demonstrates how you to use Azure Cache for Redis to store ASP.NET Session and Output Cache using the SessionState and OutputCache providers for Redis.

使用 MAML 管理 Azure Redis 缓存Manage Azure Cache for Redis with MAML

使用 Azure Management Libraries 管理 Azure Redis 缓存示例展示如何使用 Azure Management Libraries 来管理(创建/更新/删除)缓存。The Manage Azure Cache for Redis using Azure Management Libraries sample demonstrates how can you use Azure Management Libraries to manage - (Create/ Update/ delete) your Cache.

自定义监视示例Custom monitoring sample

访问 Azure Redis 缓存监视数据示例演示了如何在 Azure 门户外访问 Azure Redis 缓存的监视数据。The Access Azure Cache for Redis Monitoring data sample demonstrates how you can access monitoring data for your Azure Cache for Redis outside of the Azure Portal.

使用 PHP 和 Redis 编写的 Twitter 式克隆A Twitter-style clone written using PHP and Redis

Retwis 示例是 Redis Hello World。The Retwis sample is the Redis Hello World. 它是最小的 Twitter 样式的社交网络克隆使用 Redis 和 PHP 编写使用 Predis 客户端。It is a minimal Twitter-style social network clone written using Redis and PHP using the Predis client. 源代码旨在是非常简单,并且在同一时间以显示其他 Redis 数据结构。The source code is designed to be very simple and at the same time to show different Redis data structures.

带宽监视器Bandwidth monitor

带宽监视器 示例允许监视客户端上使用的带宽。The Bandwidth monitor sample allows you to monitor the bandwidth used on the client. 要测量带宽、请在缓存客户端计算机上运行该示例,对缓存执行调用,并观察带宽监视器示例报告的带宽。To measure the bandwidth, run the sample on the cache client machine, make calls to the cache, and observe the bandwidth reported by the bandwidth monitor sample.