|
1 | 1 | ---
|
2 | 2 | title: Use redis-cli with Azure Cache for Redis
|
3 |
| -description: Learn how to use *redis-cli.exe* as a command-line tool for interacting with an Azure Cache for Redis as a client |
| 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 | author: flang-msft
|
5 | 5 | ms.author: franlanglois
|
6 | 6 | ms.service: cache
|
7 | 7 | ms.topic: conceptual
|
8 |
| -ms.date: 01/25/2022 |
| 8 | +ms.date: 01/04/2024 |
9 | 9 | ---
|
10 | 10 | # Use the Redis command-line tool with Azure Cache for Redis
|
11 | 11 |
|
12 |
| -Use the popular `redis-cli.exe` command-line tool to interact with an Azure Cache for Redis as a client. The tool is available for Windows platforms by downloading the [Redis command-line tools for Windows](https://github.com/MSOpenTech/redis/releases/). |
| 12 | +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. |
13 | 13 |
|
14 |
| -If you want to run the command-line tool on another platform, download open-source Redis from [https://redis.io/download](https://redis.io/download). |
| 14 | +## Install redis-cli |
15 | 15 |
|
16 |
| -## Gather cache access information |
| 16 | +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. |
| 17 | + |
| 18 | +### Linux |
| 19 | + |
| 20 | +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: |
17 | 21 |
|
18 |
| -[!INCLUDE [updated-for-az](../../includes/updated-for-az.md)] |
| 22 | +```linux |
| 23 | +sudo apt-get update |
| 24 | +sudo apt-get install redis |
| 25 | +``` |
| 26 | + |
| 27 | +### Windows |
19 | 28 |
|
20 |
| -You can gather the information needed to access the cache using three methods: |
| 29 | +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). |
21 | 30 |
|
22 |
| -1. Azure CLI using [az redis list-keys](/cli/azure/redis#az-redis-list-keys) |
23 |
| -2. Azure PowerShell using [Get-AzRedisCacheKey](/powershell/module/az.rediscache/Get-AzRedisCacheKey) |
24 |
| -3. Using the Azure portal |
| 31 | +Once WSL is installed, you can install _redis-cli_ using whatever package management is available in the Linux distro you chose for WSL. |
| 32 | + |
| 33 | +## Gather cache access information |
| 34 | + |
| 35 | +You can gather the information needed to access the cache using these methods: |
| 36 | + |
| 37 | +- Azure CLI using [az redis list-keys](/cli/azure/redis#az-redis-list-keys) |
| 38 | +- Azure PowerShell using [Get-AzRedisCacheKey](/powershell/module/az.rediscache/Get-AzRedisCacheKey) |
| 39 | +- Using the Azure portal |
25 | 40 |
|
26 | 41 | In this section, you retrieve the keys from the Azure portal.
|
27 | 42 |
|
28 | 43 | [!INCLUDE [redis-cache-create](includes/redis-cache-access-keys.md)]
|
29 | 44 |
|
30 |
| -## Enable access for redis-cli.exe |
| 45 | +## Connect using redis-cli |
31 | 46 |
|
32 |
| -With Azure Cache for Redis, only the TLS port (6380) is enabled by default. The `redis-cli.exe` command-line tool doesn't support TLS. You have two configuration choices to use it: |
| 47 | +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: |
33 | 48 |
|
34 |
| -1. [Enable the non-TLS port (6379)](cache-configure.md#access-ports) - **This configuration is not recommended** because in this configuration, the access keys are sent via TCP in clear text. This change can compromise access to your cache. The only scenario where you might consider this configuration is when you’re just accessing a test cache. |
| 49 | +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. |
| 50 | +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. |
| 51 | +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. |
35 | 52 |
|
36 |
| -2. Download and install [stunnel](https://www.stunnel.org/downloads.html). |
| 53 | +### Examples |
37 | 54 |
|
38 |
| - Run **stunnel GUI Start** to start the server. |
| 55 | +1. Use the following command to connect to a Basic, Standard, or Premium tier Azure Cache for Redis instance using TLS: |
39 | 56 |
|
40 |
| - Right-click the taskbar icon for the *stunnel* server and select **Show Log Window**. |
| 57 | + ```console |
| 58 | + redis-cli.exe -p 6380 -h yourcachename.redis.cache.windows.net -a YourAccessKey --tls |
| 59 | + ``` |
41 | 60 |
|
42 |
| - On the *stunnel* Log Window menu, select **Configuration** > **Edit Configuration** to open the current configuration file. |
| 61 | +1. Connect to a Basic, Standard, or Premium tier Azure Cache for Redis instance that doesn't use TLS: |
43 | 62 |
|
44 |
| - Add the following entry for `redis-cli.exe` under the **Service definitions** section. Insert your actual cache name in place of `yourcachename`. |
| 63 | + ```console |
| 64 | + redis-cli.exe -p 6379 -h yourcachename.redis.cache.windows.net -a YourAccessKey |
| 65 | + ``` |
45 | 66 |
|
46 |
| - ```properties |
47 |
| - [redis-cli] |
48 |
| - client = yes |
49 |
| - accept = 127.0.0.1:6380 |
50 |
| - connect = yourcachename.redis.cache.windows.net:6380 |
| 67 | +1. Connect to a Basic, Standard, or Premium tier Azure Cache for Redis instance using TLS and clustering: |
| 68 | + |
| 69 | + ```console |
| 70 | + redis-cli.exe -p 6380 -h yourcachename.redis.cache.windows.net -a YourAccessKey --tls -c |
51 | 71 | ```
|
52 | 72 |
|
53 |
| - Save and close the configuration file. |
54 |
| - |
55 |
| - On the stunnel Log Window menu, select **Configuration** > **Reload Configuration**. |
| 73 | +1. Connect to an Enterprise or Enterprise Flash tier cache instance using Enterprise cluster policy with TLS: |
56 | 74 |
|
57 |
| -## Connect using the Redis command-line tool. |
| 75 | + ```console |
| 76 | + redis-cli.exe -p 10000 -h yourcachename.eastus.redisenterprise.cache.azure.net -a YourAccessKey --tls |
| 77 | + ``` |
58 | 78 |
|
59 |
| -When using *stunnel*, run `redis-cli.exe`, and pass only your *port*, and *access key* (primary or secondary) to connect to the cache. |
| 79 | +1. Connect to an Enterprise or Enterprise Flash tier cache instance using OSS cluster policy without TLS: |
60 | 80 |
|
61 |
| -```console |
62 |
| -redis-cli.exe -p 6380 -a YourAccessKey |
63 |
| -``` |
| 81 | + ```console |
| 82 | + redis-cli.exe -p 10000 -h yourcachename.eastus.redisenterprise.cache.azure.net -a YourAccessKey -c |
| 83 | + ``` |
| 84 | + |
| 85 | +### Testing the connection |
64 | 86 |
|
65 |
| - |
| 87 | +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. |
66 | 88 |
|
67 |
| -If you're using a test cache with the **unsecure** non-TLS port, run `redis-cli.exe` and pass your *host name*, *port*, and *access key* (primary or secondary) to connect to the test cache. |
| 89 | +```output |
| 90 | +yourcachename.redis.cache.windows.net:6380> PING |
| 91 | +PONG |
| 92 | +``` |
| 93 | + |
| 94 | +You can also run commands like `SET` and `GET`: |
68 | 95 |
|
69 |
| -```console |
70 |
| -redis-cli.exe -h yourcachename.redis.cache.windows.net -p 6379 -a YourAccessKey |
| 96 | +```output |
| 97 | +yourcachename.redis.cache.windows.net:6380> SET hello world |
| 98 | +OK |
| 99 | +yourcachename.redis.cache.windows.net:6380> GET hello |
| 100 | +"world" |
71 | 101 | ```
|
72 | 102 |
|
73 |
| - |
| 103 | +You're now connected to your Azure Cache for Redis instance using the _redis-cli_. |
| 104 | + |
| 105 | +## redis-cli alternatives |
| 106 | + |
| 107 | +While the _redis-cli_ is a useful tool, you can connect to your cache in other ways for troubleshooting or testing: |
| 108 | + |
| 109 | +- 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. |
| 110 | +- [RedisInsight](https://redis.com/redis-enterprise/redis-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. |
74 | 111 |
|
75 |
| -## Next steps |
| 112 | +## Related content |
76 | 113 |
|
77 |
| -Learn more about using the [Redis Console](cache-configure.md#redis-console) to issue commands. |
| 114 | +Get started by creating a [new Enterprise-tier cache](quickstart-create-redis-enterprise.md) instance. |
0 commit comments