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/60] 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/60] 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/60] 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/60] 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/60] 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/60] 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/60] 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/60] 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/60] 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/60] 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/60] 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/60] 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") From 94e1ffc46209e0475cbc7b22b9ffa86ea71989ee Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 17 Jul 2026 07:52:49 -0700 Subject: [PATCH 13/60] Further cleanup of boilerplate. TODO - looking at multithreaded example --- .../client/{exists_many.py => batch_read.py} | 16 ++- examples/client/client_big_list.py | 79 +++++--------- examples/client/delete.py | 97 +++-------------- examples/client/get_key_digest.py | 85 +-------------- examples/client/get_many.py | 103 ------------------ examples/client/get_nodes.py | 66 +---------- examples/client/increment.py | 99 ++--------------- examples/client/index_create.py | 89 ++------------- examples/client/index_remove.py | 74 +------------ examples/client/info.py | 75 ++----------- examples/client/is_connected.py | 83 +------------- examples/client/kvs.py | 71 +++--------- 12 files changed, 116 insertions(+), 821 deletions(-) rename examples/client/{exists_many.py => batch_read.py} (72%) delete mode 100644 examples/client/get_many.py diff --git a/examples/client/exists_many.py b/examples/client/batch_read.py similarity index 72% rename from examples/client/exists_many.py rename to examples/client/batch_read.py index 70fc7555e2..63bfc6080b 100644 --- a/examples/client/exists_many.py +++ b/examples/client/batch_read.py @@ -20,10 +20,22 @@ # TODO: should use fixture with multiple records -class ExistsMany(ExampleWithRecord): +class BatchRead(ExampleWithRecord): def run(self): keys = [f"key{i}" for i in range(5)] - records = self.client.exists_many(keys) + + # Get records + records = self.client.batch_read(keys) + + if records != None: + print(f"{len(records)} records were found") + print(records) + else: + print('error: Not Found.') + + # TODO: verify syntax + # Verify existence of records + records = self.client.batch_read(keys, bins=[]) if records != None: print(f"{len(records)} records were found") diff --git a/examples/client/client_big_list.py b/examples/client/client_big_list.py index b173e436a5..6effafbe2b 100644 --- a/examples/client/client_big_list.py +++ b/examples/client/client_big_list.py @@ -17,6 +17,7 @@ from __future__ import print_function import argparse +from .. import Example import aerospike from aerospike import exception as as_exceptions @@ -66,7 +67,7 @@ class ASMetadataRecordTooLarge(Exception): pass -class ClientSideBigList(object): +class ClientSideBigList: ''' Abstraction around an unbounded size list for Aerospike. Relies on a top level record containing metadata about subrecords. When a subrecord fills up, a new subrecord is created @@ -323,61 +324,33 @@ def sr_iter(): # Instantiate the generator and return it. return sr_iter() +class ClientSideBigListExample(Example): + def run(self): + ''' + Simple tests demonstrating the functionality. + If the database is set up with a small enough write block-size, several subrecords + will be created. + ''' + item_count = 1000 -def main(): - ''' - Simple tests demonstrating the functionality. - If the database is set up with a small enough write block-size, several subrecords - 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") - - options = optparser.parse_args() - print(options) - - client = aerospike.client({'hosts': [('localhost', 3000)]}).connect() - ldt = ClientSideBigList(client, 'person1_friends') - - for i in range(options.items): - # Store a reasonably large item - ldt.add_item('friend{}'.format(i) * 100) - - print("Stored {} items".format(options.items)) + client = aerospike.client({'hosts': [('localhost', 3000)]}).connect() + ldt = ClientSideBigList(client, 'person1_friends') - items = ldt.get_all_entries() - _, _, bins = ldt.get_metadata_record() - print(bins) - print("Known subrecord count is: {}".format(bins['sr_count'])) - print("Fetched {} items:".format(len(items))) + for i in range(item_count): + # Store a reasonably large item + ldt.add_item('friend{}'.format(i) * 100) - count = 0 - for sr in ldt.subrecord_iterator(): - if sr: - count = count + 1 + print("Stored {} items".format(item_count)) - print("Records yielded: {}".format(count)) + items = ldt.get_all_entries() + _, _, bins = ldt.get_metadata_record() + print(bins) + print("Known subrecord count is: {}".format(bins['sr_count'])) + print("Fetched {} items:".format(len(items))) + count = 0 + for sr in ldt.subrecord_iterator(): + if sr: + count = count + 1 -if __name__ == '__main__': - main() + print("Records yielded: {}".format(count)) diff --git a/examples/client/delete.py b/examples/client/delete.py index 661656e17e..4a865ad95f 100644 --- a/examples/client/delete.py +++ b/examples/client/delete.py @@ -15,99 +15,38 @@ # limitations under the License. ########################################################################## -import asyncio -import sys import aerospike -import array -from optparse import OptionParser - -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog [options]" - -optparser = OptionParser(usage=usage, add_help_option=False) - -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 test cases to run.") - -########################################################################## -# Client Configuration -########################################################################## +from .. import ExampleWithRecord +# TODO: missing this config = { - 'hosts': [(options.host, options.port)], + # TODO: this is deprecated? 'policies': { - 'total_timeout': options.timeout + 'total_timeout': 1000 } } -########################################################################## -# Application -########################################################################## - -exitCode = 0 - -try: - - # ---------------------------------------------------------------------------- - # Connect to Cluster - # ---------------------------------------------------------------------------- - - client = aerospike.client(config).connect( - options.username, options.password) - - # ---------------------------------------------------------------------------- - # Perform Operation - # ---------------------------------------------------------------------------- - - try: - 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 +class Delete(ExampleWithRecord): + def run(self): + # TODO; these two were configurable + test_count = 128 policy = { - 'total_timeout': options.timeout + 'total_timeout': 1000 } meta = None print(f"IO test count:{test_count}") def delete(namespace, set, test_count): - for i in range(0, test_count): - key = {'ns': namespace, \ - 'set':set, \ - 'key': str(i), \ - 'digest': aerospike.calc_digest(namespace, set, str(i))} + self.client.remove(self.key) + # for i in range(0, test_count): - policy = None + # TODO + # key = {'ns': namespace, \ + # 'set':set, \ + # 'key': str(i), \ + # 'digest': aerospike.calc_digest(namespace, set, str(i))} + # self.client.remove(self.key) - client.remove(key) - - delete(namespace, set, test_count) + delete(self.namespace, set, test_count) print(f"Deleted {test_count} records") - - 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/get_key_digest.py b/examples/client/get_key_digest.py index f5421c299f..2e577ee7bb 100644 --- a/examples/client/get_key_digest.py +++ b/examples/client/get_key_digest.py @@ -16,86 +16,11 @@ ########################################################################## - +from .. import ExampleWithRecord import aerospike -import sys - -from optparse import OptionParser - -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog [options] key" - - -optparser.add_option( - "--timeout", dest="timeout", type="int", default=1000, metavar="", - help="Client timeout") -(options, args) = optparser.parse_args() - - -if len(args) != 1: - optparser.print_help() - print() - sys.exit(1) - -########################################################################## -# Client Configuration -########################################################################## - -config = { - 'hosts': [(options.host, options.port)], - 'policies': { - 'read': {'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(0) - - digest = aerospike.calc_digest(namespace, set, key) - print("---") - print("Digest is: ", digest) - - 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) +class CalcDigest(ExampleWithRecord): + def run(self): + digest = aerospike.calc_digest(self.namespace, self.set_name, self.key) + print(digest) diff --git a/examples/client/get_many.py b/examples/client/get_many.py deleted file mode 100644 index 76bc97a289..0000000000 --- a/examples/client/get_many.py +++ /dev/null @@ -1,103 +0,0 @@ - -########################################################################## -# 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 aerospike -import sys - -from optparse import OptionParser - - -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog [options]" - -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") - -########################################################################## -# 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.get_many(keylist) - - if records is not None: - 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) diff --git a/examples/client/get_nodes.py b/examples/client/get_nodes.py index 2b67240075..ce52610930 100644 --- a/examples/client/get_nodes.py +++ b/examples/client/get_nodes.py @@ -16,12 +16,7 @@ ########################################################################## - -import aerospike -import sys - -from optparse import OptionParser - +from .. import Example ########################################################################## # Options Parsing @@ -29,59 +24,8 @@ usage = "usage: %prog" -########################################################################## -# 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: - response = client.get_nodes() - - if response is not None: - print(response) - print("---") - 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) +class GetNodes(Example): + def run(self): + # TODO: Demonstrate different outcomes (i.e response is None or not) + response = self.client.get_nodes() diff --git a/examples/client/increment.py b/examples/client/increment.py index ee91e05da4..cf148f51b7 100644 --- a/examples/client/increment.py +++ b/examples/client/increment.py @@ -16,112 +16,33 @@ ########################################################################## +from .. import ExampleWithRecord -import aerospike -import sys - -from optparse import OptionParser - -########################################################################## -# Option Parsing -########################################################################## - -usage = "usage: %prog [options] key" - -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.") - - -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 Increment(ExampleWithRecord): + def run(self): record = { 'example_name': 'John', 'example_age': 1 } - meta = {'ttl': options.ttl, 'gen': options.gen} + # TODO: configurable + # TODO: deprecated + meta = {'ttl': 1000, 'gen': 10} policy = None # invoke operation - client.put((namespace, set, key), record, meta, policy) - - print("---") - print("OK, 1 record written.") + self.client.put(self.key, record, meta, policy) - (returnedkey, meta, bins) = client.get((namespace, set, key)) + (returnedkey, meta, bins) = self.client.get(self.key) - print("---") print("Before increment operation") print(bins) - client.increment((namespace, set, key), "example_age", 5, meta, policy) - print("---") - print("OK, 1 record touched.") + self.client.increment(self.key, "example_age", 5, meta, policy) - (returnedkey, meta, bins) = client.get((namespace, set, key)) + (returnedkey, meta, bins) = self.client.get(self.key) - print("---") print("After increment 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) diff --git a/examples/client/index_create.py b/examples/client/index_create.py index 84a8e03edb..1c5dfd3c3e 100644 --- a/examples/client/index_create.py +++ b/examples/client/index_create.py @@ -15,90 +15,15 @@ # limitations under the License. ########################################################################## - - +from .. import Example import aerospike -import sys - -from optparse import OptionParser - -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog [options] bin index_name" - - -optparser.add_option( - "-t", "--type", dest="type", type="string", default="string", metavar="", - help="The type of index to create") - - -if len(args) != 2: - 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: - args.reverse() +class IndexCreate(Example): + def run(self): policy = {} - namespace = options.namespace - set = options.set - type = options.type - bin = args.pop() - index_name = args.pop() - - if type == 'string': - client.index_string_create(namespace, set, bin, index_name, policy) - print("OK, 1 Secondary Index Created ") - elif type == 'integer': - client.index_integer_create( - namespace, set, bin, index_name, policy) - print("OK, 1 Secondary Index Created ") - - 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 -########################################################################## + # TODO: these are configurable + BIN_NAME = "a" + INDEX_DATATYPE = aerospike.INDEX_INTEGER -sys.exit(exitCode) + self.client.index_single_value_create(self.namespace, self.set_name, BIN_NAME, INDEX_DATATYPE, "index_name", policy) diff --git a/examples/client/index_remove.py b/examples/client/index_remove.py index b2907106da..538ca46425 100644 --- a/examples/client/index_remove.py +++ b/examples/client/index_remove.py @@ -16,75 +16,13 @@ ########################################################################## +from .. import Example -import aerospike -import sys - -from optparse import OptionParser - -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog [options] bin index_name" - -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: +class IndexRemove(Example): + def run(self): policy = {} - namespace = options.namespace - index_name = args.pop() - - client.index_remove(namespace, index_name, policy) - print("OK, 1 Integer Secondary Index Removed ") - - 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 -########################################################################## + # TODO: should be configurable... + INDEX_NAME = "index_name" -sys.exit(exitCode) + self.client.index_remove(self.namespace, INDEX_NAME, policy) diff --git a/examples/client/info.py b/examples/client/info.py index 3128902216..ec5ad5ec0e 100644 --- a/examples/client/info.py +++ b/examples/client/info.py @@ -17,58 +17,17 @@ -import aerospike -import sys +from .. import Example -from optparse import OptionParser - -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog [options] [REQUEST]" - - -(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: +class Info(Example): + def run(self): + # Default info request + # TODO: configurable request = "statistics" - if len(args) > 0: - request = ' '.join(args) - for node, (err, res) in list(client.info_all(request).items()): + # TODO: needs review + for node, (err, res) in list(self.client.info_all(request).items()): if res is not None: res = res.strip() if len(res) > 0: @@ -90,23 +49,3 @@ count += 1 else: print("{0}: {1}".format(node, res)) - - 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/is_connected.py b/examples/client/is_connected.py index ea0317b549..98be1c9586 100644 --- a/examples/client/is_connected.py +++ b/examples/client/is_connected.py @@ -14,84 +14,11 @@ # See the License for the specific language governing permissions and # limitations under the License. ########################################################################## +from .. import Example - -import aerospike -import sys - -from optparse import OptionParser - -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog [options]" - -optparser = OptionParser(usage=usage, add_help_option=False) - - -if len(args) != 0: - 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 - if client.is_connected() == True: +class IsConnected(Example): + def run(self): + # TODO: negative path where not connected, or exception raised was removed + if self.client.is_connected() is True: print("Connected to Aerospike DB.") - - except Exception as xxx_todo_changeme: - (code, msg, file, line) = xxx_todo_changeme.args - if code == 1: - print("error: Connect failed") - 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) diff --git a/examples/client/kvs.py b/examples/client/kvs.py index bde2c26969..5584d7fb1c 100644 --- a/examples/client/kvs.py +++ b/examples/client/kvs.py @@ -17,39 +17,10 @@ -import aerospike -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 Operation - # ---------------------------------------------------------------------------- - - try: +from .. import Example +class KVS(Example): + def run(self): print( '########################################################################') print('PUT') @@ -66,7 +37,8 @@ 'm': {'a': 2, 'b': 4, 'c': 8, 'd': 16} } print(rec) - client.put(('test', 'demo', str(i)), rec) + KEY = ('test', 'demo', str(i)) + self.client.put(KEY, rec) print( '########################################################################') @@ -75,7 +47,8 @@ '########################################################################') for i in range(1, 1000): - (key, metadata) = client.exists(('test', 'demo', str(i))) + KEY = ('test', 'demo', str(i)) + (key, metadata) = self.client.exists(KEY) print(key, metadata) print( @@ -85,7 +58,8 @@ '########################################################################') for i in range(1, 1000): - (key, metadata, record) = client.get(('test', 'demo', str(i))) + KEY = ('test', 'demo', str(i)) + (key, metadata, record) = self.client.get(KEY) print(key, metadata, record) print( @@ -94,11 +68,11 @@ print( '########################################################################') - client.udf_put('simple.lua') + self.client.udf_put('simple.lua') for i in range(1, 1000): key = ('test', 'demo', 'key{0}'.format(i)) - val1 = client.apply(key, 'simple', 'concat', ['a', 30000]) + val1 = self.client.apply(key, 'simple', 'concat', ['a', 30000]) print(val1) print( @@ -108,24 +82,5 @@ '########################################################################') for i in range(1, 1000): - client.remove(('test', 'demo', str(i))) - - 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) + KEY = ('test', 'demo', str(i)) + self.client.remove(KEY) From 6ae77d5017e92841a188a6cc8895bd5daae1ff18 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 17 Jul 2026 08:50:14 -0700 Subject: [PATCH 14/60] More boilerplate removal... --- examples/client/multi_thread.py | 164 +++++++++++++----------------- examples/client/query.py | 20 ---- examples/client/query_apply.py | 84 +++------------ examples/client/remove_bin.py | 108 ++------------------ examples/client/scan.py | 91 ++--------------- examples/client/scan_apply.py | 118 ++++++--------------- examples/client/scan_partition.py | 99 +++--------------- examples/client/select_many.py | 90 +++------------- examples/client/select_record.py | 59 ++--------- examples/client/touch.py | 95 ++--------------- examples/client/ttl.py | 19 ---- examples/client/udf_get.py | 37 ------- 12 files changed, 181 insertions(+), 803 deletions(-) diff --git a/examples/client/multi_thread.py b/examples/client/multi_thread.py index 08b02f0d4f..ac47e60ab8 100644 --- a/examples/client/multi_thread.py +++ b/examples/client/multi_thread.py @@ -22,107 +22,79 @@ import time import threading -from optparse import OptionParser +from .. import Example from aerospike import exception as e -########################################################################## -# Options Parsing -########################################################################## -usage = "usage: %prog [options]" +class Multithread(Example): + numKeys = 10000 + numReads = 1000000 + fNames = ('Jimmy', 'Johnny', 'Sammy', 'Sally', 'Sandy', 'Mandy', 'Billy') + lNames = ('Bama', 'Mama', 'Sama', 'Lama', 'Cama', 'Rama', 'Tama') + numThreads = 5 -########################################################################## -# Client Configuration -########################################################################## -config = { - 'hosts': [(options.host, options.port)], - 'lua': {'user_path': '.'} -} + def writeWork(self, nKeys): + t0 = float(time.time()) -########################################################################## -# Application -########################################################################## + for x in range(0, nKeys): + kstr = 'k' + str(x) + key = (self.namespace, self.set_name, kstr) + + try: + # Write a record + self.client.put(key, { + 'name': random.choice(self.fNames) + ' ' + random.choice(self.lNames), + 'age': random.randint(10, 100), + 'value': x + }) + except Exception as e: + print('write error {0}'.format(e)) + + if x % 1000 == 0 and x > 0: + print('Wrote {0} records at T = {1:.2f} sec'.format( + x, float(time.time()) - t0)) + + print('Wrote {0} records at T = {1:.2f} sec'.format( + nKeys, float(time.time()) - t0)) + + + def readWork(self, nReads, thrName): + print('Thread #{0} is starting to read {1} records'.format( + thrName, nReads)) + + # Read records + t0 = float(time.time()) + + for x in range(0, nReads): + kstr = 'k' + str(random.randrange(0, self.numKeys)) + key = (self.namespace, self.set_name, kstr) + try: + (key, _, _) = self.client.get(key) + except aerospike.exception.ClientError as e: + print('Aerospike Error: {0} [{1}]'.format(e.msg, e.code)) + return None + + if x % 10000 == 0 and x > 0: + print('Thread #{0} : Read {1} records at T = {2:.2f} sec'.format( + thrName, x, float(time.time()) - t0)) + print('Thread #{0} : Read {1} records at T = {2:.2f} sec'.format( + thrName, nReads, float(time.time()) - t0)) + + + def run(self): + print('Writing data into Aerospike DB') + self.writeWork(self.numKeys) + + print('Reading data from Aerospike DB using {0} threads'.format(self.numThreads)) + t = [] + + for i in range(self.numThreads): + thread = threading.Thread(target=self.readWork, + args=(self.numReads // self.numThreads, str(i))) + thread.start() + t.append(thread) -try: - client = aerospike.client(config).connect( - options.username, options.password) -except e.ClientError as exception: - print('Error: {0} [{1}]'.format(exception.msg, exception.code)) - sys.exit(1) - -namespace = 'test' -testSet = 'test' -numKeys = 10000 -numReads = 1000000 -fNames = ('Jimmy', 'Johnny', 'Sammy', 'Sally', 'Sandy', 'Mandy', 'Billy') -lNames = ('Bama', 'Mama', 'Sama', 'Lama', 'Cama', 'Rama', 'Tama') -numThreads = 5 - - -def writeWork(nKeys): - t0 = float(time.time()) - - for x in range(0, nKeys): - kstr = 'k' + str(x) - key = (namespace, testSet, kstr) - - try: - # Write a record - client.put(key, { - 'name': random.choice(fNames) + ' ' + random.choice(lNames), - 'age': random.randint(10, 100), - 'value': x - }) - except Exception as e: - print('write error {0}'.format(e)) - - if x % 1000 == 0 and x > 0: - print('Wrote {0} records at T = {1:.2f} sec'.format( - x, float(time.time()) - t0)) - - print('Wrote {0} records at T = {1:.2f} sec'.format( - nKeys, float(time.time()) - t0)) - - -def readWork(nReads, thrName): - print('Thread #{0} is starting to read {1} records'.format( - thrName, nReads)) - - # Read records - t0 = float(time.time()) - - for x in range(0, nReads): - kstr = 'k' + str(random.randrange(0, numKeys)) - key = (namespace, testSet, kstr) - try: - (key, _, _) = client.get(key) - except aerospike.exception.ClientError as e: - print('Aerospike Error: {0} [{1}]'.format(e.msg, e.code)) - return None - - if x % 10000 == 0 and x > 0: - print('Thread #{0} : Read {1} records at T = {2:.2f} sec'.format( - thrName, x, float(time.time()) - t0)) - print('Thread #{0} : Read {1} records at T = {2:.2f} sec'.format( - thrName, nReads, float(time.time()) - t0)) - - -print('Writing data into Aerospike DB') -writeWork(numKeys) - -print('Reading data from Aerospike DB using {0} threads'.format(numThreads)) -t = [] - -for i in range(numThreads): - thread = threading.Thread(target=readWork, - args=(numReads // numThreads, str(i))) - thread.start() - t.append(thread) - -for i in range(numThreads): - t[i].join() - -print('Finished. Closing Aerospike connection.') -client.close() + for i in range(self.numThreads): + t[i].join() diff --git a/examples/client/query.py b/examples/client/query.py index a1bbae5087..c615426dbb 100644 --- a/examples/client/query.py +++ b/examples/client/query.py @@ -57,26 +57,6 @@ 'user_path': os.path.dirname(__file__) } } - -########################################################################## -# Application -########################################################################## - -exitCode = 0 - -try: - - # ---------------------------------------------------------------------------- - # Connect to Cluster - # ---------------------------------------------------------------------------- - - client = aerospike.client(config).connect( - options.username, options.password) - - # ---------------------------------------------------------------------------- - # Perform Operation - # ---------------------------------------------------------------------------- - try: re_bin = "(.{1,14})" diff --git a/examples/client/query_apply.py b/examples/client/query_apply.py index ad9747734f..efe56bc30f 100644 --- a/examples/client/query_apply.py +++ b/examples/client/query_apply.py @@ -22,7 +22,6 @@ import sys import os.path -from optparse import OptionParser from aerospike import predicates as p ########################################################################## @@ -60,59 +59,29 @@ def query_callback(option, opt, value, parser): help="If set, displays the metadata.") -(options, args) = optparser.parse_args() +from .. import Example -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__) } } -########################################################################## -# Application -########################################################################## - -exitCode = 0 - -try: - - # ---------------------------------------------------------------------------- - # Connect to Cluster - # ---------------------------------------------------------------------------- - - client = aerospike.client(config).connect() +class QueryApply(Example): + def run(self): # ---------------------------------------------------------------------------- # Perform Operation # ---------------------------------------------------------------------------- - try: - query_id = 0 re_bin = "(.{1,14})" re_str_eq = "\s+=\s*(?:(?:\"(.*)\")|(?:\'(.*)\'))" re_int_eq = "\s+=\s*(\d+)" re_int_rg = "\s+between\s+\(\s*(\d+)\s*,\s*(\d+)\s*\)" re_w = re.compile("%s(?:%s|%s|%s)" % - (re_bin, re_str_eq, re_int_eq, re_int_rg)) - - namespace = options.namespace if options.namespace and options.namespace != 'None' else None - set = options.set if options.set and options.set != 'None' else None + (re_bin, re_str_eq, re_int_eq, re_int_rg)) q = None @@ -130,31 +99,31 @@ def query_callback(option, opt, value, parser): b = w.group(1) v = w.group(2) query_id = client.query_apply(options.namespace, - options.set, p.equals( - b, v), options.module, - options.function, options.arguments) + options.set, p.equals( + b, v), options.module, + options.function, options.arguments) elif w.group(3): b = w.group(1) v = w.group(3) query_id = client.query_apply(options.namespace, - options.set, p.equals( - b, v), options.module, - options.function, options.arguments) + options.set, p.equals( + b, v), options.module, + options.function, options.arguments) elif w.group(4): b = w.group(1) v = int(w.group(4)) query_id = client.query_apply(options.namespace, - options.set, p.equals( - b, v), options.module, - options.function, options.arguments) + options.set, p.equals( + b, v), options.module, + options.function, options.arguments) elif w.group(5) and w.group(6): b = w.group(1) l = int(w.group(5)) u = int(w.group(6)) query_id = client.query_apply(options.namespace, - options.set, p.between( - b, l, u), options.module, - options.function, options.arguments) + options.set, p.between( + b, l, u), options.module, + options.function, options.arguments) while True: response = client.job_info(query_id, aerospike.JOB_QUERY) @@ -165,24 +134,3 @@ def query_callback(option, opt, value, parser): print("Background query is successful") else: print("Query_apply failed") - - 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) diff --git a/examples/client/remove_bin.py b/examples/client/remove_bin.py index 85ed8c94cd..bc16ca3a14 100644 --- a/examples/client/remove_bin.py +++ b/examples/client/remove_bin.py @@ -27,106 +27,18 @@ usage = "usage: %prog [options] key bin_names" -optparser = OptionParser(usage=usage, add_help_option=False) +from .. import ExampleWithRecord -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) < 2: - 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 - - pk = args.pop(0) - bin_names = args - status = client.remove_bin((namespace, set, pk), bin_names) - print("Status of bin removal is: %d" % (status)) - print("OK, bins removed from the record at", (namespace, set, pk)) - - except Exception as exception: - if exception.code == 602: - print("error: Record not found") - else: - print("error: {0}".format( - (exception.code, exception.msg, file, exception.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 -########################################################################## +class RemoveBin(ExampleWithRecord): + def run(self): + # TODO: both configurable + # pk + bin_names = [] -sys.exit(exitCode) + retval = self.client.remove_bin(self.key, bin_names) + print("Status of bin removal is: %d" % (retval)) + print("OK, bins removed from the record at", self.key) + # TODO: why RecordNotFound used to map to 602? diff --git a/examples/client/scan.py b/examples/client/scan.py index b8e4862ef3..03c9e4c69c 100644 --- a/examples/client/scan.py +++ b/examples/client/scan.py @@ -15,66 +15,17 @@ # limitations under the License. ########################################################################## +from .. import Example -import aerospike -import sys -from optparse import OptionParser +class Scan(Example): + def run(self): + s = self.client.scan(self.namespace, self.set_name) -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog [options]" - -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) - -########################################################################## -# 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 - - s = client.scan(namespace, set) - - if options.bins and len(options.bins) > 0: - # project specified bins - s.select(*options.bins) + # TODO: configurable + bins = [] + # project specified bins + s.select(*bins) records = [] @@ -87,28 +38,4 @@ def callback(input_tuple): # invoke the operations, and for each record invoke the callback s.foreach(callback) - print("---") - if len(records) == 1: - print("OK, 1 record found.") - else: - print("OK, %d records found." % len(records)) - - 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) + print("OK, %d records found." % len(records)) diff --git a/examples/client/scan_apply.py b/examples/client/scan_apply.py index 39e750739b..9212e31272 100644 --- a/examples/client/scan_apply.py +++ b/examples/client/scan_apply.py @@ -32,47 +32,23 @@ def scan_callback(option, opt, value, parser): setattr(parser.values, option.dest, value.split(',')) -optparser = OptionParser(usage=usage, add_help_option=False) +# optparser.add_option( +# "-m", "--module", dest="module", type="string", +# help="UDF Module.") -optparser.add_option( - "-m", "--module", dest="module", type="string", - help="UDF Module.") +# optparser.add_option( +# "-f", "--function", dest="function", type="string", +# help="UDF Function.") -optparser.add_option( - "-f", "--function", dest="function", type="string", - help="UDF Function.") +# optparser.add_option( +# "-a", "--arg", dest="arguments", type="string", action="callback", +# callback=scan_callback, help="UDF Arguments.") -optparser.add_option( - "-a", "--arg", dest="arguments", type="string", action="callback", - callback=scan_callback, help="UDF Arguments.") +# optparser.add_option( +# "-b", "--bins", dest="bins", type="string", action="append", +# help="Bins to select from each record.") -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) > 0: - optparser.print_help() - print() - sys.exit(1) -############################################################################### -# Client Configuration -############################################################################### - -config = { - 'hosts': [(options.host, options.port)] -} - -############################################################################### -# Application -############################################################################### exitCode = 0 @@ -85,61 +61,29 @@ def parse_arg(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() - - module = options.module - function = options.function + args.reverse() - for i, param in enumerate(options.arguments): - if param.isdigit(): - options.arguments[i] = int(param) + module = options.module + function = options.function - policy = {} - scan_id = client.scan_apply( - namespace, set, module, function, options.arguments, policy) + for i, param in enumerate(options.arguments): + if param.isdigit(): + options.arguments[i] = int(param) - while True: - response = client.job_info(scan_id, aerospike.JOB_SCAN) - if response['status'] == aerospike.JOB_STATUS_COMPLETED: - break + policy = {} + scan_id = client.scan_apply( + namespace, set, module, function, options.arguments, policy) + while True: + response = client.job_info(scan_id, aerospike.JOB_SCAN) if response['status'] == aerospike.JOB_STATUS_COMPLETED: - print("Background scan is successful") - else: - print("Scan_apply failed") - - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - rc = 1 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- + break - client.close() - -except Exception as eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 3 - -########################################################################## -# Exit -########################################################################## + if response['status'] == aerospike.JOB_STATUS_COMPLETED: + print("Background scan is successful") + else: + print("Scan_apply failed") -sys.exit(exitCode) +except Exception as e: + print("error: {0}".format(e), file=sys.stderr) + rc = 1 diff --git a/examples/client/scan_partition.py b/examples/client/scan_partition.py index 7405cf6315..930bfaca26 100644 --- a/examples/client/scan_partition.py +++ b/examples/client/scan_partition.py @@ -15,69 +15,20 @@ # limitations under the License. ########################################################################## +from .. import Example -import aerospike -import sys -from optparse import OptionParser - -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog [options]" - -optparser.add_option( - "-i", "--partition_id", dest="partition", type="int", default=0, - help="Partition id from where to scan.") - -(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 - - s = client.scan(namespace, set) +class ScanPartition(Example): + def run(self): + s = self.client.scan(self.namespace, self.set_name) partition_policy = None - if options.partition > 0: + # TODO: configurable + STARTING_PARTITION = 1 + if STARTING_PARTITION > 0: # project specified bins - partition_policy = {'partition_filter': {'begin': options.partition, 'count': 1}} - print(f'partition_id: {options.partition}') + partition_policy = {'partition_filter': {'begin': STARTING_PARTITION, 'count': 1}} records = [] @@ -87,19 +38,19 @@ def callback(input_tuple): records.append(record) print(record) - client.truncate('test', "demo", 0) + self.client.truncate(self.namespace, self.set_name, 0) # invoke the operations, and for each record invoke the callback s.foreach(callback, partition_policy) existing_count = len(records) if existing_count > 0: - print(f"{existing_count} records are exist already in partition:{options.partition}.") + print(f"{existing_count} records already exist in partition: {STARTING_PARTITION}.") count = 0 for i in range(1, 80000): - rec_partition = client.get_key_partition_id('test', 'demo', str(i)) + rec_partition = self.client.get_key_partition_id(self.namespace, self.set_name, str(i)) - if rec_partition == options.partition: # and not client.exists(('test', 'demo', str(i))): + if rec_partition == STARTING_PARTITION: # and not client.exists(('test', 'demo', str(i))): count = count + 1 rec = { @@ -108,32 +59,12 @@ def callback(input_tuple): 'l': [2, 4, 8, 16, 32, None, 128, 256], 'm': {'partition': rec_partition, 'b': 4, 'c': 8, 'd': 16} } - client.put(('test', 'demo', str(i)), rec) + self.client.put((self.namespace, self.set_name, str(i)), rec) records.clear() # invoke the operations, and for each record invoke the callback s.foreach(callback, partition_policy) print("---") - print(f"{count} records are put into partition:{options.partition}.") - print(f"{len(records)} records are found in partition:{options.partition}.") - - 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) + print(f"{count} records are put into partition: {STARTING_PARTITION}.") + print(f"{len(records)} records are found in partition: {STARTING_PARTITION}.") diff --git a/examples/client/select_many.py b/examples/client/select_many.py index 4b9e2e97ad..10422e0996 100644 --- a/examples/client/select_many.py +++ b/examples/client/select_many.py @@ -20,91 +20,31 @@ import aerospike import sys -from optparse import OptionParser -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog [options]" - -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 +# 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") -try: +from .. import Example - # ---------------------------------------------------------------------------- - # 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 +class SelectMany(Example): + def run(self): # args.pop() + # TODO: configurable + keys = [] + # keys = options.keys.split(',') + # keylist = [] + # for key in keys: + # individualkey = (namespace, set, key) + # keylist.append(individualkey) - keys = options.keys.split(',') - keylist = [] - for key in keys: - individualkey = (namespace, set, key) - keylist.append(individualkey) - - records = client.select_many(keylist, ['i', 'd']) + records = self.client.select_many(keys, ['i', 'd']) if records is not None: print(records) print("---") print("OK, %d records found." % len(records)) else: + # TODO: not sure if this is right 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) diff --git a/examples/client/select_record.py b/examples/client/select_record.py index 29abeded74..8d5212167e 100644 --- a/examples/client/select_record.py +++ b/examples/client/select_record.py @@ -49,43 +49,21 @@ 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) +from .. import ExampleWithRecord - # ---------------------------------------------------------------------------- - # 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 +class SelectRecord(ExampleWithRecord): + def run(self): + # TODO: both configurable key = args.pop(0) + bins = [] + policy = None print(args) - (key, metadata, record) = client.select( - (namespace, set, key), args, policy) + (key, metadata, record) = self.client.select( + (self.namespace, self.set_name, key), bins, policy) if metadata is not None: if options.nometadata and options.nokey: @@ -99,25 +77,6 @@ print("---") print("OK, 1 record found.") else: + # TODO: not sure if this is right. 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) diff --git a/examples/client/touch.py b/examples/client/touch.py index beae74a229..4f6ad2d647 100644 --- a/examples/client/touch.py +++ b/examples/client/touch.py @@ -25,110 +25,31 @@ # Option Parsing ########################################################################## -usage = "usage: %prog [options] key" +# TODO: ttl/gen configurable -optparser.add_option( - "--gen", dest="gen", type="int", default=10, metavar="", - help="Generation of the record being written.") +from .. import ExampleWithRecord -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 +class Touch(ExampleWithRecord): + def run(self): + # TODO configurable key = args.pop() - record = { - 'example_name': 'John', - 'example_age': 1 - } - meta = {'ttl': options.ttl, 'gen': options.gen} policy = None - # invoke operation - - client.put((namespace, set, key), record, meta, policy) - - print(record) - print("---") - print("OK, 1 record written.") - - (returnedkey, meta) = client.exists((namespace, set, key)) + (returnedkey, meta) = self.client.exists(self.key) print("---") print("Ttl before touch operation") print(meta) - client.touch((namespace, set, key), options.ttl + 1000, meta, policy) + self.client.touch(self.key, options.ttl + 1000, meta, policy) print("---") print("OK, 1 record touched.") - (returnedkey, meta) = client.exists((namespace, set, key)) + (returnedkey, meta) = self.client.exists(self.key) print("---") print("Ttl after touch operation") print(meta) - - 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/ttl.py b/examples/client/ttl.py index 941612885b..7e338241a5 100644 --- a/examples/client/ttl.py +++ b/examples/client/ttl.py @@ -35,25 +35,6 @@ from optparse import OptionParser from aerospike import exception as e -########################################################################## -# Option Parsing -########################################################################## - -usage = "usage: %prog [options]" - -optparser = OptionParser(usage=usage, add_help_option=False) - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -########################################################################## -# CONSTANTS -########################################################################## - TTL_DEFAULT = 10 TTL_MAX = 20 TTL_NO_EXPIRE = -1 diff --git a/examples/client/udf_get.py b/examples/client/udf_get.py index da22c6cdd9..87a85e5c7c 100644 --- a/examples/client/udf_get.py +++ b/examples/client/udf_get.py @@ -27,43 +27,6 @@ usage = "usage: %prog [options] module" -(options, args) = optparser.parse_args() - -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() language = aerospike.UDF_TYPE_LUA policy = {} From ebc537caf69c8f791b7ad3cba5eb5e93e775fe14 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Mon, 20 Jul 2026 09:26:25 -0700 Subject: [PATCH 15/60] Finish first pass of converting all examples to use boilerplate class --- examples/client/udf_get.py | 39 ++--------- examples/client/udf_list.py | 66 ++---------------- examples/client/udf_put.py | 74 ++------------------ examples/client/unicode_smiles.py | 109 +++++++----------------------- 4 files changed, 44 insertions(+), 244 deletions(-) diff --git a/examples/client/udf_get.py b/examples/client/udf_get.py index 87a85e5c7c..743ade5455 100644 --- a/examples/client/udf_get.py +++ b/examples/client/udf_get.py @@ -15,43 +15,18 @@ # limitations under the License. ########################################################################## - +from .. import Example import aerospike -import sys - -from optparse import OptionParser -########################################################################## -# Options Parsing -########################################################################## -usage = "usage: %prog [options] module" - - module = args.pop() +class UDFGet(Example): + def run(self): + # TODO: configurable + module = "a" language = aerospike.UDF_TYPE_LUA policy = {} - client.udf_put(module, language, policy) - udf_contents = client.udf_get(module, language, policy) + self.client.udf_put(module, language, policy) + udf_contents = self.client.udf_get(module, language, policy) print("Module contents : ") print(udf_contents) - - 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/udf_list.py b/examples/client/udf_list.py index 0f65661de3..75362e6b84 100644 --- a/examples/client/udf_list.py +++ b/examples/client/udf_list.py @@ -15,69 +15,11 @@ # limitations under the License. ########################################################################## +from .. import Example -import aerospike -import sys - -from optparse import OptionParser - -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog [options]" - - -########################################################################## -# 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: +class UDFList(Example): + def run(self): policy = {} - - llist = client.udf_list(policy) + llist = self.client.udf_list(policy) print(llist) - - 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/udf_put.py b/examples/client/udf_put.py index 3b95fa4661..3b5eee61bd 100644 --- a/examples/client/udf_put.py +++ b/examples/client/udf_put.py @@ -16,75 +16,15 @@ ########################################################################## -import aerospike -import sys +from .. import Example -from optparse import OptionParser - -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog [options] filename" - - -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: +class UDFPut(Example): + def run(self): policy = {} - filename = args.pop() + # TODO + # filename = args.pop() + filename = "z" udf_type = 0 # 0 for LUA - client.udf_put(filename, udf_type, policy) - print("OK, 1 new UDF 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) + self.client.udf_put(filename, udf_type, policy) diff --git a/examples/client/unicode_smiles.py b/examples/client/unicode_smiles.py index 2706ec6b29..7b7b709cde 100644 --- a/examples/client/unicode_smiles.py +++ b/examples/client/unicode_smiles.py @@ -17,68 +17,33 @@ +from .. import Example import aerospike -import sys -from optparse import OptionParser -from aerospike import exception as e - -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog [options]" - -optparser = OptionParser(usage=usage, add_help_option=False) - - -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") - - -########################################################################## -# Application -########################################################################## - -try: - - # ---------------------------------------------------------------------------- - # Connect to Cluster - # ---------------------------------------------------------------------------- - - config = { - 'hosts': [(options.host, options.port)], - 'policies': { - 'total_timeout': options.timeout - } +config = { + 'policies': { + # TODO: configurable + 'total_timeout': 1000 } - 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 +class UnicodeSmiles(Example): + def run(self): smile = u"smilé" + # TODO: configurable + read_timeout = 1000 - key = (namespace, set, smile) + key = (self.namespace, self.set_name, smile) bins = {'smiley': smile, 'smile_count': 1, 'mood': 'happy'} print("Storing ", bins, "at a record identified by the tuple", key) # overwrite the record if it exists, otherwise create it - client.put(key, bins, + self.client.put(key, bins, policy={'exists': aerospike.POLICY_EXISTS_CREATE_OR_REPLACE, 'key': aerospike.POLICY_KEY_SEND}) print("Retrieving the record from the server for comparison") - (key, meta, record) = client.get( - key, policy={'total_timeout': options.read_timeout}) + (key, meta, record) = self.client.get( + key, policy={'total_timeout': read_timeout}) print("The value of the 'smiley' bin is", record['smiley'], "\n") print("By the way, this record has been written", meta['gen'], "times") future_gen = str(int(meta['gen']) + 2) @@ -88,8 +53,8 @@ # add a dictionary under a bin named 'data' bins = {'data': {'smiley_key': smile, smile: 'this is a smiley '}} print("Storing ", bins, "at the record", key) - client.put(key, bins) - (key, metadata, bins) = client.get(key) + self.client.put(key, bins) + (key, metadata, bins) = self.client.get(key) print("The value of the 'smiley_key' of the 'data' bin is", bins['data']['smiley_key'], "\n") # print("The value of the", smile, " key is:", @@ -98,16 +63,16 @@ # append to the value of the smile key print("Before appending, the value of the 'mood' key is:", bins['mood']) - client.append(key, 'mood', smile) - (key, metadata, bins) = client.get(key) + self.client.append(key, 'mood', smile) + (key, metadata, bins) = self.client.get(key) print("After appending, the value of the 'mood' key is:", bins['mood'], "\n") # prepend to the value of the smile key print("Before prepending, the value of the 'mood' key is:", bins['mood']) - client.prepend(key, 'mood', smile) - (key, metadata, bins) = client.get(key) + self.client.prepend(key, 'mood', smile) + (key, metadata, bins) = self.client.get(key) print("After prepending, the value of the 'mood' key is:", bins['mood'], "\n") @@ -116,45 +81,23 @@ {'bin': 'smile_count', 'op': aerospike.OPERATOR_INCR, 'val': 5}, {'bin': 'smiley', 'op': aerospike.OPERATOR_READ}] print("Setting the following multiops on the same record\n", ops) - (key, meta, bins) = client.operate(key, ops) + (key, meta, bins) = self.client.operate(key, ops) print("The value of the 'smiley' bin is", bins['smiley'], "\n") print("Displaying the key, metadata, and bins of the record") - (key, meta, bins) = client.get(key) + (key, meta, bins) = self.client.get(key) print(key) print(meta) print(bins, "\n") - client.remove(key) + self.client.remove(key) # example of a bytearray primary key print("Save a new record with a bytearray primary key") smiley_pk = smile.encode("utf-8") - client.put((namespace, set, smiley_pk), {'smiley': smile, 'smiley_pk': + self.client.put((self.namespace, self.set_name, smiley_pk), {'smiley': smile, 'smiley_pk': smiley_pk}) print("Display the bins of a record with a bytearray key") - (key, meta, bins) = client.get((namespace, set, smiley_pk)) + (key, meta, bins) = self.client.get((self.namespace, self.set_name, smiley_pk)) print(bins) print("The value of the 'smiley_pk' bin is", bins['smiley_pk'], "\n") - client.remove(key) - exitCode = 0 - except Exception as exception: - print("error: {0}".format(exception), file=sys.stderr) - exitCode = 2 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- - - client.close() - -except e.ClientError as exception: - print("Error: {0} [{1}]".format(exception.msg, exception.code)) - exitCode = 3 - -########################################################################## -# Exit -########################################################################## - -sys.exit(exitCode) - -# + self.client.remove(key) From 85743a383b64ceb12dfc8f298488e198f188bf7f Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Tue, 21 Jul 2026 14:49:51 -0700 Subject: [PATCH 16/60] Further cleanup. Update all copyright notices in examples/client. --- examples/client/aggregate.py | 165 ++++++++++++------------------ examples/client/append.py | 17 +-- examples/client/apply.py | 2 +- examples/client/batch_read.py | 2 +- examples/client/bin_ops.py | 2 +- examples/client/delete.py | 2 +- examples/client/exists.py | 2 +- examples/client/get.py | 2 +- examples/client/get_key_digest.py | 2 +- examples/client/get_nodes.py | 2 +- examples/client/increment.py | 15 +-- examples/client/index_create.py | 2 +- examples/client/index_remove.py | 2 +- examples/client/info.py | 2 +- examples/client/is_connected.py | 2 +- examples/client/kvs.py | 2 +- examples/client/multi_thread.py | 2 +- examples/client/operate.py | 8 +- examples/client/prepend.py | 12 +-- examples/client/put.py | 7 +- examples/client/query.py | 2 +- examples/client/query_apply.py | 2 +- examples/client/remove.py | 2 +- examples/client/remove_bin.py | 2 +- examples/client/scan.py | 2 +- examples/client/scan_apply.py | 2 +- examples/client/scan_partition.py | 2 +- examples/client/select_many.py | 2 +- examples/client/select_record.py | 2 +- examples/client/simple.lua | 2 +- examples/client/touch.py | 31 ++---- examples/client/ttl.py | 54 +++------- examples/client/udf_get.py | 2 +- examples/client/udf_list.py | 2 +- examples/client/udf_put.py | 2 +- examples/client/udf_remove.py | 2 +- examples/client/unicode_smiles.py | 2 +- 37 files changed, 129 insertions(+), 238 deletions(-) diff --git a/examples/client/aggregate.py b/examples/client/aggregate.py index 2bfc172637..1b8a1c2fa5 100644 --- a/examples/client/aggregate.py +++ b/examples/client/aggregate.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -37,25 +37,12 @@ "-b", "--bins", dest="bins", type="string", action="append", help="Bins to select from each record.") -(options, args) = optparser.parse_args() - -if len(args) < 3: - optparser.print_help() - print() - sys.exit(1) - config = { 'lua': { 'user_path': os.path.dirname(__file__) } } -########################################################################## -# Application -########################################################################## - -exitCode = 0 - def parse_arg(s): try: @@ -63,93 +50,67 @@ def parse_arg(s): except ValueError: return s -try: - - # ---------------------------------------------------------------------------- - # Perform Operation - # ---------------------------------------------------------------------------- - try: - - re_bin = "(.{1,14})" - re_str_eq = "\s+=\s*(?:(?:\"(.*)\")|(?:\'(.*)\'))" - re_int_eq = "\s+=\s*(\d+)" - re_int_rg = "\s+between\s+\(\s*(\d+)\s*,\s*(\d+)\s*\)" - re_w = re.compile("%s(?:%s|%s|%s)" % - (re_bin, re_str_eq, re_int_eq, re_int_rg)) - - 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() - where = args.pop() - module = args.pop() - function = args.pop() - - # If predicate is provided, then perform a query - q = client.query(namespace, set) - w = re_w.match(where) - if w is not None: - if w.group(2): - b = w.group(1) - v = w.group(2) - q.where(p.equals(b, v)) - elif w.group(3): - b = w.group(1) - v = w.group(3) - q.where(p.equals(b, v)) - elif w.group(4): - b = w.group(1) - v = int(w.group(4)) - q.where(p.equals(b, v)) - elif w.group(5) and w.group(6): - b = w.group(1) - l = int(w.group(5)) - u = int(w.group(6)) - q.where(p.between(b, l, u)) - - if options.bins and len(options.bins) > 0: - # project specified bins - q.select(*options.bins) - - args.reverse() - argl = list(map(parse_arg, args)) - print("argl == ", argl) - q.apply(module, function, *argl) - - results = [] - - # callback to be called for each record read - def callback(result): - results.append(result) - print(result) - - # invoke the operations, and for each record invoke the callback - q.foreach(callback) - - print("---") - if len(results) == 1: - print("OK, 1 result found.") - else: - print("OK, %d results found." % len(results)) - - 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) +# ---------------------------------------------------------------------------- +# Perform Operation +# ---------------------------------------------------------------------------- + +re_bin = "(.{1,14})" +re_str_eq = "\s+=\s*(?:(?:\"(.*)\")|(?:\'(.*)\'))" +re_int_eq = "\s+=\s*(\d+)" +re_int_rg = "\s+between\s+\(\s*(\d+)\s*,\s*(\d+)\s*\)" +re_w = re.compile("%s(?:%s|%s|%s)" % + (re_bin, re_str_eq, re_int_eq, re_int_rg)) + +args.reverse() +where = args.pop() +module = args.pop() +function = args.pop() + +# If predicate is provided, then perform a query +q = client.query(namespace, set) +w = re_w.match(where) +if w is not None: + if w.group(2): + b = w.group(1) + v = w.group(2) + q.where(p.equals(b, v)) + elif w.group(3): + b = w.group(1) + v = w.group(3) + q.where(p.equals(b, v)) + elif w.group(4): + b = w.group(1) + v = int(w.group(4)) + q.where(p.equals(b, v)) + elif w.group(5) and w.group(6): + b = w.group(1) + l = int(w.group(5)) + u = int(w.group(6)) + q.where(p.between(b, l, u)) + +if options.bins and len(options.bins) > 0: + # project specified bins + q.select(*options.bins) + +args.reverse() +argl = list(map(parse_arg, args)) +print("argl == ", argl) +q.apply(module, function, *argl) + +results = [] + +# callback to be called for each record read +def callback(result): + results.append(result) + print(result) + +# invoke the operations, and for each record invoke the callback +q.foreach(callback) + +print("---") +if len(results) == 1: + print("OK, 1 result found.") +else: + print("OK, %d results found." % len(results)) diff --git a/examples/client/append.py b/examples/client/append.py index 796aa4c277..1183b42608 100644 --- a/examples/client/append.py +++ b/examples/client/append.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -25,17 +25,8 @@ def run(self): 'example_name': 'John', 'example_age': 1 } + self.client.put(self.key, record) - # TODO meta gen/ttl should be options? - meta = { - 'gen': 10 - } - policy = { - 'ttl': 1000 - } - self.client.put(self.key, record, meta, policy) - - self.client.append( - self.key, "example_name", " Smith", meta, policy) - (key, meta, bins) = self.client.get(self.key) + self.client.append(self.key, "example_name", " Smith") + _, _, bins = self.client.get(self.key) print(bins) diff --git a/examples/client/apply.py b/examples/client/apply.py index b9d56cc09e..399f615937 100644 --- a/examples/client/apply.py +++ b/examples/client/apply.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/batch_read.py b/examples/client/batch_read.py index 63bfc6080b..b39bf0a40d 100644 --- a/examples/client/batch_read.py +++ b/examples/client/batch_read.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/bin_ops.py b/examples/client/bin_ops.py index 6faace60e1..844afdf48b 100644 --- a/examples/client/bin_ops.py +++ b/examples/client/bin_ops.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/delete.py b/examples/client/delete.py index 4a865ad95f..bc878d6930 100644 --- a/examples/client/delete.py +++ b/examples/client/delete.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/exists.py b/examples/client/exists.py index 83ace5fade..9009f26b7e 100644 --- a/examples/client/exists.py +++ b/examples/client/exists.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/get.py b/examples/client/get.py index 1b7c742d55..8e85ccaa85 100644 --- a/examples/client/get.py +++ b/examples/client/get.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/get_key_digest.py b/examples/client/get_key_digest.py index 2e577ee7bb..1d379f8af7 100644 --- a/examples/client/get_key_digest.py +++ b/examples/client/get_key_digest.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/get_nodes.py b/examples/client/get_nodes.py index ce52610930..7e4905fd8a 100644 --- a/examples/client/get_nodes.py +++ b/examples/client/get_nodes.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/increment.py b/examples/client/increment.py index cf148f51b7..1987c1d65b 100644 --- a/examples/client/increment.py +++ b/examples/client/increment.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -26,23 +26,18 @@ def run(self): 'example_age': 1 } - # TODO: configurable - # TODO: deprecated - meta = {'ttl': 1000, 'gen': 10} - policy = None - # invoke operation - self.client.put(self.key, record, meta, policy) + self.client.put(self.key, record) - (returnedkey, meta, bins) = self.client.get(self.key) + _, _, bins = self.client.get(self.key) print("Before increment operation") print(bins) - self.client.increment(self.key, "example_age", 5, meta, policy) + self.client.increment(self.key, "example_age", 5) - (returnedkey, meta, bins) = self.client.get(self.key) + _, _, bins = self.client.get(self.key) print("After increment operation") print(bins) diff --git a/examples/client/index_create.py b/examples/client/index_create.py index 1c5dfd3c3e..f5a71a29ef 100644 --- a/examples/client/index_create.py +++ b/examples/client/index_create.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/index_remove.py b/examples/client/index_remove.py index 538ca46425..2ef978ab14 100644 --- a/examples/client/index_remove.py +++ b/examples/client/index_remove.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/info.py b/examples/client/info.py index ec5ad5ec0e..04c0254fee 100644 --- a/examples/client/info.py +++ b/examples/client/info.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/is_connected.py b/examples/client/is_connected.py index 98be1c9586..b4f4878b94 100644 --- a/examples/client/is_connected.py +++ b/examples/client/is_connected.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/kvs.py b/examples/client/kvs.py index 5584d7fb1c..3b7b603fff 100644 --- a/examples/client/kvs.py +++ b/examples/client/kvs.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/multi_thread.py b/examples/client/multi_thread.py index ac47e60ab8..e64443e9f0 100644 --- a/examples/client/multi_thread.py +++ b/examples/client/multi_thread.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/operate.py b/examples/client/operate.py index ec37158caf..76ddaf5f82 100644 --- a/examples/client/operate.py +++ b/examples/client/operate.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -27,9 +27,7 @@ def run(self): 'example_age': 1 } - meta = {'ttl': 1000, 'gen': 10} - policy = None - self.client.put(self.key, record, meta, policy) + self.client.put(self.key, record) _, _, bins = self.client.get(self.key) print("Before operation:", bins) @@ -39,7 +37,7 @@ def run(self): op_helpers.increment("example_age", 3), op_helpers.read("example_name") ] - _, _, bins = self.client.operate(self.key, ops, meta, policy) + _, _, bins = self.client.operate(self.key, ops) print("Record returned by operate():", bins) _, _, bins = self.client.get(self.key) diff --git a/examples/client/prepend.py b/examples/client/prepend.py index 20707a221c..55b6031fcd 100644 --- a/examples/client/prepend.py +++ b/examples/client/prepend.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -26,12 +26,8 @@ def run(self): 'example_age': 1 } - # TODO: should this be configurable? - meta = {'ttl': 1000, 'gen': 10} - policy = None + self.client.put(self.key, record) - 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) + self.client.prepend(self.key, "example_name", "Mr ") + _, _, bins = self.client.get(self.key) print(bins) diff --git a/examples/client/put.py b/examples/client/put.py index c4eefe7a8e..7edc9c1dd4 100644 --- a/examples/client/put.py +++ b/examples/client/put.py @@ -2,7 +2,7 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -31,7 +31,4 @@ def run(self): '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}} } - # TODO: should TTL and gen be configurable? - meta = {'ttl': 1000, 'gen': 5} - policy = None - self.client.put(self.key, record, meta, policy) + self.client.put(self.key, record) diff --git a/examples/client/query.py b/examples/client/query.py index c615426dbb..37a081a72a 100644 --- a/examples/client/query.py +++ b/examples/client/query.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/query_apply.py b/examples/client/query_apply.py index efe56bc30f..565836023f 100644 --- a/examples/client/query_apply.py +++ b/examples/client/query_apply.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/remove.py b/examples/client/remove.py index 654f8b1e60..335bc1596c 100644 --- a/examples/client/remove.py +++ b/examples/client/remove.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/remove_bin.py b/examples/client/remove_bin.py index bc16ca3a14..c5fedcddd6 100644 --- a/examples/client/remove_bin.py +++ b/examples/client/remove_bin.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/scan.py b/examples/client/scan.py index 03c9e4c69c..58969e56d8 100644 --- a/examples/client/scan.py +++ b/examples/client/scan.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/scan_apply.py b/examples/client/scan_apply.py index 9212e31272..a23fbd1af9 100644 --- a/examples/client/scan_apply.py +++ b/examples/client/scan_apply.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/scan_partition.py b/examples/client/scan_partition.py index 930bfaca26..c42106b1a6 100644 --- a/examples/client/scan_partition.py +++ b/examples/client/scan_partition.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/select_many.py b/examples/client/select_many.py index 10422e0996..42d780efe4 100644 --- a/examples/client/select_many.py +++ b/examples/client/select_many.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/select_record.py b/examples/client/select_record.py index 8d5212167e..56fc909402 100644 --- a/examples/client/select_record.py +++ b/examples/client/select_record.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/simple.lua b/examples/client/simple.lua index 972aaa33bd..76bfa1d111 100644 --- a/examples/client/simple.lua +++ b/examples/client/simple.lua @@ -1,6 +1,6 @@ -------------------------------------------------------------------------------- -- --- Copyright 2013-2021 Aerospike, Inc. +-- Copyright 2013-2026 Aerospike, Inc. -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. diff --git a/examples/client/touch.py b/examples/client/touch.py index 4f6ad2d647..b0ea45b47c 100644 --- a/examples/client/touch.py +++ b/examples/client/touch.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,40 +16,21 @@ ########################################################################## -import aerospike -import sys - -from optparse import OptionParser - -########################################################################## -# Option Parsing -########################################################################## - -# TODO: ttl/gen configurable - from .. import ExampleWithRecord class Touch(ExampleWithRecord): def run(self): - # TODO configurable - key = args.pop() - - meta = {'ttl': options.ttl, 'gen': options.gen} - policy = None - - (returnedkey, meta) = self.client.exists(self.key) + _, meta = self.client.exists(self.key) print("---") - print("Ttl before touch operation") + print("TTL before touch operation") print(meta) - self.client.touch(self.key, options.ttl + 1000, meta, policy) - print("---") - print("OK, 1 record touched.") + self.client.touch(self.key, meta["ttl"] + 1000) - (returnedkey, meta) = self.client.exists(self.key) + _, meta = self.client.exists(self.key) print("---") - print("Ttl after touch operation") + print("TTL after touch operation") print(meta) diff --git a/examples/client/ttl.py b/examples/client/ttl.py index 7e338241a5..173e2bf78d 100644 --- a/examples/client/ttl.py +++ b/examples/client/ttl.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -37,6 +37,7 @@ TTL_DEFAULT = 10 TTL_MAX = 20 +# TODO: is there an aerospike constant for this? TTL_NO_EXPIRE = -1 @@ -53,46 +54,33 @@ # and does not trigger the "greater than max ttl" warning. # Also, we'll check that one of our records DOES trigger the Max TTL warning # with a TTL of greater than 20. +# TODO: max-ttl removed in aerospike 5.0 PARAMS_NAMESPACE = [[('default-ttl', TTL_DEFAULT), ('max-ttl', TTL_MAX)]] +AS_POLICY_W_RETRY = "retry" + +# TODO: needs to be updated # Write Policy names and related values AS_POLICY_W_TIMEOUT = "timeout" -AS_POLICY_W_RETRY = "retry" -AS_POLICY_RETRY_UNDEF = 0 # Use Default value -AS_POLICY_RETRY_NONE = 1 # No retry -AS_POLICY_RETRY_ONCE = 2 # Retry Once - AS_POLICY_W_KEY = "key" -AS_POLICY_KEY_UNDEF = 0 # If set, then the value will default to either -# as_config.policies.key or `AS_POLICY_KEY_DEFAULT`. -AS_POLICY_KEY_DIGEST = 1 # Send the digest value of the key. -AS_POLICY_KEY_SEND = 2 # Send the key, but do not store it. +# TODO: don't know what this is for... AS_POLICY_KEY_STORE = 3 # Store the key (NOT YET IMPLEMENTED) AS_POLICY_W_GEN = "generation" -AS_POLICY_GEN_UNDEF = 0 # Use default value -AS_POLICY_GEN_IGNORE = 1 # Write a record, regardless of generation. -AS_POLICY_GEN_EQ = 2 # Write a record, ONLY if generations are equal -AS_POLICY_GEN_GT = 3 # Write a record, ONLY if local generation is -# greater-than remote generation. +# TODO: verify this works? AS_POLICY_GEN_DUP = 4 # Write a record creating a duplicate, ONLY if # the generation collides (?) AS_POLICY_W_EXISTS = "exists" -AS_POLICY_EXISTS_UNDEF = 0 # Use default value -AS_POLICY_EXISTS_IGNORE = 1 # Write the record, regardless of existence. -AS_POLICY_EXISTS_CREATE = 2 # Create a record, ONLY if it doesn't exist. -# Update a record, ONLY if it exist (NOT YET IMPL). -AS_POLICY_EXISTS_UPDATE = 3 # Setup write policy wr_policy = { AS_POLICY_W_TIMEOUT: 5000, - AS_POLICY_W_RETRY: AS_POLICY_RETRY_NONE, - AS_POLICY_W_KEY: AS_POLICY_KEY_DIGEST, - AS_POLICY_W_GEN: AS_POLICY_GEN_IGNORE, - AS_POLICY_W_EXISTS: AS_POLICY_EXISTS_IGNORE + AS_POLICY_W_RETRY: aerospike.POLICY_RETRY_NONE, + AS_POLICY_W_KEY: aerospike.POLICY_KEY_DIGEST, + AS_POLICY_W_GEN: aerospike.POLICY_GEN_IGNORE, + AS_POLICY_W_EXISTS: aerospike.POLICY_EXISTS_IGNORE } BASE_KEY_RANGE = list(range(1, 11)) @@ -102,7 +90,7 @@ 'desc': '5 sec TTL'}, 40: {'ttl': 15, 'desc': '15 sec TTL'}, - 60: {'ttl': TTL_NO_EXPIRE, + 60: {'ttl': aerospike.TTL_NEVER_EXPIRE, 'desc': 'NO_EXPIRE TTL'}, 80: {'ttl': TTL_MAX + 1, 'desc': 'Larger than MAX TTL'} @@ -110,22 +98,6 @@ KEYS = BASE_KEY_RANGE + list(SPECIAL_KEYS.keys()) -########################################################################## -# Connect to Cluster -########################################################################## - -config = { - 'hosts': [(options.host, options.port)] -} - -print('Connect to Server: ', config) -client = aerospike.client(config).connect(options.username, options.password) - -########################################################################## -# Perform Operation -########################################################################## - - def test_params_for_stanza(p, contx, is_namespace): for t in p: if is_namespace: diff --git a/examples/client/udf_get.py b/examples/client/udf_get.py index 743ade5455..0966fb30f3 100644 --- a/examples/client/udf_get.py +++ b/examples/client/udf_get.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/udf_list.py b/examples/client/udf_list.py index 75362e6b84..cb5d0ab66b 100644 --- a/examples/client/udf_list.py +++ b/examples/client/udf_list.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/udf_put.py b/examples/client/udf_put.py index 3b5eee61bd..997702843e 100644 --- a/examples/client/udf_put.py +++ b/examples/client/udf_put.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/udf_remove.py b/examples/client/udf_remove.py index daeb4c08c9..434a935123 100644 --- a/examples/client/udf_remove.py +++ b/examples/client/udf_remove.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/unicode_smiles.py b/examples/client/unicode_smiles.py index 7b7b709cde..9c7354fa77 100644 --- a/examples/client/unicode_smiles.py +++ b/examples/client/unicode_smiles.py @@ -1,6 +1,6 @@ ########################################################################## -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. From 6ef6645ccdb16826d3acc7019dc192c102098a27 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Tue, 21 Jul 2026 15:30:53 -0700 Subject: [PATCH 17/60] WIP on resolving import modules when importing each code example --- examples/client/__init__.py | 0 examples/client/aggregate.py | 108 ++++++++++++++++--------------- examples/client/query.py | 69 ++++++-------------- examples/client/query_apply.py | 36 +++++------ examples/client/scan_apply.py | 41 ++++++------ examples/client/select_record.py | 34 +++++----- examples/run_all_examples.py | 35 +++++----- 7 files changed, 150 insertions(+), 173 deletions(-) create mode 100644 examples/client/__init__.py diff --git a/examples/client/__init__.py b/examples/client/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/examples/client/aggregate.py b/examples/client/aggregate.py index 1b8a1c2fa5..dd3c55da6b 100644 --- a/examples/client/aggregate.py +++ b/examples/client/aggregate.py @@ -16,14 +16,13 @@ ########################################################################## -import aerospike import json import re -import sys import os.path from optparse import OptionParser from aerospike import predicates as p +from .. import Example ########################################################################## # Option Parsing @@ -63,54 +62,57 @@ def parse_arg(s): re_w = re.compile("%s(?:%s|%s|%s)" % (re_bin, re_str_eq, re_int_eq, re_int_rg)) -args.reverse() -where = args.pop() -module = args.pop() -function = args.pop() - -# If predicate is provided, then perform a query -q = client.query(namespace, set) -w = re_w.match(where) -if w is not None: - if w.group(2): - b = w.group(1) - v = w.group(2) - q.where(p.equals(b, v)) - elif w.group(3): - b = w.group(1) - v = w.group(3) - q.where(p.equals(b, v)) - elif w.group(4): - b = w.group(1) - v = int(w.group(4)) - q.where(p.equals(b, v)) - elif w.group(5) and w.group(6): - b = w.group(1) - l = int(w.group(5)) - u = int(w.group(6)) - q.where(p.between(b, l, u)) - -if options.bins and len(options.bins) > 0: - # project specified bins - q.select(*options.bins) - -args.reverse() -argl = list(map(parse_arg, args)) -print("argl == ", argl) -q.apply(module, function, *argl) - -results = [] - -# callback to be called for each record read -def callback(result): - results.append(result) - print(result) - -# invoke the operations, and for each record invoke the callback -q.foreach(callback) - -print("---") -if len(results) == 1: - print("OK, 1 result found.") -else: - print("OK, %d results found." % len(results)) +# args.reverse() +# where = args.pop() +# module = args.pop() +# function = args.pop() + +class Aggregate(Example): + def run(self): + # If predicate is provided, then perform a query + q = self.client.query(self.namespace, self.set_name) + + w = re_w.match(where) + if w is not None: + if w.group(2): + b = w.group(1) + v = w.group(2) + q.where(p.equals(b, v)) + elif w.group(3): + b = w.group(1) + v = w.group(3) + q.where(p.equals(b, v)) + elif w.group(4): + b = w.group(1) + v = int(w.group(4)) + q.where(p.equals(b, v)) + elif w.group(5) and w.group(6): + b = w.group(1) + l = int(w.group(5)) + u = int(w.group(6)) + q.where(p.between(b, l, u)) + + if options.bins and len(options.bins) > 0: + # project specified bins + q.select(*options.bins) + + args.reverse() + argl = list(map(parse_arg, args)) + print("argl == ", argl) + q.apply(module, function, *argl) + + results = [] + + # callback to be called for each record read + def callback(result): + results.append(result) + print(result) + + # invoke the operations, and for each record invoke the callback + q.foreach(callback) + + print("---") + if len(results) == 1: + print("OK, 1 result found.") + else: + print("OK, %d results found." % len(results)) diff --git a/examples/client/query.py b/examples/client/query.py index 37a081a72a..f58a4ea935 100644 --- a/examples/client/query.py +++ b/examples/client/query.py @@ -16,49 +16,46 @@ ########################################################################## -import aerospike import re import sys import os.path from optparse import OptionParser from aerospike import predicates as p +from .. import Example -########################################################################## -# Option Parsing -########################################################################## +# optparser.add_option( +# "-m", "--module", dest="module", type="string", +# help="UDF Module.") -optparser.add_option( - "-m", "--module", dest="module", type="string", - help="UDF Module.") +# optparser.add_option( +# "-f", "--function", dest="function", type="string", +# help="UDF Function.") -optparser.add_option( - "-f", "--function", dest="function", type="string", - help="UDF Function.") +# optparser.add_option( +# "-a", "--arg", dest="arguments", action="append", type="string", +# help="UDF Arguments.") -optparser.add_option( - "-a", "--arg", dest="arguments", action="append", type="string", - help="UDF Arguments.") +# optparser.add_option( +# "-b", "--bins", dest="bins", type="string", action="append", +# help="Bins to select from each record.") -optparser.add_option( - "-b", "--bins", dest="bins", type="string", action="append", - help="Bins to select from each record.") +# optparser.add_option( +# "--show-key", dest="show_key", action="store_true", +# help="If set, displays the key/digest.") -optparser.add_option( - "--show-key", dest="show_key", action="store_true", - help="If set, displays the key/digest.") - -optparser.add_option( - "--show-meta", dest="show_meta", action="store_true", - help="If set, displays the metadata.") +# optparser.add_option( +# "--show-meta", dest="show_meta", action="store_true", +# help="If set, displays the metadata.") config = { 'lua': { 'user_path': os.path.dirname(__file__) } } - try: +class Query(Example): + def run(self): re_bin = "(.{1,14})" re_str_eq = "\s+=\s*(?:(?:\"(.*)\")|(?:\'(.*)\'))" re_int_eq = "\s+=\s*(\d+)" @@ -66,9 +63,6 @@ re_w = re.compile("%s(?:%s|%s|%s)" % (re_bin, re_str_eq, re_int_eq, re_int_rg)) - namespace = options.namespace if options.namespace and options.namespace != 'None' else None - set = options.set if options.set and options.set != 'None' else None - q = None if len(args) == 1: @@ -134,24 +128,3 @@ def callback(input_tuple): print("OK, 1 result found.") else: print("OK, %d results found." % len(results)) - - 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) diff --git a/examples/client/query_apply.py b/examples/client/query_apply.py index 565836023f..1adc44557a 100644 --- a/examples/client/query_apply.py +++ b/examples/client/query_apply.py @@ -34,29 +34,29 @@ def query_callback(option, opt, value, parser): setattr(parser.values, option.dest, value.split(',')) -optparser.add_option( - "-m", "--module", dest="module", type="string", - help="UDF Module.") +# optparser.add_option( +# "-m", "--module", dest="module", type="string", +# help="UDF Module.") -optparser.add_option( - "-f", "--function", dest="function", type="string", - help="UDF Function.") +# optparser.add_option( +# "-f", "--function", dest="function", type="string", +# help="UDF Function.") -optparser.add_option( - "-a", "--arg", dest="arguments", type="string", action="callback", - callback=query_callback, help="UDF Arguments.") +# optparser.add_option( +# "-a", "--arg", dest="arguments", type="string", action="callback", +# callback=query_callback, help="UDF Arguments.") -optparser.add_option( - "-b", "--bins", dest="bins", type="string", action="append", - help="Bins to select from each record.") +# optparser.add_option( +# "-b", "--bins", dest="bins", type="string", action="append", +# help="Bins to select from each record.") -optparser.add_option( - "--show-key", dest="show_key", action="store_true", - help="If set, displays the key/digest.") +# optparser.add_option( +# "--show-key", dest="show_key", action="store_true", +# help="If set, displays the key/digest.") -optparser.add_option( - "--show-meta", dest="show_meta", action="store_true", - help="If set, displays the metadata.") +# optparser.add_option( +# "--show-meta", dest="show_meta", action="store_true", +# help="If set, displays the metadata.") from .. import Example diff --git a/examples/client/scan_apply.py b/examples/client/scan_apply.py index a23fbd1af9..cc937759a4 100644 --- a/examples/client/scan_apply.py +++ b/examples/client/scan_apply.py @@ -59,31 +59,30 @@ def parse_arg(s): except ValueError: return s -try: +from .. import Example - args.reverse() - module = options.module - function = options.function +class ScanApply(Example): + def run(self): + # args.reverse() - for i, param in enumerate(options.arguments): - if param.isdigit(): - options.arguments[i] = int(param) + module = options.module + function = options.function - policy = {} - scan_id = client.scan_apply( - namespace, set, module, function, options.arguments, policy) + for i, param in enumerate(options.arguments): + if param.isdigit(): + options.arguments[i] = int(param) - while True: - response = client.job_info(scan_id, aerospike.JOB_SCAN) - if response['status'] == aerospike.JOB_STATUS_COMPLETED: - break + policy = {} + scan_id = client.scan_apply( + namespace, set, module, function, options.arguments, policy) - if response['status'] == aerospike.JOB_STATUS_COMPLETED: - print("Background scan is successful") - else: - print("Scan_apply failed") + while True: + response = client.job_info(scan_id, aerospike.JOB_SCAN) + if response['status'] == aerospike.JOB_STATUS_COMPLETED: + break -except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - rc = 1 + if response['status'] == aerospike.JOB_STATUS_COMPLETED: + print("Background scan is successful") + else: + print("Scan_apply failed") diff --git a/examples/client/select_record.py b/examples/client/select_record.py index 56fc909402..82c305faa3 100644 --- a/examples/client/select_record.py +++ b/examples/client/select_record.py @@ -25,29 +25,29 @@ # Options Parsing ########################################################################## -usage = "usage: %prog [options] key bin [bin ...]" +# usage = "usage: %prog [options] key bin [bin ...]" -optparser = OptionParser(usage=usage, add_help_option=False) +# optparser = OptionParser(usage=usage, add_help_option=False) -optparser.add_option( - "--no-key", dest="nokey", action="store_true", - help="Do not return the key") +# 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") +# optparser.add_option( +# "--no-metadata", dest="nometadata", action="store_true", +# help="Do not return the metadata") -(options, args) = optparser.parse_args() +# (options, args) = optparser.parse_args() -if options.help: - optparser.print_help() - print() - sys.exit(1) +# if options.help: +# optparser.print_help() +# print() +# sys.exit(1) -if len(args) < 1: - optparser.print_help() - print() - sys.exit(1) +# if len(args) < 1: +# optparser.print_help() +# print() +# sys.exit(1) from .. import ExampleWithRecord diff --git a/examples/run_all_examples.py b/examples/run_all_examples.py index a3ffbd1335..faf859a97e 100644 --- a/examples/run_all_examples.py +++ b/examples/run_all_examples.py @@ -1,20 +1,23 @@ -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 -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 +import pkgutil +import importlib +import inspect +import os +from . import Example -example_classes = [ - Get, - EmailNormalizationOld, - EmailNormalizationNew, - PartialExtractionNew, - PartialExtractionOld, - StringExpressions, - StringOps, -] + +example_classes = [] + +dir_containing_this_module = os.path.dirname(os.path.abspath(__file__)) +all_packages = pkgutil.walk_packages([dir_containing_this_module + "/client"]) +for package in all_packages: + print(package) + importlib.import_module("." + package.name, ".examples.client") + for name, obj in inspect.getmembers(package, inspect.isclass): + if obj.__module__ != package.name: + continue + if not issubclass(obj, Example): + continue + example_classes.append(obj) for cls in example_classes: example = cls().run() From 8ed0dcddfead4b631d8ddc73dc0a3c24df0e634a Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 22 Jul 2026 08:05:01 -0700 Subject: [PATCH 18/60] WIP. Reduce nested ifs in info_all example. --- examples/client/aggregate.py | 89 +++++----------------------- examples/client/client_big_list.py | 3 +- examples/client/info.py | 45 +++++++------- examples/client/query_apply.py | 95 ++++++------------------------ 4 files changed, 57 insertions(+), 175 deletions(-) diff --git a/examples/client/aggregate.py b/examples/client/aggregate.py index dd3c55da6b..66a4b7e05c 100644 --- a/examples/client/aggregate.py +++ b/examples/client/aggregate.py @@ -16,25 +16,11 @@ ########################################################################## -import json -import re import os.path -from optparse import OptionParser from aerospike import predicates as p from .. import Example -########################################################################## -# Option Parsing -########################################################################## - -usage = "usage: %prog [options] where module function [args...]" - -optparser = OptionParser(usage=usage, add_help_option=False) - -optparser.add_option( - "-b", "--bins", dest="bins", type="string", action="append", - help="Bins to select from each record.") config = { 'lua': { @@ -42,64 +28,25 @@ } } +class Aggregate(Example): + def run(self): + # If predicate is provided, then perform a query + query = self.client.query(self.namespace, self.set_name) -def parse_arg(s): - try: - return json.loads(s) - except ValueError: - return s - - + BIN = "bin" + query.where(p.equals(BIN, 1)) -# ---------------------------------------------------------------------------- -# Perform Operation -# ---------------------------------------------------------------------------- + query.where(p.equals(BIN, "a")) -re_bin = "(.{1,14})" -re_str_eq = "\s+=\s*(?:(?:\"(.*)\")|(?:\'(.*)\'))" -re_int_eq = "\s+=\s*(\d+)" -re_int_rg = "\s+between\s+\(\s*(\d+)\s*,\s*(\d+)\s*\)" -re_w = re.compile("%s(?:%s|%s|%s)" % - (re_bin, re_str_eq, re_int_eq, re_int_rg)) + query.where(p.between(BIN, 1, 3)) -# args.reverse() -# where = args.pop() -# module = args.pop() -# function = args.pop() + BINS = [BIN] + query.select(BINS) -class Aggregate(Example): - def run(self): - # If predicate is provided, then perform a query - q = self.client.query(self.namespace, self.set_name) - - w = re_w.match(where) - if w is not None: - if w.group(2): - b = w.group(1) - v = w.group(2) - q.where(p.equals(b, v)) - elif w.group(3): - b = w.group(1) - v = w.group(3) - q.where(p.equals(b, v)) - elif w.group(4): - b = w.group(1) - v = int(w.group(4)) - q.where(p.equals(b, v)) - elif w.group(5) and w.group(6): - b = w.group(1) - l = int(w.group(5)) - u = int(w.group(6)) - q.where(p.between(b, l, u)) - - if options.bins and len(options.bins) > 0: - # project specified bins - q.select(*options.bins) - - args.reverse() - argl = list(map(parse_arg, args)) - print("argl == ", argl) - q.apply(module, function, *argl) + MODULE = "a" + FUNCTION = "b" + ARGS = [] + query.apply(MODULE, FUNCTION, ARGS) results = [] @@ -109,10 +56,6 @@ def callback(result): print(result) # invoke the operations, and for each record invoke the callback - q.foreach(callback) + query.foreach(callback) - print("---") - if len(results) == 1: - print("OK, 1 result found.") - else: - print("OK, %d results found." % len(results)) + print(len(results)) diff --git a/examples/client/client_big_list.py b/examples/client/client_big_list.py index 6effafbe2b..5e7815cda1 100644 --- a/examples/client/client_big_list.py +++ b/examples/client/client_big_list.py @@ -333,8 +333,7 @@ def run(self): ''' item_count = 1000 - client = aerospike.client({'hosts': [('localhost', 3000)]}).connect() - ldt = ClientSideBigList(client, 'person1_friends') + ldt = ClientSideBigList(self.client, 'person1_friends') for i in range(item_count): # Store a reasonably large item diff --git a/examples/client/info.py b/examples/client/info.py index 04c0254fee..983a51c30a 100644 --- a/examples/client/info.py +++ b/examples/client/info.py @@ -27,25 +27,26 @@ def run(self): request = "statistics" # TODO: needs review - for node, (err, res) in list(self.client.info_all(request).items()): - if res is not None: - res = res.strip() - if len(res) > 0: - entries = res.split(';') - if len(entries) > 1: - print("{0}:".format(node)) - for entry in entries: - entry = entry.strip() - if len(entry) > 0: - count = 0 - if "=" in entry: - (name, value) = entry.split('=') - if count > 0: - print( - " {0}: {1}".format(name, value)) - else: - print( - " - {0}: {1}".format(name, value)) - count += 1 - else: - print("{0}: {1}".format(node, res)) + response = self.client.info_all(request) + for node, (_, res) in response.items(): + if res is None: + continue + + res = res.strip() + if len(res) == 0: + continue + + entries = res.split(';') + if len(entries) <= 1: + print("{0}: {1}".format(node, res)) + + print("{0}:".format(node)) + for entry in entries: + entry = entry.strip() + if len(entry) == 0: + continue + if "=" not in entry: + continue + + (name, value) = entry.split('=') + print(" - {0}: {1}".format(name, value)) diff --git a/examples/client/query_apply.py b/examples/client/query_apply.py index 1adc44557a..522f765390 100644 --- a/examples/client/query_apply.py +++ b/examples/client/query_apply.py @@ -34,22 +34,6 @@ def query_callback(option, opt, value, parser): setattr(parser.values, option.dest, value.split(',')) -# optparser.add_option( -# "-m", "--module", dest="module", type="string", -# help="UDF Module.") - -# optparser.add_option( -# "-f", "--function", dest="function", type="string", -# help="UDF Function.") - -# optparser.add_option( -# "-a", "--arg", dest="arguments", type="string", action="callback", -# callback=query_callback, help="UDF Arguments.") - -# optparser.add_option( -# "-b", "--bins", dest="bins", type="string", action="append", -# help="Bins to select from each record.") - # optparser.add_option( # "--show-key", dest="show_key", action="store_true", # help="If set, displays the key/digest.") @@ -71,66 +55,21 @@ def query_callback(option, opt, value, parser): class QueryApply(Example): def run(self): - # ---------------------------------------------------------------------------- - # Perform Operation - # ---------------------------------------------------------------------------- - - query_id = 0 - re_bin = "(.{1,14})" - re_str_eq = "\s+=\s*(?:(?:\"(.*)\")|(?:\'(.*)\'))" - re_int_eq = "\s+=\s*(\d+)" - re_int_rg = "\s+between\s+\(\s*(\d+)\s*,\s*(\d+)\s*\)" - re_w = re.compile("%s(?:%s|%s|%s)" % - (re_bin, re_str_eq, re_int_eq, re_int_rg)) - - q = None - - for i, param in enumerate(options.arguments): - if param.isdigit(): - options.arguments[i] = int(param) - - if len(args) == 1: - w = re_w.match(args[0]) - if w is not None: - - # If predicate is provided, then perform a query - - if w.group(2): - b = w.group(1) - v = w.group(2) - query_id = client.query_apply(options.namespace, - options.set, p.equals( - b, v), options.module, - options.function, options.arguments) - elif w.group(3): - b = w.group(1) - v = w.group(3) - query_id = client.query_apply(options.namespace, - options.set, p.equals( - b, v), options.module, - options.function, options.arguments) - elif w.group(4): - b = w.group(1) - v = int(w.group(4)) - query_id = client.query_apply(options.namespace, - options.set, p.equals( - b, v), options.module, - options.function, options.arguments) - elif w.group(5) and w.group(6): - b = w.group(1) - l = int(w.group(5)) - u = int(w.group(6)) - query_id = client.query_apply(options.namespace, - options.set, p.between( - b, l, u), options.module, - options.function, options.arguments) - - while True: - response = client.job_info(query_id, aerospike.JOB_QUERY) - if response['status'] == aerospike.JOB_STATUS_COMPLETED: - break + predicates = [ + p.equals(b, v), + p.equals(b, v), + p.between(b, l, u) + ] + for predicate in predicates: + query_id = self.client.query_apply(self.namespace, + self.set_name, predicate, MODULE, + FUNCTION, ARGS) + while True: + response = self.client.job_info(query_id, aerospike.JOB_QUERY) + if response['status'] == aerospike.JOB_STATUS_COMPLETED: + break - if response['status'] == aerospike.JOB_STATUS_COMPLETED: - print("Background query is successful") - else: - print("Query_apply failed") + if response['status'] == aerospike.JOB_STATUS_COMPLETED: + print("Background query is successful") + else: + print("Query_apply failed") From 66827c4ff933c1938432081ae8d04c3861feb958 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 22 Jul 2026 08:16:33 -0700 Subject: [PATCH 19/60] Clean up query code example. --- examples/client/query.py | 97 +++++----------------------------------- 1 file changed, 10 insertions(+), 87 deletions(-) diff --git a/examples/client/query.py b/examples/client/query.py index f58a4ea935..60f2e034e4 100644 --- a/examples/client/query.py +++ b/examples/client/query.py @@ -16,38 +16,11 @@ ########################################################################## -import re -import sys import os.path -from optparse import OptionParser from aerospike import predicates as p from .. import Example -# optparser.add_option( -# "-m", "--module", dest="module", type="string", -# help="UDF Module.") - -# optparser.add_option( -# "-f", "--function", dest="function", type="string", -# help="UDF Function.") - -# optparser.add_option( -# "-a", "--arg", dest="arguments", action="append", type="string", -# help="UDF Arguments.") - -# optparser.add_option( -# "-b", "--bins", dest="bins", type="string", action="append", -# help="Bins to select from each record.") - -# optparser.add_option( -# "--show-key", dest="show_key", action="store_true", -# help="If set, displays the key/digest.") - -# optparser.add_option( -# "--show-meta", dest="show_meta", action="store_true", -# help="If set, displays the metadata.") - config = { 'lua': { 'user_path': os.path.dirname(__file__) @@ -56,54 +29,15 @@ class Query(Example): def run(self): - re_bin = "(.{1,14})" - re_str_eq = "\s+=\s*(?:(?:\"(.*)\")|(?:\'(.*)\'))" - re_int_eq = "\s+=\s*(\d+)" - re_int_rg = "\s+between\s+\(\s*(\d+)\s*,\s*(\d+)\s*\)" - re_w = re.compile("%s(?:%s|%s|%s)" % - (re_bin, re_str_eq, re_int_eq, re_int_rg)) - - q = None - - if len(args) == 1: - - w = re_w.match(args[0]) - if w is not None: - - # If predicate is provided, then perform a query - q = client.query(namespace, set) - - if w.group(2): - b = w.group(1) - v = w.group(2) - q.where(p.equals(b, v)) - elif w.group(3): - b = w.group(1) - v = w.group(3) - q.where(p.equals(b, v)) - elif w.group(4): - b = w.group(1) - v = int(w.group(4)) - q.where(p.equals(b, v)) - elif w.group(5) and w.group(6): - b = w.group(1) - l = int(w.group(5)) - u = int(w.group(6)) - q.where(p.between(b, l, u)) - - if q is None: - # If predicate not provided, then perform a scan - q = client.scan(namespace, set) + #. TODO: check if predicate to decide if using scan/query. + query = self.client.query(self.namespace, self.set_name) - if options.bins and len(options.bins) > 0: - # project specified bins - q.select(*options.bins) + query = self.client.scan(self.namespace, self.set_name) - if options.module and options.function: - if options.arguments: - q.apply(options.module, options.function, *options.arguments) - else: - q.apply(options.module, options.function) + # TODO + BINS = [] + query.select(BINS) + query.apply(MODULE, FUNCTION, *ARGS) results = [] @@ -111,20 +45,9 @@ def run(self): def callback(input_tuple): (key, meta, rec) = input_tuple results.append((key, meta, rec)) - if options.show_key and options.show_meta: - print(key, meta, rec) - elif options.show_key: - print(key, rec) - elif options.show_meta: - print(meta, rec) - else: - print(rec) + print(key, meta, rec) # invoke the operations, and for each record invoke the callback - q.foreach(callback) + query.foreach(callback) - print("---") - if len(results) == 1: - print("OK, 1 result found.") - else: - print("OK, %d results found." % len(results)) + print(len(results)) From fa048f71d078d86cca84c38600844354fc655b1b Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:02:38 -0700 Subject: [PATCH 20/60] more cleanup of TTL example. --- examples/client/ttl.py | 162 ++++++++++------------------------------- 1 file changed, 39 insertions(+), 123 deletions(-) diff --git a/examples/client/ttl.py b/examples/client/ttl.py index 173e2bf78d..612d5492e0 100644 --- a/examples/client/ttl.py +++ b/examples/client/ttl.py @@ -20,10 +20,6 @@ # We will write records that expire BEFORE the default namespace TTL, # we will write records that expire with the default TTL, and we'll # write records that NEVER expire. -# -# NOTE: -# 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. import aerospike @@ -32,19 +28,16 @@ import re import time -from optparse import OptionParser from aerospike import exception as e TTL_DEFAULT = 10 TTL_MAX = 20 -# TODO: is there an aerospike constant for this? -TTL_NO_EXPIRE = -1 - +# TODO: include instructions to have docker commands to set up server instead of through python # Define the Namespace Supervisor parms -- setting the period very short # so that we know it will have visited all of our records before we look # at them at each TTL interval. -PARAMS_SERVICE = [[('nsup-period', 1)]] +# PARAMS_SERVICE = [[('nsup-period', 1)]] # Define the default Namespace Time To Live at 10 seconds. We will write # some records that expire EARLY (5 seconds), some records that expire at @@ -54,38 +47,32 @@ # and does not trigger the "greater than max ttl" warning. # Also, we'll check that one of our records DOES trigger the Max TTL warning # with a TTL of greater than 20. -# TODO: max-ttl removed in aerospike 5.0 -PARAMS_NAMESPACE = [[('default-ttl', TTL_DEFAULT), ('max-ttl', TTL_MAX)]] - -AS_POLICY_W_RETRY = "retry" +# PARAMS_NAMESPACE = [[('default-ttl', TTL_DEFAULT)]] # TODO: needs to be updated # Write Policy names and related values AS_POLICY_W_TIMEOUT = "timeout" -AS_POLICY_W_KEY = "key" # TODO: don't know what this is for... AS_POLICY_KEY_STORE = 3 # Store the key (NOT YET IMPLEMENTED) -AS_POLICY_W_GEN = "generation" # TODO: verify this works? AS_POLICY_GEN_DUP = 4 # Write a record creating a duplicate, ONLY if # the generation collides (?) -AS_POLICY_W_EXISTS = "exists" # Setup write policy wr_policy = { - AS_POLICY_W_TIMEOUT: 5000, - AS_POLICY_W_RETRY: aerospike.POLICY_RETRY_NONE, - AS_POLICY_W_KEY: aerospike.POLICY_KEY_DIGEST, - AS_POLICY_W_GEN: aerospike.POLICY_GEN_IGNORE, - AS_POLICY_W_EXISTS: aerospike.POLICY_EXISTS_IGNORE + "total_timeout": 5000, + "max_retries": 0, + "key": aerospike.POLICY_KEY_DIGEST, + "gen": aerospike.POLICY_GEN_IGNORE, + "exists": aerospike.POLICY_EXISTS_IGNORE } -BASE_KEY_RANGE = list(range(1, 11)) +PRIMARY_KEYS_WITHOUT_TTL = list(range(1, 11)) -SPECIAL_KEYS = { +KEYS_WITH_TTL = { 20: {'ttl': 5, 'desc': '5 sec TTL'}, 40: {'ttl': 15, @@ -96,45 +83,16 @@ 'desc': 'Larger than MAX TTL'} } -KEYS = BASE_KEY_RANGE + list(SPECIAL_KEYS.keys()) - -def test_params_for_stanza(p, contx, is_namespace): - for t in p: - if is_namespace: - info_code = "set-config:context=namespace;id=" + \ - contx + ";" + t[0] + "=" + str(t[1]) - else: - info_code = "set-config:context=" + \ - contx + ";" + t[0] + "=" + str(t[1]) - try: - v = list(client.info_all(info_code).items()) - res = v[0][1][1] - if res != "ok\n": - print( - "setting {0} to {1} failed. Got result({2})".format(t[0], t[1], res)) - sys.exit(1) - else: - print("setting {0} to {1} succeeded".format(t[0], t[1])) - except: - print("error: info_code({0}) result({1})".format(info_code, v)) - - -def print_header(header, message=None): - print() - print(''.ljust(80, '=')) - print(header) - print(message) if message else None - print(''.ljust(80, '-')) - +ALL_KEYS = PRIMARY_KEYS_WITHOUT_TTL + list(KEYS_WITH_TTL.keys()) -def print_record(xxx_todo_changeme, prefix=''): - (key, meta, record) = xxx_todo_changeme +def print_record(record_tuple, prefix=''): + (key, meta, bins) = record_tuple print("%s%-4d %-4s %-8s %s" % ( prefix, int(key[2] or 0), meta.get('gen') if meta and 'gen' in meta else '-', meta.get('ttl') if meta and 'ttl' in meta else '-', - record if record else '-' + bins if bins else '-' )) @@ -147,8 +105,15 @@ def print_records(records, prefix=''): [print_record(r, prefix) for r in records] +def print_header(header, message=None): + print() + print(''.ljust(80, '=')) + print(header) + print(message) if message else None + print(''.ljust(80, '-')) + def print_histogram(prefix=''): - request = ''.join(["hist-dump:ns=", options.namespace, ";hist=ttl"]) + request = ''.join(["histogram:ns=", options.namespace, ";hist=ttl"]) header = "%sHISTOGRAM (%s)" % (prefix, request) border = prefix.ljust(80, '-') @@ -176,38 +141,24 @@ def check_records(start, wait=0, message=None): try: print_records( - [client.get((options.namespace, options.set, k)) for k in KEYS], ' ') + [client.get((options.namespace, options.set, k)) for k in ALL_KEYS], ' ') except Exception as e: print("error: {0}".format(e), file=sys.stderr) print_histogram(' ') -def delete_records(): - try: - for key in KEYS: - # first remove the existing record - client.remove((options.namespace, options.set, key)) - except e.RecordNotFound: - print("Record not found") - except Exception as err: - if err[0] != 2: - print("delete_records() error: {0}".format( - err[0]), file=sys.stderr) - sys.exit(1) - - def write_records(): try: - for key in KEYS: - ttl = SPECIAL_KEYS[key]['ttl'] if key in SPECIAL_KEYS else None + for key in ALL_KEYS: + ttl = KEYS_WITH_TTL[key]['ttl'] if key in KEYS_WITH_TTL else None rec = {} rec['key'] = key rec['ttl'] = ttl if ttl else TTL_DEFAULT - rec['desc'] = SPECIAL_KEYS[key][ - 'desc'] if key in SPECIAL_KEYS else 'default TTL' + rec['desc'] = KEYS_WITH_TTL[key][ + 'desc'] if key in KEYS_WITH_TTL else 'default TTL' try: # write a new record @@ -233,55 +184,20 @@ def write_records(): # CONFIGURE SERVER ########################################################################## -print_header("CONFIGURE THE SERVER") - -# Now go off and set the params -print('Set Parameters for Service') -for p in PARAMS_SERVICE: - test_params_for_stanza(p, "service", False) - time.sleep(1) -print("service parameters passed") - -print("getting initial ttl values") -info = client.info_all("namespace/" + options.namespace) -default_ttl = 0 -max_ttl = 0 -for key, value in list(info.items()): - array_of_items = re.split(';|=', value[1]) - i = 0 - for item in array_of_items: - i = i + 1 - if item == "default-ttl": - default_ttl = array_of_items[i] - if item == "max-ttl": - max_ttl = array_of_items[i] - -print('Set Parameters for Namespace') -for p in PARAMS_NAMESPACE: - test_params_for_stanza(p, options.namespace, True) - time.sleep(1) -print("namespace parameters passed") - -########################################################################## -# CHECK RECORDS ON INTERVALS -########################################################################## +# TODO: use docker container -start = time.time() +from .. import Example -delete_records() -check_records(start, 0, 'Clean state') +class TTL(Example): + def run(self): + start = time.time() -write_records() + check_records(start, 0, 'Clean state') -check_records(start, 0, 'Initial state') -check_records(start, 2, 'Expect all records with TTL-2') -check_records(start, 6, 'Expect all records with TTL<=5 to be gone') -check_records(start, 3, 'Expect all records with TTL<=10 to be gone') -check_records(start, 6, 'Expect all records to be gone, except NO_EXPIRE') -client.remove((options.namespace, options.set, 60)) + write_records() -PARAMS_NAMESPACE = [[('default-ttl', default_ttl), ('max-ttl', max_ttl)]] -print('Reset Parameters for Namespace') -for p in PARAMS_NAMESPACE: - test_params_for_stanza(p, options.namespace, True) - time.sleep(1) + check_records(start, 0, 'Initial state') + check_records(start, 2, 'Expect all records with TTL-2') + check_records(start, 6, 'Expect all records with TTL<=5 to be gone') + check_records(start, 3, 'Expect all records with TTL<=10 to be gone') + check_records(start, 6, 'Expect all records to be gone, except NO_EXPIRE') From c8004f718b7b1519c94b7298bca9a57c20e93f9b Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:16:21 -0700 Subject: [PATCH 21/60] run_all_examples.py now works. TODO - aggregate.py failing. --- examples/client/aggregate.py | 57 ++++++++++++++++++------------------ examples/run_all_examples.py | 16 ++++++---- 2 files changed, 40 insertions(+), 33 deletions(-) diff --git a/examples/client/aggregate.py b/examples/client/aggregate.py index 66a4b7e05c..934fbe787a 100644 --- a/examples/client/aggregate.py +++ b/examples/client/aggregate.py @@ -30,32 +30,33 @@ class Aggregate(Example): def run(self): - # If predicate is provided, then perform a query - query = self.client.query(self.namespace, self.set_name) - BIN = "bin" - query.where(p.equals(BIN, 1)) - - query.where(p.equals(BIN, "a")) - - query.where(p.between(BIN, 1, 3)) - - BINS = [BIN] - query.select(BINS) - - MODULE = "a" - FUNCTION = "b" - ARGS = [] - query.apply(MODULE, FUNCTION, ARGS) - - results = [] - - # callback to be called for each record read - def callback(result): - results.append(result) - print(result) - - # invoke the operations, and for each record invoke the callback - query.foreach(callback) - - print(len(results)) + predicates = [ + p.equals(BIN, 1), + p.equals(BIN, "a"), + p.between(BIN, 1, 3) + ] + + for predicate in predicates: + # If predicate is provided, then perform a query + query = self.client.query(self.namespace, self.set_name) + query.where(predicate) + BINS = [BIN] + query.select(*BINS) + + MODULE = "a" + FUNCTION = "b" + ARGS = [] + query.apply(MODULE, FUNCTION, ARGS) + + results = [] + + # callback to be called for each record read + def callback(result): + results.append(result) + print(result) + + # invoke the operations, and for each record invoke the callback + query.foreach(callback) + + print(len(results)) diff --git a/examples/run_all_examples.py b/examples/run_all_examples.py index faf859a97e..f2ef6b835e 100644 --- a/examples/run_all_examples.py +++ b/examples/run_all_examples.py @@ -2,7 +2,7 @@ import importlib import inspect import os -from . import Example +# from . import Example example_classes = [] @@ -11,13 +11,19 @@ all_packages = pkgutil.walk_packages([dir_containing_this_module + "/client"]) for package in all_packages: print(package) - importlib.import_module("." + package.name, ".examples.client") - for name, obj in inspect.getmembers(package, inspect.isclass): - if obj.__module__ != package.name: + module = importlib.import_module("." + package.name, ".examples.client") + for name, obj in inspect.getmembers(module, inspect.isclass): + if obj.__module__ != module.__name__: continue - if not issubclass(obj, Example): + print("Class found:", obj) + # print(Example is obj.__bases__[0]) + # TODO - comparing the same class imported two different ways fails + # There might a better way to do this + if obj.__bases__[0].__name__ != "Example": continue example_classes.append(obj) +print("Running examples...") for cls in example_classes: + print(cls) example = cls().run() From 5461b69d0297797f1e785cab7d3c2fa39a84e3e8 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 24 Jul 2026 12:32:44 -0700 Subject: [PATCH 22/60] Get all code examples to run successfully --- examples/__init__.py | 20 ++- examples/client/aggregate.py | 18 +-- examples/client/bin_ops.py | 2 +- examples/client/kvs.py | 2 +- examples/client/multi_thread.py | 2 +- examples/client/query.py | 14 +- examples/client/query_apply.py | 23 ++-- examples/client/scan_apply.py | 14 +- examples/client/scan_partition.py | 3 +- examples/client/select_many.py | 50 -------- examples/client/ttl.py | 206 +++++++++++++++--------------- examples/client/udf_get.py | 2 +- examples/client/udf_put.py | 2 +- 13 files changed, 159 insertions(+), 199 deletions(-) delete mode 100644 examples/client/select_many.py diff --git a/examples/__init__.py b/examples/__init__.py index 2036629bb2..21c8308cc8 100644 --- a/examples/__init__.py +++ b/examples/__init__.py @@ -1,4 +1,5 @@ import aerospike +import os class Example: @@ -11,12 +12,16 @@ def __init__( namespace: str = "test", set_name: str = "demo" ): - config = { + self.config = { "hosts": [(host, port)], "user": user, - "password": password + "password": password, + # TODO: should belong in a different fixture to make less complex + 'lua': { + 'user_path': os.path.dirname(__file__) + "/client/" + } } - client = aerospike.client(config) + client = aerospike.client(self.config) self.client = client self.namespace = namespace @@ -26,6 +31,15 @@ def __init__( def __del__(self): self.client.close() + +class ExampleWithIndex(Example): + INDEX_NAME = "index_name" + def __init__(self): + self.client.index_single_value_create(self.namespace, self.set_name, aerospike.INDEX_INTEGER, self.INDEX_NAME) + + def __del__(self): + self.client.index_remove(self.namespace, self.INDEX_NAME) + # TODO: I'm wondering if pytest can be used since # it has fixtures as a built-in feature class ExampleWithRecord(Example): diff --git a/examples/client/aggregate.py b/examples/client/aggregate.py index 934fbe787a..44957629f3 100644 --- a/examples/client/aggregate.py +++ b/examples/client/aggregate.py @@ -19,22 +19,16 @@ import os.path from aerospike import predicates as p -from .. import Example +from .. import ExampleWithIndex -config = { - 'lua': { - 'user_path': os.path.dirname(__file__) - } -} - -class Aggregate(Example): +class Aggregate(ExampleWithIndex): def run(self): BIN = "bin" predicates = [ p.equals(BIN, 1), - p.equals(BIN, "a"), - p.between(BIN, 1, 3) + # p.equals(BIN, "a"), + # p.between(BIN, 1, 3) ] for predicate in predicates: @@ -44,8 +38,8 @@ def run(self): BINS = [BIN] query.select(*BINS) - MODULE = "a" - FUNCTION = "b" + MODULE = "stream_example" + FUNCTION = "count" ARGS = [] query.apply(MODULE, FUNCTION, ARGS) diff --git a/examples/client/bin_ops.py b/examples/client/bin_ops.py index 844afdf48b..e4a624262f 100644 --- a/examples/client/bin_ops.py +++ b/examples/client/bin_ops.py @@ -52,7 +52,7 @@ def run(self): # kitty loses another life, gains a color, all as part of a record # multi-op ops = [ - operations.write(bin="color", write_item="smoke"), + operations.write(bin_name="color", write_item="smoke"), operations.increment(bin_name="lives", amount=-1), operations.read("ailments"), operations.read("lives") diff --git a/examples/client/kvs.py b/examples/client/kvs.py index 3b7b603fff..776f8a0caa 100644 --- a/examples/client/kvs.py +++ b/examples/client/kvs.py @@ -68,7 +68,7 @@ def run(self): print( '########################################################################') - self.client.udf_put('simple.lua') + self.client.udf_put('./examples/client/simple.lua') for i in range(1, 1000): key = ('test', 'demo', 'key{0}'.format(i)) diff --git a/examples/client/multi_thread.py b/examples/client/multi_thread.py index e64443e9f0..56e15edc33 100644 --- a/examples/client/multi_thread.py +++ b/examples/client/multi_thread.py @@ -29,7 +29,7 @@ class Multithread(Example): numKeys = 10000 - numReads = 1000000 + numReads = 100000 fNames = ('Jimmy', 'Johnny', 'Sammy', 'Sally', 'Sandy', 'Mandy', 'Billy') lNames = ('Bama', 'Mama', 'Sama', 'Lama', 'Cama', 'Rama', 'Tama') numThreads = 5 diff --git a/examples/client/query.py b/examples/client/query.py index 60f2e034e4..ed53c02993 100644 --- a/examples/client/query.py +++ b/examples/client/query.py @@ -21,11 +21,6 @@ from aerospike import predicates as p from .. import Example -config = { - 'lua': { - 'user_path': os.path.dirname(__file__) - } -} class Query(Example): def run(self): @@ -35,9 +30,12 @@ def run(self): query = self.client.scan(self.namespace, self.set_name) # TODO - BINS = [] - query.select(BINS) - query.apply(MODULE, FUNCTION, *ARGS) + BINS = ["a"] + query.select(*BINS) + MODULE = "stream_example" + FUNCTION = "count" + ARGS = [] + query.apply(MODULE, FUNCTION, ARGS) results = [] diff --git a/examples/client/query_apply.py b/examples/client/query_apply.py index 522f765390..6b08fde140 100644 --- a/examples/client/query_apply.py +++ b/examples/client/query_apply.py @@ -43,7 +43,7 @@ def query_callback(option, opt, value, parser): # help="If set, displays the metadata.") -from .. import Example +from .. import ExampleWithIndex config = { @@ -53,17 +53,24 @@ def query_callback(option, opt, value, parser): } -class QueryApply(Example): +class QueryApply(ExampleWithIndex): def run(self): + BIN = "bin" predicates = [ - p.equals(b, v), - p.equals(b, v), - p.between(b, l, u) + p.equals(BIN, 1), + # p.equals(BIN, "a"), + # p.between(BIN, 1, 3) ] + for predicate in predicates: - query_id = self.client.query_apply(self.namespace, - self.set_name, predicate, MODULE, - FUNCTION, ARGS) + # If predicate is provided, then perform a query + BINS = [BIN] + + MODULE = "stream_example" + FUNCTION = "count" + ARGS = [] + query_id = self.client.query_apply(self.namespace, self.set_name, predicate, MODULE, FUNCTION, ARGS) + while True: response = self.client.job_info(query_id, aerospike.JOB_QUERY) if response['status'] == aerospike.JOB_STATUS_COMPLETED: diff --git a/examples/client/scan_apply.py b/examples/client/scan_apply.py index cc937759a4..e4f2c50c95 100644 --- a/examples/client/scan_apply.py +++ b/examples/client/scan_apply.py @@ -66,19 +66,15 @@ class ScanApply(Example): def run(self): # args.reverse() - module = options.module - function = options.function - - for i, param in enumerate(options.arguments): - if param.isdigit(): - options.arguments[i] = int(param) + MODULE = "stream_example" + FUNCTION = "count" policy = {} - scan_id = client.scan_apply( - namespace, set, module, function, options.arguments, policy) + scan_id = self.client.scan_apply( + self.namespace, self.set_name, MODULE, FUNCTION, [], policy) while True: - response = client.job_info(scan_id, aerospike.JOB_SCAN) + response = self.client.job_info(scan_id, aerospike.JOB_SCAN) if response['status'] == aerospike.JOB_STATUS_COMPLETED: break diff --git a/examples/client/scan_partition.py b/examples/client/scan_partition.py index c42106b1a6..d6fa474260 100644 --- a/examples/client/scan_partition.py +++ b/examples/client/scan_partition.py @@ -33,7 +33,8 @@ def run(self): records = [] # callback to be called for each record read - def callback(input_tuple): + def callback(part_id, input_tuple): + print(part_id) (_, _, record) = input_tuple records.append(record) print(record) diff --git a/examples/client/select_many.py b/examples/client/select_many.py deleted file mode 100644 index 42d780efe4..0000000000 --- a/examples/client/select_many.py +++ /dev/null @@ -1,50 +0,0 @@ - -########################################################################## -# Copyright 2013-2026 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 aerospike -import sys - - - -# 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") - -from .. import Example - -class SelectMany(Example): - def run(self): - # args.pop() - # TODO: configurable - keys = [] - # keys = options.keys.split(',') - # keylist = [] - # for key in keys: - # individualkey = (namespace, set, key) - # keylist.append(individualkey) - - records = self.client.select_many(keys, ['i', 'd']) - - if records is not None: - print(records) - print("---") - print("OK, %d records found." % len(records)) - else: - # TODO: not sure if this is right - print('error: Not Found.', file=sys.stderr) diff --git a/examples/client/ttl.py b/examples/client/ttl.py index 612d5492e0..d073c293d4 100644 --- a/examples/client/ttl.py +++ b/examples/client/ttl.py @@ -85,101 +85,6 @@ ALL_KEYS = PRIMARY_KEYS_WITHOUT_TTL + list(KEYS_WITH_TTL.keys()) -def print_record(record_tuple, prefix=''): - (key, meta, bins) = record_tuple - print("%s%-4d %-4s %-8s %s" % ( - prefix, - int(key[2] or 0), - meta.get('gen') if meta and 'gen' in meta else '-', - meta.get('ttl') if meta and 'ttl' in meta else '-', - bins if bins else '-' - )) - - -def print_records(records, prefix=''): - header = "%s---- ---- -------- " % prefix - header = header.ljust(80, '-') - print() - print("%s%-4s %-4s %-8s %s" % (prefix, "key", "gen", "ttl", "record")) - print(header) - [print_record(r, prefix) for r in records] - - -def print_header(header, message=None): - print() - print(''.ljust(80, '=')) - print(header) - print(message) if message else None - print(''.ljust(80, '-')) - -def print_histogram(prefix=''): - request = ''.join(["histogram:ns=", options.namespace, ";hist=ttl"]) - - header = "%sHISTOGRAM (%s)" % (prefix, request) - border = prefix.ljust(80, '-') - - print() - print(header) - print(border) - for _, (error, response) in list(client.info(request).items()): - if error: - print('%serror: %s' % (prefix, error)) - else: - for line in textwrap.wrap(response, 80 - len(prefix)): - print("%s%s" % (prefix, line)) - - -def check_records(start, wait=0, message=None): - - if wait: - time.sleep(wait) - - stop = time.time() - duration = int(stop - start) - - print_header('CHECK :: wait=%s duration=%s' % (wait, duration), message) - - try: - print_records( - [client.get((options.namespace, options.set, k)) for k in ALL_KEYS], ' ') - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - - print_histogram(' ') - - -def write_records(): - - try: - for key in ALL_KEYS: - ttl = KEYS_WITH_TTL[key]['ttl'] if key in KEYS_WITH_TTL else None - - rec = {} - rec['key'] = key - rec['ttl'] = ttl if ttl else TTL_DEFAULT - rec['desc'] = KEYS_WITH_TTL[key][ - 'desc'] if key in KEYS_WITH_TTL else 'default TTL' - - try: - # write a new record - # ttl=None is equivalent to not setting a ttl - print("writing key :=", key) - client.put( - (options.namespace, options.set, key), rec, {'ttl': ttl}) - - except Exception as e: - ttlVal = int(ttl or 0) - if ttlVal > TTL_MAX: - print('error: (correct) failed to write record with TTL(%d) > TTL_MAX(%d)' % ( - ttlVal, TTL_MAX)) - else: - print('error: failed to write record with TTL = %d ' % - ttlVal) - - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - sys.exit(1) - ########################################################################## # CONFIGURE SERVER ########################################################################## @@ -192,12 +97,107 @@ class TTL(Example): def run(self): start = time.time() - check_records(start, 0, 'Clean state') - - write_records() + self.check_records(start, 0, 'Clean state') - check_records(start, 0, 'Initial state') - check_records(start, 2, 'Expect all records with TTL-2') - check_records(start, 6, 'Expect all records with TTL<=5 to be gone') - check_records(start, 3, 'Expect all records with TTL<=10 to be gone') - check_records(start, 6, 'Expect all records to be gone, except NO_EXPIRE') + self.write_records() + + self.check_records(start, 0, 'Initial state') + self.check_records(start, 2, 'Expect all records with TTL-2') + self.check_records(start, 6, 'Expect all records with TTL<=5 to be gone') + self.check_records(start, 3, 'Expect all records with TTL<=10 to be gone') + self.check_records(start, 6, 'Expect all records to be gone, except NO_EXPIRE') + + def print_record(self, record_tuple, prefix=''): + (key, meta, bins) = record_tuple + print("%s%-4d %-4s %-8s %s" % ( + prefix, + int(key[2] or 0), + meta.get('gen') if meta and 'gen' in meta else '-', + meta.get('ttl') if meta and 'ttl' in meta else '-', + bins if bins else '-' + )) + + + def print_records(self, records, prefix=''): + header = "%s---- ---- -------- " % prefix + header = header.ljust(80, '-') + print() + print("%s%-4s %-4s %-8s %s" % (prefix, "key", "gen", "ttl", "record")) + print(header) + [self.print_record(r, prefix) for r in records] + + + def print_header(self, header, message=None): + print() + print(''.ljust(80, '=')) + print(header) + print(message) if message else None + print(''.ljust(80, '-')) + + def print_histogram(self, prefix=''): + request = ''.join(["histogram:namespace=", self.namespace, ";type=ttl"]) + + header = "%sHISTOGRAM (%s)" % (prefix, request) + border = prefix.ljust(80, '-') + + print() + print(header) + print(border) + for _, (error, response) in list(self.client.info_all(request).items()): + if error: + print('%serror: %s' % (prefix, error)) + else: + for line in textwrap.wrap(response, 80 - len(prefix)): + print("%s%s" % (prefix, line)) + + + def check_records(self, start, wait=0, message=None): + + if wait: + time.sleep(wait) + + stop = time.time() + duration = int(stop - start) + + self.print_header('CHECK :: wait=%s duration=%s' % (wait, duration), message) + + try: + self.print_records( + [self.client.get((self.namespace, self.set_name, k)) for k in ALL_KEYS], ' ') + except Exception as e: + print("error: {0}".format(e), file=sys.stderr) + + self.print_histogram(' ') + + + def write_records(self): + + try: + for key in ALL_KEYS: + ttl = KEYS_WITH_TTL[key]['ttl'] if key in KEYS_WITH_TTL else None + + rec = {} + rec['key'] = key + rec['ttl'] = ttl if ttl else TTL_DEFAULT + rec['desc'] = KEYS_WITH_TTL[key][ + 'desc'] if key in KEYS_WITH_TTL else 'default TTL' + + try: + # write a new record + # ttl=None is equivalent to not setting a ttl + print("writing key :=", key) + self.client.put( + (self.namespace, self.set_name, key), rec, {'ttl': ttl}) + + except Exception as e: + ttlVal = int(ttl or 0) + if ttlVal > TTL_MAX: + print('error: (correct) failed to write record with TTL(%d) > TTL_MAX(%d)' % ( + ttlVal, TTL_MAX)) + else: + print('error: failed to write record with TTL = %d ' % + ttlVal) + + except Exception as e: + print("error: {0}".format(e), file=sys.stderr) + sys.exit(1) diff --git a/examples/client/udf_get.py b/examples/client/udf_get.py index 0966fb30f3..aabf6ed0c9 100644 --- a/examples/client/udf_get.py +++ b/examples/client/udf_get.py @@ -22,7 +22,7 @@ class UDFGet(Example): def run(self): # TODO: configurable - module = "a" + module = "./examples/client/example.lua" language = aerospike.UDF_TYPE_LUA policy = {} diff --git a/examples/client/udf_put.py b/examples/client/udf_put.py index 997702843e..90b18b13b6 100644 --- a/examples/client/udf_put.py +++ b/examples/client/udf_put.py @@ -24,7 +24,7 @@ def run(self): policy = {} # TODO # filename = args.pop() - filename = "z" + filename = "./examples/client/example.lua" udf_type = 0 # 0 for LUA self.client.udf_put(filename, udf_type, policy) From ac205f52ad4a193fd949f006324167483d9f18b2 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 24 Jul 2026 12:34:28 -0700 Subject: [PATCH 23/60] Convert outdated select_many code example to batch_read. --- examples/client/batch_read.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/client/batch_read.py b/examples/client/batch_read.py index b39bf0a40d..d03986ece7 100644 --- a/examples/client/batch_read.py +++ b/examples/client/batch_read.py @@ -27,6 +27,15 @@ def run(self): # Get records records = self.client.batch_read(keys) + if records != None: + print(f"{len(records)} records were found") + print(records) + else: + print('error: Not Found.') + + # Select bins + records = self.client.batch_read(keys, bins=["a"]) + if records != None: print(f"{len(records)} records were found") print(records) From fcfce76af204c775441f4994f55fad667fb1be9f Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Mon, 27 Jul 2026 08:45:23 -0700 Subject: [PATCH 24/60] Further WIP cleanup for ttl example. Add ability to run specific code examples. --- .github/workflows/smoke-tests.yml | 5 +- examples/client/ttl.py | 176 ++++++------------------------ examples/run_all_examples.py | 6 +- 3 files changed, 43 insertions(+), 144 deletions(-) diff --git a/.github/workflows/smoke-tests.yml b/.github/workflows/smoke-tests.yml index e3031a8d0d..17261b31e4 100644 --- a/.github/workflows/smoke-tests.yml +++ b/.github/workflows/smoke-tests.yml @@ -275,7 +275,10 @@ 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 examples.run_all_examples + run: | + docker run --rm --network host aerospike/aerospike-tools asinfo -v "set-config:context=namespace;id=test;nsup-period=1" + docker run --rm --network host aerospike/aerospike-tools asinfo -v "set-config:context=namespace;namespace=test;default-ttl=10S" + python3 -m examples.run_all_examples - name: Install test dependencies if: ${{ matrix.test == 'doctest' }} diff --git a/examples/client/ttl.py b/examples/client/ttl.py index d073c293d4..f747a10d49 100644 --- a/examples/client/ttl.py +++ b/examples/client/ttl.py @@ -31,7 +31,6 @@ from aerospike import exception as e TTL_DEFAULT = 10 -TTL_MAX = 20 # TODO: include instructions to have docker commands to set up server instead of through python # Define the Namespace Supervisor parms -- setting the period very short @@ -43,161 +42,54 @@ # some records that expire EARLY (5 seconds), some records that expire at # the default (10 seconds), some that expire LATE (15 seconds) and some # that NEVER expire. -# We set MAX ttl to 20 to check that our flag (0xFFFFFFFF) is allowed in -# and does not trigger the "greater than max ttl" warning. -# Also, we'll check that one of our records DOES trigger the Max TTL warning -# with a TTL of greater than 20. # PARAMS_NAMESPACE = [[('default-ttl', TTL_DEFAULT)]] -# TODO: needs to be updated -# Write Policy names and related values -AS_POLICY_W_TIMEOUT = "timeout" -# TODO: don't know what this is for... -AS_POLICY_KEY_STORE = 3 # Store the key (NOT YET IMPLEMENTED) - -# TODO: verify this works? -AS_POLICY_GEN_DUP = 4 # Write a record creating a duplicate, ONLY if -# the generation collides (?) - - -# Setup write policy -wr_policy = { - "total_timeout": 5000, - "max_retries": 0, - "key": aerospike.POLICY_KEY_DIGEST, - "gen": aerospike.POLICY_GEN_IGNORE, - "exists": aerospike.POLICY_EXISTS_IGNORE -} - -PRIMARY_KEYS_WITHOUT_TTL = list(range(1, 11)) - -KEYS_WITH_TTL = { - 20: {'ttl': 5, - 'desc': '5 sec TTL'}, - 40: {'ttl': 15, - 'desc': '15 sec TTL'}, - 60: {'ttl': aerospike.TTL_NEVER_EXPIRE, - 'desc': 'NO_EXPIRE TTL'}, - 80: {'ttl': TTL_MAX + 1, - 'desc': 'Larger than MAX TTL'} +USER_KEYS = { + 5: 5, + 15: 15, + "ns_default": aerospike.TTL_NAMESPACE_DEFAULT, + "dont_expire": aerospike.TTL_NEVER_EXPIRE, } -ALL_KEYS = PRIMARY_KEYS_WITHOUT_TTL + list(KEYS_WITH_TTL.keys()) - -########################################################################## -# CONFIGURE SERVER -########################################################################## - -# TODO: use docker container - from .. import Example class TTL(Example): def run(self): - start = time.time() - - self.check_records(start, 0, 'Clean state') - + self.time_elapsed = 0 self.write_records() - - self.check_records(start, 0, 'Initial state') - self.check_records(start, 2, 'Expect all records with TTL-2') - self.check_records(start, 6, 'Expect all records with TTL<=5 to be gone') - self.check_records(start, 3, 'Expect all records with TTL<=10 to be gone') - self.check_records(start, 6, 'Expect all records to be gone, except NO_EXPIRE') - - def print_record(self, record_tuple, prefix=''): - (key, meta, bins) = record_tuple - print("%s%-4d %-4s %-8s %s" % ( - prefix, - int(key[2] or 0), - meta.get('gen') if meta and 'gen' in meta else '-', - meta.get('ttl') if meta and 'ttl' in meta else '-', - bins if bins else '-' - )) - - - def print_records(self, records, prefix=''): - header = "%s---- ---- -------- " % prefix - header = header.ljust(80, '-') - print() - print("%s%-4s %-4s %-8s %s" % (prefix, "key", "gen", "ttl", "record")) - print(header) - [self.print_record(r, prefix) for r in records] - - - def print_header(self, header, message=None): - print() - print(''.ljust(80, '=')) - print(header) - print(message) if message else None - print(''.ljust(80, '-')) - - def print_histogram(self, prefix=''): - request = ''.join(["histogram:namespace=", self.namespace, ";type=ttl"]) - - header = "%sHISTOGRAM (%s)" % (prefix, request) - border = prefix.ljust(80, '-') - - print() - print(header) - print(border) - for _, (error, response) in list(self.client.info_all(request).items()): - if error: - print('%serror: %s' % (prefix, error)) - else: - for line in textwrap.wrap(response, 80 - len(prefix)): - print("%s%s" % (prefix, line)) - - - def check_records(self, start, wait=0, message=None): - + self.check_records(0, 'Initial state') + self.check_records(2, 'Expect all records with TTL<=2 to be gone.') + self.check_records(6, 'Expect all records with TTL<=5 to be gone') + self.check_records(3, 'Expect all records with TTL<=10 to be gone') + self.check_records(6, 'Expect all records to be gone, except NO_EXPIRE') + + def __del__(self): + self.client.batch_remove([(self.namespace, self.set_name, key) for key in USER_KEYS]) + super().__del__() + + def print_histogram(self): + request = f"histogram:namespace={self.namespace};type=ttl" + response = self.client.info_random_node(request) + print("Server TTL histogram:", response) + + def check_records(self, wait=0, message=None): if wait: time.sleep(wait) + print(f"Waited {wait} seconds") + self.time_elapsed += wait - stop = time.time() - duration = int(stop - start) - - self.print_header('CHECK :: wait=%s duration=%s' % (wait, duration), message) + print(f"Total elapsed time is {self.time_elapsed}. {message}") + pks = [(self.namespace, self.set_name, user_key) for user_key in USER_KEYS] + brs = self.client.batch_read(pks) + for br in brs.batch_records: + print(f"Server returned error code {br.result} for record with ttl of {br.key[2]}") - try: - self.print_records( - [self.client.get((self.namespace, self.set_name, k)) for k in ALL_KEYS], ' ') - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - - self.print_histogram(' ') + self.print_histogram() def write_records(self): - - try: - for key in ALL_KEYS: - ttl = KEYS_WITH_TTL[key]['ttl'] if key in KEYS_WITH_TTL else None - - rec = {} - rec['key'] = key - rec['ttl'] = ttl if ttl else TTL_DEFAULT - rec['desc'] = KEYS_WITH_TTL[key][ - 'desc'] if key in KEYS_WITH_TTL else 'default TTL' - - try: - # write a new record - # ttl=None is equivalent to not setting a ttl - print("writing key :=", key) - self.client.put( - (self.namespace, self.set_name, key), rec, {'ttl': ttl}) - - except Exception as e: - ttlVal = int(ttl or 0) - if ttlVal > TTL_MAX: - print('error: (correct) failed to write record with TTL(%d) > TTL_MAX(%d)' % ( - ttlVal, TTL_MAX)) - else: - print('error: failed to write record with TTL = %d ' % - ttlVal) - - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - sys.exit(1) + for key, ttl in USER_KEYS.items(): + pk = (self.namespace, self.set_name, key) + print("writing key :=", key) + self.client.put(pk, {"a": 1}, policy={"ttl": ttl}) diff --git a/examples/run_all_examples.py b/examples/run_all_examples.py index f2ef6b835e..c41b5ee328 100644 --- a/examples/run_all_examples.py +++ b/examples/run_all_examples.py @@ -2,10 +2,11 @@ import importlib import inspect import os +import sys # from . import Example -example_classes = [] +example_classes: list[type] = [] dir_containing_this_module = os.path.dirname(os.path.abspath(__file__)) all_packages = pkgutil.walk_packages([dir_containing_this_module + "/client"]) @@ -23,6 +24,9 @@ continue example_classes.append(obj) +if len(sys.argv) == 2: + example_classes = [cls for cls in example_classes if cls.__name__ == sys.argv[1]] + print("Running examples...") for cls in example_classes: print(cls) From 2e58cc2026a805d4ddc2588e11c419f06905da16 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Mon, 27 Jul 2026 12:00:37 -0700 Subject: [PATCH 25/60] Finish up ttl code example changes --- examples/client/ttl.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/client/ttl.py b/examples/client/ttl.py index f747a10d49..07ac61fb28 100644 --- a/examples/client/ttl.py +++ b/examples/client/ttl.py @@ -45,7 +45,7 @@ # PARAMS_NAMESPACE = [[('default-ttl', TTL_DEFAULT)]] -USER_KEYS = { +USER_KEYS_TO_TTL = { 5: 5, 15: 15, "ns_default": aerospike.TTL_NAMESPACE_DEFAULT, @@ -56,6 +56,7 @@ class TTL(Example): def run(self): + self.KEYS = [(self.namespace, self.set_name, key) for key in USER_KEYS_TO_TTL] self.time_elapsed = 0 self.write_records() self.check_records(0, 'Initial state') @@ -65,7 +66,7 @@ def run(self): self.check_records(6, 'Expect all records to be gone, except NO_EXPIRE') def __del__(self): - self.client.batch_remove([(self.namespace, self.set_name, key) for key in USER_KEYS]) + self.client.batch_remove(self.KEYS) super().__del__() def print_histogram(self): @@ -80,8 +81,7 @@ def check_records(self, wait=0, message=None): self.time_elapsed += wait print(f"Total elapsed time is {self.time_elapsed}. {message}") - pks = [(self.namespace, self.set_name, user_key) for user_key in USER_KEYS] - brs = self.client.batch_read(pks) + brs = self.client.batch_read(self.KEYS) for br in brs.batch_records: print(f"Server returned error code {br.result} for record with ttl of {br.key[2]}") @@ -89,7 +89,7 @@ def check_records(self, wait=0, message=None): def write_records(self): - for key, ttl in USER_KEYS.items(): - pk = (self.namespace, self.set_name, key) + for key in self.KEYS: print("writing key :=", key) - self.client.put(pk, {"a": 1}, policy={"ttl": ttl}) + user_key = key[2] + self.client.put(key, {"a": 1}, policy={"ttl": USER_KEYS_TO_TTL[user_key]}) From d599c8ce04b0542929bfab9af314448ac740a319 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Mon, 27 Jul 2026 12:11:00 -0700 Subject: [PATCH 26/60] Create subclass that injects udf_path into client config. Have UDF code examples inherit from that subclass --- examples/__init__.py | 22 ++++++++++++++++------ examples/client/kvs.py | 4 ++-- examples/client/udf_get.py | 4 ++-- examples/client/udf_put.py | 4 ++-- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/examples/__init__.py b/examples/__init__.py index 21c8308cc8..0ce07b9dc0 100644 --- a/examples/__init__.py +++ b/examples/__init__.py @@ -10,17 +10,15 @@ def __init__( user: str = None, password: str = None, namespace: str = "test", - set_name: str = "demo" + set_name: str = "demo", + extra_config: dict = {} ): self.config = { "hosts": [(host, port)], "user": user, - "password": password, - # TODO: should belong in a different fixture to make less complex - 'lua': { - 'user_path': os.path.dirname(__file__) + "/client/" - } + "password": password } + self.config |= extra_config client = aerospike.client(self.config) self.client = client @@ -32,6 +30,18 @@ def __del__(self): self.client.close() +class UDFExample(Example): + def __init__(self): + extra_config = { + 'lua': { + 'user_path': os.path.dirname(__file__) + "/client/" + } + } + super().__init__(extra_config) + + def __del__(self): + pass + class ExampleWithIndex(Example): INDEX_NAME = "index_name" def __init__(self): diff --git a/examples/client/kvs.py b/examples/client/kvs.py index 776f8a0caa..ffa651f9c7 100644 --- a/examples/client/kvs.py +++ b/examples/client/kvs.py @@ -17,9 +17,9 @@ -from .. import Example +from .. import UDFExample -class KVS(Example): +class KVS(UDFExample): def run(self): print( '########################################################################') diff --git a/examples/client/udf_get.py b/examples/client/udf_get.py index aabf6ed0c9..da8616acc7 100644 --- a/examples/client/udf_get.py +++ b/examples/client/udf_get.py @@ -15,11 +15,11 @@ # limitations under the License. ########################################################################## -from .. import Example +from .. import UDFExample import aerospike -class UDFGet(Example): +class UDFGet(UDFExample): def run(self): # TODO: configurable module = "./examples/client/example.lua" diff --git a/examples/client/udf_put.py b/examples/client/udf_put.py index 90b18b13b6..2927eec107 100644 --- a/examples/client/udf_put.py +++ b/examples/client/udf_put.py @@ -16,10 +16,10 @@ ########################################################################## -from .. import Example +from .. import UDFExample -class UDFPut(Example): +class UDFPut(UDFExample): def run(self): policy = {} # TODO From b70e637bed8caf03d6796394e1eab21426c377ec Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Mon, 27 Jul 2026 12:30:16 -0700 Subject: [PATCH 27/60] WIP on addressing TODO's left in PR --- examples/__init__.py | 3 +-- examples/client/batch_read.py | 8 +++---- examples/client/client_big_list.py | 1 - examples/client/delete.py | 37 ++++++++---------------------- examples/client/exists.py | 5 ++-- examples/client/get_nodes.py | 2 +- examples/client/index_create.py | 4 +++- examples/client/index_remove.py | 9 +++----- examples/client/info.py | 1 - 9 files changed, 24 insertions(+), 46 deletions(-) diff --git a/examples/__init__.py b/examples/__init__.py index 0ce07b9dc0..b0767834d7 100644 --- a/examples/__init__.py +++ b/examples/__init__.py @@ -25,6 +25,7 @@ def __init__( self.namespace = namespace self.set_name = set_name self.key = (self.namespace, self.set_name, "docreadkey") + self.non_existent_key = (self.namespace, self.set_name, "nonexistent") def __del__(self): self.client.close() @@ -50,8 +51,6 @@ def __init__(self): def __del__(self): self.client.index_remove(self.namespace, self.INDEX_NAME) -# 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__() diff --git a/examples/client/batch_read.py b/examples/client/batch_read.py index d03986ece7..08a37aaa52 100644 --- a/examples/client/batch_read.py +++ b/examples/client/batch_read.py @@ -19,12 +19,13 @@ from .. import ExampleWithRecord -# TODO: should use fixture with multiple records class BatchRead(ExampleWithRecord): - def run(self): - keys = [f"key{i}" for i in range(5)] + def __init__(self): + pass + def run(self): # Get records + keys = [self.key, self.non_existent_key] records = self.client.batch_read(keys) if records != None: @@ -42,7 +43,6 @@ def run(self): else: print('error: Not Found.') - # TODO: verify syntax # Verify existence of records records = self.client.batch_read(keys, bins=[]) diff --git a/examples/client/client_big_list.py b/examples/client/client_big_list.py index 5e7815cda1..587f13bc81 100644 --- a/examples/client/client_big_list.py +++ b/examples/client/client_big_list.py @@ -273,7 +273,6 @@ def _update_metadata_record(self, generation): 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): diff --git a/examples/client/delete.py b/examples/client/delete.py index bc878d6930..d3eea5fbc2 100644 --- a/examples/client/delete.py +++ b/examples/client/delete.py @@ -15,38 +15,19 @@ # limitations under the License. ########################################################################## -import aerospike - +from aerospike import exception as e from .. import ExampleWithRecord -# TODO: missing this -config = { - # TODO: this is deprecated? - 'policies': { - 'total_timeout': 1000 - } -} class Delete(ExampleWithRecord): def run(self): - # TODO; these two were configurable - test_count = 128 - policy = { - 'total_timeout': 1000 - } - meta = None - print(f"IO test count:{test_count}") - def delete(namespace, set, test_count): - self.client.remove(self.key) - # for i in range(0, test_count): - - # TODO - # key = {'ns': namespace, \ - # 'set':set, \ - # 'key': str(i), \ - # 'digest': aerospike.calc_digest(namespace, set, str(i))} - # self.client.remove(self.key) + self.client.remove(self.key) + try: + self.client.remove(self.key) + except e.RecordNotFound: + print(f"Could not find {self.key}") - delete(self.namespace, set, test_count) - print(f"Deleted {test_count} records") + # Override default destructor + def __del__(self): + pass diff --git a/examples/client/exists.py b/examples/client/exists.py index 9009f26b7e..bd1cea5267 100644 --- a/examples/client/exists.py +++ b/examples/client/exists.py @@ -20,7 +20,8 @@ class Exists(ExampleWithRecord): def run(self): - (key, metadata) = self.client.exists(self.key) + key, metadata = self.client.exists(self.key) print(key, metadata) - # TODO: missing negative path example (e.g where metadata is None) + key, metadata = self.client.exists(self.non_existent_key) + print(key, metadata) diff --git a/examples/client/get_nodes.py b/examples/client/get_nodes.py index 7e4905fd8a..3296eb3685 100644 --- a/examples/client/get_nodes.py +++ b/examples/client/get_nodes.py @@ -27,5 +27,5 @@ class GetNodes(Example): def run(self): - # TODO: Demonstrate different outcomes (i.e response is None or not) response = self.client.get_nodes() + print(response) diff --git a/examples/client/index_create.py b/examples/client/index_create.py index f5a71a29ef..5ba98c7b2a 100644 --- a/examples/client/index_create.py +++ b/examples/client/index_create.py @@ -22,8 +22,10 @@ class IndexCreate(Example): def run(self): policy = {} - # TODO: these are configurable BIN_NAME = "a" INDEX_DATATYPE = aerospike.INDEX_INTEGER self.client.index_single_value_create(self.namespace, self.set_name, BIN_NAME, INDEX_DATATYPE, "index_name", policy) + + def __del__(self): + self.client.index_remove(self.namespace, "index_name") diff --git a/examples/client/index_remove.py b/examples/client/index_remove.py index 2ef978ab14..c487883a11 100644 --- a/examples/client/index_remove.py +++ b/examples/client/index_remove.py @@ -16,13 +16,10 @@ ########################################################################## -from .. import Example +from .. import ExampleWithIndex -class IndexRemove(Example): +class IndexRemove(ExampleWithIndex): def run(self): policy = {} - # TODO: should be configurable... - INDEX_NAME = "index_name" - - self.client.index_remove(self.namespace, INDEX_NAME, policy) + self.client.index_remove(self.namespace, self.INDEX_NAME, policy) diff --git a/examples/client/info.py b/examples/client/info.py index 983a51c30a..329263e5cf 100644 --- a/examples/client/info.py +++ b/examples/client/info.py @@ -23,7 +23,6 @@ class Info(Example): def run(self): # Default info request - # TODO: configurable request = "statistics" # TODO: needs review From 3ec81a3d3b81c893c8bdf954472d05b6b49f17d7 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Mon, 27 Jul 2026 12:55:10 -0700 Subject: [PATCH 28/60] Further cleanup and addressing of TODO's. Convert scan examples to query since scan is deprecated. --- examples/__init__.py | 5 +- examples/client/aggregate.py | 8 +-- examples/client/append.py | 1 - examples/client/get_nodes.py | 6 -- examples/client/increment.py | 1 - examples/client/is_connected.py | 7 ++- examples/client/prepend.py | 2 - examples/client/query.py | 7 +-- examples/client/query_apply.py | 25 +------- .../{scan_partition.py => query_partition.py} | 17 +++-- examples/client/remove.py | 8 ++- examples/client/remove_bin.py | 17 +---- examples/client/scan_apply.py | 42 ------------- examples/client/select_record.py | 62 ++----------------- examples/client/ttl.py | 2 +- 15 files changed, 33 insertions(+), 177 deletions(-) rename examples/client/{scan_partition.py => query_partition.py} (83%) diff --git a/examples/__init__.py b/examples/__init__.py index b0767834d7..2a3fa33b8a 100644 --- a/examples/__init__.py +++ b/examples/__init__.py @@ -26,6 +26,7 @@ def __init__( self.set_name = set_name self.key = (self.namespace, self.set_name, "docreadkey") self.non_existent_key = (self.namespace, self.set_name, "nonexistent") + self.BIN_NAME = "a" def __del__(self): self.client.close() @@ -46,7 +47,7 @@ def __del__(self): class ExampleWithIndex(Example): INDEX_NAME = "index_name" def __init__(self): - self.client.index_single_value_create(self.namespace, self.set_name, aerospike.INDEX_INTEGER, self.INDEX_NAME) + self.client.index_single_value_create(self.namespace, self.set_name, self.BIN_NAME, aerospike.INDEX_INTEGER, self.INDEX_NAME) def __del__(self): self.client.index_remove(self.namespace, self.INDEX_NAME) @@ -55,7 +56,7 @@ class ExampleWithRecord(Example): def __init__(self): super().__init__() - self.client.put(self.key, bins={"a": 1}) + self.client.put(self.key, bins={self.BIN_NAME: 1}) def __del__(self): self.client.remove(self.key) diff --git a/examples/client/aggregate.py b/examples/client/aggregate.py index 44957629f3..ee113844ba 100644 --- a/examples/client/aggregate.py +++ b/examples/client/aggregate.py @@ -24,18 +24,16 @@ class Aggregate(ExampleWithIndex): def run(self): - BIN = "bin" predicates = [ - p.equals(BIN, 1), - # p.equals(BIN, "a"), - # p.between(BIN, 1, 3) + p.equals(self.BIN, 1), + p.between(self.BIN, 1, 3) ] for predicate in predicates: # If predicate is provided, then perform a query query = self.client.query(self.namespace, self.set_name) query.where(predicate) - BINS = [BIN] + BINS = [self.BIN] query.select(*BINS) MODULE = "stream_example" diff --git a/examples/client/append.py b/examples/client/append.py index 1183b42608..446cacbd1b 100644 --- a/examples/client/append.py +++ b/examples/client/append.py @@ -23,7 +23,6 @@ class Append(Example): def run(self): record = { 'example_name': 'John', - 'example_age': 1 } self.client.put(self.key, record) diff --git a/examples/client/get_nodes.py b/examples/client/get_nodes.py index 3296eb3685..114a361145 100644 --- a/examples/client/get_nodes.py +++ b/examples/client/get_nodes.py @@ -18,12 +18,6 @@ from .. import Example -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog" - class GetNodes(Example): def run(self): diff --git a/examples/client/increment.py b/examples/client/increment.py index 1987c1d65b..9d3c664272 100644 --- a/examples/client/increment.py +++ b/examples/client/increment.py @@ -22,7 +22,6 @@ class Increment(ExampleWithRecord): def run(self): record = { - 'example_name': 'John', 'example_age': 1 } diff --git a/examples/client/is_connected.py b/examples/client/is_connected.py index b4f4878b94..8d767606c9 100644 --- a/examples/client/is_connected.py +++ b/examples/client/is_connected.py @@ -19,6 +19,7 @@ class IsConnected(Example): def run(self): - # TODO: negative path where not connected, or exception raised was removed - if self.client.is_connected() is True: - print("Connected to Aerospike DB.") + print(self.client.is_connected()) + + self.client.close() + print(self.client.is_connected()) diff --git a/examples/client/prepend.py b/examples/client/prepend.py index 55b6031fcd..bbea7048de 100644 --- a/examples/client/prepend.py +++ b/examples/client/prepend.py @@ -20,10 +20,8 @@ class Prepend(Example): def run(self): - # TODO: can share this in a fixture class? record = { 'example_name': 'John', - 'example_age': 1 } self.client.put(self.key, record) diff --git a/examples/client/query.py b/examples/client/query.py index ed53c02993..fa24a8a76f 100644 --- a/examples/client/query.py +++ b/examples/client/query.py @@ -24,14 +24,9 @@ class Query(Example): def run(self): - #. TODO: check if predicate to decide if using scan/query. query = self.client.query(self.namespace, self.set_name) - query = self.client.scan(self.namespace, self.set_name) - - # TODO - BINS = ["a"] - query.select(*BINS) + query.select(self.BIN_NAME) MODULE = "stream_example" FUNCTION = "count" ARGS = [] diff --git a/examples/client/query_apply.py b/examples/client/query_apply.py index 6b08fde140..4604d48b71 100644 --- a/examples/client/query_apply.py +++ b/examples/client/query_apply.py @@ -17,33 +17,12 @@ import aerospike -import json -import re -import sys import os.path from aerospike import predicates as p -########################################################################## -# Option Parsing -########################################################################## - -usage = "usage: %prog [options] [where]" - - -def query_callback(option, opt, value, parser): - setattr(parser.values, option.dest, value.split(',')) - -# optparser.add_option( -# "--show-key", dest="show_key", action="store_true", -# help="If set, displays the key/digest.") - -# optparser.add_option( -# "--show-meta", dest="show_meta", action="store_true", -# help="If set, displays the metadata.") - -from .. import ExampleWithIndex +from .. import ExampleWithIndex, UDFExample config = { @@ -53,7 +32,7 @@ def query_callback(option, opt, value, parser): } -class QueryApply(ExampleWithIndex): +class QueryApply(ExampleWithIndex, UDFExample): def run(self): BIN = "bin" predicates = [ diff --git a/examples/client/scan_partition.py b/examples/client/query_partition.py similarity index 83% rename from examples/client/scan_partition.py rename to examples/client/query_partition.py index d6fa474260..9e6c3c0763 100644 --- a/examples/client/scan_partition.py +++ b/examples/client/query_partition.py @@ -18,17 +18,14 @@ from .. import Example -class ScanPartition(Example): +class QueryPartition(Example): def run(self): - s = self.client.scan(self.namespace, self.set_name) + query = self.client.query(self.namespace, self.set_name) - partition_policy = None + query_policy = None - # TODO: configurable - STARTING_PARTITION = 1 - if STARTING_PARTITION > 0: - # project specified bins - partition_policy = {'partition_filter': {'begin': STARTING_PARTITION, 'count': 1}} + STARTING_PARTITION = 1000 + query_policy = {'partition_filter': {'begin': STARTING_PARTITION, 'count': 1}} records = [] @@ -42,7 +39,7 @@ def callback(part_id, input_tuple): self.client.truncate(self.namespace, self.set_name, 0) # invoke the operations, and for each record invoke the callback - s.foreach(callback, partition_policy) + query.foreach(callback, query_policy) existing_count = len(records) if existing_count > 0: print(f"{existing_count} records already exist in partition: {STARTING_PARTITION}.") @@ -64,7 +61,7 @@ def callback(part_id, input_tuple): records.clear() # invoke the operations, and for each record invoke the callback - s.foreach(callback, partition_policy) + query.foreach(callback, query_policy) print("---") print(f"{count} records are put into partition: {STARTING_PARTITION}.") diff --git a/examples/client/remove.py b/examples/client/remove.py index 335bc1596c..e6fee53c41 100644 --- a/examples/client/remove.py +++ b/examples/client/remove.py @@ -16,10 +16,14 @@ ########################################################################## from .. import ExampleWithRecord +from aerospike import exception as e 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) + + try: + self.client.remove(self.key) + except e.RecordNotFound: + print("Record already removed") diff --git a/examples/client/remove_bin.py b/examples/client/remove_bin.py index c5fedcddd6..c4627eb980 100644 --- a/examples/client/remove_bin.py +++ b/examples/client/remove_bin.py @@ -16,29 +16,14 @@ ########################################################################## -import aerospike -import sys - -from optparse import OptionParser - -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog [options] key bin_names" from .. import ExampleWithRecord -exitCode = 0 - class RemoveBin(ExampleWithRecord): def run(self): - # TODO: both configurable - # pk - bin_names = [] + bin_names = [self.BIN_NAME] retval = self.client.remove_bin(self.key, bin_names) print("Status of bin removal is: %d" % (retval)) print("OK, bins removed from the record at", self.key) - # TODO: why RecordNotFound used to map to 602? diff --git a/examples/client/scan_apply.py b/examples/client/scan_apply.py index e4f2c50c95..b7e9eec35a 100644 --- a/examples/client/scan_apply.py +++ b/examples/client/scan_apply.py @@ -17,55 +17,13 @@ import aerospike -import json -import sys -from optparse import OptionParser - -########################################################################## -# Options Parsing -########################################################################## - -usage = "usage: %prog [options] module function [args...]" - - -def scan_callback(option, opt, value, parser): - setattr(parser.values, option.dest, value.split(',')) - - -# optparser.add_option( -# "-m", "--module", dest="module", type="string", -# help="UDF Module.") - -# optparser.add_option( -# "-f", "--function", dest="function", type="string", -# help="UDF Function.") - -# optparser.add_option( -# "-a", "--arg", dest="arguments", type="string", action="callback", -# callback=scan_callback, help="UDF Arguments.") - -# optparser.add_option( -# "-b", "--bins", dest="bins", type="string", action="append", -# help="Bins to select from each record.") - - -exitCode = 0 - - -def parse_arg(s): - try: - return json.loads(s) - except ValueError: - return s from .. import Example class ScanApply(Example): def run(self): - # args.reverse() - MODULE = "stream_example" FUNCTION = "count" diff --git a/examples/client/select_record.py b/examples/client/select_record.py index 82c305faa3..221824f635 100644 --- a/examples/client/select_record.py +++ b/examples/client/select_record.py @@ -16,67 +16,15 @@ ########################################################################## -import aerospike -import sys - -from optparse import OptionParser - -########################################################################## -# Options Parsing -########################################################################## - -# usage = "usage: %prog [options] key bin [bin ...]" - -# optparser = OptionParser(usage=usage, add_help_option=False) - -# 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) - from .. import ExampleWithRecord class SelectRecord(ExampleWithRecord): def run(self): - # TODO: both configurable - key = args.pop(0) - bins = [] - + bins = [self.BIN_NAME] policy = None + (key, metadata, record) = self.client.select(self.key, bins, policy) - print(args) - - (key, metadata, record) = self.client.select( - (self.namespace, self.set_name, key), bins, 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: - # TODO: not sure if this is right. - print('error: Not Found.', file=sys.stderr) - exitCode = 1 + print(key) + print(metadata) + print(record) diff --git a/examples/client/ttl.py b/examples/client/ttl.py index 07ac61fb28..2ed33782db 100644 --- a/examples/client/ttl.py +++ b/examples/client/ttl.py @@ -92,4 +92,4 @@ def write_records(self): for key in self.KEYS: print("writing key :=", key) user_key = key[2] - self.client.put(key, {"a": 1}, policy={"ttl": USER_KEYS_TO_TTL[user_key]}) + self.client.put(key, {self.BIN_NAME: 1}, policy={"ttl": USER_KEYS_TO_TTL[user_key]}) From 910936409664e65f422468c64db24e23535652da Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Tue, 28 Jul 2026 15:40:30 -0700 Subject: [PATCH 29/60] Address UDF not found errors by ensuring the user path is loaded properly. --- examples/client/aggregate.py | 4 ++-- examples/client/query.py | 4 ++-- examples/client/scan_apply.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/client/aggregate.py b/examples/client/aggregate.py index ee113844ba..7fc0f053ac 100644 --- a/examples/client/aggregate.py +++ b/examples/client/aggregate.py @@ -19,10 +19,10 @@ import os.path from aerospike import predicates as p -from .. import ExampleWithIndex +from .. import ExampleWithIndex, UDFExample -class Aggregate(ExampleWithIndex): +class Aggregate(ExampleWithIndex, UDFExample): def run(self): predicates = [ p.equals(self.BIN, 1), diff --git a/examples/client/query.py b/examples/client/query.py index fa24a8a76f..dd4d8f2c48 100644 --- a/examples/client/query.py +++ b/examples/client/query.py @@ -19,10 +19,10 @@ import os.path from aerospike import predicates as p -from .. import Example +from .. import UDFExample -class Query(Example): +class Query(UDFExample): def run(self): query = self.client.query(self.namespace, self.set_name) diff --git a/examples/client/scan_apply.py b/examples/client/scan_apply.py index b7e9eec35a..f2affe6ee6 100644 --- a/examples/client/scan_apply.py +++ b/examples/client/scan_apply.py @@ -19,10 +19,10 @@ import aerospike -from .. import Example +from .. import UDFExample -class ScanApply(Example): +class ScanApply(UDFExample): def run(self): MODULE = "stream_example" FUNCTION = "count" From 3ed393310387ae1f73005d711e6df002e217b647 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Tue, 28 Jul 2026 15:46:54 -0700 Subject: [PATCH 30/60] UDFExample also needs to close the client connection... --- examples/__init__.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/__init__.py b/examples/__init__.py index 2a3fa33b8a..0b167c7597 100644 --- a/examples/__init__.py +++ b/examples/__init__.py @@ -41,9 +41,6 @@ def __init__(self): } super().__init__(extra_config) - def __del__(self): - pass - class ExampleWithIndex(Example): INDEX_NAME = "index_name" def __init__(self): From 85a87eb8b2c5d0cfe2c74d77f9696e187a6c6cb3 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Tue, 28 Jul 2026 15:49:50 -0700 Subject: [PATCH 31/60] Add missing super() commands or class won't be cleaned up / set up properly... --- examples/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/__init__.py b/examples/__init__.py index 0b167c7597..796a9a6f50 100644 --- a/examples/__init__.py +++ b/examples/__init__.py @@ -44,11 +44,15 @@ def __init__(self): class ExampleWithIndex(Example): INDEX_NAME = "index_name" def __init__(self): + super().__init__() + self.client.index_single_value_create(self.namespace, self.set_name, self.BIN_NAME, aerospike.INDEX_INTEGER, self.INDEX_NAME) def __del__(self): self.client.index_remove(self.namespace, self.INDEX_NAME) + super().__del__() + class ExampleWithRecord(Example): def __init__(self): super().__init__() From b42cac9f2aa62ef27e950b2c8582fb6980b49c64 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 08:28:26 -0700 Subject: [PATCH 32/60] Also run string ops code examples (fixes regression). Makes sure example classes that don't directly inherit from Example base class are run. Addressed a few of those examples failing. --- examples/__init__.py | 5 +++-- examples/client/aggregate.py | 6 ++--- examples/client/apply.py | 12 +++++----- examples/client/batch_read.py | 9 +++----- examples/client/get_key_digest.py | 2 +- examples/client/query.py | 10 ++++++--- examples/run_all_examples.py | 37 ++++++++++++++++++------------- 7 files changed, 46 insertions(+), 35 deletions(-) diff --git a/examples/__init__.py b/examples/__init__.py index 796a9a6f50..162585420f 100644 --- a/examples/__init__.py +++ b/examples/__init__.py @@ -24,7 +24,8 @@ def __init__( self.client = client self.namespace = namespace self.set_name = set_name - self.key = (self.namespace, self.set_name, "docreadkey") + self.user_key = "docreadkey" + self.key = (self.namespace, self.set_name, self.user_key) self.non_existent_key = (self.namespace, self.set_name, "nonexistent") self.BIN_NAME = "a" @@ -39,7 +40,7 @@ def __init__(self): 'user_path': os.path.dirname(__file__) + "/client/" } } - super().__init__(extra_config) + super().__init__(extra_config=extra_config) class ExampleWithIndex(Example): INDEX_NAME = "index_name" diff --git a/examples/client/aggregate.py b/examples/client/aggregate.py index 7fc0f053ac..1a43a51988 100644 --- a/examples/client/aggregate.py +++ b/examples/client/aggregate.py @@ -25,15 +25,15 @@ class Aggregate(ExampleWithIndex, UDFExample): def run(self): predicates = [ - p.equals(self.BIN, 1), - p.between(self.BIN, 1, 3) + p.equals(self.BIN_NAME, 1), + p.between(self.BIN_NAME, 1, 3) ] for predicate in predicates: # If predicate is provided, then perform a query query = self.client.query(self.namespace, self.set_name) query.where(predicate) - BINS = [self.BIN] + BINS = [self.BIN_NAME] query.select(*BINS) MODULE = "stream_example" diff --git a/examples/client/apply.py b/examples/client/apply.py index 399f615937..ae7e1e65ed 100644 --- a/examples/client/apply.py +++ b/examples/client/apply.py @@ -16,14 +16,16 @@ ########################################################################## -from .. import ExampleWithRecord +from .. import ExampleWithRecord, UDFExample -class Apply(ExampleWithRecord): +class Apply(ExampleWithRecord, UDFExample): def run(self): - module = "module" - function = "a" - args = [] + self.client.udf_put("./examples/client/simple.lua") + + module = "simple" + function = "add" + args = [1, 2] res = self.client.apply(self.key, module, function, args) print(res) diff --git a/examples/client/batch_read.py b/examples/client/batch_read.py index 08a37aaa52..9f3df22826 100644 --- a/examples/client/batch_read.py +++ b/examples/client/batch_read.py @@ -20,16 +20,13 @@ class BatchRead(ExampleWithRecord): - def __init__(self): - pass - def run(self): # Get records keys = [self.key, self.non_existent_key] records = self.client.batch_read(keys) if records != None: - print(f"{len(records)} records were found") + print(f"{len(records.batch_records)} records were found") print(records) else: print('error: Not Found.') @@ -38,7 +35,7 @@ def run(self): records = self.client.batch_read(keys, bins=["a"]) if records != None: - print(f"{len(records)} records were found") + print(f"{len(records.batch_records)} records were found") print(records) else: print('error: Not Found.') @@ -47,7 +44,7 @@ def run(self): records = self.client.batch_read(keys, bins=[]) if records != None: - print(f"{len(records)} records were found") + print(f"{len(records.batch_records)} records were found") print(records) else: print('error: Not Found.') diff --git a/examples/client/get_key_digest.py b/examples/client/get_key_digest.py index 1d379f8af7..b307e1e70f 100644 --- a/examples/client/get_key_digest.py +++ b/examples/client/get_key_digest.py @@ -22,5 +22,5 @@ class CalcDigest(ExampleWithRecord): def run(self): - digest = aerospike.calc_digest(self.namespace, self.set_name, self.key) + digest = aerospike.calc_digest(self.namespace, self.set_name, self.user_key) print(digest) diff --git a/examples/client/query.py b/examples/client/query.py index dd4d8f2c48..e6cc6996dc 100644 --- a/examples/client/query.py +++ b/examples/client/query.py @@ -24,6 +24,8 @@ class Query(UDFExample): def run(self): + self.client.udf_put("./examples/client/stream_example.lua") + query = self.client.query(self.namespace, self.set_name) query.select(self.BIN_NAME) @@ -36,9 +38,11 @@ def run(self): # callback to be called for each record read def callback(input_tuple): - (key, meta, rec) = input_tuple - results.append((key, meta, rec)) - print(key, meta, rec) + print(input_tuple) + # (key, meta, rec) = input_tuple + # nonlocal results + # results.append((key, meta, rec)) + # print(key, meta, rec) # invoke the operations, and for each record invoke the callback query.foreach(callback) diff --git a/examples/run_all_examples.py b/examples/run_all_examples.py index c41b5ee328..0c5c726fce 100644 --- a/examples/run_all_examples.py +++ b/examples/run_all_examples.py @@ -3,26 +3,33 @@ import inspect import os import sys -# from . import Example example_classes: list[type] = [] dir_containing_this_module = os.path.dirname(os.path.abspath(__file__)) -all_packages = pkgutil.walk_packages([dir_containing_this_module + "/client"]) -for package in all_packages: - print(package) - module = importlib.import_module("." + package.name, ".examples.client") - for name, obj in inspect.getmembers(module, inspect.isclass): - if obj.__module__ != module.__name__: - continue - print("Class found:", obj) - # print(Example is obj.__bases__[0]) - # TODO - comparing the same class imported two different ways fails - # There might a better way to do this - if obj.__bases__[0].__name__ != "Example": - continue - example_classes.append(obj) + +for folder in ["client", "string_ops"]: + all_packages = pkgutil.walk_packages([ + dir_containing_this_module + "/" + folder, + ]) + for package in all_packages: + print(package) + module = importlib.import_module("." + package.name, ".examples." + folder) + for name, obj in inspect.getmembers(module, inspect.isclass): + if obj.__module__ != module.__name__: + continue + # print(Example is obj.__bases__[0]) + # TODO - comparing the same class imported two different ways fails + # There might a better way to do this + print("Found class has these base classes:", obj.__mro__) + if "Example" not in [obj.__name__ for obj in obj.__mro__]: + continue + if not hasattr(obj, "run") or not callable(getattr(obj, "run")): + continue + + print("Class found:", obj) + example_classes.append(obj) if len(sys.argv) == 2: example_classes = [cls for cls in example_classes if cls.__name__ == sys.argv[1]] From a74354268f09b042a732425d9c260fcd8d26dccf Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 08:39:33 -0700 Subject: [PATCH 33/60] Verified that all code examples that indirectly inherit from Example class now pass. --- examples/client/query.py | 8 ++------ examples/client/query_apply.py | 5 ++--- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/examples/client/query.py b/examples/client/query.py index e6cc6996dc..d90da053e5 100644 --- a/examples/client/query.py +++ b/examples/client/query.py @@ -37,12 +37,8 @@ def run(self): results = [] # callback to be called for each record read - def callback(input_tuple): - print(input_tuple) - # (key, meta, rec) = input_tuple - # nonlocal results - # results.append((key, meta, rec)) - # print(key, meta, rec) + def callback(result): + results.append(result) # invoke the operations, and for each record invoke the callback query.foreach(callback) diff --git a/examples/client/query_apply.py b/examples/client/query_apply.py index 4604d48b71..4d016b79b4 100644 --- a/examples/client/query_apply.py +++ b/examples/client/query_apply.py @@ -34,16 +34,15 @@ class QueryApply(ExampleWithIndex, UDFExample): def run(self): - BIN = "bin" predicates = [ - p.equals(BIN, 1), + p.equals(self.BIN_NAME, 1), # p.equals(BIN, "a"), # p.between(BIN, 1, 3) ] for predicate in predicates: # If predicate is provided, then perform a query - BINS = [BIN] + # BINS = [BIN] MODULE = "stream_example" FUNCTION = "count" From 01cc03555141c52df3bd65e028de65c8945319b1 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 08:46:54 -0700 Subject: [PATCH 34/60] Improve commenting. --- examples/run_all_examples.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/run_all_examples.py b/examples/run_all_examples.py index 0c5c726fce..815c441beb 100644 --- a/examples/run_all_examples.py +++ b/examples/run_all_examples.py @@ -19,13 +19,13 @@ for name, obj in inspect.getmembers(module, inspect.isclass): if obj.__module__ != module.__name__: continue - # print(Example is obj.__bases__[0]) # TODO - comparing the same class imported two different ways fails # There might a better way to do this print("Found class has these base classes:", obj.__mro__) if "Example" not in [obj.__name__ for obj in obj.__mro__]: continue if not hasattr(obj, "run") or not callable(getattr(obj, "run")): + # Some classes that inherit from Example base class are "abstract" classes continue print("Class found:", obj) From cadb5d925849b4fd5ac98fc280928eaaaa76f164 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 08:53:17 -0700 Subject: [PATCH 35/60] Prevent exception raised by __del__ due to record being deleted. Remove duplicate example. TODO - exceptions raised during __del__() don't cause run_all_examples to fail --- examples/client/remove.py | 29 ----------------------------- examples/client/remove_bin.py | 3 +++ 2 files changed, 3 insertions(+), 29 deletions(-) delete mode 100644 examples/client/remove.py diff --git a/examples/client/remove.py b/examples/client/remove.py deleted file mode 100644 index e6fee53c41..0000000000 --- a/examples/client/remove.py +++ /dev/null @@ -1,29 +0,0 @@ - -########################################################################## -# Copyright 2013-2026 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. -########################################################################## - -from .. import ExampleWithRecord -from aerospike import exception as e - - -class Remove(ExampleWithRecord): - def run(self): - self.client.remove(self.key) - - try: - self.client.remove(self.key) - except e.RecordNotFound: - print("Record already removed") diff --git a/examples/client/remove_bin.py b/examples/client/remove_bin.py index c4627eb980..8909e51654 100644 --- a/examples/client/remove_bin.py +++ b/examples/client/remove_bin.py @@ -27,3 +27,6 @@ def run(self): retval = self.client.remove_bin(self.key, bin_names) print("Status of bin removal is: %d" % (retval)) print("OK, bins removed from the record at", self.key) + + def __del__(self): + pass From 5ac4317639ebebbc8bc36a89f1612fe9293b8e04 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 09:04:18 -0700 Subject: [PATCH 36/60] Clean up batch read example output. --- examples/client/batch_read.py | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/examples/client/batch_read.py b/examples/client/batch_read.py index 9f3df22826..9fc46cb45e 100644 --- a/examples/client/batch_read.py +++ b/examples/client/batch_read.py @@ -16,35 +16,30 @@ ########################################################################## +from aerospike_helpers.batch.records import BatchRecords from .. import ExampleWithRecord class BatchRead(ExampleWithRecord): + def show_records(self, records: BatchRecords): + print(f"{len(records.batch_records)} records were found") + for br in records.batch_records: + pk = br.key + print("Record with digest", pk[3], "has result code", br.result, "with record", br.record) + def run(self): # Get records keys = [self.key, self.non_existent_key] + print("All bins should be returned") records = self.client.batch_read(keys) - - if records != None: - print(f"{len(records.batch_records)} records were found") - print(records) - else: - print('error: Not Found.') + self.show_records(records) # Select bins - records = self.client.batch_read(keys, bins=["a"]) - - if records != None: - print(f"{len(records.batch_records)} records were found") - print(records) - else: - print('error: Not Found.') + print("\"a\" should be filtered out") + records = self.client.batch_read(keys, bins=["b"]) + self.show_records(records) # Verify existence of records + print("Bins should not be returned") records = self.client.batch_read(keys, bins=[]) - - if records != None: - print(f"{len(records.batch_records)} records were found") - print(records) - else: - print('error: Not Found.') + self.show_records(records) From 60a8dadadd2674b8142cc79254b53f83e749bcd7 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 09:41:48 -0700 Subject: [PATCH 37/60] Final review pass --- examples/client/index_create.py | 5 +---- examples/client/index_remove.py | 3 +++ examples/client/query_apply.py | 10 ---------- examples/client/query_partition.py | 2 +- examples/client/scan.py | 3 +-- examples/client/ttl.py | 7 ------- examples/client/udf_put.py | 4 ++-- examples/client/udf_remove.py | 7 ++++++- examples/client/unicode_smiles.py | 11 +++++++---- 9 files changed, 21 insertions(+), 31 deletions(-) diff --git a/examples/client/index_create.py b/examples/client/index_create.py index 5ba98c7b2a..113a4d68d6 100644 --- a/examples/client/index_create.py +++ b/examples/client/index_create.py @@ -22,10 +22,7 @@ class IndexCreate(Example): def run(self): policy = {} - BIN_NAME = "a" - INDEX_DATATYPE = aerospike.INDEX_INTEGER - - self.client.index_single_value_create(self.namespace, self.set_name, BIN_NAME, INDEX_DATATYPE, "index_name", policy) + self.client.index_single_value_create(self.namespace, self.set_name, self.BIN_NAME, aerospike.INDEX_INTEGER, "index_name", policy) def __del__(self): self.client.index_remove(self.namespace, "index_name") diff --git a/examples/client/index_remove.py b/examples/client/index_remove.py index c487883a11..0cbeccb6f4 100644 --- a/examples/client/index_remove.py +++ b/examples/client/index_remove.py @@ -23,3 +23,6 @@ class IndexRemove(ExampleWithIndex): def run(self): policy = {} self.client.index_remove(self.namespace, self.INDEX_NAME, policy) + + def __del__(self): + super().__del__() diff --git a/examples/client/query_apply.py b/examples/client/query_apply.py index 4d016b79b4..9d89ba28c7 100644 --- a/examples/client/query_apply.py +++ b/examples/client/query_apply.py @@ -25,13 +25,6 @@ from .. import ExampleWithIndex, UDFExample -config = { - 'lua': { - 'user_path': os.path.dirname(__file__) - } -} - - class QueryApply(ExampleWithIndex, UDFExample): def run(self): predicates = [ @@ -41,9 +34,6 @@ def run(self): ] for predicate in predicates: - # If predicate is provided, then perform a query - # BINS = [BIN] - MODULE = "stream_example" FUNCTION = "count" ARGS = [] diff --git a/examples/client/query_partition.py b/examples/client/query_partition.py index 9e6c3c0763..57f81cb7bc 100644 --- a/examples/client/query_partition.py +++ b/examples/client/query_partition.py @@ -50,7 +50,7 @@ def callback(part_id, input_tuple): if rec_partition == STARTING_PARTITION: # and not client.exists(('test', 'demo', str(i))): - count = count + 1 + count += 1 rec = { 'i': i, 's': 'xyz', diff --git a/examples/client/scan.py b/examples/client/scan.py index 58969e56d8..349e9fd99a 100644 --- a/examples/client/scan.py +++ b/examples/client/scan.py @@ -22,8 +22,7 @@ class Scan(Example): def run(self): s = self.client.scan(self.namespace, self.set_name) - # TODO: configurable - bins = [] + bins = [self.BIN_NAME] # project specified bins s.select(*bins) diff --git a/examples/client/ttl.py b/examples/client/ttl.py index 2ed33782db..d6f603451f 100644 --- a/examples/client/ttl.py +++ b/examples/client/ttl.py @@ -69,11 +69,6 @@ def __del__(self): self.client.batch_remove(self.KEYS) super().__del__() - def print_histogram(self): - request = f"histogram:namespace={self.namespace};type=ttl" - response = self.client.info_random_node(request) - print("Server TTL histogram:", response) - def check_records(self, wait=0, message=None): if wait: time.sleep(wait) @@ -85,8 +80,6 @@ def check_records(self, wait=0, message=None): for br in brs.batch_records: print(f"Server returned error code {br.result} for record with ttl of {br.key[2]}") - self.print_histogram() - def write_records(self): for key in self.KEYS: diff --git a/examples/client/udf_put.py b/examples/client/udf_put.py index 2927eec107..9f3fa04c90 100644 --- a/examples/client/udf_put.py +++ b/examples/client/udf_put.py @@ -17,6 +17,7 @@ from .. import UDFExample +import aerospike class UDFPut(UDFExample): @@ -25,6 +26,5 @@ def run(self): # TODO # filename = args.pop() filename = "./examples/client/example.lua" - udf_type = 0 # 0 for LUA - self.client.udf_put(filename, udf_type, policy) + self.client.udf_put(filename, aerospike.UDF_TYPE_LUA, policy) diff --git a/examples/client/udf_remove.py b/examples/client/udf_remove.py index 434a935123..040a4a1511 100644 --- a/examples/client/udf_remove.py +++ b/examples/client/udf_remove.py @@ -17,9 +17,14 @@ from .. import Example +from aerospike import exception as e class UDFRemove(Example): def run(self): - # TODO: need negative path module = "example.lua" self.client.udf_remove(module) + + try: + self.client.udf_remove(module) + except e.UDFNotFound: + print("Already removed UDF.") diff --git a/examples/client/unicode_smiles.py b/examples/client/unicode_smiles.py index 9c7354fa77..da8a768bf9 100644 --- a/examples/client/unicode_smiles.py +++ b/examples/client/unicode_smiles.py @@ -19,6 +19,7 @@ from .. import Example import aerospike +from aerospike_helpers.operations import operations config = { 'policies': { @@ -30,7 +31,7 @@ class UnicodeSmiles(Example): def run(self): - smile = u"smilé" + smile = "smilé" # TODO: configurable read_timeout = 1000 @@ -77,9 +78,11 @@ def run(self): bins['mood'], "\n") # multiple operations on the record using the operate() method - ops = [{'bin': 'smiley', 'op': aerospike.OPERATOR_APPEND, 'val': smile}, - {'bin': 'smile_count', 'op': aerospike.OPERATOR_INCR, 'val': 5}, - {'bin': 'smiley', 'op': aerospike.OPERATOR_READ}] + ops = [ + operations.append(bin_name="smiley", append_item=smile), + operations.increment(bin_name="smile_count", amount=5), + operations.read(bin_name="smiley"), + ] print("Setting the following multiops on the same record\n", ops) (key, meta, bins) = self.client.operate(key, ops) print("The value of the 'smiley' bin is", bins['smiley'], "\n") From 13313272dcc1c5532055e66858c506f62faf2482 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 09:47:32 -0700 Subject: [PATCH 38/60] update instructions on how to run examples. --- README.rst | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index a8a0f89398..837feb18da 100644 --- a/README.rst +++ b/README.rst @@ -94,12 +94,15 @@ Examples Example applications are provided in the `examples directory of the GitHub repository `__ -For examples, to run the ``kvs.py``: +For examples, to run all code examples: :: - python examples/client/kvs.py + python3 -m examples.run_all_examples +To run a specific code example from ``examples/client/kvs.py``: + + python3 -m examples.run_all_examples KVS Benchmarks ---------- From 12847648a8ce9d8eb0ba0676c5e221d33d395ead Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 09:54:59 -0700 Subject: [PATCH 39/60] Replace __del__ with cleanup method and call it explicitly in run_all_examples to prevent exceptions being suppressed during cleanup. --- examples/__init__.py | 10 +++++----- examples/client/delete.py | 2 +- examples/client/index_create.py | 2 +- examples/client/index_remove.py | 4 ++-- examples/client/remove_bin.py | 2 +- examples/client/ttl.py | 4 ++-- examples/run_all_examples.py | 4 +++- examples/string_ops/customer_experience/__init__.py | 4 ++-- 8 files changed, 17 insertions(+), 15 deletions(-) diff --git a/examples/__init__.py b/examples/__init__.py index 162585420f..ef28036059 100644 --- a/examples/__init__.py +++ b/examples/__init__.py @@ -29,7 +29,7 @@ def __init__( self.non_existent_key = (self.namespace, self.set_name, "nonexistent") self.BIN_NAME = "a" - def __del__(self): + def cleanup(self): self.client.close() @@ -49,10 +49,10 @@ def __init__(self): self.client.index_single_value_create(self.namespace, self.set_name, self.BIN_NAME, aerospike.INDEX_INTEGER, self.INDEX_NAME) - def __del__(self): + def cleanup(self): self.client.index_remove(self.namespace, self.INDEX_NAME) - super().__del__() + super().cleanup() class ExampleWithRecord(Example): def __init__(self): @@ -60,7 +60,7 @@ def __init__(self): self.client.put(self.key, bins={self.BIN_NAME: 1}) - def __del__(self): + def cleanup(self): self.client.remove(self.key) - super().__del__() + super().cleanup() diff --git a/examples/client/delete.py b/examples/client/delete.py index d3eea5fbc2..c59411d5cb 100644 --- a/examples/client/delete.py +++ b/examples/client/delete.py @@ -29,5 +29,5 @@ def run(self): print(f"Could not find {self.key}") # Override default destructor - def __del__(self): + def cleanup(self): pass diff --git a/examples/client/index_create.py b/examples/client/index_create.py index 113a4d68d6..c15ab61124 100644 --- a/examples/client/index_create.py +++ b/examples/client/index_create.py @@ -24,5 +24,5 @@ def run(self): policy = {} self.client.index_single_value_create(self.namespace, self.set_name, self.BIN_NAME, aerospike.INDEX_INTEGER, "index_name", policy) - def __del__(self): + def cleanup(self): self.client.index_remove(self.namespace, "index_name") diff --git a/examples/client/index_remove.py b/examples/client/index_remove.py index 0cbeccb6f4..0808045dd6 100644 --- a/examples/client/index_remove.py +++ b/examples/client/index_remove.py @@ -24,5 +24,5 @@ def run(self): policy = {} self.client.index_remove(self.namespace, self.INDEX_NAME, policy) - def __del__(self): - super().__del__() + def cleanup(self): + super().cleanup() diff --git a/examples/client/remove_bin.py b/examples/client/remove_bin.py index 8909e51654..d16327313b 100644 --- a/examples/client/remove_bin.py +++ b/examples/client/remove_bin.py @@ -28,5 +28,5 @@ def run(self): print("Status of bin removal is: %d" % (retval)) print("OK, bins removed from the record at", self.key) - def __del__(self): + def cleanup(self): pass diff --git a/examples/client/ttl.py b/examples/client/ttl.py index d6f603451f..81ad9ae2c6 100644 --- a/examples/client/ttl.py +++ b/examples/client/ttl.py @@ -65,9 +65,9 @@ def run(self): self.check_records(3, 'Expect all records with TTL<=10 to be gone') self.check_records(6, 'Expect all records to be gone, except NO_EXPIRE') - def __del__(self): + def cleanup(self): self.client.batch_remove(self.KEYS) - super().__del__() + super().cleanup() def check_records(self, wait=0, message=None): if wait: diff --git a/examples/run_all_examples.py b/examples/run_all_examples.py index 815c441beb..3e20ff8924 100644 --- a/examples/run_all_examples.py +++ b/examples/run_all_examples.py @@ -37,4 +37,6 @@ print("Running examples...") for cls in example_classes: print(cls) - example = cls().run() + example = cls() + example.run() + example.cleanup() diff --git a/examples/string_ops/customer_experience/__init__.py b/examples/string_ops/customer_experience/__init__.py index 64cb347632..0f2eae339a 100644 --- a/examples/string_ops/customer_experience/__init__.py +++ b/examples/string_ops/customer_experience/__init__.py @@ -10,6 +10,6 @@ def __init__(self): self.client.put(self.key, bins={"email": ORIG_EMAIL}) - def __del__(self): + def cleanup(self): self.client.remove(self.key) - super().__del__() + super().cleanup() From 9ebbb490281ebf582b3be6b3e5bf78e9c0694398 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 09:58:44 -0700 Subject: [PATCH 40/60] Make gha step easier to read --- .github/workflows/smoke-tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/smoke-tests.yml b/.github/workflows/smoke-tests.yml index 17261b31e4..364449951b 100644 --- a/.github/workflows/smoke-tests.yml +++ b/.github/workflows/smoke-tests.yml @@ -271,7 +271,8 @@ jobs: server-container-repo: database-docker-virtual/aerospike-server config-file: ./.github/workflows/aerospike-ce.conf - - if: ${{ matrix.test == 'code-examples' }} + - name: Run canonical code examples + if: ${{ matrix.test == 'code-examples' }} # We cannot run this module with the cwd being string_ops # Otherwise we will get relative import errors # https://stackoverflow.com/a/47030746 From 64b81ed52fdb55c3e309891f880fe11b265a14be Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 10:01:01 -0700 Subject: [PATCH 41/60] Clear up why we set additional config settings after running the server. --- .github/workflows/smoke-tests.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/smoke-tests.yml b/.github/workflows/smoke-tests.yml index 364449951b..e6bcf0e74f 100644 --- a/.github/workflows/smoke-tests.yml +++ b/.github/workflows/smoke-tests.yml @@ -273,12 +273,11 @@ jobs: - name: Run canonical code examples if: ${{ matrix.test == 'code-examples' }} - # We cannot run this module with the cwd being string_ops - # Otherwise we will get relative import errors - # https://stackoverflow.com/a/47030746 run: | + # This is required for the TTL code example docker run --rm --network host aerospike/aerospike-tools asinfo -v "set-config:context=namespace;id=test;nsup-period=1" docker run --rm --network host aerospike/aerospike-tools asinfo -v "set-config:context=namespace;namespace=test;default-ttl=10S" + python3 -m examples.run_all_examples - name: Install test dependencies From 88a69ffcb4dd30da316ed6e3fba102ce62d61d0d Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 10:34:43 -0700 Subject: [PATCH 42/60] Move admin examples to examples/client for consistency. WIP on converting admin examples to use harness system. --- examples/__init__.py | 15 +++ examples/admin/change_password.py | 127 ------------------ examples/admin/create_role.py | 119 ---------------- examples/admin/create_user.py | 121 ----------------- examples/admin/drop_role.py | 118 ---------------- examples/admin/drop_user.py | 118 ---------------- examples/admin/grant_privileges.py | 120 ----------------- examples/client/admin/__init__.py | 0 examples/client/admin/change_password.py | 30 +++++ examples/client/admin/create_role.py | 32 +++++ examples/client/admin/create_user.py | 31 +++++ examples/client/admin/drop_role.py | 28 ++++ examples/client/admin/drop_user.py | 29 ++++ examples/client/admin/grant_privileges.py | 28 ++++ examples/{ => client}/admin/grant_roles.py | 0 examples/{ => client}/admin/query_role.py | 0 examples/{ => client}/admin/query_roles.py | 0 examples/{ => client}/admin/query_user.py | 0 .../{ => client}/admin/query_user_info.py | 0 examples/{ => client}/admin/query_users.py | 0 .../{ => client}/admin/query_users_info.py | 0 .../{ => client}/admin/revoke_privileges.py | 0 examples/{ => client}/admin/revoke_roles.py | 0 examples/{ => client}/admin/set_password.py | 0 examples/client/unicode_smiles.py | 7 - 25 files changed, 193 insertions(+), 730 deletions(-) delete mode 100644 examples/admin/change_password.py delete mode 100644 examples/admin/create_role.py delete mode 100644 examples/admin/create_user.py delete mode 100644 examples/admin/drop_role.py delete mode 100644 examples/admin/drop_user.py delete mode 100644 examples/admin/grant_privileges.py create mode 100644 examples/client/admin/__init__.py create mode 100644 examples/client/admin/change_password.py create mode 100644 examples/client/admin/create_role.py create mode 100644 examples/client/admin/create_user.py create mode 100644 examples/client/admin/drop_role.py create mode 100644 examples/client/admin/drop_user.py create mode 100644 examples/client/admin/grant_privileges.py rename examples/{ => client}/admin/grant_roles.py (100%) rename examples/{ => client}/admin/query_role.py (100%) rename examples/{ => client}/admin/query_roles.py (100%) rename examples/{ => client}/admin/query_user.py (100%) rename examples/{ => client}/admin/query_user_info.py (100%) rename examples/{ => client}/admin/query_users.py (100%) rename examples/{ => client}/admin/query_users_info.py (100%) rename examples/{ => client}/admin/revoke_privileges.py (100%) rename examples/{ => client}/admin/revoke_roles.py (100%) rename examples/{ => client}/admin/set_password.py (100%) diff --git a/examples/__init__.py b/examples/__init__.py index ef28036059..c729d44c04 100644 --- a/examples/__init__.py +++ b/examples/__init__.py @@ -32,6 +32,21 @@ def __init__( def cleanup(self): self.client.close() +class AdminExample(Example): + def __init__(self): + # TODO: admin user doesn't have enough permissions + super().__init__(user="admin", password="admin") + +class ExampleWithUser(AdminExample): + def __init__(self): + super().__init__() + self.user = "foo-example" + self.password = "foobar" + self.client.admin_create_user(self.user, self.password, roles=[]) + + def cleanup(self): + self.client.admin_drop_user(self.user) + super().cleanup() class UDFExample(Example): def __init__(self): diff --git a/examples/admin/change_password.py b/examples/admin/change_password.py deleted file mode 100644 index d5cc6a33a7..0000000000 --- a/examples/admin/change_password.py +++ /dev/null @@ -1,127 +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. -################################################################################ - -from __future__ import print_function - -import aerospike -import sys -from aerospike.exception import * - -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( - "-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( - "-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.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if options.username == None or options.password == None: - 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: - - policy = {} - user = "foo-example" - password = "foobar" - try: - client_new = aerospike.client(config).connect(user, "bar") - except ClientError: - print("User might not be created or node may be down. In case of non-existent user run create_user.py first") - client.close() - sys.exit() - status = client_new.admin_change_password(user, password) - client_new.close() - - print("Status of changing password is: %d" % status) - print("OK, password changed for 1 user") - - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - exitCode = 2 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- - - client.close() - -except Exception, eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 3 - -################################################################################ -# Exit -################################################################################ - -sys.exit(exitCode) diff --git a/examples/admin/create_role.py b/examples/admin/create_role.py deleted file mode 100644 index 26c0ac3c78..0000000000 --- a/examples/admin/create_role.py +++ /dev/null @@ -1,119 +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. -################################################################################ - -from __future__ import print_function - -import aerospike -import sys - -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( - "-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( - "-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.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if options.username == None or options.password == None: - 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: - - policy = {} - role = "example_foo" - privileges = [{"code": aerospike.PRIV_READ}, {"code": aerospike.PRIV_USER_ADMIN}] - - client.admin_create_role(role, privileges, policy) - - print("OK, 1 new role created") - - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - exitCode = 2 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- - - client.close() - -except Exception, eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 3 - -################################################################################ -# Exit -################################################################################ - -sys.exit(exitCode) diff --git a/examples/admin/create_user.py b/examples/admin/create_user.py deleted file mode 100644 index 00006500f3..0000000000 --- a/examples/admin/create_user.py +++ /dev/null @@ -1,121 +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. -################################################################################ - -from __future__ import print_function - -import aerospike -import sys - -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( - "-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( - "-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.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if options.username == None or options.password == None: - 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: - - policy = {} - user = "foo-example" - password = "bar" - roles = ["read-write", "read"] - roles_size = len(roles) - - client.admin_create_user(user, password, roles, policy) - - print("OK, 1 new user created") - - 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/admin/drop_role.py b/examples/admin/drop_role.py deleted file mode 100644 index 60a1bf95a1..0000000000 --- a/examples/admin/drop_role.py +++ /dev/null @@ -1,118 +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. -################################################################################ - -from __future__ import print_function - -import aerospike -import sys - -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( - "-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( - "-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.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if options.username == None or options.password == None: - 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: - - policy = {} - role = "example_foo" - - client.admin_drop_role(role, policy) - - print("OK, 1 role dropped") - - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - exitCode = 2 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- - - client.close() - -except Exception, eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 3 - -################################################################################ -# Exit -################################################################################ - -sys.exit(exitCode) diff --git a/examples/admin/drop_user.py b/examples/admin/drop_user.py deleted file mode 100644 index cba66d61e2..0000000000 --- a/examples/admin/drop_user.py +++ /dev/null @@ -1,118 +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. -################################################################################ - -from __future__ import print_function - -import aerospike -import sys - -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( - "-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( - "-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.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if options.username == None or options.password == None: - 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: - - policy = {} - user = "foo-example" - - client.admin_drop_user(user, policy) - - print("OK, 1 user dropped") - - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - exitCode = 2 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- - - client.close() - -except Exception, eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 3 - -################################################################################ -# Exit -################################################################################ - -sys.exit(exitCode) diff --git a/examples/admin/grant_privileges.py b/examples/admin/grant_privileges.py deleted file mode 100644 index fbde412653..0000000000 --- a/examples/admin/grant_privileges.py +++ /dev/null @@ -1,120 +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. -################################################################################ - -from __future__ import print_function - -import aerospike -import sys - -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( - "-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( - "-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.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if options.username == None or options.password == None: - 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: - - policy = {} - role = "example_foo" - privileges = [{"code": aerospike.PRIV_SYS_ADMIN}] - - client.admin_grant_privileges(role, privileges) - - print("OK, new privileges granted to 1 role") - - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - print("In case of invalid role first create role by running create_role.py") - exitCode = 2 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- - - client.close() - -except Exception, eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 3 - -################################################################################ -# Exit -################################################################################ - -sys.exit(exitCode) diff --git a/examples/client/admin/__init__.py b/examples/client/admin/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/examples/client/admin/change_password.py b/examples/client/admin/change_password.py new file mode 100644 index 0000000000..01028a2ef9 --- /dev/null +++ b/examples/client/admin/change_password.py @@ -0,0 +1,30 @@ +# -*- 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. +################################################################################ + +from __future__ import print_function + +from ... import ExampleWithUser +import aerospike +import sys +from aerospike.exception import * + + +class ChangePassword(ExampleWithUser): + def run(self): + status = self.client.admin_change_password(self.user, self.password) + print("Status of changing password is: %d" % status) + print("OK, password changed for 1 user") diff --git a/examples/client/admin/create_role.py b/examples/client/admin/create_role.py new file mode 100644 index 0000000000..129dd0b42d --- /dev/null +++ b/examples/client/admin/create_role.py @@ -0,0 +1,32 @@ +# -*- 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. +################################################################################ + +from __future__ import print_function + +import aerospike +from ... import AdminExample + + +class CreateRole(AdminExample): + def run(self): + policy = {} + self.role = "example_foo" + privileges = [{"code": aerospike.PRIV_READ}, {"code": aerospike.PRIV_USER_ADMIN}] + + self.client.admin_create_role(self.role, privileges, policy) + + print("OK, 1 new role created") diff --git a/examples/client/admin/create_user.py b/examples/client/admin/create_user.py new file mode 100644 index 0000000000..ac1a4dbb32 --- /dev/null +++ b/examples/client/admin/create_user.py @@ -0,0 +1,31 @@ +# -*- 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. +################################################################################ + +from __future__ import print_function + +from ... import AdminExample + +class CreateUser(AdminExample): + def run(self): + policy = {} + self.user = "foo-example" + password = "foobar" + roles = ["read-write", "read"] + + self.client.admin_create_user(self.user, password, roles, policy) + + print("OK, 1 new user created") diff --git a/examples/client/admin/drop_role.py b/examples/client/admin/drop_role.py new file mode 100644 index 0000000000..1e0d2619ce --- /dev/null +++ b/examples/client/admin/drop_role.py @@ -0,0 +1,28 @@ +# -*- 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. +################################################################################ + +from __future__ import print_function + +from .create_role import CreateRole + +class DropRole(CreateRole): + def run(self): + super().run() + policy = {} + + self.client.admin_drop_role(self.role, policy) + print("OK, 1 role dropped") diff --git a/examples/client/admin/drop_user.py b/examples/client/admin/drop_user.py new file mode 100644 index 0000000000..cbdbabcf43 --- /dev/null +++ b/examples/client/admin/drop_user.py @@ -0,0 +1,29 @@ +# -*- 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. +################################################################################ + +from __future__ import print_function + +from .create_user import CreateUser + +class DropUser(CreateUser): + def run(self): + super().run() + policy = {} + + self.client.admin_drop_user(self.user, policy) + + print("OK, 1 user dropped") diff --git a/examples/client/admin/grant_privileges.py b/examples/client/admin/grant_privileges.py new file mode 100644 index 0000000000..1386c481b5 --- /dev/null +++ b/examples/client/admin/grant_privileges.py @@ -0,0 +1,28 @@ +# -*- 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. +################################################################################ + +from .create_role import CreateRole +import aerospike + + +class GrantPrivileges(CreateRole): + def run(self): + privileges = [{"code": aerospike.PRIV_SYS_ADMIN}] + + self.client.admin_grant_privileges(self.role, privileges) + + print("OK, new privileges granted to 1 role") diff --git a/examples/admin/grant_roles.py b/examples/client/admin/grant_roles.py similarity index 100% rename from examples/admin/grant_roles.py rename to examples/client/admin/grant_roles.py diff --git a/examples/admin/query_role.py b/examples/client/admin/query_role.py similarity index 100% rename from examples/admin/query_role.py rename to examples/client/admin/query_role.py diff --git a/examples/admin/query_roles.py b/examples/client/admin/query_roles.py similarity index 100% rename from examples/admin/query_roles.py rename to examples/client/admin/query_roles.py diff --git a/examples/admin/query_user.py b/examples/client/admin/query_user.py similarity index 100% rename from examples/admin/query_user.py rename to examples/client/admin/query_user.py diff --git a/examples/admin/query_user_info.py b/examples/client/admin/query_user_info.py similarity index 100% rename from examples/admin/query_user_info.py rename to examples/client/admin/query_user_info.py diff --git a/examples/admin/query_users.py b/examples/client/admin/query_users.py similarity index 100% rename from examples/admin/query_users.py rename to examples/client/admin/query_users.py diff --git a/examples/admin/query_users_info.py b/examples/client/admin/query_users_info.py similarity index 100% rename from examples/admin/query_users_info.py rename to examples/client/admin/query_users_info.py diff --git a/examples/admin/revoke_privileges.py b/examples/client/admin/revoke_privileges.py similarity index 100% rename from examples/admin/revoke_privileges.py rename to examples/client/admin/revoke_privileges.py diff --git a/examples/admin/revoke_roles.py b/examples/client/admin/revoke_roles.py similarity index 100% rename from examples/admin/revoke_roles.py rename to examples/client/admin/revoke_roles.py diff --git a/examples/admin/set_password.py b/examples/client/admin/set_password.py similarity index 100% rename from examples/admin/set_password.py rename to examples/client/admin/set_password.py diff --git a/examples/client/unicode_smiles.py b/examples/client/unicode_smiles.py index da8a768bf9..6d4d933328 100644 --- a/examples/client/unicode_smiles.py +++ b/examples/client/unicode_smiles.py @@ -21,13 +21,6 @@ import aerospike from aerospike_helpers.operations import operations -config = { - 'policies': { - # TODO: configurable - 'total_timeout': 1000 - } -} - class UnicodeSmiles(Example): def run(self): From 0b12ab38799d7415eb226f2e49c01258ea181ab4 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 11:35:35 -0700 Subject: [PATCH 43/60] Finish cleaning up admin examples. --- examples/client/admin/change_password.py | 17 ++- examples/client/admin/create_role.py | 3 + examples/client/admin/create_user.py | 4 + examples/client/admin/drop_user.py | 5 +- examples/client/admin/grant_privileges.py | 1 + examples/client/admin/grant_roles.py | 108 +----------------- examples/client/admin/query_role.py | 106 +----------------- examples/client/admin/query_roles.py | 100 +---------------- examples/client/admin/query_user.py | 121 --------------------- examples/client/admin/query_user_info.py | 104 +----------------- examples/client/admin/query_users.py | 120 -------------------- examples/client/admin/query_users_info.py | 103 +----------------- examples/client/admin/revoke_privileges.py | 102 +---------------- examples/client/admin/revoke_roles.py | 105 +----------------- examples/client/admin/set_password.py | 103 +----------------- 15 files changed, 61 insertions(+), 1041 deletions(-) delete mode 100644 examples/client/admin/query_user.py delete mode 100644 examples/client/admin/query_users.py diff --git a/examples/client/admin/change_password.py b/examples/client/admin/change_password.py index 01028a2ef9..f3ba01f68d 100644 --- a/examples/client/admin/change_password.py +++ b/examples/client/admin/change_password.py @@ -17,14 +17,19 @@ from __future__ import print_function -from ... import ExampleWithUser + +from .create_user import CreateUser import aerospike -import sys -from aerospike.exception import * -class ChangePassword(ExampleWithUser): +class ChangePassword(CreateUser): def run(self): - status = self.client.admin_change_password(self.user, self.password) + super().run() + + config2 = self.config.copy() + config2["user"] = self.user + config2["password"] = self.password + client2 = aerospike.client(config2) + + status = client2.admin_change_password(self.user, self.password) print("Status of changing password is: %d" % status) - print("OK, password changed for 1 user") diff --git a/examples/client/admin/create_role.py b/examples/client/admin/create_role.py index 129dd0b42d..e33976f78a 100644 --- a/examples/client/admin/create_role.py +++ b/examples/client/admin/create_role.py @@ -30,3 +30,6 @@ def run(self): self.client.admin_create_role(self.role, privileges, policy) print("OK, 1 new role created") + + def cleanup(self): + self.client.admin_drop_role(self.role) diff --git a/examples/client/admin/create_user.py b/examples/client/admin/create_user.py index ac1a4dbb32..e198386ab5 100644 --- a/examples/client/admin/create_user.py +++ b/examples/client/admin/create_user.py @@ -29,3 +29,7 @@ def run(self): self.client.admin_create_user(self.user, password, roles, policy) print("OK, 1 new user created") + + def cleanup(self): + self.client.admin_drop_user(self.user) + super().cleanup() diff --git a/examples/client/admin/drop_user.py b/examples/client/admin/drop_user.py index cbdbabcf43..37d7f5aae2 100644 --- a/examples/client/admin/drop_user.py +++ b/examples/client/admin/drop_user.py @@ -17,7 +17,7 @@ from __future__ import print_function -from .create_user import CreateUser +from .create_user import CreateUser, AdminExample class DropUser(CreateUser): def run(self): @@ -27,3 +27,6 @@ def run(self): self.client.admin_drop_user(self.user, policy) print("OK, 1 user dropped") + + def cleanup(self): + AdminExample.cleanup(self) diff --git a/examples/client/admin/grant_privileges.py b/examples/client/admin/grant_privileges.py index 1386c481b5..84afa54dc3 100644 --- a/examples/client/admin/grant_privileges.py +++ b/examples/client/admin/grant_privileges.py @@ -21,6 +21,7 @@ class GrantPrivileges(CreateRole): def run(self): + super().run() privileges = [{"code": aerospike.PRIV_SYS_ADMIN}] self.client.admin_grant_privileges(self.role, privileges) diff --git a/examples/client/admin/grant_roles.py b/examples/client/admin/grant_roles.py index 2eee99558f..dfe6360283 100644 --- a/examples/client/admin/grant_roles.py +++ b/examples/client/admin/grant_roles.py @@ -15,107 +15,11 @@ # limitations under the License. ################################################################################ -from __future__ import print_function +from .create_user import CreateUser -import aerospike -import sys -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( - "-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( - "-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.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if options.username == None or options.password == None: - 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: - - policy = {} - user = "foo-example" - roles = ["read-write", "user-admin"] - roles_size = len(roles) - - client.admin_grant_roles(user, roles) - - print("OK, new roles granted to 1 user") - - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - print("In case of invalid user first create user by running create_user.py") - exitCode = 2 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- - - client.close() - -except Exception, eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 3 - -################################################################################ -# Exit -################################################################################ - -sys.exit(exitCode) +class GrantRoles(CreateUser): + def run(self): + super().run() + self.roles = ["read-write", "user-admin"] + self.client.admin_grant_roles(self.user, roles) diff --git a/examples/client/admin/query_role.py b/examples/client/admin/query_role.py index 7f0de7185f..3cf2bec72c 100644 --- a/examples/client/admin/query_role.py +++ b/examples/client/admin/query_role.py @@ -14,108 +14,12 @@ # See the License for the specific language governing permissions and # limitations under the License. ################################################################################ +from .create_role import CreateRole -from __future__ import print_function - -import aerospike -import sys - -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( - "-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( - "-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.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if options.username == None or options.password == None: - 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: +class QueryRole(CreateRole): + def run(self): + super().run() policy = {} - role = "example_foo" - - privileges = client.admin_query_role(role, policy) - + privileges = self.client.admin_query_role(self.role, policy) print(privileges) - print("---") - print("OK, Privileges retrieved for one role") - - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - print("In case of invalid role, first create role using create_role.py") - 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/admin/query_roles.py b/examples/client/admin/query_roles.py index e524be6f71..c1037c43a4 100644 --- a/examples/client/admin/query_roles.py +++ b/examples/client/admin/query_roles.py @@ -15,104 +15,12 @@ # limitations under the License. ################################################################################ -from __future__ import print_function +from ... import AdminExample -import aerospike -import sys - -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( - "-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( - "-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.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if options.username == None or options.password == None: - 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: +class QueryRoles(AdminExample): + def run(self): policy = {} - roles = client.admin_query_roles(policy) + roles = self.client.admin_query_roles(policy) print(roles) - print("---") - print("OK, All roles retrieved") - - 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/admin/query_user.py b/examples/client/admin/query_user.py deleted file mode 100644 index 0534792948..0000000000 --- a/examples/client/admin/query_user.py +++ /dev/null @@ -1,121 +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. -################################################################################ - -from __future__ import print_function - -import aerospike -import sys - -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( - "-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( - "-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.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if options.username == None or options.password == None: - 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: - - policy = {} - - roles = client.admin_query_user(options.username, policy) - - print(roles) - print("---") - print("OK, Roles retrieved for 1 user") - - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - print("In case of invalid user first create user by running create_user.py") - 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/admin/query_user_info.py b/examples/client/admin/query_user_info.py index 331772e07b..ddba618376 100644 --- a/examples/client/admin/query_user_info.py +++ b/examples/client/admin/query_user_info.py @@ -15,107 +15,13 @@ # limitations under the License. ################################################################################ -from __future__ import print_function +from .create_user import CreateUser -import aerospike -import sys - -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( - "-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( - "-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.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if options.username == None or options.password == None: - 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: +class QueryUserInfo(CreateUser): + def run(self): + super().run() policy = {} - roles = client.admin_query_user_info(options.username, policy) - + roles = self.client.admin_query_user_info(self.user, policy) print(roles) - print("---") - print("OK, Roles retrieved for 1 user") - - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - print("In case of invalid user first create user by running create_user.py") - 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/admin/query_users.py b/examples/client/admin/query_users.py deleted file mode 100644 index eba5104f2f..0000000000 --- a/examples/client/admin/query_users.py +++ /dev/null @@ -1,120 +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. -################################################################################ - -from __future__ import print_function - -import aerospike -import sys - -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( - "-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( - "-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.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if options.username == None or options.password == None: - 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: - - policy = {} - - user_roles = client.admin_query_users(policy) - - print(user_roles) - print("---") - print("OK, All users retrieved") - - 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/admin/query_users_info.py b/examples/client/admin/query_users_info.py index bd5fff2308..738b184283 100644 --- a/examples/client/admin/query_users_info.py +++ b/examples/client/admin/query_users_info.py @@ -15,106 +15,13 @@ # limitations under the License. ################################################################################ -from __future__ import print_function +from .create_user import CreateUser -import aerospike -import sys - -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( - "-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( - "-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.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if options.username == None or options.password == None: - 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: +class QueryUsersInfo(CreateUser): + def run(self): + super().run() policy = {} - user_roles = client.admin_query_users_info(policy) - + user_roles = self.client.admin_query_users_info(policy) print(user_roles) - print("---") - print("OK, All users retrieved") - - 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/admin/revoke_privileges.py b/examples/client/admin/revoke_privileges.py index 2434af064e..4f88dc8fdb 100644 --- a/examples/client/admin/revoke_privileges.py +++ b/examples/client/admin/revoke_privileges.py @@ -14,107 +14,13 @@ # See the License for the specific language governing permissions and # limitations under the License. ################################################################################ - -from __future__ import print_function - +from .create_role import CreateRole import aerospike -import sys - -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( - "-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( - "-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.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if options.username == None or options.password == None: - 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: +class RevokePrivileges(CreateRole): + def run(self): policy = {} - role = "example_foo" privileges = [{"code": aerospike.PRIV_SYS_ADMIN}] - client.admin_revoke_privileges(role, privileges, policy) - - print("OK, privileges revoked from 1 role") - - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - print("In case of invalid role first create roles using create_role.py") - exitCode = 2 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- - - client.close() - -except Exception, eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 3 - -################################################################################ -# Exit -################################################################################ - -sys.exit(exitCode) + self.client.admin_revoke_privileges(self.role, privileges, policy) diff --git a/examples/client/admin/revoke_roles.py b/examples/client/admin/revoke_roles.py index f43b4300ce..b17d447a35 100644 --- a/examples/client/admin/revoke_roles.py +++ b/examples/client/admin/revoke_roles.py @@ -15,107 +15,10 @@ # limitations under the License. ################################################################################ -from __future__ import print_function +from .grant_roles import GrantRoles -import aerospike -import sys - -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( - "-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( - "-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.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if options.username == None or options.password == None: - 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: +class RevokeRoles(GrantRoles): + def run(self): policy = {} - user = "foo-example" - roles = ["user-admin", "read"] - roles_size = len(roles) - - client.admin_revoke_roles(user, roles, policy) - - print("OK, roles revoked from 1 user") - - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - print("In case of invalid user first create user using create_user.py") - exitCode = 2 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- - - client.close() - -except Exception, eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 3 - -################################################################################ -# Exit -################################################################################ - -sys.exit(exitCode) + self.client.admin_revoke_roles(self.user, self.roles, policy) diff --git a/examples/client/admin/set_password.py b/examples/client/admin/set_password.py index 4003ec1106..571b06c8d3 100644 --- a/examples/client/admin/set_password.py +++ b/examples/client/admin/set_password.py @@ -17,104 +17,11 @@ from __future__ import print_function -import aerospike -import sys - -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( - "-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( - "-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.") - -(options, args) = optparser.parse_args() - -if options.help: - optparser.print_help() - print() - sys.exit(1) - -if options.username == None or options.password == None: - 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: +from .create_user import CreateUser +class SetPassword(CreateUser): + def run(self): policy = {} - user = "foo-example" - password = "bar" - - client.admin_set_password(user, password, policy) - - print("OK, password set for 1 user") - - except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - print("In case of invalid user first create user using create_user.py") - exitCode = 2 - - # ---------------------------------------------------------------------------- - # Close Connection to Cluster - # ---------------------------------------------------------------------------- - - client.close() - -except Exception, eargs: - print("error: {0}".format(eargs), file=sys.stderr) - exitCode = 3 - -################################################################################ -# Exit -################################################################################ + password = "bar" -sys.exit(exitCode) + self.client.admin_set_password(self.user, password, policy) From 472e6a1cf99c90b70512807a6111a5c4efcfe7e8 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 11:38:00 -0700 Subject: [PATCH 44/60] Move AdminExample base class to client/admin subfolder since that's the only place that uses it. --- examples/__init__.py | 16 ---------------- examples/client/admin/__init__.py | 7 +++++++ examples/client/admin/create_role.py | 2 +- examples/client/admin/create_user.py | 2 +- examples/client/admin/query_roles.py | 2 +- 5 files changed, 10 insertions(+), 19 deletions(-) diff --git a/examples/__init__.py b/examples/__init__.py index c729d44c04..250d0c9cd1 100644 --- a/examples/__init__.py +++ b/examples/__init__.py @@ -32,22 +32,6 @@ def __init__( def cleanup(self): self.client.close() -class AdminExample(Example): - def __init__(self): - # TODO: admin user doesn't have enough permissions - super().__init__(user="admin", password="admin") - -class ExampleWithUser(AdminExample): - def __init__(self): - super().__init__() - self.user = "foo-example" - self.password = "foobar" - self.client.admin_create_user(self.user, self.password, roles=[]) - - def cleanup(self): - self.client.admin_drop_user(self.user) - super().cleanup() - class UDFExample(Example): def __init__(self): extra_config = { diff --git a/examples/client/admin/__init__.py b/examples/client/admin/__init__.py index e69de29bb2..5cf48776fb 100644 --- a/examples/client/admin/__init__.py +++ b/examples/client/admin/__init__.py @@ -0,0 +1,7 @@ +from ... import Example + + +class AdminExample(Example): + def __init__(self): + # TODO: admin user doesn't have enough permissions + super().__init__(user="admin", password="admin") diff --git a/examples/client/admin/create_role.py b/examples/client/admin/create_role.py index e33976f78a..1bcec4511b 100644 --- a/examples/client/admin/create_role.py +++ b/examples/client/admin/create_role.py @@ -18,7 +18,7 @@ from __future__ import print_function import aerospike -from ... import AdminExample +from . import AdminExample class CreateRole(AdminExample): diff --git a/examples/client/admin/create_user.py b/examples/client/admin/create_user.py index e198386ab5..8d504b191c 100644 --- a/examples/client/admin/create_user.py +++ b/examples/client/admin/create_user.py @@ -17,7 +17,7 @@ from __future__ import print_function -from ... import AdminExample +from . import AdminExample class CreateUser(AdminExample): def run(self): diff --git a/examples/client/admin/query_roles.py b/examples/client/admin/query_roles.py index c1037c43a4..206c2cea47 100644 --- a/examples/client/admin/query_roles.py +++ b/examples/client/admin/query_roles.py @@ -15,7 +15,7 @@ # limitations under the License. ################################################################################ -from ... import AdminExample +from . import AdminExample class QueryRoles(AdminExample): From be1aae3c219d68df914646875fd329446dce4301 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 11:59:41 -0700 Subject: [PATCH 45/60] Address runtime errors for admin tests --- examples/client/admin/create_role.py | 2 ++ examples/client/admin/create_user.py | 4 ++-- examples/client/admin/drop_role.py | 4 ++++ examples/client/admin/grant_roles.py | 2 +- examples/client/admin/revoke_privileges.py | 1 + examples/client/admin/revoke_roles.py | 1 + examples/client/admin/set_password.py | 1 + examples/client/remove_bin.py | 1 - examples/run_all_examples.py | 14 ++++++++++---- 9 files changed, 22 insertions(+), 8 deletions(-) diff --git a/examples/client/admin/create_role.py b/examples/client/admin/create_role.py index 1bcec4511b..cc2115a283 100644 --- a/examples/client/admin/create_role.py +++ b/examples/client/admin/create_role.py @@ -19,6 +19,7 @@ import aerospike from . import AdminExample +import time class CreateRole(AdminExample): @@ -33,3 +34,4 @@ def run(self): def cleanup(self): self.client.admin_drop_role(self.role) + time.sleep(3) diff --git a/examples/client/admin/create_user.py b/examples/client/admin/create_user.py index 8d504b191c..7cc441b7ae 100644 --- a/examples/client/admin/create_user.py +++ b/examples/client/admin/create_user.py @@ -23,10 +23,10 @@ class CreateUser(AdminExample): def run(self): policy = {} self.user = "foo-example" - password = "foobar" + self.password = "foobar" roles = ["read-write", "read"] - self.client.admin_create_user(self.user, password, roles, policy) + self.client.admin_create_user(self.user, self.password, roles, policy) print("OK, 1 new user created") diff --git a/examples/client/admin/drop_role.py b/examples/client/admin/drop_role.py index 1e0d2619ce..56bff99d6b 100644 --- a/examples/client/admin/drop_role.py +++ b/examples/client/admin/drop_role.py @@ -18,6 +18,7 @@ from __future__ import print_function from .create_role import CreateRole +from . import AdminExample class DropRole(CreateRole): def run(self): @@ -26,3 +27,6 @@ def run(self): self.client.admin_drop_role(self.role, policy) print("OK, 1 role dropped") + + def cleanup(self): + AdminExample.cleanup(self) diff --git a/examples/client/admin/grant_roles.py b/examples/client/admin/grant_roles.py index dfe6360283..a260f3763e 100644 --- a/examples/client/admin/grant_roles.py +++ b/examples/client/admin/grant_roles.py @@ -22,4 +22,4 @@ class GrantRoles(CreateUser): def run(self): super().run() self.roles = ["read-write", "user-admin"] - self.client.admin_grant_roles(self.user, roles) + self.client.admin_grant_roles(self.user, self.roles) diff --git a/examples/client/admin/revoke_privileges.py b/examples/client/admin/revoke_privileges.py index 4f88dc8fdb..c6d33d9a03 100644 --- a/examples/client/admin/revoke_privileges.py +++ b/examples/client/admin/revoke_privileges.py @@ -20,6 +20,7 @@ class RevokePrivileges(CreateRole): def run(self): + super().run() policy = {} privileges = [{"code": aerospike.PRIV_SYS_ADMIN}] diff --git a/examples/client/admin/revoke_roles.py b/examples/client/admin/revoke_roles.py index b17d447a35..d4cb8f78aa 100644 --- a/examples/client/admin/revoke_roles.py +++ b/examples/client/admin/revoke_roles.py @@ -20,5 +20,6 @@ class RevokeRoles(GrantRoles): def run(self): + super().run() policy = {} self.client.admin_revoke_roles(self.user, self.roles, policy) diff --git a/examples/client/admin/set_password.py b/examples/client/admin/set_password.py index 571b06c8d3..39f985ff03 100644 --- a/examples/client/admin/set_password.py +++ b/examples/client/admin/set_password.py @@ -21,6 +21,7 @@ class SetPassword(CreateUser): def run(self): + super().run() policy = {} password = "bar" diff --git a/examples/client/remove_bin.py b/examples/client/remove_bin.py index d16327313b..deec979232 100644 --- a/examples/client/remove_bin.py +++ b/examples/client/remove_bin.py @@ -26,7 +26,6 @@ def run(self): retval = self.client.remove_bin(self.key, bin_names) print("Status of bin removal is: %d" % (retval)) - print("OK, bins removed from the record at", self.key) def cleanup(self): pass diff --git a/examples/run_all_examples.py b/examples/run_all_examples.py index 3e20ff8924..eaada0d112 100644 --- a/examples/run_all_examples.py +++ b/examples/run_all_examples.py @@ -9,9 +9,13 @@ dir_containing_this_module = os.path.dirname(os.path.abspath(__file__)) -for folder in ["client", "string_ops"]: +for folder in [ + "client", + "string_ops", + "client.admin" +]: all_packages = pkgutil.walk_packages([ - dir_containing_this_module + "/" + folder, + dir_containing_this_module + "/" + folder.replace(".", "/"), ]) for package in all_packages: print(package) @@ -38,5 +42,7 @@ for cls in example_classes: print(cls) example = cls() - example.run() - example.cleanup() + try: + example.run() + finally: + example.cleanup() From 97359a3236e7ede50f8a77ab41a426d10ff85377 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 13:31:50 -0700 Subject: [PATCH 46/60] Run non-EE code examples without logging in, and run admin code examples while logged in. I believe customers starting out with aerospike would use CE before trying a build with EE features like security. --- .github/workflows/smoke-tests.yml | 15 +++-- examples/run_all_examples.py | 96 ++++++++++++++++++------------- 2 files changed, 64 insertions(+), 47 deletions(-) diff --git a/.github/workflows/smoke-tests.yml b/.github/workflows/smoke-tests.yml index e6bcf0e74f..95ab554e4f 100644 --- a/.github/workflows/smoke-tests.yml +++ b/.github/workflows/smoke-tests.yml @@ -229,7 +229,8 @@ jobs: test: [ stubtest, doctest, - code-examples + ce-code-examples, + ee-code-examples ] fail-fast: false needs: [ @@ -261,24 +262,26 @@ jobs: - name: Install client run: pip install ./*.whl - - if: ${{ matrix.test == 'doctest' || matrix.test == 'code-examples' }} + - if: ${{ matrix.test == 'doctest' || endsWith(matrix.test, 'code-examples') }} uses: aerospike/shared-workflows/.github/actions/setup-aerospike-server@bd168dedaa4fc0b17a560541779d815540eded2d # v3.7.0 with: num-nodes: 1 oidc-provider: ${{ vars.OIDC_PROVIDER_NAME }} oidc-audience: ${{ vars.OIDC_AUDIENCE }} server-tag: ${{ matrix.test == 'code-examples' && '8.1.3.0-35-20260629033923' || needs.get-env-vars.outputs.server-tag }} - server-container-repo: database-docker-virtual/aerospike-server - config-file: ./.github/workflows/aerospike-ce.conf + server-container-repo: database-docker-virtual/aerospike-server${{ matrix.test == 'ee-code-examples' && '-enterprise' || '' }} + config-file: ./.github/workflows/aerospike${{ (matrix.test == 'doctest' || matrix.test == 'ce-code-examples') && '-ce' || '' }}.conf - name: Run canonical code examples - if: ${{ matrix.test == 'code-examples' }} + if: ${{ endsWith(matrix.test, 'code-examples') }} run: | # This is required for the TTL code example docker run --rm --network host aerospike/aerospike-tools asinfo -v "set-config:context=namespace;id=test;nsup-period=1" docker run --rm --network host aerospike/aerospike-tools asinfo -v "set-config:context=namespace;namespace=test;default-ttl=10S" - python3 -m examples.run_all_examples + python3 -m examples.run_all_examples "$SERVER_EDITION" + env: + SERVER_EDITION: ${{ matrix.test == 'ce-code-examples' && 'CE' || 'EE' }} - name: Install test dependencies if: ${{ matrix.test == 'doctest' }} diff --git a/examples/run_all_examples.py b/examples/run_all_examples.py index eaada0d112..61156d6b07 100644 --- a/examples/run_all_examples.py +++ b/examples/run_all_examples.py @@ -4,45 +4,59 @@ import os import sys +def run_examples_in(modules: list[str], class_name: str | None = None): + example_classes: list[type] = [] -example_classes: list[type] = [] - -dir_containing_this_module = os.path.dirname(os.path.abspath(__file__)) - -for folder in [ - "client", - "string_ops", - "client.admin" -]: - all_packages = pkgutil.walk_packages([ - dir_containing_this_module + "/" + folder.replace(".", "/"), - ]) - for package in all_packages: - print(package) - module = importlib.import_module("." + package.name, ".examples." + folder) - for name, obj in inspect.getmembers(module, inspect.isclass): - if obj.__module__ != module.__name__: - continue - # TODO - comparing the same class imported two different ways fails - # There might a better way to do this - print("Found class has these base classes:", obj.__mro__) - if "Example" not in [obj.__name__ for obj in obj.__mro__]: - continue - if not hasattr(obj, "run") or not callable(getattr(obj, "run")): - # Some classes that inherit from Example base class are "abstract" classes - continue - - print("Class found:", obj) - example_classes.append(obj) - -if len(sys.argv) == 2: - example_classes = [cls for cls in example_classes if cls.__name__ == sys.argv[1]] - -print("Running examples...") -for cls in example_classes: - print(cls) - example = cls() - try: - example.run() - finally: - example.cleanup() + dir_containing_this_module = os.path.dirname(os.path.abspath(__file__)) + + for folder in modules: + all_packages = pkgutil.walk_packages([ + dir_containing_this_module + "/" + folder.replace(".", "/"), + ]) + for package in all_packages: + print(package) + module = importlib.import_module("." + package.name, ".examples." + folder) + for name, obj in inspect.getmembers(module, inspect.isclass): + if obj.__module__ != module.__name__: + continue + # TODO - comparing the same class imported two different ways fails + # There might a better way to do this + if "Example" not in [obj.__name__ for obj in obj.__mro__]: + continue + if not hasattr(obj, "run") or not callable(getattr(obj, "run")): + # Some classes that inherit from Example base class are "abstract" classes + continue + + # Now we know this class is a valid example + if class_name and name != class_name: + continue + + print("Class found:", obj) + example_classes.append(obj) + + print("Running examples...") + for cls in example_classes: + print(cls) + print() + + example = cls() + try: + example.run() + finally: + example.cleanup() + +if len(sys.argv) < 2: + print("Missing arguments: EE/CE") + exit(1) + +if sys.argv[1] == "CE": + modules = [ + "client", + "string_ops" + ] +else: + modules = [ + "client.admin" + ] + +run_examples_in(modules) From 96887fd6f4e71d6de5dfd838f42999c298a80193 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 13:38:42 -0700 Subject: [PATCH 47/60] For the EE code examples, only run with security enabled without TLS and SC enabled.. --- .github/workflows/smoke-tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/smoke-tests.yml b/.github/workflows/smoke-tests.yml index 95ab554e4f..c62d2c4a6f 100644 --- a/.github/workflows/smoke-tests.yml +++ b/.github/workflows/smoke-tests.yml @@ -270,7 +270,8 @@ jobs: oidc-audience: ${{ vars.OIDC_AUDIENCE }} server-tag: ${{ matrix.test == 'code-examples' && '8.1.3.0-35-20260629033923' || needs.get-env-vars.outputs.server-tag }} server-container-repo: database-docker-virtual/aerospike-server${{ matrix.test == 'ee-code-examples' && '-enterprise' || '' }} - config-file: ./.github/workflows/aerospike${{ (matrix.test == 'doctest' || matrix.test == 'ce-code-examples') && '-ce' || '' }}.conf + config-file: ${{ (matrix.test == 'doctest' || matrix.test == 'ce-code-examples') && './.github/workflows/aerospike-ce.conf' || '' }} + enable-security: ${{ matrix.test == 'ee-code-examples' }} - name: Run canonical code examples if: ${{ endsWith(matrix.test, 'code-examples') }} From 327d3244ecef0212942a46df9cca98cf2f4d2e14 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 13:47:34 -0700 Subject: [PATCH 48/60] Make sure server config commands work with EE. --- .github/workflows/smoke-tests.yml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/smoke-tests.yml b/.github/workflows/smoke-tests.yml index c62d2c4a6f..6faf031f74 100644 --- a/.github/workflows/smoke-tests.yml +++ b/.github/workflows/smoke-tests.yml @@ -277,8 +277,19 @@ jobs: if: ${{ endsWith(matrix.test, 'code-examples') }} run: | # This is required for the TTL code example - docker run --rm --network host aerospike/aerospike-tools asinfo -v "set-config:context=namespace;id=test;nsup-period=1" - docker run --rm --network host aerospike/aerospike-tools asinfo -v "set-config:context=namespace;namespace=test;default-ttl=10S" + configure_server=( + docker run --rm --network host aerospike/aerospike-tools asinfo + ) + if [[ ${{ matrix.test == 'ee-code-examples' }} == true ]]; then + configure_server+=( + -U admin -P admin + ) + fi + configure_server+=( + -v + ) + "${configure_server[@]}" "set-config:context=namespace;id=test;nsup-period=1" + "${configure_server[@]}" "set-config:context=namespace;namespace=test;default-ttl=10S" python3 -m examples.run_all_examples "$SERVER_EDITION" env: From ac45dde1f3f70533f6b9ca15592452814311756f Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 14:05:25 -0700 Subject: [PATCH 49/60] In order for admin user to change the server config dynamically, it must have the sys-admin role. We can add it since admin user has user-admin role by default. --- .github/workflows/smoke-tests.yml | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/workflows/smoke-tests.yml b/.github/workflows/smoke-tests.yml index 6faf031f74..6d4b0f91cc 100644 --- a/.github/workflows/smoke-tests.yml +++ b/.github/workflows/smoke-tests.yml @@ -277,19 +277,18 @@ jobs: if: ${{ endsWith(matrix.test, 'code-examples') }} run: | # This is required for the TTL code example - configure_server=( - docker run --rm --network host aerospike/aerospike-tools asinfo + run_tools=( + docker run --rm --network host aerospike/aerospike-tools ) + + admin_args=() if [[ ${{ matrix.test == 'ee-code-examples' }} == true ]]; then - configure_server+=( - -U admin -P admin - ) + admin_args+=(-U admin -P admin) + + "${run_tools[@]}" asadm "${admin_args[@]}" --enable -e "manage acl grant user admin roles sys-admin" fi - configure_server+=( - -v - ) - "${configure_server[@]}" "set-config:context=namespace;id=test;nsup-period=1" - "${configure_server[@]}" "set-config:context=namespace;namespace=test;default-ttl=10S" + "${run_tools[@]}" asinfo "${admin_args[@]}" -v "set-config:context=namespace;id=test;nsup-period=1" + "${run_tools[@]}" asinfo "${admin_args[@]}" -v "set-config:context=namespace;namespace=test;default-ttl=10S" python3 -m examples.run_all_examples "$SERVER_EDITION" env: From efbc4a3c0a5c77ffc392353b832afb3b0d0a9a32 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 14:13:52 -0700 Subject: [PATCH 50/60] Make sure server has time to finish creating role before cleanup step runs. --- examples/client/admin/create_role.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/client/admin/create_role.py b/examples/client/admin/create_role.py index cc2115a283..6b46dc128f 100644 --- a/examples/client/admin/create_role.py +++ b/examples/client/admin/create_role.py @@ -33,5 +33,6 @@ def run(self): print("OK, 1 new role created") def cleanup(self): + time.sleep(2) self.client.admin_drop_role(self.role) time.sleep(3) From 1dc8f96e5cde2337e501cef8fd1ddf31431d53a4 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 14:19:34 -0700 Subject: [PATCH 51/60] Address CI failures by making sure user is created before being cleaned up --- examples/client/admin/create_user.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/client/admin/create_user.py b/examples/client/admin/create_user.py index 7cc441b7ae..9cef23174d 100644 --- a/examples/client/admin/create_user.py +++ b/examples/client/admin/create_user.py @@ -18,6 +18,7 @@ from __future__ import print_function from . import AdminExample +import time class CreateUser(AdminExample): def run(self): @@ -31,5 +32,6 @@ def run(self): print("OK, 1 new user created") def cleanup(self): + time.sleep(2) self.client.admin_drop_user(self.user) super().cleanup() From 8939f1e96a479c9f02e26265bde2c294af978238 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 14:26:28 -0700 Subject: [PATCH 52/60] Add delay after every admin command that sends changes to server. --- examples/client/admin/create_role.py | 2 +- examples/client/admin/create_user.py | 3 ++- examples/client/admin/drop_role.py | 3 +++ examples/client/admin/drop_user.py | 3 +++ examples/client/admin/grant_privileges.py | 2 ++ examples/client/admin/grant_roles.py | 2 ++ examples/client/admin/query_role.py | 1 + examples/client/admin/revoke_privileges.py | 2 ++ examples/client/admin/revoke_roles.py | 2 ++ examples/client/admin/set_password.py | 3 +++ 10 files changed, 21 insertions(+), 2 deletions(-) diff --git a/examples/client/admin/create_role.py b/examples/client/admin/create_role.py index 6b46dc128f..afb557397e 100644 --- a/examples/client/admin/create_role.py +++ b/examples/client/admin/create_role.py @@ -29,10 +29,10 @@ def run(self): privileges = [{"code": aerospike.PRIV_READ}, {"code": aerospike.PRIV_USER_ADMIN}] self.client.admin_create_role(self.role, privileges, policy) + time.sleep(3) print("OK, 1 new role created") def cleanup(self): - time.sleep(2) self.client.admin_drop_role(self.role) time.sleep(3) diff --git a/examples/client/admin/create_user.py b/examples/client/admin/create_user.py index 9cef23174d..322f7b2795 100644 --- a/examples/client/admin/create_user.py +++ b/examples/client/admin/create_user.py @@ -28,10 +28,11 @@ def run(self): roles = ["read-write", "read"] self.client.admin_create_user(self.user, self.password, roles, policy) + time.sleep(3) print("OK, 1 new user created") def cleanup(self): - time.sleep(2) self.client.admin_drop_user(self.user) + time.sleep(3) super().cleanup() diff --git a/examples/client/admin/drop_role.py b/examples/client/admin/drop_role.py index 56bff99d6b..670f6bae15 100644 --- a/examples/client/admin/drop_role.py +++ b/examples/client/admin/drop_role.py @@ -19,6 +19,8 @@ from .create_role import CreateRole from . import AdminExample +import time + class DropRole(CreateRole): def run(self): @@ -26,6 +28,7 @@ def run(self): policy = {} self.client.admin_drop_role(self.role, policy) + time.sleep(3) print("OK, 1 role dropped") def cleanup(self): diff --git a/examples/client/admin/drop_user.py b/examples/client/admin/drop_user.py index 37d7f5aae2..fa4db7e045 100644 --- a/examples/client/admin/drop_user.py +++ b/examples/client/admin/drop_user.py @@ -18,6 +18,8 @@ from __future__ import print_function from .create_user import CreateUser, AdminExample +import time + class DropUser(CreateUser): def run(self): @@ -25,6 +27,7 @@ def run(self): policy = {} self.client.admin_drop_user(self.user, policy) + time.sleep(3) print("OK, 1 user dropped") diff --git a/examples/client/admin/grant_privileges.py b/examples/client/admin/grant_privileges.py index 84afa54dc3..a8bce5193e 100644 --- a/examples/client/admin/grant_privileges.py +++ b/examples/client/admin/grant_privileges.py @@ -17,6 +17,7 @@ from .create_role import CreateRole import aerospike +import time class GrantPrivileges(CreateRole): @@ -25,5 +26,6 @@ def run(self): privileges = [{"code": aerospike.PRIV_SYS_ADMIN}] self.client.admin_grant_privileges(self.role, privileges) + time.sleep(3) print("OK, new privileges granted to 1 role") diff --git a/examples/client/admin/grant_roles.py b/examples/client/admin/grant_roles.py index a260f3763e..69dd0d9cc9 100644 --- a/examples/client/admin/grant_roles.py +++ b/examples/client/admin/grant_roles.py @@ -16,6 +16,7 @@ ################################################################################ from .create_user import CreateUser +import time class GrantRoles(CreateUser): @@ -23,3 +24,4 @@ def run(self): super().run() self.roles = ["read-write", "user-admin"] self.client.admin_grant_roles(self.user, self.roles) + time.sleep(3) diff --git a/examples/client/admin/query_role.py b/examples/client/admin/query_role.py index 3cf2bec72c..8213805838 100644 --- a/examples/client/admin/query_role.py +++ b/examples/client/admin/query_role.py @@ -15,6 +15,7 @@ # limitations under the License. ################################################################################ from .create_role import CreateRole +import time class QueryRole(CreateRole): diff --git a/examples/client/admin/revoke_privileges.py b/examples/client/admin/revoke_privileges.py index c6d33d9a03..4b499881bd 100644 --- a/examples/client/admin/revoke_privileges.py +++ b/examples/client/admin/revoke_privileges.py @@ -16,6 +16,7 @@ ################################################################################ from .create_role import CreateRole import aerospike +import time class RevokePrivileges(CreateRole): @@ -25,3 +26,4 @@ def run(self): privileges = [{"code": aerospike.PRIV_SYS_ADMIN}] self.client.admin_revoke_privileges(self.role, privileges, policy) + time.sleep(3) diff --git a/examples/client/admin/revoke_roles.py b/examples/client/admin/revoke_roles.py index d4cb8f78aa..0c3a38cf5d 100644 --- a/examples/client/admin/revoke_roles.py +++ b/examples/client/admin/revoke_roles.py @@ -16,6 +16,7 @@ ################################################################################ from .grant_roles import GrantRoles +import time class RevokeRoles(GrantRoles): @@ -23,3 +24,4 @@ def run(self): super().run() policy = {} self.client.admin_revoke_roles(self.user, self.roles, policy) + time.sleep(3) diff --git a/examples/client/admin/set_password.py b/examples/client/admin/set_password.py index 39f985ff03..253e5a0abc 100644 --- a/examples/client/admin/set_password.py +++ b/examples/client/admin/set_password.py @@ -18,6 +18,8 @@ from __future__ import print_function from .create_user import CreateUser +import time + class SetPassword(CreateUser): def run(self): @@ -26,3 +28,4 @@ def run(self): password = "bar" self.client.admin_set_password(self.user, password, policy) + time.sleep(3) From 1fec48e36c485bb03d2a7ed48074d19e351a6ec7 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 14:34:18 -0700 Subject: [PATCH 53/60] Remove Python 2 compatibility code. --- examples/client/admin/change_password.py | 1 - examples/client/admin/create_role.py | 1 - examples/client/admin/create_user.py | 1 - examples/client/admin/drop_role.py | 1 - examples/client/admin/drop_user.py | 1 - examples/client/admin/set_password.py | 1 - examples/client/client_big_list.py | 1 - 7 files changed, 7 deletions(-) diff --git a/examples/client/admin/change_password.py b/examples/client/admin/change_password.py index f3ba01f68d..1e11c6f3ef 100644 --- a/examples/client/admin/change_password.py +++ b/examples/client/admin/change_password.py @@ -15,7 +15,6 @@ # limitations under the License. ################################################################################ -from __future__ import print_function from .create_user import CreateUser diff --git a/examples/client/admin/create_role.py b/examples/client/admin/create_role.py index afb557397e..22c7035afb 100644 --- a/examples/client/admin/create_role.py +++ b/examples/client/admin/create_role.py @@ -15,7 +15,6 @@ # limitations under the License. ################################################################################ -from __future__ import print_function import aerospike from . import AdminExample diff --git a/examples/client/admin/create_user.py b/examples/client/admin/create_user.py index 322f7b2795..a18e2c4757 100644 --- a/examples/client/admin/create_user.py +++ b/examples/client/admin/create_user.py @@ -15,7 +15,6 @@ # limitations under the License. ################################################################################ -from __future__ import print_function from . import AdminExample import time diff --git a/examples/client/admin/drop_role.py b/examples/client/admin/drop_role.py index 670f6bae15..cee58f6064 100644 --- a/examples/client/admin/drop_role.py +++ b/examples/client/admin/drop_role.py @@ -15,7 +15,6 @@ # limitations under the License. ################################################################################ -from __future__ import print_function from .create_role import CreateRole from . import AdminExample diff --git a/examples/client/admin/drop_user.py b/examples/client/admin/drop_user.py index fa4db7e045..ccf5340aea 100644 --- a/examples/client/admin/drop_user.py +++ b/examples/client/admin/drop_user.py @@ -15,7 +15,6 @@ # limitations under the License. ################################################################################ -from __future__ import print_function from .create_user import CreateUser, AdminExample import time diff --git a/examples/client/admin/set_password.py b/examples/client/admin/set_password.py index 253e5a0abc..14378177f8 100644 --- a/examples/client/admin/set_password.py +++ b/examples/client/admin/set_password.py @@ -15,7 +15,6 @@ # limitations under the License. ################################################################################ -from __future__ import print_function from .create_user import CreateUser import time diff --git a/examples/client/client_big_list.py b/examples/client/client_big_list.py index 587f13bc81..0fa7c875b7 100644 --- a/examples/client/client_big_list.py +++ b/examples/client/client_big_list.py @@ -15,7 +15,6 @@ # limitations under the License. ########################################################################## -from __future__ import print_function import argparse from .. import Example From a96007c12712672c2cb32ef23fedadd722125c86 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 14:37:38 -0700 Subject: [PATCH 54/60] Remove deprecated code examples with APIs that were removed a long time ago. --- examples/deprecated/exists.py | 108 ----------------------------- examples/deprecated/get.py | 108 ----------------------------- examples/deprecated/put.py | 126 ---------------------------------- examples/deprecated/remove.py | 100 --------------------------- 4 files changed, 442 deletions(-) delete mode 100644 examples/deprecated/exists.py delete mode 100644 examples/deprecated/get.py delete mode 100644 examples/deprecated/put.py delete mode 100644 examples/deprecated/remove.py diff --git a/examples/deprecated/exists.py b/examples/deprecated/exists.py deleted file mode 100644 index 364254eb09..0000000000 --- a/examples/deprecated/exists.py +++ /dev/null @@ -1,108 +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. -################################################################################ - -from __future__ import print_function - -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( - "-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) - -################################################################ -# Connect to Cluster -################################################################ - -config = { - 'hosts': [ (options.host, options.port) ] -} - -client = aerospike.client(config).connect() - -################################################################ -# Perform Operation -################################################################ - -rc = 0 -key = args.pop() - -try: - - (key, metadata) = client.key(options.namespace, options.set, key).exists() - - if metadata != None: - print(metadata) - print("---") - print("OK, 1 record found.") - else: - print('error: Not Found.', file=sys.stderr) - rc = 1 - -except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - rc = 1 - -################################################################ -# Close Connection to Cluster -################################################################ - -client.close() - -################################################################ -# Exit -################################################################ - -sys.exit(rc) diff --git a/examples/deprecated/get.py b/examples/deprecated/get.py deleted file mode 100644 index 6adcffae01..0000000000 --- a/examples/deprecated/get.py +++ /dev/null @@ -1,108 +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. -################################################################################ - -from __future__ import print_function - -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( - "-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) - -################################################################ -# Connect to Cluster -################################################################ - -config = { - 'hosts': [ (options.host, options.port) ] -} - -client = aerospike.client(config).connect() - -################################################################ -# Perform Operation -################################################################ - -rc = 0 -key = args.pop() - -try: - (key, metadata, record) = client.key(options.namespace, options.set, key).get() - - if metadata != None: - print(metadata) - print(record) - print("---") - print("OK, 1 record found.") - else: - print('error: Not Found.', file=sys.stderr) - rc = 1 - -except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - rc = 1 - -################################################################ -# Close Connection to Cluster -################################################################ - -client.close() - -################################################################ -# Exit -################################################################ - -sys.exit(rc) diff --git a/examples/deprecated/put.py b/examples/deprecated/put.py deleted file mode 100644 index 65cbc43736..0000000000 --- a/examples/deprecated/put.py +++ /dev/null @@ -1,126 +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. -################################################################################ - -from __future__ import print_function - -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( - "-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) - -################################################################ -# Connect to Cluster -################################################################ - -config = { - 'hosts': [ (options.host, options.port) ] -} - -client = aerospike.client(config).connect() - -################################################################ -# Perform Operation -################################################################ - -rc = 0 -key = args.pop() - -record = { - 'i': 123, - 's': 'abc', - # 'b': bytearray(['d','e','f']), - # 'l': [123, 'abc', bytearray(['d','e','f']), ['x', 'y', 'z'], {'x': 1, 'y': 2, 'z': 3}], - # 'm': {'i': 123, 's': 'abc', 'b': bytearray(['d','e','f']), 'l': ['x', 'y', 'z'], 'd': {'x': 1, 'y': 2, 'z': 3}} - 'l': [123, 'abc', ['x', 'y', 'z'], {'x': 1, 'y': 2, 'z': 3}], - 'm': {'i': 123, 's': 'abc', 'l': ['x', 'y', 'z'], 'd': {'x': 1, 'y': 2, 'z': 3}} -} - -try: - meta = {'ttl': options.ttl, 'gen': options.gen} - # meta = None - # policy = { 'gen': 0 } - policy = None - client.key(options.namespace, options.set, key).put(record, meta) - - print(record) - print("---") - print("OK, 1 record written.") - -except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - rc = 1 - -################################################################ -# Close Connection to Cluster -################################################################ - -client.close() - -################################################################ -# Exit -################################################################ - -sys.exit(rc) diff --git a/examples/deprecated/remove.py b/examples/deprecated/remove.py deleted file mode 100644 index 9d66c68e90..0000000000 --- a/examples/deprecated/remove.py +++ /dev/null @@ -1,100 +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. -################################################################################ - -from __future__ import print_function - -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( - "-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) - -################################################################ -# Connect to Cluster -################################################################ - -config = { - 'hosts': [ (options.host, options.port) ] -} - -client = aerospike.client(config).connect() - -################################################################ -# Perform Operation -################################################################ - -rc = 0 -key = args.pop() - -try: - client.key(options.namespace, options.set, key).remove() - print("OK, 1 record removed.") - -except Exception as e: - print("error: {0}".format(e), file=sys.stderr) - rc = 1 - -################################################################ -# Close Connection to Cluster -################################################################ - -client.close() - -################################################################ -# Exit -################################################################ - -sys.exit(rc) From f2cb78ceaa5544ce220947bd23a79a090eb27927 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 14:44:32 -0700 Subject: [PATCH 55/60] nsup-period and default-ttl need to be configured only for the CE examples... --- .github/workflows/smoke-tests.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/smoke-tests.yml b/.github/workflows/smoke-tests.yml index 6d4b0f91cc..a95c2f413b 100644 --- a/.github/workflows/smoke-tests.yml +++ b/.github/workflows/smoke-tests.yml @@ -278,17 +278,13 @@ jobs: run: | # This is required for the TTL code example run_tools=( - docker run --rm --network host aerospike/aerospike-tools + docker run --rm --network host aerospike/aerospike-tools asinfo -v ) - admin_args=() - if [[ ${{ matrix.test == 'ee-code-examples' }} == true ]]; then - admin_args+=(-U admin -P admin) - - "${run_tools[@]}" asadm "${admin_args[@]}" --enable -e "manage acl grant user admin roles sys-admin" + if [[ ${{ matrix.test == 'ce-code-examples' }} == true ]]; then + "${run_tools[@]}" "set-config:context=namespace;id=test;nsup-period=1" + "${run_tools[@]}" "set-config:context=namespace;namespace=test;default-ttl=10S" fi - "${run_tools[@]}" asinfo "${admin_args[@]}" -v "set-config:context=namespace;id=test;nsup-period=1" - "${run_tools[@]}" asinfo "${admin_args[@]}" -v "set-config:context=namespace;namespace=test;default-ttl=10S" python3 -m examples.run_all_examples "$SERVER_EDITION" env: From 2202c243a5449d4e96c45e6e01b6b928f959d32a Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 14:51:42 -0700 Subject: [PATCH 56/60] TODO addressed --- examples/client/admin/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/client/admin/__init__.py b/examples/client/admin/__init__.py index 5cf48776fb..e25e9243b6 100644 --- a/examples/client/admin/__init__.py +++ b/examples/client/admin/__init__.py @@ -3,5 +3,4 @@ class AdminExample(Example): def __init__(self): - # TODO: admin user doesn't have enough permissions super().__init__(user="admin", password="admin") From 31ac41014debb49a130bf7a8941e3dd951c4110f Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 14:54:16 -0700 Subject: [PATCH 57/60] Remove Python 2 comment. --- examples/client/admin/change_password.py | 1 - examples/client/admin/create_role.py | 1 - examples/client/admin/create_user.py | 1 - examples/client/admin/drop_role.py | 1 - examples/client/admin/drop_user.py | 1 - examples/client/admin/grant_privileges.py | 1 - examples/client/admin/grant_roles.py | 1 - examples/client/admin/query_role.py | 1 - examples/client/admin/query_roles.py | 1 - examples/client/admin/query_user_info.py | 1 - examples/client/admin/query_users_info.py | 1 - examples/client/admin/revoke_privileges.py | 1 - examples/client/admin/revoke_roles.py | 1 - examples/client/admin/set_password.py | 1 - examples/client/client_big_list.py | 1 - 15 files changed, 15 deletions(-) diff --git a/examples/client/admin/change_password.py b/examples/client/admin/change_password.py index 1e11c6f3ef..04094ade3d 100644 --- a/examples/client/admin/change_password.py +++ b/examples/client/admin/change_password.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ################################################################################ # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/admin/create_role.py b/examples/client/admin/create_role.py index 22c7035afb..1275d9c6a5 100644 --- a/examples/client/admin/create_role.py +++ b/examples/client/admin/create_role.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ################################################################################ # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/admin/create_user.py b/examples/client/admin/create_user.py index a18e2c4757..142f1cb532 100644 --- a/examples/client/admin/create_user.py +++ b/examples/client/admin/create_user.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ################################################################################ # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/admin/drop_role.py b/examples/client/admin/drop_role.py index cee58f6064..34748c7755 100644 --- a/examples/client/admin/drop_role.py +++ b/examples/client/admin/drop_role.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ################################################################################ # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/admin/drop_user.py b/examples/client/admin/drop_user.py index ccf5340aea..24a24c8fe0 100644 --- a/examples/client/admin/drop_user.py +++ b/examples/client/admin/drop_user.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ################################################################################ # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/admin/grant_privileges.py b/examples/client/admin/grant_privileges.py index a8bce5193e..a351e58f2b 100644 --- a/examples/client/admin/grant_privileges.py +++ b/examples/client/admin/grant_privileges.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ################################################################################ # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/admin/grant_roles.py b/examples/client/admin/grant_roles.py index 69dd0d9cc9..fb93039cbf 100644 --- a/examples/client/admin/grant_roles.py +++ b/examples/client/admin/grant_roles.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ################################################################################ # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/admin/query_role.py b/examples/client/admin/query_role.py index 8213805838..2446370f98 100644 --- a/examples/client/admin/query_role.py +++ b/examples/client/admin/query_role.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ################################################################################ # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/admin/query_roles.py b/examples/client/admin/query_roles.py index 206c2cea47..5f56c11099 100644 --- a/examples/client/admin/query_roles.py +++ b/examples/client/admin/query_roles.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ################################################################################ # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/admin/query_user_info.py b/examples/client/admin/query_user_info.py index ddba618376..08b99e2686 100644 --- a/examples/client/admin/query_user_info.py +++ b/examples/client/admin/query_user_info.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ################################################################################ # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/admin/query_users_info.py b/examples/client/admin/query_users_info.py index 738b184283..52c48617ba 100644 --- a/examples/client/admin/query_users_info.py +++ b/examples/client/admin/query_users_info.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ################################################################################ # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/admin/revoke_privileges.py b/examples/client/admin/revoke_privileges.py index 4b499881bd..581b474ef4 100644 --- a/examples/client/admin/revoke_privileges.py +++ b/examples/client/admin/revoke_privileges.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ################################################################################ # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/admin/revoke_roles.py b/examples/client/admin/revoke_roles.py index 0c3a38cf5d..1687779219 100644 --- a/examples/client/admin/revoke_roles.py +++ b/examples/client/admin/revoke_roles.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ################################################################################ # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/admin/set_password.py b/examples/client/admin/set_password.py index 14378177f8..96f1ee9d7c 100644 --- a/examples/client/admin/set_password.py +++ b/examples/client/admin/set_password.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ################################################################################ # Copyright 2013-2021 Aerospike, Inc. # diff --git a/examples/client/client_big_list.py b/examples/client/client_big_list.py index 0fa7c875b7..4da2b4c469 100644 --- a/examples/client/client_big_list.py +++ b/examples/client/client_big_list.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ########################################################################## # Copyright 2018 Aerospike, Inc. # From eea234656e9ae1be809c9427f8c3b0d72f545728 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 15:02:02 -0700 Subject: [PATCH 58/60] Address var naming for admin_query_user*_info. It's not just roles that are returned --- examples/client/admin/query_user_info.py | 4 ++-- examples/client/admin/query_users_info.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/client/admin/query_user_info.py b/examples/client/admin/query_user_info.py index 08b99e2686..3687f3e54b 100644 --- a/examples/client/admin/query_user_info.py +++ b/examples/client/admin/query_user_info.py @@ -22,5 +22,5 @@ def run(self): super().run() policy = {} - roles = self.client.admin_query_user_info(self.user, policy) - print(roles) + user = self.client.admin_query_user_info(self.user, policy) + print(user) diff --git a/examples/client/admin/query_users_info.py b/examples/client/admin/query_users_info.py index 52c48617ba..db8801ace1 100644 --- a/examples/client/admin/query_users_info.py +++ b/examples/client/admin/query_users_info.py @@ -22,5 +22,5 @@ def run(self): super().run() policy = {} - user_roles = self.client.admin_query_users_info(policy) - print(user_roles) + users = self.client.admin_query_users_info(policy) + print(users) From e145b7760fda2629bea0c1f3624ae2b67f1d789e Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 29 Jul 2026 18:32:15 -0700 Subject: [PATCH 59/60] leave comment to optimize later. It doesn't matter though since it doesn't take long to collect all the example classes. --- examples/run_all_examples.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/run_all_examples.py b/examples/run_all_examples.py index 61156d6b07..c61b420c58 100644 --- a/examples/run_all_examples.py +++ b/examples/run_all_examples.py @@ -28,6 +28,7 @@ def run_examples_in(modules: list[str], class_name: str | None = None): continue # Now we know this class is a valid example + # TODO: there's probably a way to get a specific class example in O(1) instead of O(n) if class_name and name != class_name: continue From 0312adac0cd32c31d0b3d5bd7fbb106600e15baa Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 7 Aug 2026 09:34:16 -0700 Subject: [PATCH 60/60] Update copyright year for all remaining code examples in examples/client that were changed in this PR --- examples/client/admin/change_password.py | 2 +- examples/client/admin/create_role.py | 2 +- examples/client/admin/create_user.py | 2 +- examples/client/admin/drop_role.py | 2 +- examples/client/admin/drop_user.py | 2 +- examples/client/admin/grant_privileges.py | 2 +- examples/client/admin/grant_roles.py | 2 +- examples/client/admin/query_role.py | 2 +- examples/client/admin/query_roles.py | 2 +- examples/client/admin/query_user_info.py | 2 +- examples/client/admin/query_users_info.py | 2 +- examples/client/admin/revoke_privileges.py | 2 +- examples/client/admin/revoke_roles.py | 2 +- examples/client/admin/set_password.py | 2 +- examples/client/client_big_list.py | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/examples/client/admin/change_password.py b/examples/client/admin/change_password.py index 04094ade3d..a5278250bf 100644 --- a/examples/client/admin/change_password.py +++ b/examples/client/admin/change_password.py @@ -1,5 +1,5 @@ ################################################################################ -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/admin/create_role.py b/examples/client/admin/create_role.py index 1275d9c6a5..e891dd5b6b 100644 --- a/examples/client/admin/create_role.py +++ b/examples/client/admin/create_role.py @@ -1,5 +1,5 @@ ################################################################################ -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/admin/create_user.py b/examples/client/admin/create_user.py index 142f1cb532..1e1655766c 100644 --- a/examples/client/admin/create_user.py +++ b/examples/client/admin/create_user.py @@ -1,5 +1,5 @@ ################################################################################ -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/admin/drop_role.py b/examples/client/admin/drop_role.py index 34748c7755..962e9d8d2c 100644 --- a/examples/client/admin/drop_role.py +++ b/examples/client/admin/drop_role.py @@ -1,5 +1,5 @@ ################################################################################ -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/admin/drop_user.py b/examples/client/admin/drop_user.py index 24a24c8fe0..2b0bb7516e 100644 --- a/examples/client/admin/drop_user.py +++ b/examples/client/admin/drop_user.py @@ -1,5 +1,5 @@ ################################################################################ -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/admin/grant_privileges.py b/examples/client/admin/grant_privileges.py index a351e58f2b..bbab3850e2 100644 --- a/examples/client/admin/grant_privileges.py +++ b/examples/client/admin/grant_privileges.py @@ -1,5 +1,5 @@ ################################################################################ -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/admin/grant_roles.py b/examples/client/admin/grant_roles.py index fb93039cbf..5190d0a448 100644 --- a/examples/client/admin/grant_roles.py +++ b/examples/client/admin/grant_roles.py @@ -1,5 +1,5 @@ ################################################################################ -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/admin/query_role.py b/examples/client/admin/query_role.py index 2446370f98..89f545ffd5 100644 --- a/examples/client/admin/query_role.py +++ b/examples/client/admin/query_role.py @@ -1,5 +1,5 @@ ################################################################################ -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/admin/query_roles.py b/examples/client/admin/query_roles.py index 5f56c11099..2b00d8bddb 100644 --- a/examples/client/admin/query_roles.py +++ b/examples/client/admin/query_roles.py @@ -1,5 +1,5 @@ ################################################################################ -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/admin/query_user_info.py b/examples/client/admin/query_user_info.py index 3687f3e54b..24342c5500 100644 --- a/examples/client/admin/query_user_info.py +++ b/examples/client/admin/query_user_info.py @@ -1,5 +1,5 @@ ################################################################################ -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/admin/query_users_info.py b/examples/client/admin/query_users_info.py index db8801ace1..8e3d93dc56 100644 --- a/examples/client/admin/query_users_info.py +++ b/examples/client/admin/query_users_info.py @@ -1,5 +1,5 @@ ################################################################################ -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/admin/revoke_privileges.py b/examples/client/admin/revoke_privileges.py index 581b474ef4..2d6e011a3a 100644 --- a/examples/client/admin/revoke_privileges.py +++ b/examples/client/admin/revoke_privileges.py @@ -1,5 +1,5 @@ ################################################################################ -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/admin/revoke_roles.py b/examples/client/admin/revoke_roles.py index 1687779219..8473bf0b85 100644 --- a/examples/client/admin/revoke_roles.py +++ b/examples/client/admin/revoke_roles.py @@ -1,5 +1,5 @@ ################################################################################ -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/admin/set_password.py b/examples/client/admin/set_password.py index 96f1ee9d7c..3a48e855eb 100644 --- a/examples/client/admin/set_password.py +++ b/examples/client/admin/set_password.py @@ -1,5 +1,5 @@ ################################################################################ -# Copyright 2013-2021 Aerospike, Inc. +# Copyright 2013-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/client/client_big_list.py b/examples/client/client_big_list.py index 4da2b4c469..506945aaaa 100644 --- a/examples/client/client_big_list.py +++ b/examples/client/client_big_list.py @@ -1,5 +1,5 @@ ########################################################################## -# Copyright 2018 Aerospike, Inc. +# Copyright 2018-2026 Aerospike, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.