Created
December 4, 2019 03:00
-
-
Save dwelch-spike/dcc1a3b1d7d38dbf58c6170bc4eb7444 to your computer and use it in GitHub Desktop.
Example using the Aerospike python client to perform bin operations with Predicate expressions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from __future__ import print_function | |
| import aerospike | |
| from aerospike import predexp | |
| from aerospike import exception as ex | |
| import sys | |
| config = { 'hosts': [('127.0.0.1', 3000)]} | |
| client = aerospike.client(config).connect() | |
| try: | |
| keys = [('test', 'demo', 1), ('test', 'demo', 2), ('test', 'demo', 3)] | |
| records = [{'number': 1}, {'number': 2}, {'number': 3}] | |
| for i in range(3): | |
| client.put(keys[i], records[i]) | |
| preds = [ # check that the record has value 'Kim' in bin 'name' | |
| predexp.integer_bin('number'), | |
| predexp.integer_value(2), | |
| predexp.integer_less() | |
| ] | |
| records = [] | |
| for i in range(3): | |
| try: | |
| records.append(client.get(keys[i], policy={'predexp': preds})) | |
| except ex.FilteredOut as e: | |
| print("Error: {0} [{1}]".format(e.msg, e.code)) | |
| print(records) | |
| except ex.AerospikeError as e: | |
| print("Error: {0} [{1}]".format(e.msg, e.code)) | |
| sys.exit(1) | |
| finally: | |
| client.close() | |
| # the get only returns records that match the preds | |
| # otherwise, an error is returned | |
| # EXPECTED OUTPUT: | |
| # Error: 127.0.0.1:3000 AEROSPIKE_FILTERED_OUT [27] | |
| # Error: 127.0.0.1:3000 AEROSPIKE_FILTERED_OUT [27] | |
| # [(('test', 'demo', 1, bytearray(b'\xb7\xf4\xb88\x89\xe2\xdag\xdeh>\x1d\xf6\x91\x9a\x1e\xac\xc4F\xc8')), | |
| # {'gen': 8, 'ttl': 2592000}, {'charges': [10, 20, 14], 'name': 'John', 'number': 1})] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment