From f132b613308fb5c8d1aa274805019e9775e34ad5 Mon Sep 17 00:00:00 2001 From: girorme Date: Wed, 17 May 2023 21:32:46 -0300 Subject: [PATCH] fix object property and add parameter to set key count Signed-off-by: girorme --- Dockerfile | 2 +- README.md | 3 ++- Scripts/redis_get_set.py | 12 ++++++------ Scripts/redis_orig.json | 3 ++- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index b4996c7..ee47c58 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM python:3.7-slim-stretch RUN apt-get -y update && apt-get -y install build-essential -RUN apt-get -y install gettext-base +RUN apt-get -y install gettext-base redis-tools RUN mkdir /redis-load-test COPY ./Scripts /redis-load-test/Scripts WORKDIR /redis-load-test/Scripts diff --git a/README.md b/README.md index b8398bb..97cdc29 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,8 @@ The use of this utility is not a fancy thing, just need to update the **[redis.j { "redis_host": "18.215.118.208", "redis_port": "6379", - "redis_password": "" + "redis_password": "", + "redis_key_count": "500" } ``` diff --git a/Scripts/redis_get_set.py b/Scripts/redis_get_set.py index 7f09ad6..1aacb79 100755 --- a/Scripts/redis_get_set.py +++ b/Scripts/redis_get_set.py @@ -42,12 +42,12 @@ def query(self, key, command='GET'): result = '' except Exception as e: total_time = int((time.time() - start_time) * 1000) - events.request_failure.fire( + events.request.fire( request_type=command, name=key, response_time=total_time, exception=e) else: total_time = int((time.time() - start_time) * 1000) length = len(result) - events.request_success.fire( + events.request.fire( request_type=command, name=key, response_time=total_time, response_length=length) return result @@ -56,24 +56,24 @@ def write(self, key, value, command='SET'): result = None start_time = time.time() try: - result = self.rc.set(key, value) + result = self.rc.setex(key, 60 * 5, value) if not result: result = '' except Exception as e: total_time = int((time.time() - start_time) * 1000) - events.request_failure.fire( + events.request.fire( request_type=command, name=key, response_time=total_time, exception=e) else: total_time = int((time.time() - start_time) * 1000) length = 1 - events.request_success.fire( + events.request.fire( request_type=command, name=key, response_time=total_time, response_length=length) return result class RedisLocust(User): wait_time = constant(0.1) - key_range = 500 + key_range = int(configs["redis_key_count"]) def __init__(self, *args, **kwargs): super(RedisLocust, self).__init__(*args, **kwargs) diff --git a/Scripts/redis_orig.json b/Scripts/redis_orig.json index 887ffec..bbdde25 100644 --- a/Scripts/redis_orig.json +++ b/Scripts/redis_orig.json @@ -1,5 +1,6 @@ { "redis_host": "$REDIS_HOST", "redis_port": "$REDIS_PORT", - "redis_password": "$REDIS_PW" + "redis_password": "$REDIS_PW", + "redis_key_count": "$REDIS_KEYS" }