Skip to content

Commit 7eaf350

Browse files
Added support for yaml array in execute_init_commands (#387)
* Added support for array in execute_init_commands * Bumping version from 0.9.30 to 0.9.31
1 parent 863a7e6 commit 7eaf350

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
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.9.29"
3+
version = "0.9.31"
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]>","Redis Performance Group <[email protected]>"]
66
readme = "README.md"

redisbench_admin/run/common.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,13 +418,16 @@ def check_dbconfig_keyspacelen_requirement(
418418

419419
def execute_init_commands(benchmark_config, r, dbconfig_keyname="dbconfig"):
420420
cmds = None
421+
res = 0
421422
if dbconfig_keyname in benchmark_config:
422423
for k in benchmark_config[dbconfig_keyname]:
423424
if "init_commands" in k:
424425
cmds = k["init_commands"]
425426
if cmds is not None:
426427
for cmd in cmds:
427428
is_array = False
429+
if type(cmd) == list:
430+
is_array = True
428431
if '"' in cmd:
429432
cols = []
430433
for lines in csv.reader(
@@ -459,6 +462,7 @@ def execute_init_commands(benchmark_config, r, dbconfig_keyname="dbconfig"):
459462
pass
460463
else:
461464
stdout = r.execute_command(cmd)
465+
res = res + 1
462466
logging.info("Command reply: {}".format(stdout))
463467
except redis.connection.ConnectionError as e:
464468
logging.error(
@@ -467,6 +471,8 @@ def execute_init_commands(benchmark_config, r, dbconfig_keyname="dbconfig"):
467471
)
468472
)
469473

474+
return res
475+
470476

471477
def extract_test_feasible_setups(
472478
benchmark_config, param, default_specs, backwards_compatible=True

tests/test_common.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import yaml
88
from redisbench_admin.utils.remote import push_data_to_redistimeseries
99

10-
1110
from redisbench_admin.export.common.common import (
1211
add_datapoint,
1312
split_tags_string,
@@ -25,6 +24,7 @@
2524
dso_check,
2625
dbconfig_keyspacelen_check,
2726
common_properties_log,
27+
execute_init_commands,
2828
)
2929
from redisbench_admin.run_remote.args import create_run_remote_arguments
3030

@@ -572,3 +572,26 @@ def test_common_properties_log():
572572
tf_triggering_env,
573573
private_key,
574574
)
575+
576+
577+
def test_execute_init_commands():
578+
from redis import StrictRedis
579+
from redis.exceptions import ConnectionError
580+
581+
redis_port = 16379
582+
try:
583+
redis = StrictRedis(port=redis_port)
584+
redis.ping()
585+
redis.flushall()
586+
redis.config_resetstat()
587+
588+
with open("./tests/test_data/init-commands-array.yml", "r") as yml_file:
589+
benchmark_config = yaml.safe_load(yml_file)
590+
# no keyspace len check
591+
total_cmds = execute_init_commands(benchmark_config, redis)
592+
assert total_cmds == 3
593+
594+
assert b"key" in redis.keys()
595+
assert b"key2" in redis.keys()
596+
except ConnectionError:
597+
pass
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 0.4
2+
name: memtier_benchmark-2keys-lua-evalsha-hset-expire
3+
description: 'Runs memtier_benchmark, for a keyspace length of 2 HASH keys. This benchmark invokes the execution of a server-side Lua script doing 2 HSET commands and doing EXPIRE on those keys. '
4+
dbconfig:
5+
- configuration-parameters:
6+
- save: '""'
7+
- init_commands:
8+
- ["SCRIPT", "LOAD" ,"redis.call('hset', 'h1', 'k', 'v');redis.call('hset', 'h2', 'k', 'v');redis.call('expire', 'h1', 3600);redis.call('expire', 'h2', 3600);return redis.call('ping')"]
9+
- ["SET", "key", "val"]
10+
- '"HSET" "key2" "FIELD" "VAL"'

0 commit comments

Comments
 (0)