Skip to content

Key validation

Starting with Python client 18.1.0, the Aerospike Python client can validate certain kinds of dictionaries to check for valid inputs.

Client configuration

The client config dictionary contains configuration information for connecting an application to an Aerospike database server. To ensure the client config dictionary contains no invalid keys, include the key-value pair "validate_keys": True.

The following example demonstrates validate_keys usage:

import aerospike
config = {
"validate_keys": True,
"hosts": [
("127.0.0.1", 3000)
],
# The correct key is "user", but "username" may be used by mistake
"username": "user",
"password": "password"
}
# This call raises a ParamError from aerospike.exception
# Exception message should be:
# "username" is an invalid client config dictionary key
client = aerospike.client(config)

For more information on connecting to an Aerospike server, see Connecting.

Policies

The policy dictionary contains configuration information to customize your client connection for optimal command performance and reliability. To ensure the policy dictionary contains no invalid keys, include the key-value pair "validate_keys": True in the client config dictionary.

Invalid policy example:

import aerospike
config = {
"validate_keys": True,
"hosts": [
("127.0.0.1", 3000)
],
}
client = aerospike.client(config)
key = ("test", "demo", 1)
# "key_policy" is used instead of the correct key named "key"
policy = {
"key_policy": aerospike.POLICY_KEY_SEND
}
# This call raises a ParamError from aerospike.exception
# Exception message should be:
# "key_policy" is an invalid policy dictionary key
client.get(key, policy=policy)

Metadata dictionary

The metadata dictionary holds two keys: "ttl" and "gen". To ensure the metadata dictionary contains no invalid keys, include the key-value pair "validate_keys": True in the config dictionary.

Invalid key example:

import aerospike
config = {
"validate_keys": True,
"hosts": [
("127.0.0.1", 3000)
],
}
client = aerospike.client(config)
key = ("test", "demo", 1)
meta = {
"ttl": 100,
# "generation" should be "gen"
"generation": 4
}
# This call raises a ParamError from aerospike.exception
# Exception message should be:
# "generation" is an invalid record metadata dictionary key
client.put(key, bins={"a": 1}, meta=meta)
client.close()
Feedback

Was this page helpful?

What type of feedback are you giving?

What would you like us to know?

+Capture screenshot

Can we reach out to you?