Azure Cache for Redis development FAQs

This article provides answers to common questions about how to develop for Azure Cache for Redis.

Common questions and answers

This section covers the following FAQs:

How can I get started with Azure Cache for Redis?

There are several ways you can get started with Azure Cache for Redis.

If you don't already have an Azure account, you can:

What do the StackExchange.Redis configuration options do?

StackExchange.Redis has many options. This section talks about some of the common settings. For more detailed information about StackExchange.Redis options, see StackExchange.Redis configuration.

ConfigurationOptions Description Recommendation
AbortOnConnectFail When set to true, the connection will not reconnect after a network failure. Set to false and let StackExchange.Redis reconnect automatically.
ConnectRetry The number of times to repeat connection attempts during initial connect. See the following notes for guidance.
ConnectTimeout Timeout in ms for connect operations. See the following notes for guidance.

Usually the default values of the client are sufficient. You can fine-tune the options based on your workload.

  • Retries

    • For ConnectRetry and ConnectTimeout, the general guidance is to fail fast and retry again. This guidance is based on your workload and how much time on average it takes for your client to issue a Redis command and receive a response.
    • Let StackExchange.Redis automatically reconnect instead of checking connection status and reconnecting yourself. Avoid using the ConnectionMultiplexer.IsConnected property.
    • Snowballing - sometimes you may run into an issue where you are retrying and the retries snowball and never recovers. If snowballing occurs, you should consider using an exponential backoff retry algorithm as described in Retry general guidance published by the Microsoft Patterns & Practices group.
  • Timeout values

    • Consider your workload and set the values accordingly. If you are storing large values, set the timeout to a higher value.
    • Set AbortOnConnectFail to false and let StackExchange.Redis reconnect for you.
    • Use a single ConnectionMultiplexer instance for the application. You can use a LazyConnection to create a single instance that is returned by a Connection property, as shown in Connect to the cache using the ConnectionMultiplexer class.
    • Set the ConnectionMultiplexer.ClientName property to an app instance unique name for diagnostic purposes.
    • Use multiple ConnectionMultiplexer instances for custom workloads.
      • You can follow this model if you have varying load in your application. For example:
      • You can have one multiplexer for dealing with large keys.
      • You can have one multiplexer for dealing with small keys.
      • You can set different values for connection timeouts and retry logic for each ConnectionMultiplexer that you use.
      • Set the ClientName property on each multiplexer to help with diagnostics.
      • This guidance may lead to more streamlined latency per ConnectionMultiplexer.

What Azure Cache for Redis clients can I use?

One of the great things about Redis is that there are many clients supporting many different development languages. For a current list of clients, see Redis clients. For tutorials that cover several different languages and clients, see How to use Azure Cache for Redis and it's sibling articles in the table of contents.

Retrieve host name, ports, and access keys from the Azure portal

To connect to an Azure Cache for Redis instance, cache clients need the host name, ports, and a key for the cache. Some clients might refer to these items by slightly different names. You can get the host name, ports, and keys from the Azure portal.

  • To get the access keys, from your cache left navigation, select Access keys.

    Azure Cache for Redis keys

  • To get the host name and ports, from your cache left navigation, select Properties. The host name is of the form <DNS name>.redis.cache.windows.net.

    Azure Cache for Redis properties

Is there a local emulator for Azure Cache for Redis?

There is no local emulator for Azure Cache for Redis, but you can run the MSOpenTech version of redis-server.exe from the Redis command-line tools on your local machine and connect to it to get a similar experience to a local cache emulator, as shown in the following example:

private static Lazy<ConnectionMultiplexer>
    lazyConnection = new Lazy<ConnectionMultiplexer> (() =>
    {
        // Connect to a locally running instance of Redis to simulate
        // a local cache emulator experience.
        return ConnectionMultiplexer.Connect("127.0.0.1:6379");
    });

public static ConnectionMultiplexer Connection
{
    get
    {
        return lazyConnection.Value;
    }
}

You can optionally configure a redis.conf file to more closely match the default cache settings for your online Azure Cache for Redis if desired.

How can I run Redis commands?

You can use any of the commands listed at Redis commands except for the commands listed at Redis commands not supported in Azure Cache for Redis. You have several options to run Redis commands.

  • If you have a Standard or Premium cache, you can run Redis commands using the Redis Console. The Redis console provides a secure way to run Redis commands in the Azure portal.
  • You can also use the Redis command-line tools. To use them, perform the following steps:
  • Download the Redis command-line tools.
  • Connect to the cache using redis-cli.exe. Pass in the cache endpoint using the -h switch and the key using -a as shown in the following example:
  • redis-cli -h <Azure Cache for Redis name>.redis.cache.windows.net -a <key>

Note

The Redis command-line tools do not work with the TLS port, but you can use a utility such as stunnel to securely connect the tools to the TLS port by following the directions in the How to use the Redis command-line tool with Azure Cache for Redis article.

Why doesn't Azure Cache for Redis have an MSDN class library reference?

Microsoft Azure Cache for Redis is based on the popular open-source in-memory data store, Redis. It can be accessed by a wide variety of Redis clients for many programming languages. Each client has its own API that makes calls to the Azure Cache for Redis instance using Redis commands.

Because each client is different, there is not one centralized class reference on MSDN, and each client maintains its own reference documentation. In addition to the reference documentation, there are several tutorials showing how to get started with Azure Cache for Redis using different languages and cache clients. To access these tutorials, see How to use Azure Cache for Redis and it's sibling articles in the table of contents.

Can I use Azure Cache for Redis as a PHP session cache?

Yes, to use Azure Cache for Redis as a PHP session cache, specify the connection string to your Azure Cache for Redis instance in session.save_path.

Important

When using Azure Cache for Redis as a PHP session cache, you must URL encode the security key used to connect to the cache, as shown in the following example:

session.save_path = "tcp://mycache.redis.cache.windows.net:6379?auth=<url encoded primary or secondary key here>";

If the key is not URL encoded, you may receive an exception with a message like: Failed to parse session.save_path

For more information about using Azure Cache for Redis as a PHP session cache with the PhpRedis client, see PHP Session handler.

What are Redis databases?

Redis Databases are just a logical separation of data within the same Redis instance. The cache memory is shared between all the databases and actual memory consumption of a given database depends on the keys/values stored in that database. For example, a C6 cache has 53 GB of memory, and a P5 has 120 GB. You can choose to put all 53 GB / 120 GB into one database or you can split it up between multiple databases.

Note

When using a Premium Azure Cache for Redis with clustering enabled, only database 0 is available. This limitation is an intrinsic Redis limitation and is not specific to Azure Cache for Redis. For more information, see Do I need to make any changes to my client application to use clustering?.

Next steps

Learn about other Azure Cache for Redis FAQs.