diff options
author | Anas <anas.el.amraoui@live.com> | 2021-11-30 18:05:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-30 18:05:51 +0200 |
commit | b94e230b17d08e6c89d134e933c706256b79bc4a (patch) | |
tree | 993bd7565169229326b810b66939587431ab9dc6 /benchmarks/command_packer_benchmark.py | |
parent | 368a25f9d163d784a8896f1c087582405e98e006 (diff) | |
download | redis-py-b94e230b17d08e6c89d134e933c706256b79bc4a.tar.gz |
Added black and isort (#1734)
Diffstat (limited to 'benchmarks/command_packer_benchmark.py')
-rw-r--r-- | benchmarks/command_packer_benchmark.py | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/benchmarks/command_packer_benchmark.py b/benchmarks/command_packer_benchmark.py index 3176c06..e66dbbc 100644 --- a/benchmarks/command_packer_benchmark.py +++ b/benchmarks/command_packer_benchmark.py @@ -1,7 +1,7 @@ -from redis.connection import (Connection, SYM_STAR, SYM_DOLLAR, SYM_EMPTY, - SYM_CRLF) from base import Benchmark +from redis.connection import SYM_CRLF, SYM_DOLLAR, SYM_EMPTY, SYM_STAR, Connection + class StringJoiningConnection(Connection): def send_packed_command(self, command, check_health=True): @@ -13,7 +13,7 @@ class StringJoiningConnection(Connection): except OSError as e: self.disconnect() if len(e.args) == 1: - _errno, errmsg = 'UNKNOWN', e.args[0] + _errno, errmsg = "UNKNOWN", e.args[0] else: _errno, errmsg = e.args raise ConnectionError(f"Error {_errno} while writing to socket. {errmsg}.") @@ -23,12 +23,17 @@ class StringJoiningConnection(Connection): def pack_command(self, *args): "Pack a series of arguments into a value Redis command" - args_output = SYM_EMPTY.join([ - SYM_EMPTY.join( - (SYM_DOLLAR, str(len(k)).encode(), SYM_CRLF, k, SYM_CRLF)) - for k in map(self.encoder.encode, args)]) + args_output = SYM_EMPTY.join( + [ + SYM_EMPTY.join( + (SYM_DOLLAR, str(len(k)).encode(), SYM_CRLF, k, SYM_CRLF) + ) + for k in map(self.encoder.encode, args) + ] + ) output = SYM_EMPTY.join( - (SYM_STAR, str(len(args)).encode(), SYM_CRLF, args_output)) + (SYM_STAR, str(len(args)).encode(), SYM_CRLF, args_output) + ) return output @@ -44,7 +49,7 @@ class ListJoiningConnection(Connection): except OSError as e: self.disconnect() if len(e.args) == 1: - _errno, errmsg = 'UNKNOWN', e.args[0] + _errno, errmsg = "UNKNOWN", e.args[0] else: _errno, errmsg = e.args raise ConnectionError(f"Error {_errno} while writing to socket. {errmsg}.") @@ -54,19 +59,20 @@ class ListJoiningConnection(Connection): def pack_command(self, *args): output = [] - buff = SYM_EMPTY.join( - (SYM_STAR, str(len(args)).encode(), SYM_CRLF)) + buff = SYM_EMPTY.join((SYM_STAR, str(len(args)).encode(), SYM_CRLF)) for k in map(self.encoder.encode, args): if len(buff) > 6000 or len(k) > 6000: buff = SYM_EMPTY.join( - (buff, SYM_DOLLAR, str(len(k)).encode(), SYM_CRLF)) + (buff, SYM_DOLLAR, str(len(k)).encode(), SYM_CRLF) + ) output.append(buff) output.append(k) buff = SYM_CRLF else: - buff = SYM_EMPTY.join((buff, SYM_DOLLAR, str(len(k)).encode(), - SYM_CRLF, k, SYM_CRLF)) + buff = SYM_EMPTY.join( + (buff, SYM_DOLLAR, str(len(k)).encode(), SYM_CRLF, k, SYM_CRLF) + ) output.append(buff) return output @@ -75,13 +81,12 @@ class CommandPackerBenchmark(Benchmark): ARGUMENTS = ( { - 'name': 'connection_class', - 'values': [StringJoiningConnection, ListJoiningConnection] + "name": "connection_class", + "values": [StringJoiningConnection, ListJoiningConnection], }, { - 'name': 'value_size', - 'values': [10, 100, 1000, 10000, 100000, 1000000, 10000000, - 100000000] + "name": "value_size", + "values": [10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000], }, ) @@ -90,9 +95,9 @@ class CommandPackerBenchmark(Benchmark): def run(self, connection_class, value_size): r = self.get_client() - x = 'a' * value_size - r.set('benchmark', x) + x = "a" * value_size + r.set("benchmark", x) -if __name__ == '__main__': +if __name__ == "__main__": CommandPackerBenchmark().run_benchmark() |