From 19f97638daab48513aff8abeecec15f91ae17835 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 10 Jul 2026 15:01:11 -0700 Subject: [PATCH 01/12] Move run_all_examples module from string_ops folder to top level examples folder --- .github/workflows/smoke-tests.yml | 3 +-- examples/__init__.py | 0 examples/run_all_examples.py | 18 ++++++++++++++++++ examples/string_ops/run_all_examples.py | 18 ------------------ 4 files changed, 19 insertions(+), 20 deletions(-) create mode 100644 examples/__init__.py create mode 100644 examples/run_all_examples.py delete mode 100644 examples/string_ops/run_all_examples.py diff --git a/.github/workflows/smoke-tests.yml b/.github/workflows/smoke-tests.yml index 1de80c89bb..e3031a8d0d 100644 --- a/.github/workflows/smoke-tests.yml +++ b/.github/workflows/smoke-tests.yml @@ -275,8 +275,7 @@ jobs: # We cannot run this module with the cwd being string_ops # Otherwise we will get relative import errors # https://stackoverflow.com/a/47030746 - run: python3 -m string_ops.run_all_examples - working-directory: examples + run: python3 -m examples.run_all_examples - name: Install test dependencies if: ${{ matrix.test == 'doctest' }} diff --git a/examples/__init__.py b/examples/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/examples/run_all_examples.py b/examples/run_all_examples.py new file mode 100644 index 0000000000..0aa12359ff --- /dev/null +++ b/examples/run_all_examples.py @@ -0,0 +1,18 @@ +from .string_ops.customer_experience.email_normalization_old import EmailNormalizationOld +from .string_ops.customer_experience.email_normalization_new import EmailNormalizationNew +from .string_ops.customer_experience.partial_extraction_old import PartialExtractionOld +from .string_ops.customer_experience.partial_extraction_new import PartialExtractionNew +from .string_ops.quickstart.string_expressions import StringExpressions +from .string_ops.quickstart.string_ops import StringOps + +example_classes = [ + EmailNormalizationOld, + EmailNormalizationNew, + PartialExtractionNew, + PartialExtractionOld, + StringExpressions, + StringOps +] + +for cls in example_classes: + example = cls().run() diff --git a/examples/string_ops/run_all_examples.py b/examples/string_ops/run_all_examples.py deleted file mode 100644 index 2a3ddaa65f..0000000000 --- a/examples/string_ops/run_all_examples.py +++ /dev/null @@ -1,18 +0,0 @@ -from .customer_experience.email_normalization_old import EmailNormalizationOld -from .customer_experience.email_normalization_new import EmailNormalizationNew -from .customer_experience.partial_extraction_old import PartialExtractionOld -from .customer_experience.partial_extraction_new import PartialExtractionNew -from .quickstart.string_expressions import StringExpressions -from .quickstart.string_ops import StringOps - -example_classes = [ - EmailNormalizationOld, - EmailNormalizationNew, - PartialExtractionNew, - PartialExtractionOld, - StringExpressions, - StringOps -] - -for cls in example_classes: - example = cls().run() From a3daf2810be41638c2eddfa19685c6eadc3d7471 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Mon, 13 Jul 2026 10:22:44 -0700 Subject: [PATCH 02/12] Move Example class from examples.string_ops to examples package --- examples/__init__.py | 14 ++++++++++++++ examples/string_ops/__init__.py | 14 -------------- .../string_ops/customer_experience/__init__.py | 2 +- .../string_ops/quickstart/string_expressions.py | 2 +- examples/string_ops/quickstart/string_ops.py | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/examples/__init__.py b/examples/__init__.py index e69de29bb2..89b3d4f7d7 100644 --- a/examples/__init__.py +++ b/examples/__init__.py @@ -0,0 +1,14 @@ +import aerospike + + +class Example: + def __init__(self): + config = { + "hosts": [("127.0.0.1", 3000)] + } + client = aerospike.client(config) + + self.client = client + + def __del__(self): + self.client.close() diff --git a/examples/string_ops/__init__.py b/examples/string_ops/__init__.py index 89b3d4f7d7..e69de29bb2 100644 --- a/examples/string_ops/__init__.py +++ b/examples/string_ops/__init__.py @@ -1,14 +0,0 @@ -import aerospike - - -class Example: - def __init__(self): - config = { - "hosts": [("127.0.0.1", 3000)] - } - client = aerospike.client(config) - - self.client = client - - def __del__(self): - self.client.close() diff --git a/examples/string_ops/customer_experience/__init__.py b/examples/string_ops/customer_experience/__init__.py index 693114a7c3..64cb347632 100644 --- a/examples/string_ops/customer_experience/__init__.py +++ b/examples/string_ops/customer_experience/__init__.py @@ -1,4 +1,4 @@ -from .. import Example +from ... import Example class CustomerExperienceExample(Example): def __init__(self): diff --git a/examples/string_ops/quickstart/string_expressions.py b/examples/string_ops/quickstart/string_expressions.py index 1e9a3891aa..833ed81920 100644 --- a/examples/string_ops/quickstart/string_expressions.py +++ b/examples/string_ops/quickstart/string_expressions.py @@ -1,4 +1,4 @@ -from .. import Example +from ... import Example from aerospike_helpers import expressions as exp from aerospike_helpers.operations import expression_operations as expr_ops diff --git a/examples/string_ops/quickstart/string_ops.py b/examples/string_ops/quickstart/string_ops.py index 37afbf3de9..143881cdba 100644 --- a/examples/string_ops/quickstart/string_ops.py +++ b/examples/string_ops/quickstart/string_ops.py @@ -1,4 +1,4 @@ -from .. import Example +from ... import Example from aerospike_helpers.operations import string_operations as so class StringOps(Example): From de158109f255b365bb1001f98bcee59d08cfa9c3 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Tue, 14 Jul 2026 08:29:33 -0700 Subject: [PATCH 03/12] Clean up Get() example using C# client's get() example as a reference. TODO - Because of the C# client's fixture system, I'm wondering if we can just use pytest --- examples/__init__.py | 16 +++- examples/client/get.py | 172 ++++++----------------------------- examples/run_all_examples.py | 4 +- 3 files changed, 47 insertions(+), 145 deletions(-) diff --git a/examples/__init__.py b/examples/__init__.py index 89b3d4f7d7..3355fdaf13 100644 --- a/examples/__init__.py +++ b/examples/__init__.py @@ -2,13 +2,25 @@ class Example: - def __init__(self): + def __init__( + self, + host: str = "127.0.0.1", + port: int = 3000, + user: str = None, + password: str = None, + namespace: str = "test", + set_name: str = "demo" + ): config = { - "hosts": [("127.0.0.1", 3000)] + "hosts": [(host, port)], + "user": user, + "password": password } client = aerospike.client(config) self.client = client + self.namespace = namespace + self.set_name = set_name def __del__(self): self.client.close() diff --git a/examples/client/get.py b/examples/client/get.py index c4ae106efb..a0c89352f6 100644 --- a/examples/client/get.py +++ b/examples/client/get.py @@ -15,148 +15,36 @@ # limitations under the License. ########################################################################## -from __future__ import print_function +from .. import Example + + +# optparser.add_option( +# "--timeout", dest="timeout", type="int", default=1000, metavar="", +# help="Client timeout") + +# optparser.add_option( +# "--read-timeout", dest="read_timeout", type="int", default=1000, metavar="", +# help="Client read timeout") + +# config = { +# 'hosts': [(options.host, options.port)], +# # TODO: not relevant to get()? C# client get() example doesn't have this +# 'policies': { +# 'total_timeout': options.timeout +# } +# } + +class Get(Example): + def run(self): + # TODO: This needs to be moved into a fixture. + # TODO: there also needs to be a cleanup step. + # TODO: at this point, I'm wondering if pytest can be used since + # it has fixtures as a built-in feature + key = (self.namespace, self.set_name, "docreadkey") + self.client.put(key, bins={"a": 1}) -import aerospike -import sys - -from optparse import OptionParser - -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog [options] key" - -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "--timeout", dest="timeout", type="int", default=1000, metavar="", - help="Client timeout") - -optparser.add_option( - "--read-timeout", dest="read_timeout", type="int", default=1000, metavar="", - help="Client read timeout") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "--no-key", dest="nokey", action="store_true", - help="Do not return the key") - -optparser.add_option( - "--no-metadata", dest="nometadata", action="store_true", - help="Do not return the metadata") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if len(args) != 1: - optparser.print_help() - print() - sys.exit(1) - -########################################################################## -# Client Configuration -########################################################################## - -config = { - 'hosts': [(options.host, options.port)], - 'policies': { - 'total_timeout': options.timeout - } -} - -########################################################################## -# Application -########################################################################## - -exitCode = 0 - -try: - - # ---------------------------------------------------------------------------- - # Connect to Cluster - # ---------------------------------------------------------------------------- - - client = aerospike.client(config).connect( - options.username, options.password) - - # ---------------------------------------------------------------------------- - # Perform Operation - # ---------------------------------------------------------------------------- - - try: - namespace = options.namespace if options.namespace and options.namespace != 'None' else None - set = options.set if options.set and options.set != 'None' else None - key = args.pop() policy = { - 'total_timeout': options.read_timeout + 'total_timeout': 300 } - - (key, metadata, record) = client.get((namespace, set, key), policy) - - if metadata is not None: - if options.nometadata and options.nokey: - print(record) - elif options.nometadata: - print(key, record) - elif options.nokey: - print(metadata, record) - else: - print(key, metadata, record) - print("---") - print("OK, 1 record found.") - else: - print('error: Not Found.', file=sys.stderr) - exitCode = 1 - - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - exitCode = 2 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- - - client.close() - -except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - exitCode = 3 - -########################################################################## -# Exit -########################################################################## - -sys.exit(exitCode) + record = self.client.get(key, policy) + print(record) diff --git a/examples/run_all_examples.py b/examples/run_all_examples.py index 0aa12359ff..a3ffbd1335 100644 --- a/examples/run_all_examples.py +++ b/examples/run_all_examples.py @@ -1,3 +1,4 @@ +from .client.get import Get from .string_ops.customer_experience.email_normalization_old import EmailNormalizationOld from .string_ops.customer_experience.email_normalization_new import EmailNormalizationNew from .string_ops.customer_experience.partial_extraction_old import PartialExtractionOld @@ -6,12 +7,13 @@ from .string_ops.quickstart.string_ops import StringOps example_classes = [ + Get, EmailNormalizationOld, EmailNormalizationNew, PartialExtractionNew, PartialExtractionOld, StringExpressions, - StringOps + StringOps, ] for cls in example_classes: From 82a0c1d91cb011fabc5e867486fc33836881c862 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Tue, 14 Jul 2026 08:56:50 -0700 Subject: [PATCH 04/12] Move setup code for Get() class to a new base class fixture. --- examples/__init__.py | 12 ++++++++++++ examples/client/get.py | 29 +++-------------------------- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/examples/__init__.py b/examples/__init__.py index 3355fdaf13..3fe3bbb524 100644 --- a/examples/__init__.py +++ b/examples/__init__.py @@ -24,3 +24,15 @@ def __init__( def __del__(self): self.client.close() + +# TODO: I'm wondering if pytest can be used since +# it has fixtures as a built-in feature +class ExampleWithRecord(Example): + def __init__(self): + super().__init__(self) + + self.key = (self.namespace, self.set_name, "docreadkey") + self.client.put(self.key, bins={"a": 1}) + + def __del__(self): + self.client.remove(self.key) diff --git a/examples/client/get.py b/examples/client/get.py index a0c89352f6..90ff1ccac2 100644 --- a/examples/client/get.py +++ b/examples/client/get.py @@ -15,36 +15,13 @@ # limitations under the License. ########################################################################## -from .. import Example +from .. import ExampleWithRecord -# optparser.add_option( -# "--timeout", dest="timeout", type="int", default=1000, metavar="", -# help="Client timeout") - -# optparser.add_option( -# "--read-timeout", dest="read_timeout", type="int", default=1000, metavar="", -# help="Client read timeout") - -# config = { -# 'hosts': [(options.host, options.port)], -# # TODO: not relevant to get()? C# client get() example doesn't have this -# 'policies': { -# 'total_timeout': options.timeout -# } -# } - -class Get(Example): +class Get(ExampleWithRecord): def run(self): - # TODO: This needs to be moved into a fixture. - # TODO: there also needs to be a cleanup step. - # TODO: at this point, I'm wondering if pytest can be used since - # it has fixtures as a built-in feature - key = (self.namespace, self.set_name, "docreadkey") - self.client.put(key, bins={"a": 1}) - policy = { 'total_timeout': 300 } - record = self.client.get(key, policy) + record = self.client.get(self.key, policy) print(record) From 8912778854469a265dd03e7a1eab2a085a5aa253 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Tue, 14 Jul 2026 09:07:18 -0700 Subject: [PATCH 05/12] Close client connection after example code has finished running. --- examples/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/__init__.py b/examples/__init__.py index 3fe3bbb524..8332bd95c7 100644 --- a/examples/__init__.py +++ b/examples/__init__.py @@ -36,3 +36,5 @@ def __init__(self): def __del__(self): self.client.remove(self.key) + + super().__del__(self) From ef3a21346ed92dd10bf0fd5006f7a7e6feee7bc7 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Tue, 14 Jul 2026 09:18:18 -0700 Subject: [PATCH 06/12] Fix invalid Python syntax. self should not be passed to super().__init__() --- examples/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/__init__.py b/examples/__init__.py index 8332bd95c7..9582d8840f 100644 --- a/examples/__init__.py +++ b/examples/__init__.py @@ -29,7 +29,7 @@ def __del__(self): # it has fixtures as a built-in feature class ExampleWithRecord(Example): def __init__(self): - super().__init__(self) + super().__init__() self.key = (self.namespace, self.set_name, "docreadkey") self.client.put(self.key, bins={"a": 1}) @@ -37,4 +37,4 @@ def __init__(self): def __del__(self): self.client.remove(self.key) - super().__del__(self) + super().__del__() From e3e3ec1fd468c8457f620ee099d77cc44d76c79c Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Tue, 14 Jul 2026 10:40:11 -0700 Subject: [PATCH 07/12] WIP --- examples/__init__.py | 2 +- examples/client/aggregate.py | 39 --------- examples/client/append.py | 146 +++---------------------------- examples/client/exists.py | 117 ++----------------------- examples/client/exists_many.py | 124 ++------------------------- examples/client/operate.py | 152 +++------------------------------ examples/client/prepend.py | 138 ++---------------------------- examples/client/put.py | 128 ++------------------------- examples/client/query.py | 50 ----------- examples/client/remove.py | 120 ++------------------------ 10 files changed, 63 insertions(+), 953 deletions(-) diff --git a/examples/__init__.py b/examples/__init__.py index 9582d8840f..2036629bb2 100644 --- a/examples/__init__.py +++ b/examples/__init__.py @@ -21,6 +21,7 @@ def __init__( self.client = client self.namespace = namespace self.set_name = set_name + self.key = (self.namespace, self.set_name, "docreadkey") def __del__(self): self.client.close() @@ -31,7 +32,6 @@ class ExampleWithRecord(Example): def __init__(self): super().__init__() - self.key = (self.namespace, self.set_name, "docreadkey") self.client.put(self.key, bins={"a": 1}) def __del__(self): diff --git a/examples/client/aggregate.py b/examples/client/aggregate.py index f5a74bcd89..f3441c84b0 100644 --- a/examples/client/aggregate.py +++ b/examples/client/aggregate.py @@ -16,7 +16,6 @@ ########################################################################## -from __future__ import print_function import aerospike import json import re @@ -34,56 +33,18 @@ optparser = OptionParser(usage=usage, add_help_option=False) -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") - optparser.add_option( "-b", "--bins", dest="bins", type="string", action="append", help="Bins to select from each record.") (options, args) = optparser.parse_args() -if options.help: - optparser.print_help() - print() - sys.exit(1) - if len(args) < 3: optparser.print_help() print() sys.exit(1) -########################################################################## -# Client Configuration -########################################################################## - config = { - 'hosts': [(options.host, options.port)], 'lua': { 'user_path': os.path.dirname(__file__) } diff --git a/examples/client/append.py b/examples/client/append.py index f76144b620..aef614fe2c 100644 --- a/examples/client/append.py +++ b/examples/client/append.py @@ -16,146 +16,28 @@ ########################################################################## -from __future__ import print_function -import aerospike -import sys +from .. import Example -from optparse import OptionParser - -########################################################################## -# Option Parsing -########################################################################## - -usage = "usage: %prog [options] key" - -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "--gen", dest="gen", type="int", default=10, metavar="", - help="Generation of the record being written.") - -optparser.add_option( - "--ttl", dest="ttl", type="int", default=1000, metavar="", - help="TTL of the record being written.") - - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if len(args) != 1: - optparser.print_help() - print() - sys.exit(1) - -########################################################################## -# Client Configuration -########################################################################## - -config = { - 'hosts': [(options.host, options.port)] -} - -########################################################################## -# Application -########################################################################## - -exitCode = 0 - -try: - - # ---------------------------------------------------------------------------- - # Connect to Cluster - # ---------------------------------------------------------------------------- - - client = aerospike.client(config).connect( - options.username, options.password) - - # ---------------------------------------------------------------------------- - # Perform Operation - # ---------------------------------------------------------------------------- - - try: - - namespace = options.namespace if options.namespace and options.namespace != 'None' else None - set = options.set if options.set and options.set != 'None' else None - key = args.pop() +class Append(Example): + def run(self): record = { 'example_name': 'John', 'example_age': 1 } - meta = {} - if (options.gen): - meta['gen'] = options.gen - if (options.ttl): - meta['ttl'] = options.ttl + # TODO meta gen/ttl should be options? + # TODO: this is the deprecated way of setting ttl and maybe gen + meta = { + 'ttl': 1000, + 'gen': 10 + } policy = None + self.client.put(self.key, record, meta, policy) - # invoke operation - - client.put((namespace, set, key), record, meta, policy) - - print(record) - print("---") - print("OK, 1 record written.") - - client.append( - (namespace, set, key), "example_name", " Smith", meta, policy) - (key, meta, bins) = client.get((namespace, set, key)) + # TODO: print statements should mark when command successfully finishes? + self.client.append( + self.key, "example_name", " Smith", meta, policy) + (key, meta, bins) = self.client.get(self.key) print(bins) - print("---") - print("OK, 1 record appended.") - - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - exitCode = 2 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- - - client.close() - -except Exception as eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 3 - -########################################################################## -# Exit -########################################################################## - -sys.exit(exitCode) diff --git a/examples/client/exists.py b/examples/client/exists.py index 9dfd67d8e1..d5805ed77b 100644 --- a/examples/client/exists.py +++ b/examples/client/exists.py @@ -15,117 +15,12 @@ # limitations under the License. ########################################################################## -from __future__ import print_function +from .. import ExampleWithRecord -import aerospike -import sys -from optparse import OptionParser +class Exists(ExampleWithRecord): + def run(self): + (key, metadata) = self.client.exists(self.key) + print(key, metadata) -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog [options] key" - -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if len(args) != 1: - optparser.print_help() - print() - sys.exit(1) - -########################################################################## -# Client Configuration -########################################################################## - -config = { - 'hosts': [(options.host, options.port)] -} - -########################################################################## -# Application -########################################################################## - -exitCode = 0 - -try: - - # ---------------------------------------------------------------------------- - # Connect to Cluster - # ---------------------------------------------------------------------------- - client = aerospike.client(config).connect( - options.username, options.password) - - # ---------------------------------------------------------------------------- - # Perform Operation - # ---------------------------------------------------------------------------- - - try: - - namespace = options.namespace if options.namespace and options.namespace != 'None' else None - set = options.set if options.set and options.set != 'None' else None - key = args.pop() - (key, metadata) = client.exists((namespace, set, key)) - if metadata is not None: - print(key, metadata) - print("---") - print("OK, 1 record found.") - else: - print('error: Not Found.', file=sys.stderr) - exitCode = 1 - - except Exception as eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 2 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- - - client.close() - -except Exception as eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 3 - -########################################################################## -# Exit -########################################################################## - -sys.exit(exitCode) + # TODO: missing negative path example (e.g where metadata is None) diff --git a/examples/client/exists_many.py b/examples/client/exists_many.py index 5f597b3afb..020b94a659 100644 --- a/examples/client/exists_many.py +++ b/examples/client/exists_many.py @@ -16,125 +16,17 @@ ########################################################################## -from __future__ import print_function -import aerospike -import sys +from .. import ExampleWithRecord -from optparse import OptionParser - -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog [options]" - -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-k", "--keys", dest="keys", type="string", default="", metavar="", - help="Keys to be accessed in the database server. Should be specified as 'name','name1','name2' etc") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -########################################################################## -# Client Configuration -########################################################################## - -config = { - 'hosts': [(options.host, options.port)] -} - -########################################################################## -# Application -########################################################################## - -exitCode = 0 - -try: - - # ---------------------------------------------------------------------------- - # Connect to Cluster - # ---------------------------------------------------------------------------- - - client = aerospike.client(config).connect( - options.username, options.password) - - # ---------------------------------------------------------------------------- - # Perform Operation - # ---------------------------------------------------------------------------- - - try: - - namespace = options.namespace if options.namespace and options.namespace != 'None' else None - set = options.set if options.set and options.set != 'None' else None - # args.pop() - - keys = options.keys.split(',') - keylist = [] - for key in keys: - individualkey = (namespace, set, key) - keylist.append(individualkey) - - records = client.exists_many(keylist) +# TODO: should use fixture with multiple records +class ExistsMany(ExampleWithRecord): + def run(self): + keys = [f"key{i}" for i in range(5)] + records = self.client.exists_many(keys) if records != None: + print(f"{len(records)} records were found") print(records) - print("---") - print("OK, %d records found." % len(records)) else: - print('error: Not Found.', file=sys.stderr) - exitCode = 1 - - except Exception as eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 2 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- - - client.close() - -except Exception as eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 3 - -########################################################################## -# Exit -########################################################################## - -sys.exit(exitCode) + print('error: Not Found.') diff --git a/examples/client/operate.py b/examples/client/operate.py index 999280ddda..605b6cd0da 100644 --- a/examples/client/operate.py +++ b/examples/client/operate.py @@ -15,160 +15,32 @@ # limitations under the License. ########################################################################## -from __future__ import print_function -import sys -from optparse import OptionParser +from .. import Example -import aerospike from aerospike_helpers.operations import operations as op_helpers -########################################################################## -# Option Parsing -########################################################################## - -usage = "usage: %prog [options] key" - -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "--gen", dest="gen", type="int", default=10, metavar="", - help="Generation of the record being written.") - -optparser.add_option( - "--ttl", dest="ttl", type="int", default=1000, metavar="", - help="TTL of the record being written.") - - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if len(args) != 1: - optparser.print_help() - print() - sys.exit(1) - -########################################################################## -# Client Configuration -########################################################################## - -config = { - 'hosts': [(options.host, options.port)] -} - -########################################################################## -# Application -########################################################################## - -exitCode = 0 - -try: - - # ---------------------------------------------------------------------------- - # Connect to Cluster - # ---------------------------------------------------------------------------- - - client = aerospike.client(config).connect( - options.username, options.password) - - # ---------------------------------------------------------------------------- - # Perform Operation - # ---------------------------------------------------------------------------- - - try: - - namespace = options.namespace if options.namespace and options.namespace != 'None' else None - setname = options.set if options.set and options.set != 'None' else None - key = args.pop() - record_key = (namespace, setname, key) - +class Operate(Example): + def run(self): record = { 'example_name': 'John', 'example_age': 1 } - meta = {'ttl': options.ttl, 'gen': options.gen} + meta = {'ttl': 1000, 'gen': 10} policy = None + self.client.put(self.key, record, meta, policy) - # invoke operation - - client.put(record_key, record, meta, policy) - - print("---") - print("OK, 1 record written.") - - _, _, bins = client.get(record_key) + _, _, bins = self.client.get(self.key) + print("Before operation:", bins) - print("---") - print("Before operate operation") - print(bins) - - operation_list = [ + ops = [ op_helpers.prepend("example_name", "Mr "), op_helpers.increment("example_age", 3), op_helpers.read("example_name") ] + _, _, bins = self.client.operate(self.key, ops, meta, policy) + print("Record returned by operate():", bins) - _, _, bins = client.operate( - record_key, operation_list, meta, policy) - print("---") - print("Record returned on operate completion") - print(bins) - - _, _, bins = client.get(record_key) - - print("---") - print("After operate operation") - print(bins) - - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - exitCode = 2 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- - - client.close() - -except Exception as eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 3 - -########################################################################## -# Exit -########################################################################## - -sys.exit(exitCode) + _, _, bins = self.client.get(self.key) + print("After operation:", bins) diff --git a/examples/client/prepend.py b/examples/client/prepend.py index cb14c0265e..6cf3f8a595 100644 --- a/examples/client/prepend.py +++ b/examples/client/prepend.py @@ -15,143 +15,23 @@ # limitations under the License. ########################################################################## -from __future__ import print_function +from .. import Example -import aerospike -import sys - -from optparse import OptionParser - -########################################################################## -# Option Parsing -########################################################################## - -usage = "usage: %prog [options] key" - -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "--gen", dest="gen", type="int", default=10, metavar="", - help="Generation of the record being written.") - -optparser.add_option( - "--ttl", dest="ttl", type="int", default=1000, metavar="", - help="TTL of the record being written.") - - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if len(args) != 1: - optparser.print_help() - print() - sys.exit(1) - -########################################################################## -# Client Configuration -########################################################################## - -config = { - 'hosts': [(options.host, options.port)] -} - -########################################################################## -# Application -########################################################################## - -exitCode = 0 - -try: - - # ---------------------------------------------------------------------------- - # Connect to Cluster - # ---------------------------------------------------------------------------- - - client = aerospike.client(config).connect( - options.username, options.password) - - # ---------------------------------------------------------------------------- - # Perform Operation - # ---------------------------------------------------------------------------- - - try: - - namespace = options.namespace if options.namespace and options.namespace != 'None' else None - set = options.set if options.set and options.set != 'None' else None - key = args.pop() +class Prepend(Example): + def run(self): + # TODO: can share this in a fixture class? record = { 'example_name': 'John', 'example_age': 1 } - meta = {'ttl': options.ttl, 'gen': options.gen} + # TODO: should this be configurable? + meta = {'ttl': 1000, 'gen': 10} policy = None - # invoke operation - - client.put((namespace, set, key), record, meta, policy) - - print(record) - print("---") - print("OK, 1 record written.") - - client.prepend( - (namespace, set, key), "example_name", "Mr ", meta, policy) - (key, meta, bins) = client.get((namespace, set, key)) + self.client.put(self.key, record, meta, policy) + self.client.prepend(self.key, "example_name", "Mr ", meta, policy) + (key, meta, bins) = self.client.get(self.key) print(bins) - print("---") - print("OK, 1 record prepended.") - - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - exitCode = 2 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- - - client.close() - -except Exception as eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 3 - -########################################################################## -# Exit -########################################################################## - -sys.exit(exitCode) diff --git a/examples/client/put.py b/examples/client/put.py index 17eea90085..dcf676e9ee 100644 --- a/examples/client/put.py +++ b/examples/client/put.py @@ -1,3 +1,5 @@ +from .. import Example + # -*- coding: utf-8 -*- ########################################################################## # Copyright 2013-2021 Aerospike, Inc. @@ -16,99 +18,8 @@ ########################################################################## -import aerospike -import sys - -from optparse import OptionParser - -########################################################################## -# Option Parsing -########################################################################## - -usage = "usage: %prog [options] key" - -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "--gen", dest="gen", type="int", default=5, metavar="", - help="Generation of the record being written.") - -optparser.add_option( - "--ttl", dest="ttl", type="int", default=1000, metavar="", - help="TTL of the record being written.") - - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if len(args) == 1: - optparser.print_help() - print() - sys.exit(1) - -########################################################################## -# Client Configuration -########################################################################## - -config = { - 'hosts': [(options.host, options.port)] -} - -########################################################################## -# Application -########################################################################## - -exitCode = 0 - -try: - - # ---------------------------------------------------------------------------- - # Connect to Cluster - # ---------------------------------------------------------------------------- - client = aerospike.client(config).connect( - options.username, options.password) - - # ---------------------------------------------------------------------------- - # Perform Operation - # ---------------------------------------------------------------------------- - try: - - namespace = options.namespace if options.namespace and options.namespace != 'None' else None - set = options.set if options.set and options.set != 'None' else None - key = args.pop() - +class Put(Example): + def run(self): record = { 'i': 123, 'f': 3.1415, @@ -120,32 +31,7 @@ 'l': [123, 'abc', '안녕하세요', ['x', 'y', 'z'], {'x': 1, 'y': 2, 'z': 3}], 'm': {'i': 123, 's': 'abc', 'u': '안녕하세요', 'l': ['x', 'y', 'z'], 'd': {'x': 1, 'y': 2, 'z': 3}} } - - meta = {'ttl': options.ttl, 'gen': options.gen} + # TODO: should TTL and gen be configurable? + meta = {'ttl': 1000, 'gen': 5} policy = None - # invoke operation - client.put((namespace, set, key), record, meta, policy) - - print(record) - print("---") - print("OK, 1 record written.") - - except Exception as e: - #print("error: {0}".format(e), file=sys.stderr) - exitCode = 2 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- - - client.close() - -except Exception as eargs: - #print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 3 - -########################################################################## -# Exit -########################################################################## - -sys.exit(exitCode) + self.client.put(self.key, record, meta, policy) diff --git a/examples/client/query.py b/examples/client/query.py index 42730d5fda..d9b41f5f22 100644 --- a/examples/client/query.py +++ b/examples/client/query.py @@ -29,38 +29,6 @@ # Option Parsing ########################################################################## -usage = "usage: %prog [options] [where]" - -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") - optparser.add_option( "-m", "--module", dest="module", type="string", help="UDF Module.") @@ -85,25 +53,7 @@ "--show-meta", dest="show_meta", action="store_true", help="If set, displays the metadata.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if len(args) > 1: - optparser.print_help() - print() - sys.exit(1) - -########################################################################## -# Client Configuration -########################################################################## - config = { - 'hosts': [(options.host, options.port)], 'lua': { 'user_path': os.path.dirname(__file__) } diff --git a/examples/client/remove.py b/examples/client/remove.py index d6efe0eab6..01f5f54a95 100644 --- a/examples/client/remove.py +++ b/examples/client/remove.py @@ -15,119 +15,11 @@ # limitations under the License. ########################################################################## -from __future__ import print_function +from .. import ExampleWithRecord -import aerospike -import sys -from optparse import OptionParser - -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog [options] key" - -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if len(args) != 1: - optparser.print_help() - print() - sys.exit(1) - -############################################################################### -# Client Configuration -############################################################################### - -config = { - 'hosts': [(options.host, options.port)] -} - - -############################################################################### -# Application -############################################################################### - -exitCode = 0 - -try: - - # ---------------------------------------------------------------------------- - # Connect to Cluster - # ---------------------------------------------------------------------------- - - client = aerospike.client(config).connect( - options.username, options.password) - - # ---------------------------------------------------------------------------- - # Perform Operation - # ---------------------------------------------------------------------------- - - try: - namespace = options.namespace if options.namespace and options.namespace != 'None' else None - set = options.set if options.set and options.set != 'None' else None - key = args.pop() - - client.remove((namespace, set, key)) - - print("OK, 1 record removed.") - - except Exception as eargs: - (code, msg, file, line) = eargs - if code == 602: - print("error: Record not found") - else: - print( - "error: {0}".format((code, msg, file, line)), file=sys.stderr) - rc = 1 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- - - client.close() - -except Exception as eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 3 - -########################################################################## -# Exit -########################################################################## - -sys.exit(exitCode) +class Remove(ExampleWithRecord): + def run(self): + # TODO: should demonstrate the negative path + # since key is an input for the old example. + self.client.remove(self.key) From c9cf5fcea2242687c60d25b63526ad920554d814 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Tue, 14 Jul 2026 10:52:26 -0700 Subject: [PATCH 08/12] Remove more boilerplate code that has been handled in the base class --- examples/client/apply.py | 30 --------- examples/client/bin_ops.py | 28 -------- examples/client/client_big_list.py | 18 ----- examples/client/delete.py | 35 ---------- examples/client/get_async.py | 30 --------- examples/client/get_key_digest.py | 33 --------- examples/client/get_many.py | 37 ---------- examples/client/get_nodes.py | 29 -------- examples/client/increment.py | 37 ---------- examples/client/index_create.py | 36 ---------- examples/client/index_remove.py | 33 --------- examples/client/info.py | 21 ------ examples/client/is_connected.py | 34 ---------- examples/client/kvs.py | 29 -------- examples/client/multi_thread.py | 29 -------- examples/client/query_apply.py | 22 ------ examples/client/scan_apply.py | 27 -------- examples/client/udf_remove.py | 104 ++--------------------------- 18 files changed, 6 insertions(+), 606 deletions(-) diff --git a/examples/client/apply.py b/examples/client/apply.py index e497a5fe7a..accb944fc2 100644 --- a/examples/client/apply.py +++ b/examples/client/apply.py @@ -29,36 +29,6 @@ usage = "usage: %prog [options] key module function [args...]" -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") - optparser.add_option( "--gen", dest="gen", type="int", default=None, metavar="", help="Generation of the record being written.") diff --git a/examples/client/bin_ops.py b/examples/client/bin_ops.py index 35826bfb3d..5b960a94b5 100644 --- a/examples/client/bin_ops.py +++ b/examples/client/bin_ops.py @@ -29,34 +29,6 @@ usage = "usage: %prog [options]" -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - ########################################################################## # Application ########################################################################## diff --git a/examples/client/client_big_list.py b/examples/client/client_big_list.py index c5fc2f7e6f..0277f849ee 100644 --- a/examples/client/client_big_list.py +++ b/examples/client/client_big_list.py @@ -322,24 +322,6 @@ def main(): will be created. ''' - optparser = argparse.ArgumentParser() - - optparser.add_argument( - "--host", type=str, default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - - optparser.add_argument( - "--port", type=int, default=3000, metavar="", - help="Port of the Aerospike server.") - - optparser.add_argument( - "--namespace", type=str, default="test", metavar="", - help="Namespace to use for this example") - - optparser.add_argument( - "-s", "--set", type=str, default="demo", metavar="", - help="Set to use for this example") - optparser.add_argument( "-i", "--items", type=int, default=1000, metavar="", help="Number of items to store into the big list") diff --git a/examples/client/delete.py b/examples/client/delete.py index 3bb9677a4d..8225eb9f92 100644 --- a/examples/client/delete.py +++ b/examples/client/delete.py @@ -30,49 +30,14 @@ optparser = OptionParser(usage=usage, add_help_option=False) -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", default="ram", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", default="ram", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="as-s1.as-network.com", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - optparser.add_option( "--timeout", dest="timeout", type="int", default=1000, metavar="", help="Client timeout") -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Namespace of database.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Set to use within namespace of database.") - optparser.add_option( "-c", "--test_count", dest="test_count", type="int", default=128, metavar="", help="Number of test cases to run.") -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - ########################################################################## # Client Configuration ########################################################################## diff --git a/examples/client/get_async.py b/examples/client/get_async.py index 693496a98f..cfc61cb6e3 100644 --- a/examples/client/get_async.py +++ b/examples/client/get_async.py @@ -29,40 +29,10 @@ usage = "usage: %prog [options]" -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", default="ram", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", default="ram", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="as-s1.as-network.com", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - optparser.add_option( "--timeout", dest="timeout", type="int", default=1000, metavar="", help="Client timeout") -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Namespace of database.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Set to use within namespace of database.") - optparser.add_option( "-c", "--test_count", dest="test_count", type="int", default=128, metavar="", help="Number of async IO to spawn.") diff --git a/examples/client/get_key_digest.py b/examples/client/get_key_digest.py index 0153092d61..7f8001c3d4 100644 --- a/examples/client/get_key_digest.py +++ b/examples/client/get_key_digest.py @@ -29,46 +29,13 @@ usage = "usage: %prog [options] key" -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") optparser.add_option( "--timeout", dest="timeout", type="int", default=1000, metavar="", help="Client timeout") -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") - (options, args) = optparser.parse_args() -if options.help: - optparser.print_help() - print() - sys.exit(1) if len(args) != 1: optparser.print_help() diff --git a/examples/client/get_many.py b/examples/client/get_many.py index c2a1f8f512..40062d7b96 100644 --- a/examples/client/get_many.py +++ b/examples/client/get_many.py @@ -30,47 +30,10 @@ usage = "usage: %prog [options]" -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") - optparser.add_option( "-k", "--keys", dest="keys", type="string", default="", metavar="", help="Keys to be accessed in the database server. Should be specified as 'name','name1','name2' etc") -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - ########################################################################## # Client Configuration ########################################################################## diff --git a/examples/client/get_nodes.py b/examples/client/get_nodes.py index 6171e5bc2c..d7d6b1408c 100644 --- a/examples/client/get_nodes.py +++ b/examples/client/get_nodes.py @@ -30,35 +30,6 @@ usage = "usage: %prog" -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - ########################################################################## # Client Configuration ########################################################################## diff --git a/examples/client/increment.py b/examples/client/increment.py index 303fa11615..e1447921c5 100644 --- a/examples/client/increment.py +++ b/examples/client/increment.py @@ -29,36 +29,6 @@ usage = "usage: %prog [options] key" -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") - optparser.add_option( "--gen", dest="gen", type="int", default=10, metavar="", help="Generation of the record being written.") @@ -68,13 +38,6 @@ help="TTL of the record being written.") -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - if len(args) != 1: optparser.print_help() print() diff --git a/examples/client/index_create.py b/examples/client/index_create.py index 8968a8ba9c..64ad72815a 100644 --- a/examples/client/index_create.py +++ b/examples/client/index_create.py @@ -29,48 +29,12 @@ usage = "usage: %prog [options] bin index_name" -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") optparser.add_option( "-t", "--type", dest="type", type="string", default="string", metavar="", help="The type of index to create") -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - if len(args) != 2: optparser.print_help() print() diff --git a/examples/client/index_remove.py b/examples/client/index_remove.py index 8f245adb82..097859ad6a 100644 --- a/examples/client/index_remove.py +++ b/examples/client/index_remove.py @@ -29,39 +29,6 @@ usage = "usage: %prog [options] bin index_name" -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - if len(args) != 1: optparser.print_help() print() diff --git a/examples/client/info.py b/examples/client/info.py index 52acf0f8de..9dc9b8e624 100644 --- a/examples/client/info.py +++ b/examples/client/info.py @@ -29,27 +29,6 @@ usage = "usage: %prog [options] [REQUEST]" -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") (options, args) = optparser.parse_args() diff --git a/examples/client/is_connected.py b/examples/client/is_connected.py index 2991c83117..9569234cec 100644 --- a/examples/client/is_connected.py +++ b/examples/client/is_connected.py @@ -31,40 +31,6 @@ optparser = OptionParser(usage=usage, add_help_option=False) -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) if len(args) != 0: optparser.print_help() diff --git a/examples/client/kvs.py b/examples/client/kvs.py index 251c944ff9..4fdf559338 100644 --- a/examples/client/kvs.py +++ b/examples/client/kvs.py @@ -29,35 +29,6 @@ usage = "usage: %prog [options]" -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - ########################################################################## # Application ########################################################################## diff --git a/examples/client/multi_thread.py b/examples/client/multi_thread.py index 43f3885687..b5a1b9423f 100644 --- a/examples/client/multi_thread.py +++ b/examples/client/multi_thread.py @@ -32,35 +32,6 @@ usage = "usage: %prog [options]" -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", - metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) ########################################################################## # Client Configuration diff --git a/examples/client/query_apply.py b/examples/client/query_apply.py index 1febe7127c..c5f8bd8662 100644 --- a/examples/client/query_apply.py +++ b/examples/client/query_apply.py @@ -36,28 +36,6 @@ def query_callback(option, opt, value, parser): setattr(parser.values, option.dest, value.split(',')) -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") - optparser.add_option( "-m", "--module", dest="module", type="string", help="UDF Module.") diff --git a/examples/client/scan_apply.py b/examples/client/scan_apply.py index fc7151d937..8a89d48563 100644 --- a/examples/client/scan_apply.py +++ b/examples/client/scan_apply.py @@ -35,33 +35,6 @@ def scan_callback(option, opt, value, parser): optparser = OptionParser(usage=usage, add_help_option=False) -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") optparser.add_option( "-m", "--module", dest="module", type="string", diff --git a/examples/client/udf_remove.py b/examples/client/udf_remove.py index 18ef2e513d..17aba34234 100644 --- a/examples/client/udf_remove.py +++ b/examples/client/udf_remove.py @@ -15,103 +15,11 @@ # limitations under the License. ########################################################################## -from __future__ import print_function -import aerospike -import sys +from .. import Example -from optparse import OptionParser - -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog [options] module" - -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if len(args) != 1: - optparser.print_help() - print() - sys.exit(1) - -########################################################################## -# Client Configuration -########################################################################## - -config = { - 'hosts': [(options.host, options.port)] -} - -########################################################################## -# Application -########################################################################## - -exitCode = 0 - -try: - - # ---------------------------------------------------------------------------- - # Connect to Cluster - # ---------------------------------------------------------------------------- - - client = aerospike.client(config).connect( - options.username, options.password) - - # ---------------------------------------------------------------------------- - # Perform Operation - # ---------------------------------------------------------------------------- - - try: - - module = args.pop() - - client.udf_remove(module) - print("OK, 1 UDF de-registered") - - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - exitCode = 2 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- - - client.close() - -except Exception as eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 3 - -########################################################################## -# Exit -########################################################################## - -sys.exit(exitCode) +class UDFRemove(Example): + def run(self): + # TODO: need negative path + module = "example.lua" + self.client.udf_remove(module) From 41c15b64a7b522242dce0cebac6646ffb9dd6929 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Tue, 14 Jul 2026 11:05:05 -0700 Subject: [PATCH 09/12] Finish removing all the boilerplate code that is handled in the parent class. --- examples/client/scan.py | 30 ---------------------------- examples/client/scan_partition.py | 30 ---------------------------- examples/client/select_many.py | 30 ---------------------------- examples/client/select_record.py | 28 -------------------------- examples/client/touch.py | 30 ---------------------------- examples/client/ttl.py | 28 -------------------------- examples/client/udf_get.py | 27 ------------------------- examples/client/udf_list.py | 28 -------------------------- examples/client/udf_put.py | 28 -------------------------- examples/client/unicode_smiles.py | 33 ------------------------------- 10 files changed, 292 deletions(-) diff --git a/examples/client/scan.py b/examples/client/scan.py index 146a08d6e8..e74274cafc 100644 --- a/examples/client/scan.py +++ b/examples/client/scan.py @@ -28,36 +28,6 @@ usage = "usage: %prog [options]" -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") - optparser.add_option( "-b", "--bins", dest="bins", type="string", action="append", help="Bins to select from each record.") diff --git a/examples/client/scan_partition.py b/examples/client/scan_partition.py index 00870b9509..80ce72fc4e 100644 --- a/examples/client/scan_partition.py +++ b/examples/client/scan_partition.py @@ -28,36 +28,6 @@ usage = "usage: %prog [options]" -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") - optparser.add_option( "-i", "--partition_id", dest="partition", type="int", default=0, help="Partition id from where to scan.") diff --git a/examples/client/select_many.py b/examples/client/select_many.py index 63eef3814c..24b657ed45 100644 --- a/examples/client/select_many.py +++ b/examples/client/select_many.py @@ -30,36 +30,6 @@ usage = "usage: %prog [options]" -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") - optparser.add_option( "-k", "--keys", dest="keys", type="string", default="", metavar="", help="Keys to be accessed in the database server. Should be specified as 'name','name1','name2' etc") diff --git a/examples/client/select_record.py b/examples/client/select_record.py index aab0780369..5a414fe294 100644 --- a/examples/client/select_record.py +++ b/examples/client/select_record.py @@ -30,34 +30,6 @@ optparser = OptionParser(usage=usage, add_help_option=False) -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") - optparser.add_option( "--no-key", dest="nokey", action="store_true", help="Do not return the key") diff --git a/examples/client/touch.py b/examples/client/touch.py index ae16eb1834..f213ccd43a 100644 --- a/examples/client/touch.py +++ b/examples/client/touch.py @@ -28,36 +28,6 @@ usage = "usage: %prog [options] key" -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") - optparser.add_option( "--gen", dest="gen", type="int", default=10, metavar="", help="Generation of the record being written.") diff --git a/examples/client/ttl.py b/examples/client/ttl.py index 1e2638c118..4c302007d6 100644 --- a/examples/client/ttl.py +++ b/examples/client/ttl.py @@ -44,34 +44,6 @@ optparser = OptionParser(usage=usage, add_help_option=False) -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") - (options, args) = optparser.parse_args() if options.help: diff --git a/examples/client/udf_get.py b/examples/client/udf_get.py index 684bb8db71..d234ae7f8d 100644 --- a/examples/client/udf_get.py +++ b/examples/client/udf_get.py @@ -28,35 +28,8 @@ usage = "usage: %prog [options] module" -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - (options, args) = optparser.parse_args() -if options.help: - optparser.print_help() - print() - sys.exit(1) - if len(args) != 1: optparser.print_help() print() diff --git a/examples/client/udf_list.py b/examples/client/udf_list.py index fc2f8b0fff..5b687a523e 100644 --- a/examples/client/udf_list.py +++ b/examples/client/udf_list.py @@ -28,34 +28,6 @@ usage = "usage: %prog [options]" -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) ########################################################################## # Client Configuration diff --git a/examples/client/udf_put.py b/examples/client/udf_put.py index c2d86530c0..139e640753 100644 --- a/examples/client/udf_put.py +++ b/examples/client/udf_put.py @@ -28,34 +28,6 @@ usage = "usage: %prog [options] filename" -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) if len(args) != 1: optparser.print_help() diff --git a/examples/client/unicode_smiles.py b/examples/client/unicode_smiles.py index bcc13959ef..3955c4c25d 100644 --- a/examples/client/unicode_smiles.py +++ b/examples/client/unicode_smiles.py @@ -32,25 +32,6 @@ optparser = OptionParser(usage=usage, add_help_option=False) -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="127.0.0.1", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") optparser.add_option( "--timeout", dest="timeout", type="int", default=1000, metavar="", @@ -60,20 +41,6 @@ "--read-timeout", dest="read_timeout", type="int", default=1000, metavar="", help="Client read timeout") -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Port of the Aerospike server.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) ########################################################################## # Application From cabc6c7ade9f985def3dafd603ac012cdc8e9569 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Tue, 14 Jul 2026 11:14:51 -0700 Subject: [PATCH 10/12] Reviewed all async examples and removed them since this client doesn't support this. Also remove outdated python 2 compatibility code --- examples/client/aggregate.py | 2 +- examples/client/append.py | 2 +- examples/client/apply.py | 3 +- examples/client/bin_ops.py | 3 +- examples/client/client_big_list.py | 3 +- examples/client/delete.py | 2 +- examples/client/exists.py | 2 +- examples/client/exists_many.py | 2 +- examples/client/get.py | 2 +- examples/client/get_async.py | 129 ---------------------- examples/client/get_key_digest.py | 3 +- examples/client/get_many.py | 3 +- examples/client/get_nodes.py | 3 +- examples/client/increment.py | 3 +- examples/client/index_create.py | 3 +- examples/client/index_remove.py | 3 +- examples/client/info.py | 3 +- examples/client/is_connected.py | 3 +- examples/client/kvs.py | 3 +- examples/client/multi_thread.py | 3 +- examples/client/operate.py | 2 +- examples/client/prepend.py | 2 +- examples/client/put.py | 2 +- examples/client/put_async.py | 169 ----------------------------- examples/client/query.py | 3 +- examples/client/query_apply.py | 3 +- examples/client/remove.py | 2 +- examples/client/remove_bin.py | 3 +- examples/client/scan.py | 3 +- examples/client/scan_apply.py | 3 +- examples/client/scan_partition.py | 3 +- examples/client/select_many.py | 3 +- examples/client/select_record.py | 3 +- examples/client/touch.py | 3 +- examples/client/ttl.py | 3 +- examples/client/udf_get.py | 3 +- examples/client/udf_list.py | 3 +- examples/client/udf_put.py | 3 +- examples/client/udf_remove.py | 2 +- examples/client/unicode_smiles.py | 3 +- 40 files changed, 38 insertions(+), 363 deletions(-) delete mode 100644 examples/client/get_async.py delete mode 100644 examples/client/put_async.py diff --git a/examples/client/aggregate.py b/examples/client/aggregate.py index f3441c84b0..d9bfd956fe 100644 --- a/examples/client/aggregate.py +++ b/examples/client/aggregate.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/append.py b/examples/client/append.py index aef614fe2c..9861e64386 100644 --- a/examples/client/append.py +++ b/examples/client/append.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/apply.py b/examples/client/apply.py index accb944fc2..8805db425d 100644 --- a/examples/client/apply.py +++ b/examples/client/apply.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -16,7 +16,6 @@ ########################################################################## -from __future__ import print_function import aerospike import json import sys diff --git a/examples/client/bin_ops.py b/examples/client/bin_ops.py index 5b960a94b5..d422a1d39e 100644 --- a/examples/client/bin_ops.py +++ b/examples/client/bin_ops.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -16,7 +16,6 @@ ########################################################################## -from __future__ import print_function import aerospike import pprint import sys diff --git a/examples/client/client_big_list.py b/examples/client/client_big_list.py index 0277f849ee..61d656ca94 100644 --- a/examples/client/client_big_list.py +++ b/examples/client/client_big_list.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2018 Aerospike, Inc. # @@ -15,7 +15,6 @@ # limitations under the License. ########################################################################## -from __future__ import print_function import argparse import aerospike diff --git a/examples/client/delete.py b/examples/client/delete.py index 8225eb9f92..661656e17e 100644 --- a/examples/client/delete.py +++ b/examples/client/delete.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/exists.py b/examples/client/exists.py index d5805ed77b..83ace5fade 100644 --- a/examples/client/exists.py +++ b/examples/client/exists.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/exists_many.py b/examples/client/exists_many.py index 020b94a659..70fc7555e2 100644 --- a/examples/client/exists_many.py +++ b/examples/client/exists_many.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/get.py b/examples/client/get.py index 90ff1ccac2..1b7c742d55 100644 --- a/examples/client/get.py +++ b/examples/client/get.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/get_async.py b/examples/client/get_async.py deleted file mode 100644 index cfc61cb6e3..0000000000 --- a/examples/client/get_async.py +++ /dev/null @@ -1,129 +0,0 @@ -# -*- coding: utf-8 -*- -########################################################################## -# Copyright 2013-2021 Aerospike, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -########################################################################## - -import asyncio -import sys -import aerospike -import time -from aerospike_helpers.awaitable import io - -from optparse import OptionParser - -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog [options]" - -optparser.add_option( - "--timeout", dest="timeout", type="int", default=1000, metavar="", - help="Client timeout") - -optparser.add_option( - "-c", "--test_count", dest="test_count", type="int", default=128, metavar="", - help="Number of async IO to spawn.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -########################################################################## -# Client Configuration -########################################################################## - -config = { - 'hosts': [(options.host, options.port)], - 'policies': { - 'total_timeout': options.timeout - } -} - -########################################################################## -# Application -########################################################################## - -exitCode = 0 - -try: - - # ---------------------------------------------------------------------------- - # Connect to Cluster - # ---------------------------------------------------------------------------- - print(f"Connecting to {options.host}:{options.port} with {options.username}:{options.password}") - client = aerospike.client(config).connect( - options.username, options.password) - - # ---------------------------------------------------------------------------- - # Perform Operation - # ---------------------------------------------------------------------------- - - try: - io_results = {} - test_count = options.test_count - namespace = options.namespace if options.namespace and options.namespace != 'None' else None - set = options.set if options.set and options.set != 'None' else None - policy = { - 'total_timeout': options.timeout - } - meta = None - - print(f"IO async test count:{test_count}") - - async def async_io(namespace, set, i): - key = (namespace, \ - set, \ - str(i), \ - client.get_key_digest(namespace, set, str(i))) - context = {'result': {}} - io_results[key[2]] = context - result = None - try: - result = await io.get(client, key, policy) - except Exception as eargs: - print(f"error: {eargs.code}, {eargs.msg}, {eargs.file}, {eargs.line}") - print(result) - io_results[key[2]]['result'] = result - async def main(): - func_list = [] - for i in range(test_count): - func_list.append(async_io(namespace, set, i)) - await asyncio.gather(*func_list) - asyncio.get_event_loop().run_until_complete(main()) - print(io_results) - print(f"get_async completed with returning {len(io_results)} records") - except Exception as e: - print(f"error: {0} ".format(e), file=sys.stderr) - rc = 1 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- - - client.close() - -except Exception as eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 3 - -########################################################################## -# Exit -########################################################################## - -sys.exit(exitCode) diff --git a/examples/client/get_key_digest.py b/examples/client/get_key_digest.py index 7f8001c3d4..f5421c299f 100644 --- a/examples/client/get_key_digest.py +++ b/examples/client/get_key_digest.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -16,7 +16,6 @@ ########################################################################## -from __future__ import print_function import aerospike import sys diff --git a/examples/client/get_many.py b/examples/client/get_many.py index 40062d7b96..76bc97a289 100644 --- a/examples/client/get_many.py +++ b/examples/client/get_many.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -16,7 +16,6 @@ ########################################################################## -from __future__ import print_function import aerospike import sys diff --git a/examples/client/get_nodes.py b/examples/client/get_nodes.py index d7d6b1408c..2b67240075 100644 --- a/examples/client/get_nodes.py +++ b/examples/client/get_nodes.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -16,7 +16,6 @@ ########################################################################## -from __future__ import print_function import aerospike import sys diff --git a/examples/client/increment.py b/examples/client/increment.py index e1447921c5..ee91e05da4 100644 --- a/examples/client/increment.py +++ b/examples/client/increment.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -16,7 +16,6 @@ ########################################################################## -from __future__ import print_function import aerospike import sys diff --git a/examples/client/index_create.py b/examples/client/index_create.py index 64ad72815a..84a8e03edb 100644 --- a/examples/client/index_create.py +++ b/examples/client/index_create.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -16,7 +16,6 @@ ########################################################################## -from __future__ import print_function import aerospike import sys diff --git a/examples/client/index_remove.py b/examples/client/index_remove.py index 097859ad6a..b2907106da 100644 --- a/examples/client/index_remove.py +++ b/examples/client/index_remove.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -16,7 +16,6 @@ ########################################################################## -from __future__ import print_function import aerospike import sys diff --git a/examples/client/info.py b/examples/client/info.py index 9dc9b8e624..3128902216 100644 --- a/examples/client/info.py +++ b/examples/client/info.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -16,7 +16,6 @@ ########################################################################## -from __future__ import print_function import aerospike import sys diff --git a/examples/client/is_connected.py b/examples/client/is_connected.py index 9569234cec..ea0317b549 100644 --- a/examples/client/is_connected.py +++ b/examples/client/is_connected.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -16,7 +16,6 @@ ########################################################################## -from __future__ import print_function import aerospike import sys diff --git a/examples/client/kvs.py b/examples/client/kvs.py index 4fdf559338..bde2c26969 100644 --- a/examples/client/kvs.py +++ b/examples/client/kvs.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -16,7 +16,6 @@ ########################################################################## -from __future__ import print_function import aerospike import sys diff --git a/examples/client/multi_thread.py b/examples/client/multi_thread.py index b5a1b9423f..08b02f0d4f 100644 --- a/examples/client/multi_thread.py +++ b/examples/client/multi_thread.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -15,7 +15,6 @@ # limitations under the License. ########################################################################## -from __future__ import print_function import aerospike import sys diff --git a/examples/client/operate.py b/examples/client/operate.py index 605b6cd0da..ec37158caf 100644 --- a/examples/client/operate.py +++ b/examples/client/operate.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/prepend.py b/examples/client/prepend.py index 6cf3f8a595..20707a221c 100644 --- a/examples/client/prepend.py +++ b/examples/client/prepend.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/put.py b/examples/client/put.py index dcf676e9ee..c4eefe7a8e 100644 --- a/examples/client/put.py +++ b/examples/client/put.py @@ -1,6 +1,6 @@ from .. import Example -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/put_async.py b/examples/client/put_async.py deleted file mode 100644 index 907ba80598..0000000000 --- a/examples/client/put_async.py +++ /dev/null @@ -1,169 +0,0 @@ -# -*- coding: utf-8 -*- -########################################################################## -# Copyright 2013-2021 Aerospike, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -########################################################################## - -import asyncio -import sys -import aerospike -import time -from aerospike_helpers.awaitable import io - -from optparse import OptionParser - -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog [options]" - -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "--help", dest="help", action="store_true", - help="Displays this message.") - -optparser.add_option( - "-U", "--username", dest="username", type="string", default="ram", metavar="", - help="Username to connect to database.") - -optparser.add_option( - "-P", "--password", dest="password", type="string", default="ram", metavar="", - help="Password to connect to database.") - -optparser.add_option( - "-h", "--host", dest="host", type="string", default="as-s1.as-network.com", metavar="
", - help="Address of Aerospike server.") - -optparser.add_option( - "-p", "--port", dest="port", type="int", default=3000, metavar="", - help="Port of the Aerospike server.") - -optparser.add_option( - "--timeout", dest="timeout", type="int", default=1000, metavar="", - help="Client timeout") - -optparser.add_option( - "-n", "--namespace", dest="namespace", type="string", default="test", metavar="", - help="Namespace of database.") - -optparser.add_option( - "-s", "--set", dest="set", type="string", default="demo", metavar="", - help="Set to use within namespace of database.") - -optparser.add_option( - "-c", "--test_count", dest="test_count", type="int", default=128, metavar="", - help="Number of async IO to spawn.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -########################################################################## -# Client Configuration -########################################################################## - -config = { - 'hosts': [(options.host, options.port)], - 'policies': { - 'total_timeout': options.timeout - } -} - -########################################################################## -# Application -########################################################################## - -exitCode = 0 - -try: - - # ---------------------------------------------------------------------------- - # Connect to Cluster - # ---------------------------------------------------------------------------- - print(f"Connecting to {options.host}:{options.port} with {options.username}:{options.password}") - client = aerospike.client(config).connect( - options.username, options.password) - - # ---------------------------------------------------------------------------- - # Perform Operation - # ---------------------------------------------------------------------------- - - try: - io_results = {} - test_count = options.test_count - namespace = options.namespace if options.namespace and options.namespace != 'None' else None - set = options.set if options.set and options.set != 'None' else None - policy = { - 'total_timeout': options.timeout - } - meta = None - - print(f"IO async test count:{test_count}") - - async def async_io(namespace, set, i): - futures = [] - key = (namespace, \ - set, \ - str(i), \ - client.get_key_digest(namespace, set, str(i))) - record = { - 'i': i, - 'f': 3.1415, - 's': 'abc', - 'u': '안녕하세요', - #'b': bytearray(['d','e','f']), - 'l': [i, 'abc', 'வணக்கம்', ['x', 'y', 'z'], {'x': 1, 'y': 2, 'z': 3}], - 'm': {'i': i, 's': 'abc', 'u': 'ஊத்தாப்பம்', 'l': ['x', 'y', 'z'], 'd': {'x': 1, 'y': 2, 'z': 3}} - } - context = {'state': 0, 'result': {}} - io_results[key[2]] = context - result = None - try: - result = await io.put(client, key, record, meta, policy) - except Exception as eargs: - print(f"error: {eargs.code}, {eargs.msg}, {eargs.file}, {eargs.line}") - pass - io_results[key[2]]['result'] = result - async def main(): - func_list = [] - for i in range(test_count): - func_list.append(async_io(namespace, set, i)) - await asyncio.gather(*func_list) - asyncio.get_event_loop().run_until_complete(main()) - print(f"put_async completed with returning {len(io_results)} records") - #print(io_results) - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - rc = 1 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- - - client.close() - -except Exception as eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 3 - -########################################################################## -# Exit -########################################################################## - -sys.exit(exitCode) diff --git a/examples/client/query.py b/examples/client/query.py index d9b41f5f22..a1bbae5087 100644 --- a/examples/client/query.py +++ b/examples/client/query.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -15,7 +15,6 @@ # limitations under the License. ########################################################################## -from __future__ import print_function import aerospike import re diff --git a/examples/client/query_apply.py b/examples/client/query_apply.py index c5f8bd8662..ad9747734f 100644 --- a/examples/client/query_apply.py +++ b/examples/client/query_apply.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -15,7 +15,6 @@ # limitations under the License. ########################################################################## -from __future__ import print_function import aerospike import json diff --git a/examples/client/remove.py b/examples/client/remove.py index 01f5f54a95..654f8b1e60 100644 --- a/examples/client/remove.py +++ b/examples/client/remove.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/remove_bin.py b/examples/client/remove_bin.py index 4adc8dd090..85ed8c94cd 100644 --- a/examples/client/remove_bin.py +++ b/examples/client/remove_bin.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -15,7 +15,6 @@ # limitations under the License. ########################################################################## -from __future__ import print_function import aerospike import sys diff --git a/examples/client/scan.py b/examples/client/scan.py index e74274cafc..b8e4862ef3 100644 --- a/examples/client/scan.py +++ b/examples/client/scan.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -15,7 +15,6 @@ # limitations under the License. ########################################################################## -from __future__ import print_function import aerospike import sys diff --git a/examples/client/scan_apply.py b/examples/client/scan_apply.py index 8a89d48563..39e750739b 100644 --- a/examples/client/scan_apply.py +++ b/examples/client/scan_apply.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -15,7 +15,6 @@ # limitations under the License. ########################################################################## -from __future__ import print_function import aerospike import json diff --git a/examples/client/scan_partition.py b/examples/client/scan_partition.py index 80ce72fc4e..7405cf6315 100644 --- a/examples/client/scan_partition.py +++ b/examples/client/scan_partition.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -15,7 +15,6 @@ # limitations under the License. ########################################################################## -from __future__ import print_function import aerospike import sys diff --git a/examples/client/select_many.py b/examples/client/select_many.py index 24b657ed45..4b9e2e97ad 100644 --- a/examples/client/select_many.py +++ b/examples/client/select_many.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -16,7 +16,6 @@ ########################################################################## -from __future__ import print_function import aerospike import sys diff --git a/examples/client/select_record.py b/examples/client/select_record.py index 5a414fe294..29abeded74 100644 --- a/examples/client/select_record.py +++ b/examples/client/select_record.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -15,7 +15,6 @@ # limitations under the License. ########################################################################## -from __future__ import print_function import aerospike import sys diff --git a/examples/client/touch.py b/examples/client/touch.py index f213ccd43a..beae74a229 100644 --- a/examples/client/touch.py +++ b/examples/client/touch.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -15,7 +15,6 @@ # limitations under the License. ########################################################################## -from __future__ import print_function import aerospike import sys diff --git a/examples/client/ttl.py b/examples/client/ttl.py index 4c302007d6..941612885b 100644 --- a/examples/client/ttl.py +++ b/examples/client/ttl.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -25,7 +25,6 @@ # This test is meant to run on an Aerospike 2.x or 3.x server, so the # records that it writes have only primitive types for bin values. -from __future__ import print_function import aerospike import sys diff --git a/examples/client/udf_get.py b/examples/client/udf_get.py index d234ae7f8d..da22c6cdd9 100644 --- a/examples/client/udf_get.py +++ b/examples/client/udf_get.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -15,7 +15,6 @@ # limitations under the License. ########################################################################## -from __future__ import print_function import aerospike import sys diff --git a/examples/client/udf_list.py b/examples/client/udf_list.py index 5b687a523e..0f65661de3 100644 --- a/examples/client/udf_list.py +++ b/examples/client/udf_list.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -15,7 +15,6 @@ # limitations under the License. ########################################################################## -from __future__ import print_function import aerospike import sys diff --git a/examples/client/udf_put.py b/examples/client/udf_put.py index 139e640753..3b95fa4661 100644 --- a/examples/client/udf_put.py +++ b/examples/client/udf_put.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -15,7 +15,6 @@ # limitations under the License. ########################################################################## -from __future__ import print_function import aerospike import sys diff --git a/examples/client/udf_remove.py b/examples/client/udf_remove.py index 17aba34234..daeb4c08c9 100644 --- a/examples/client/udf_remove.py +++ b/examples/client/udf_remove.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/unicode_smiles.py b/examples/client/unicode_smiles.py index 3955c4c25d..2706ec6b29 100644 --- a/examples/client/unicode_smiles.py +++ b/examples/client/unicode_smiles.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- + ########################################################################## # Copyright 2013-2021 Aerospike, Inc. # @@ -16,7 +16,6 @@ ########################################################################## -from __future__ import print_function import aerospike import sys From 660048ba5d53f461bd8819fabbe2317b7b3d0272 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Thu, 16 Jul 2026 13:26:12 -0700 Subject: [PATCH 11/12] Clean up more examples. TODO - looking at client big list --- examples/client/aggregate.py | 7 --- examples/client/append.py | 8 +-- examples/client/apply.py | 108 +++-------------------------------- examples/client/bin_ops.py | 94 ++++++++++-------------------- 4 files changed, 39 insertions(+), 178 deletions(-) diff --git a/examples/client/aggregate.py b/examples/client/aggregate.py index d9bfd956fe..2bfc172637 100644 --- a/examples/client/aggregate.py +++ b/examples/client/aggregate.py @@ -65,13 +65,6 @@ def parse_arg(s): try: - # ---------------------------------------------------------------------------- - # Connect to Cluster - # ---------------------------------------------------------------------------- - - client = aerospike.client(config).connect( - options.username, options.password) - # ---------------------------------------------------------------------------- # Perform Operation # ---------------------------------------------------------------------------- diff --git a/examples/client/append.py b/examples/client/append.py index 9861e64386..796aa4c277 100644 --- a/examples/client/append.py +++ b/examples/client/append.py @@ -27,16 +27,14 @@ def run(self): } # TODO meta gen/ttl should be options? - # TODO: this is the deprecated way of setting ttl and maybe gen meta = { - 'ttl': 1000, 'gen': 10 } - policy = None + policy = { + 'ttl': 1000 + } self.client.put(self.key, record, meta, policy) - # TODO: print statements should mark when command successfully finishes? - self.client.append( self.key, "example_name", " Smith", meta, policy) (key, meta, bins) = self.client.get(self.key) diff --git a/examples/client/apply.py b/examples/client/apply.py index 8805db425d..b9d56cc09e 100644 --- a/examples/client/apply.py +++ b/examples/client/apply.py @@ -16,108 +16,14 @@ ########################################################################## -import aerospike -import json -import sys +from .. import ExampleWithRecord -from optparse import OptionParser - -########################################################################## -# Option Parsing -########################################################################## - -usage = "usage: %prog [options] key module function [args...]" - -optparser.add_option( - "--gen", dest="gen", type="int", default=None, metavar="", - help="Generation of the record being written.") - -optparser.add_option( - "--ttl", dest="ttl", type="int", default=None, metavar="", - help="TTL of the record being written.") - - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if len(args) < 3: - optparser.print_help() - print() - sys.exit(1) - -########################################################################## -# Client Configuration -########################################################################## - -config = { - 'hosts': [(options.host, options.port)] -} - -########################################################################## -# Application -########################################################################## - -exitCode = 0 - -def parse_arg(s): - try: - return json.loads(s) - except ValueError: - return s - -try: - - # ---------------------------------------------------------------------------- - # Connect to Cluster - # ---------------------------------------------------------------------------- - - client = aerospike.client(config).connect( - options.username, options.password) - - # ---------------------------------------------------------------------------- - # Perform Operation - # ---------------------------------------------------------------------------- - - try: - - namespace = options.namespace if options.namespace and options.namespace != 'None' else None - set = options.set if options.set and options.set != 'None' else None - - args.reverse() - key = args.pop() - module = args.pop() - function = args.pop() - - # invoke operation - args.reverse() - argl = list(map(parse_arg, args)) - res = client.apply((namespace, set, key), module, function, argl) +class Apply(ExampleWithRecord): + def run(self): + module = "module" + function = "a" + args = [] + res = self.client.apply(self.key, module, function, args) print(res) - print("---") - print("OK, 1 UDF applied.") - - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - exitCode = 2 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- - - client.close() - -except Exception as eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 3 - -########################################################################## -# Exit -########################################################################## - -sys.exit(exitCode) diff --git a/examples/client/bin_ops.py b/examples/client/bin_ops.py index d422a1d39e..6faace60e1 100644 --- a/examples/client/bin_ops.py +++ b/examples/client/bin_ops.py @@ -14,95 +14,59 @@ # See the License for the specific language governing permissions and # limitations under the License. ########################################################################## +from .. import Example import aerospike +from aerospike_helpers.operations import operations import pprint -import sys -from optparse import OptionParser -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog [options]" - -########################################################################## -# Application -########################################################################## - -exitCode = 0 - -try: - # ---------------------------------------------------------------------------- - # Connect to Cluster - # ---------------------------------------------------------------------------- - - config = {'hosts': [(options.host, options.port)]} - client = aerospike.client(config).connect( - options.username, options.password) - # ---------------------------------------------------------------------------- - # Perform Operations - # ---------------------------------------------------------------------------- - - try: +class BinOps(Example): + def run(self): pp = pprint.PrettyPrinter(indent=2) - client.put(('test', 'cats', 'mr. peppy'), {'breed': 'persian'}, + key = ('test', 'cats', 'mr. peppy') + + self.client.put(key, {'breed': 'persian'}, policy={'exists': aerospike.POLICY_EXISTS_CREATE_OR_REPLACE, - 'key': aerospike.POLICY_KEY_DIGEST}, - meta={'ttl': 120}) - (key, meta, bins) = client.get(('test', 'cats', 'mr. peppy')) + 'key': aerospike.POLICY_KEY_DIGEST, 'ttl': 120}) + (key, meta, bins) = self.client.get(key) + print("Before:", bins) - client.increment( - key, 'lives', -1, {'gen': 2, 'ttl': 1000}, policy={'total_timeout': 1500}) - (key, meta, bins) = client.get(key) + self.client.increment( + key, 'lives', -1, {'gen': 2}, policy={'total_timeout': 1500, 'ttl': 1000}) + (key, meta, bins) = self.client.get(key) + print("After:", bins) # the key we got back when we fetched the record with get() is useable # as-is because it contains the record's digest - client.increment(key, 'lives', -1) - (key, meta, bins) = client.get(key) + self.client.increment(key, 'lives', -1) + (key, meta, bins) = self.client.get(key) + # kitty lost a life, unfortunately print("Poor Kitty:", bins) - client.put(key, {'owner': 'Fry'}) - client.prepend(key, 'owner', 'Philip J. ') - client.append(key, 'owner', ' Esq.') + self.client.put(key, {'owner': 'Fry'}) + self.client.prepend(key, 'owner', 'Philip J. ') + self.client.append(key, 'owner', ' Esq.') + # kitty loses another life, gains a color, all as part of a record # multi-op - ops = [{'bin': 'color', 'op': aerospike.OPERATOR_WRITE, 'val': 'smoke'}, - {'bin': 'lives', 'op': aerospike.OPERATOR_INCR, 'val': -1}, - {'bin': 'ailments', 'op': aerospike.OPERATOR_READ}, - {'bin': 'lives', 'op': aerospike.OPERATOR_READ}] - (key, meta, bins) = client.operate(key, ops) + ops = [ + operations.write(bin="color", write_item="smoke"), + operations.increment(bin_name="lives", amount=-1), + operations.read("ailments"), + operations.read("lives") + ] + (key, meta, bins) = self.client.operate(key, ops) print("After calling operate(), kitty is down to", bins['lives'], "lives") pp.pprint(bins) # display the record as it is after all the operations - (key, meta, bins) = client.get(key) + (key, meta, bins) = self.client.get(key) print("\nRecord\n======\nKey\n---") pp.pprint(key) print("Meta\n----") pp.pprint(meta) print("Bins\n----") pp.pprint(bins) - - except Exception as eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 2 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- - - client.close() - -except Exception as eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 3 - -########################################################################## -# Exit -########################################################################## - -sys.exit(exitCode) From 5f105e8c4b462912b7d2eddc2252811da48e7ad8 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Thu, 16 Jul 2026 14:21:54 -0700 Subject: [PATCH 12/12] Get client_big_list.py to work again. TODO - need to decide whether to keep this. --- examples/client/client_big_list.py | 40 +++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/examples/client/client_big_list.py b/examples/client/client_big_list.py index 61d656ca94..b173e436a5 100644 --- a/examples/client/client_big_list.py +++ b/examples/client/client_big_list.py @@ -1,4 +1,4 @@ - +# -*- coding: utf-8 -*- ########################################################################## # Copyright 2018 Aerospike, Inc. # @@ -15,10 +15,12 @@ # limitations under the License. ########################################################################## +from __future__ import print_function import argparse import aerospike from aerospike import exception as as_exceptions +from aerospike_helpers.operations import list_operations, operations ''' This provides a rough implementation of an expandable list for Aerospike It utilizes a metadata record to provide information about associated subrecords. @@ -171,7 +173,7 @@ def get_all_entries(self, extended_search=False): ) keys.append(key) - subrecords = self.client.get_many(keys) + subrecords = self.client.batch_read(keys) entries = self._get_items_from_subrecords(subrecords) # Try to get subrecords beyond the listed amount. @@ -242,8 +244,11 @@ def _create_or_update_subrecord(self, item, subrecord_number, generation, retrie subrecord_userkey = self._make_user_key(subrecord_number) subrecord_record_key = (self.ns, self.set, subrecord_userkey) try: - self.client.list_append( - subrecord_record_key, self.subrecord_list_bin, item) + ops = [ + list_operations.list_append(self.subrecord_list_bin, item) + ] + self.client.operate( + subrecord_record_key, ops) except as_exceptions.RecordTooBig as e: if retries_remaining == 0: raise e @@ -259,11 +264,15 @@ def _update_metadata_record(self, generation): update_policy = {'gen': aerospike.POLICY_GEN_EQ} meta = {'gen': generation} try: - self.client.increment(self.metadata_key, self.subrecourd_count_name, 1, meta=meta, policy=update_policy) + ops = [ + operations.increment(self.subrecourd_count_name, 1) + ] + self.client.operate(self.metadata_key, ops, meta=meta, policy=update_policy) except as_exceptions.RecordTooBig: raise ASMetadataRecordTooLarge except as_exceptions.RecordGenerationError: # This means that somebody else has updated the record count already. Don't risk updating again. + # TODO: if this happens then there's no way to further update the list from this client? pass def _get_items_from_subrecords(self, subrecords): @@ -285,7 +294,8 @@ def _get_items_from_subrecords(self, subrecords): entries = [] # If a subrecord was included in the header of the top level record, but the matching subrecord # was not found, ignore it. - for _, _, sr_bins in subrecords: + for br in subrecords.batch_records: + sr_bins = br.record[2] if sr_bins: entries.extend(sr_bins[self.subrecord_list_bin]) return entries @@ -321,6 +331,24 @@ def main(): will be created. ''' + optparser = argparse.ArgumentParser() + + optparser.add_argument( + "--host", type=str, default="127.0.0.1", metavar="
", + help="Address of Aerospike server.") + + optparser.add_argument( + "--port", type=int, default=3000, metavar="", + help="Port of the Aerospike server.") + + optparser.add_argument( + "--namespace", type=str, default="test", metavar="", + help="Namespace to use for this example") + + optparser.add_argument( + "-s", "--set", type=str, default="demo", metavar="", + help="Set to use for this example") + optparser.add_argument( "-i", "--items", type=int, default=1000, metavar="", help="Number of items to store into the big list")