Last active
June 10, 2024 18:31
-
-
Save aperezlillo/f72f17d9cd74932ca55103565ad2e045 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Configuración del servidor Redis | |
| REDIS_HOST="localhost" | |
| REDIS_PORT=6379 | |
| REDIS_PASSWORD="mypassword" | |
| # Función para realizar una prueba de uso en Redis usando Docker | |
| function test_redis { | |
| # Realizar un PING y obtener el tiempo de respuesta usando Docker | |
| local start_time=$(date +%s%N) | |
| local response=$(export REDISCLI_AUTH=$REDIS_PASSWORD && redis-cli -h $REDIS_HOST -p $REDIS_PORT ping) | |
| local end_time=$(date +%s%N) | |
| # Calcular el tiempo de respuesta en milisegundos | |
| local duration=$((($end_time - $start_time) / 1000000)) | |
| # Verificar la respuesta | |
| if [[ $response == "PONG" ]]; then | |
| echo "$(date '+%Y-%m-%d %H:%M:%S') - Redis PING successful - Response time: ${duration}ms" | |
| else | |
| echo "$(date '+%Y-%m-%d %H:%M:%S') - Redis PING failed - Response: $response" | |
| fi | |
| } | |
| # Bucle infinito para realizar la prueba cada segundo | |
| while true; do | |
| test_redis | |
| sleep 1 | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment