|
1 | 1 | ---
|
2 |
| -title: Use redis-cli with Azure Cache for Redis |
3 |
| -description: Learn how to use *redis-cli* as a command-line tool for interacting with an Azure Cache for Redis as a client |
| 2 | +title: Use redis-cli |
| 3 | +description: Learn how to use redis-cli as a command-line tool for interacting with an Azure Cache for Redis as a client. |
4 | 4 |
|
5 | 5 |
|
6 | 6 |
|
7 |
| -ms.topic: conceptual |
8 |
| -ms.date: 01/04/2024 |
| 7 | +ms.topic: how-to |
| 8 | +ms.date: 04/04/2025 |
9 | 9 | appliesto:
|
10 | 10 | - ✅ Azure Cache for Redis
|
11 | 11 | ---
|
12 | 12 | # Use the Redis command-line tool with Azure Cache for Redis
|
13 | 13 |
|
14 |
| -Use the [redis-cli command-line tool](https://redis.io/docs/connect/cli/) to interact with an Azure Cache for Redis as a client. Use this tool to directly interact with your Azure Cache for Redis instance and for debugging and troubleshooting. |
| 14 | +This article describes how to use the [redis-cli command-line interface](https://redis.io/docs/connect/cli/) to interact with Azure Cache for Redis as a client. You can use *redis-cli* to directly interact with your Azure Redis cache instance, and for debugging and troubleshooting. |
| 15 | + |
| 16 | +## Prerequisite |
| 17 | + |
| 18 | +Access to an Azure Cache for Redis server instance. |
15 | 19 |
|
16 | 20 | ## Install redis-cli
|
17 | 21 |
|
18 |
| -The _redis-cli_ tool is installed automatically with the _Redis package_, which is available for multiple operating systems. See the open source [install Redis](https://redis.io/docs/install/install-redis/) guide for the most detailed documentation on your preferred operating system. |
| 22 | +The redis-cli tool installs automatically with the Redis package, which is available for Linux, macOS, and Windows. For detailed installation instructions, see the open-source [Redis documentation](https://redis.io/docs). |
19 | 23 |
|
20 |
| -### Linux |
| 24 | +### Install on Linux |
21 | 25 |
|
22 |
| -The _redis-cli_ runs natively on Linux, and most distributions include a _Redis package_ that contains the _redis-cli_ tool. On Ubuntu, for instance, you install the _Redis package_ with the following commands: |
| 26 | +The redis-cli tool runs natively on Linux, and most Linux distributions include a Redis package that contains redis-cli. For instance, you install the Redis package on Ubuntu with the following commands: |
23 | 27 |
|
24 | 28 | ```linux
|
25 | 29 | sudo apt-get update
|
26 | 30 | sudo apt-get install redis
|
27 | 31 | ```
|
28 | 32 |
|
29 |
| -### Windows |
| 33 | +### Install on Windows |
30 | 34 |
|
31 |
| -The best way to use _redis-cli_ on a Windows computer is to install the [Windows Subsystem for Linux (WSL)](/windows/wsl/about). The Linux subsystem allows you to run linux tools directly on Windows. To install WSL, follow the [WSL installation instructions](/windows/wsl/install). |
| 35 | +The best way to use redis-cli on Windows is to install the [Windows Subsystem for Linux](/windows/wsl/about) (WSL), which allows you to run Linux tools directly on Windows. To install WSL, see [How to install Linux on Windows with WSL](/windows/wsl/install). |
32 | 36 |
|
33 |
| -Once WSL is installed, you can install _redis-cli_ using whatever package management is available in the Linux distro you chose for WSL. |
| 37 | +Once installed, use WSL to install a Linux distro, and then install redis-cli by using the available package management for the Linux distro you chose. The default distro for WSL is Ubuntu. For more information, see the open-source [Redis documentation](https://redis.io/docs). |
34 | 38 |
|
35 |
| -## Gather cache access information |
| 39 | +## Connect using redis-cli |
36 | 40 |
|
37 |
| -You can gather the information needed to access the cache using these methods: |
| 41 | +To use redis-cli to connect to your Azure Redis cache as a client, you must specify the cache host name, port, and keys. You can retrieve these values by the following methods: |
38 | 42 |
|
39 | 43 | - Azure CLI using [az redis list-keys](/cli/azure/redis#az-redis-list-keys)
|
40 | 44 | - Azure PowerShell using [Get-AzRedisCacheKey](/powershell/module/az.rediscache/Get-AzRedisCacheKey)
|
41 |
| -- Using the Azure portal |
| 45 | +- [Azure portal](https://portal.azure.com) |
42 | 46 |
|
43 |
| -In this section, you retrieve the keys from the Azure portal. |
| 47 | +The following section describes how to get these values from the Azure portal. |
44 | 48 |
|
45 | 49 | [!INCLUDE [redis-cache-create](includes/redis-cache-access-keys.md)]
|
46 | 50 |
|
47 |
| -## Connect using redis-cli |
| 51 | +### Get other cache information |
| 52 | + |
| 53 | +You might also need to specify the following options for redis-cli: |
48 | 54 |
|
49 |
| -Open up a shell or terminal on a computer with the _Redis package_ installed. If using WSL, you can [use the Windows Terminal](/windows/wsl/install#ways-to-run-multiple-linux-distributions-with-wsl) to open a Linux command line. Before connecting with redis-cli, check: |
| 55 | +- **TLS**: By default, Azure Redis instances use [TLS](cache-remove-tls-10-11.md) encryption for connections. If the cache uses TLS, you must enable TLS for redis-cli by using the `--tls` option. |
| 56 | +- **Clustering**: If you have a Premium tier cache that uses clustering, or an Enterprise or Enterprise Flash tier cache that uses OSS cluster policy, add the `-c` option to ensure that all shards can be accessed. |
50 | 57 |
|
51 |
| -1. Whether TLS access is needed - By default, Azure Cache for Redis instances use [TLS](cache-remove-tls-10-11.md) encryption for connections. Whenever TLS is used on the server side, TLS on redis-cli must be enabled using the `--tls` option. |
52 |
| -1. The port used - All Enterprise and Enterprise Flash tier caches use port `10000`. Basic, Standard, and Premium tier caches, however, use either port `6379` for non-TLS connections or port `6380` for TLS connections. |
53 |
| -1. Whether the cache instance uses clustering - If you're using a Premium tier cache that uses clustering or an Enterprise/Enterprise Flash tier cache that is using OSS cluster policy, add the `-c`option to ensure all shards can be accessed. |
| 58 | +### Run the redis-cli connection command |
54 | 59 |
|
55 |
| -### Examples |
| 60 | +To connect to your cache, open a shell or terminal on a computer with the Redis package installed. On Windows, you can use WSL with [Windows Terminal](/windows/wsl/install#ways-to-run-multiple-linux-distributions-with-wsl) to open a Linux command line. |
56 | 61 |
|
57 |
| -1. Use the following command to connect to a Basic, Standard, or Premium tier Azure Cache for Redis instance using TLS: |
| 62 | +Run one of the following command lines, depending on your TLS, port, and clustering options. Replace the `<cache name>` and `<access key>` placeholders with the values for your cache. |
58 | 63 |
|
59 |
| - ```console |
60 |
| - redis-cli -p 6380 -h yourcachename.redis.cache.windows.net -a YourAccessKey --tls |
61 |
| - ``` |
| 64 | +- Connect to a Basic, Standard, or Premium tier Azure Redis instance that uses TLS: |
62 | 65 |
|
63 |
| -1. Connect to a Basic, Standard, or Premium tier Azure Cache for Redis instance that doesn't use TLS: |
| 66 | + ```console |
| 67 | + redis-cli -p 6380 -h <cache name>.redis.cache.windows.net -a <access key> --tls |
| 68 | + ``` |
64 | 69 |
|
65 |
| - ```console |
66 |
| - redis-cli -p 6379 -h yourcachename.redis.cache.windows.net -a YourAccessKey |
67 |
| - ``` |
| 70 | +- Connect to a Basic, Standard, or Premium tier Azure Redis instance that doesn't use TLS: |
68 | 71 |
|
69 |
| -1. Connect to a Basic, Standard, or Premium tier Azure Cache for Redis instance using TLS and clustering: |
| 72 | + ```console |
| 73 | + redis-cli -p 6379 -h <cache name>.redis.cache.windows.net -a <access key> |
| 74 | + ``` |
70 | 75 |
|
71 |
| - ```console |
72 |
| - redis-cli -p 6380 -h yourcachename.redis.cache.windows.net -a YourAccessKey --tls -c |
73 |
| - ``` |
| 76 | +- Connect to a Premium tier Azure Redis instance that uses TLS and clustering: |
74 | 77 |
|
75 |
| -1. Connect to an Enterprise or Enterprise Flash tier cache instance using Enterprise cluster policy with TLS: |
| 78 | + ```console |
| 79 | + redis-cli -p 6380 -h <cache name>.redis.cache.windows.net -a <access key> --tls -c |
| 80 | + ``` |
76 | 81 |
|
77 |
| - ```console |
78 |
| - redis-cli -p 10000 -h yourcachename.eastus.redisenterprise.cache.azure.net -a YourAccessKey --tls |
79 |
| - ``` |
| 82 | +- Connect to an Enterprise or Enterprise Flash tier cache instance that uses Enterprise cluster policy with TLS: |
80 | 83 |
|
81 |
| -1. Connect to an Enterprise or Enterprise Flash tier cache instance using OSS cluster policy without TLS: |
| 84 | + ```console |
| 85 | + redis-cli -p 10000 -h <cache name>.eastus.redisenterprise.cache.azure.net -a <access key> --tls |
| 86 | + ``` |
82 | 87 |
|
83 |
| - ```console |
84 |
| - redis-cli -p 10000 -h yourcachename.eastus.redisenterprise.cache.azure.net -a YourAccessKey -c |
85 |
| - ``` |
| 88 | +- Connect to an Enterprise or Enterprise Flash tier cache instance that uses OSS cluster policy without TLS: |
86 | 89 |
|
87 |
| -### Testing the connection |
| 90 | + ```console |
| 91 | + redis-cli -p 10000 -h <cache name>.eastus.redisenterprise.cache.azure.net -a <access key> -c |
| 92 | + ``` |
88 | 93 |
|
89 |
| -Once the connection is established, you can issue commands to your Azure Cache for Redis instance. One easy way to test the connection is to use the [`PING`](https://redis.io/commands/ping/) command. This command returns `PONG` in the console. |
| 94 | +You're now connected to your Azure Redis cache instance. |
90 | 95 |
|
91 |
| -```output |
92 |
| -yourcachename.redis.cache.windows.net:6380> PING |
| 96 | +## Use redis-cli commands with your Azure Redis cache |
| 97 | + |
| 98 | +Once you establish the connection, you can issue commands to your Azure Redis instance at the redis-cli command prompt. The following examples show a connection to a cache named `contoso` that uses port `6380`. |
| 99 | + |
| 100 | +One easy way to test the connection is to use the [`PING`](https://redis.io/commands/ping/) command. The command returns `PONG` in the console. |
| 101 | + |
| 102 | +```console |
| 103 | +contoso.redis.cache.windows.net:6380> PING |
93 | 104 | PONG
|
94 | 105 | ```
|
95 | 106 |
|
96 |
| -You can also run commands like `SET` and `GET`: |
| 107 | +You can also run commands like `SET` and `GET`. |
97 | 108 |
|
98 |
| -```output |
99 |
| -yourcachename.redis.cache.windows.net:6380> SET hello world |
| 109 | +```console |
| 110 | +contoso.redis.cache.windows.net:6380> SET hello world |
100 | 111 | OK
|
101 |
| -yourcachename.redis.cache.windows.net:6380> GET hello |
| 112 | +contoso.redis.cache.windows.net:6380> GET hello |
102 | 113 | "world"
|
103 | 114 | ```
|
104 | 115 |
|
105 |
| -You're now connected to your Azure Cache for Redis instance using the _redis-cli_. |
106 |
| - |
107 |
| -## redis-cli alternatives |
| 116 | +## Alternatives to redis-cli |
108 | 117 |
|
109 |
| -While the _redis-cli_ is a useful tool, you can connect to your cache in other ways for troubleshooting or testing: |
| 118 | +While the redis-cli is a useful tool, you can also use the following other methods to connect to your cache for troubleshooting or testing: |
110 | 119 |
|
111 |
| -- Azure Cache for Redis offers a [Redis Console](cache-configure.md#redis-console) built into the Azure portal where you can issue commands without needing to install the command-line tool. The Redis Console feature is currently only available in the Basic, Standard, and Premium tiers. |
112 |
| -- [RedisInsight](https://redis.io/insight/) is a rich open source graphical tool for issuing Redis commands and viewing the contents of a Redis instance. It works with Azure Cache for Redis and is supported on Linux, Windows, and macOS. |
| 120 | +- [Redis Console](cache-configure.md#redis-console) lets you issue commands without having to install redis-cli. Redis Console is currently available only for Basic, Standard, and Premium tiers. If Redis Console is available, you can use it by selecting **Console** in the top toolbar of your cache **Overview** page in the Azure portal. |
| 121 | +- [RedisInsight](https://redis.io/insight/) is a rich open-source graphical tool for issuing Redis commands and viewing the contents of a Redis instance. RedisInsight works with Azure Cache for Redis and is supported on Linux, Windows, and macOS. |
113 | 122 |
|
114 | 123 | ## Related content
|
115 | 124 |
|
116 |
| -Get started by creating a [new Enterprise-tier cache](quickstart-create-redis-enterprise.md) instance. |
| 125 | +Get started by creating a [new Enterprise-tier cache](quickstart-create-redis-enterprise.md). |
0 commit comments