Export (0) Print
Expand All

Develop in other languages for Azure Redis Cache

Updated: February 20, 2015

.NET Azure Redis Cache applications developed in Visual Studio can use the StackExchange.Redis cache client, but there are also many other Redis clients that can be used to access caches hosted on Azure Redis Cache. While each client is different, they use the same information to connect to Azure Redis Cache. This topic provides an overview of reviewing cache properties and access keys, and how to use this information to connect to Azure Redis Cache. For code snippets using C#, see Caching data in Azure Redis Cache.

Caches can be accessed in the Azure Management Portal Preview using the Browse blade.

Azure Redis Cache Browse Blade

Click Caches to view your caches.

Azure Redis Cache Browse Cache List

Select the desired cache to view the properties for that cache.

Azure Redis Cache New Cache Overview

Click Properties to view information about your cache, including the cache endpoint and ports.

Azure Redis Cache Properties

The host name takes the format yourcache.redis.cache.windows.net. Different clients may refer to this as the endpoint. If your client supports SSL, the SSL Host is *.redis.cache.windows.net. 6379 is the port for non-SSL cache access, and 6380 is the port when using SSL.

noteNote
Azure Redis Cache supports SSL to secure cache/client applications. Clients that do not support SSL should use the non-SSL port. In most cases, this is the default port if ssl=true is not specified.

Click Manage Keys to view or regenerate the access keys for your cache. These keys are used along with the host name and ports from the Properties blade by the clients connecting to your cache.

Azure Redis Cache Manage Keys

Access keys are used to provide access to the cache. Different clients may refer to this as the key or password.

One popular client for Redis cache is Predis. This section provides an overview of connecting to your Azure Redis Cache instance using Predis.

noteNote
For complete documentation and instructions on using the Predis cache client, see the Predis github site.

Include the following items at the top of your PHP file from which you want to access the cache.

<?php
require "predis/autoloader.php";
Predis\Autoloader::register();
...
noteNote
If you already include a file that has these statements, you don’t need to add them again.

To connect to the cache, you can use a function similar to the following example. Use the host name and port from your Azure Redis Cache instance’s Properties blade, and the access key from the Manage keys blade.

function redisLink() {
    static $r = false;

    if ($r) return $r;
     $r = new Predis\Client('tcp://<cache endpoint>:<port>');
     $r->auth("<access key>");

    return $r;
}

You can call the redisLink function when you connect to the cache to add and retrieve items from the cache.

function loadUserInfo($userid) {
    global $User;

    $r = redisLink();
    $User['id'] = $userid;
    $User['username'] = $r->get("uid:$userid:username");
    return true;
}

Show:
© 2015 Microsoft