Skip to content

Commit a997803

Browse files
Fixed init_commands to be agnostic no matter the arg size (#137)
1 parent 26acb37 commit a997803

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "redisbench-admin"
3-
version = "0.2.7"
3+
version = "0.2.8"
44
description = "Redis benchmark run helper. A wrapper around Redis and Redis Modules benchmark tools ( ftsb_redisearch, memtier_benchmark, redis-benchmark, aibench, etc... )."
55
authors = ["filipecosta90 <[email protected]>"]
66
readme = "README.md"

redisbench_admin/run/common.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
# Copyright (c) 2021., Redis Labs Modules
44
# All rights reserved.
55
#
6-
6+
import csv
77
import datetime as dt
88
import logging
99
import os
1010

11+
import redis
12+
1113
from redisbench_admin.run.redis_benchmark.redis_benchmark import (
1214
prepare_redis_benchmark_command,
1315
)
@@ -234,6 +236,30 @@ def execute_init_commands(benchmark_config, r, dbconfig_keyname="dbconfig"):
234236
cmds = k["init_commands"]
235237
if cmds is not None:
236238
for cmd in cmds:
237-
cmd_split = cmd.split(None, 2)
238-
stdout = r.execute_command(*cmd_split)
239-
print(stdout)
239+
is_array = False
240+
if '"' in cmd:
241+
cols = []
242+
for lines in csv.reader(
243+
cmd,
244+
quotechar='"',
245+
delimiter=" ",
246+
quoting=csv.QUOTE_ALL,
247+
skipinitialspace=True,
248+
):
249+
if lines[0] != " " and len(lines[0]) > 0:
250+
cols.append(lines[0])
251+
cmd = cols
252+
is_array = True
253+
try:
254+
logging.info("Sending init command: {}".format(cmd))
255+
if is_array:
256+
stdout = r.execute_command(*cmd)
257+
else:
258+
stdout = r.execute_command(cmd)
259+
logging.info("Command reply: {}".format(stdout))
260+
except redis.connection.ConnectionError as e:
261+
logging.error(
262+
"Error establishing connection to Redis. Message: {}".format(
263+
e.__str__()
264+
)
265+
)

0 commit comments

Comments
 (0)