website/docs/azure/quickstart.md
This guide will walk you through creating and connecting to your first Azure Cosmos DB Garnet Cache.
During provisioning, you must either create a new virtual network for your cache or use an existing one. All application access to the cache must be from within this virtual network.
Azure Cosmos DB Garnet Cache uses Azure RBAC to grant access to supported Redis commands. Assigning Microsoft Entra ID RBAC roles is required to use data plane operations. No roles are assigned by default, including to the resource creator. There are several built-in roles, see data plane built-in roles to choose the most appropriate role assignments for each user. Role assignments can take 5-10 minutes to become effective.
Roles can be assigned at various scopes, in both examples below we will assign the Garnet Data Contributor role at the Azure Cosmos DB Garnet Cache resource scope. To assign Azure roles, you must have Microsoft.Authorization/roleAssignments/write permissions, such as Owner or User Access Administrator.
You can assign data access roles for the Azure Cosmos DB Garnet Cache clusters using the Access control (IAM) page.
You can assign data access roles for the Azure Cosmos DB Garnet Cache clusters using the Azure CLI.
az login
# Get your own Object ID
az ad signed-in-user show --query id -o tsv
# Or get another user's Object ID
az ad user show --id "[email protected]" --query id -o tsv
# Set your parameters
userObjectId="your-object-id-from-step-1"
subscriptionId="your-subscription-id"
resourceGroup="your-garnet-cache-resource-group"
cacheName="your-garnet-cache-name"
# Assign Garnet Data Contributor to yourself
az role assignment create \
--assignee $userObjectId \
--role "Garnet Data Contributor" \
--scope "/subscriptions/$subscriptionId/resourceGroups/$resourceGroup/providers/Microsoft.DocumentDB/garnetClusters/$cacheName"
Azure Cosmos DB Garnet Cache does not provide public IP addresses or DNS and can't be accessed from the public internet. Cache nodes are provisioned on the virtual network provided during cluster creation. They are accessible via the internal IP addresses from the same virtual network. Your client machine must use the same network.
You can create a new virtual machine in the same virtual network as your Azure Cosmos DB Garnet cache.
You can use an existing VM or host machine in the same virtual network as your Azure Cosmos DB Garnet Cache. If your VM is in a different virtual network, set up virtual network peering. Ensure that the IP address spaces of the two virtual networks do not overlap. Once peering is established successfully, the client application in one virtual network can access the cache endpoints on the other network using their local IP addresses.
Now you're ready to connect to your Azure Cosmos DB Garnet Cache!
# Get your own Object ID
az login
az ad signed-in-user show --query id -o tsv
az account get-access-token --scope https://cosmos.azure.com/.default --query accessToken -o tsv
Find the IP address of your cache nodes. Redis clients can connect to one of the node IP addresses and get the list of all replicas and ports automatically.
Connect using a Redis client. You can use any Redis client of your choice to connect to the cluster. Connecting with the Redis CLI is optional, and it provides a quick way to test data access for your cache.
sudo apt-get install redis-tools
# Replace with your actual values
export USER_OBJECT_ID="your-object-id-from-step-1"
export ACCESS_TOKEN="your-access-token-from-step-2"
export GARNET_HOST="10.0.0.5" # Any IP from step 3
export GARNET_PORT="6379"
# Connect
redis-cli -h $GARNET_HOST -p $GARNET_PORT --tls -c --user $USER_OBJECT_ID --pass $ACCESS_TOKEN
# Test connection
PING
# Set and get values
SET mykey "Hello Garnet Cache!"
GET mykey
# Explore cluster topology
CLUSTER NODES
CLUSTER INFO
# Test data types
HSET user:1 name "John" age 30
HGET user:1 name