All Products
Search
Document Center

:How to use redis-cli to run the same command

Last Updated:Dec 29, 2020

Introduction

This topic describes how to run the same command in the redis-cli.

Background

Prerequisites

  • You are using an Alibaba cloud environment, and at least one ECS instance and one Redis instance can communicate with each other.
  • The Linux operating system is running on the ECS instance.

Procedure

Run the same command multiple times

Run the INCR count command 10 times continuously on the ECS instance:

redis-cli -h [$Host] -a [$Password] -r 10 INCR counter

Note:

  • [$Host] is the connection address of the apsaradb for Redis instance.
  • [$Password] is the Password of the Redis instance. If you have enabled virtual private cloud (VPC) password-free authentication, you do not need to enter a password.
  • -r is a redis-cli function that specifies the number of times to run the command.
  • The system runs the command as specified. No latency exists between each operation.

The following command output is returned.

Run the same command continuously at a specified frequency

Run the following command on the ECS instance to query the used memory once every second for 600 seconds or 10 minutes.

redis-cli -h [$Host] -a [$Password] -r 600 -i 1 INFO | grep used_memory:

Note: redis-cli function specifies the interval at which the command is run. Unit: seconds.

The following command output is returned.

Application scope

  • ApsaraDB for Redis