Class Key

java.lang.Object
com.aerospike.client.Key

public final class Key extends Object
Unique record identifier. Records can be identified using a specified namespace, an optional set name, and a user defined key which must be unique within a set. Records can also be identified by namespace/digest which is the combination used on the server.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final byte[]
    Unique server hash value generated from set name and user key.
    final String
    Namespace.
    final String
    Optional set name.
    final Value
    Original user key.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Key(String namespace, byte[] digest, String setName, Value userKey)
    Initialize key from namespace, digest, optional set name and optional userKey.
    Key(String namespace, String setName, byte[] key)
    Initialize key from namespace, optional set name and user key.
    Key(String namespace, String setName, byte[] key, int offset, int length)
    Initialize key from namespace, optional set name and user key.
    Key(String namespace, String setName, int key)
    Initialize key from namespace, optional set name and user key.
    Key(String namespace, String setName, long key)
    Initialize key from namespace, optional set name and user key.
    Key(String namespace, String setName, Value key)
    Initialize key from namespace, optional set name and user key.
    Key(String namespace, String setName, String key)
    Initialize key from namespace, optional set name and user key.
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    computeDigest(String setName, Value key)
    Generate unique server hash value from set name, key type and user defined key.
    boolean
    Equality uses namespace and digest.
    int
    Hash lookup uses namespace and digest.
     

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • namespace

      public final String namespace
      Namespace. Equivalent to database name.
    • setName

      public final String setName
      Optional set name. Equivalent to database table.
    • digest

      public final byte[] digest
      Unique server hash value generated from set name and user key.
    • userKey

      public final Value userKey
      Original user key. This key is immediately converted to a hash digest. This key is not used or returned by the server by default. If the user key needs to persist on the server, use one of the following methods:
      • Set "WritePolicy.sendKey" to true. In this case, the key will be sent to the server for storage on writes and retrieved on multi-record scans and queries.
      • Explicitly store and retrieve the key in a bin.
  • Constructor Details

    • Key

      public Key(String namespace, String setName, String key) throws AerospikeException
      Initialize key from namespace, optional set name and user key. The set name and user defined key are converted to a digest before sending to the server. The user key is not used or returned by the server by default. If the user key needs to persist on the server, use one of the following methods:
      • Set "WritePolicy.sendKey" to true. In this case, the key will be sent to the server for storage on writes and retrieved on multi-record scans and queries.
      • Explicitly store and retrieve the key in a bin.

      The key is converted to bytes to compute the digest. The key's byte size is limited to the current thread's buffer size (min 8KB). To store keys > 8KB, do one of the following:

      • Set once:
        ThreadLocalData.DefaultBufferSize = maxKeySize + maxSetNameSize + 1;
      • Or for every key:
         int len = key.length() + setName.length() + 1;
         if (len > ThreadLocalData.getBuffer().length))
             ThreadLocalData.resizeBuffer(len);
         
      Parameters:
      namespace - namespace
      setName - optional set name, enter null when set does not exist
      key - user defined unique identifier within set.
      Throws:
      AerospikeException - if digest computation fails
    • Key

      public Key(String namespace, String setName, byte[] key) throws AerospikeException
      Initialize key from namespace, optional set name and user key. The set name and user defined key are converted to a digest before sending to the server. The user key is not used or returned by the server by default. If the user key needs to persist on the server, use one of the following methods:
      • Set "WritePolicy.sendKey" to true. In this case, the key will be sent to the server for storage on writes and retrieved on multi-record scans and queries.
      • Explicitly store and retrieve the key in a bin.

      The key's byte size is limited to the current thread's buffer size (min 8KB). To store keys > 8KB, do one of the following:

      • Set once:
        ThreadLocalData.DefaultBufferSize = maxKeySize + maxSetNameSize + 1;
      • Or for every key:
         int len = key.length + setName.length() + 1;
         if (len > ThreadLocalData.getBuffer().length))
             ThreadLocalData.resizeBuffer(len);
         
      Parameters:
      namespace - namespace
      setName - optional set name, enter null when set does not exist
      key - user defined unique identifier within set.
      Throws:
      AerospikeException - if digest computation fails
    • Key

      public Key(String namespace, String setName, byte[] key, int offset, int length) throws AerospikeException
      Initialize key from namespace, optional set name and user key. The set name and user defined key are converted to a digest before sending to the server. The user key is not used or returned by the server by default. If the user key needs to persist on the server, use one of the following methods:
      • Set "WritePolicy.sendKey" to true. In this case, the key will be sent to the server for storage on writes and retrieved on multi-record scans and queries.
      • Explicitly store and retrieve the key in a bin.

      The key's byte size is limited to the current thread's buffer size (min 8KB). To store keys > 8KB, do one of the following:

      • Set once:
        ThreadLocalData.DefaultBufferSize = maxKeySize + maxSetNameSize + 1;
      • Or for every key:
         int len = length + setName.length() + 1;
         if (len > ThreadLocalData.getBuffer().length))
             ThreadLocalData.resizeBuffer(len);
         
      Parameters:
      namespace - namespace
      setName - optional set name, enter null when set does not exist
      key - user defined unique identifier within set.
      offset - byte array segment offset
      length - byte array segment length
      Throws:
      AerospikeException - if digest computation fails
    • Key

      public Key(String namespace, String setName, int key) throws AerospikeException
      Initialize key from namespace, optional set name and user key. The set name and user defined key are converted to a digest before sending to the server. The user key is not used or returned by the server by default. If the user key needs to persist on the server, use one of the following methods:
      • Set "WritePolicy.sendKey" to true. In this case, the key will be sent to the server for storage on writes and retrieved on multi-record scans and queries.
      • Explicitly store and retrieve the key in a bin.
      Parameters:
      namespace - namespace
      setName - optional set name, enter null when set does not exist
      key - user defined unique identifier within set.
      Throws:
      AerospikeException - if digest computation fails
    • Key

      public Key(String namespace, String setName, long key) throws AerospikeException
      Initialize key from namespace, optional set name and user key. The set name and user defined key are converted to a digest before sending to the server. The user key is not used or returned by the server by default. If the user key needs to persist on the server, use one of the following methods:
      • Set "WritePolicy.sendKey" to true. In this case, the key will be sent to the server for storage on writes and retrieved on multi-record scans and queries.
      • Explicitly store and retrieve the key in a bin.
      Parameters:
      namespace - namespace
      setName - optional set name, enter null when set does not exist
      key - user defined unique identifier within set.
      Throws:
      AerospikeException - if digest computation fails
    • Key

      public Key(String namespace, String setName, Value key) throws AerospikeException
      Initialize key from namespace, optional set name and user key. The set name and user defined key are converted to a digest before sending to the server. The user key is not used or returned by the server by default. If the user key needs to persist on the server, use one of the following methods:
      • Set "WritePolicy.sendKey" to true. In this case, the key will be sent to the server for storage on writes and retrieved on multi-record scans and queries.
      • Explicitly store and retrieve the key in a bin.
      Parameters:
      namespace - namespace
      setName - optional set name, enter null when set does not exist
      key - user defined unique identifier within set.
      Throws:
      AerospikeException - if digest computation fails
    • Key

      public Key(String namespace, byte[] digest, String setName, Value userKey)
      Initialize key from namespace, digest, optional set name and optional userKey.
      Parameters:
      namespace - namespace
      digest - unique server hash value
      setName - optional set name, enter null when set does not exist
      userKey - optional original user key (not hash digest).
  • Method Details

    • hashCode

      public int hashCode()
      Hash lookup uses namespace and digest.
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Equality uses namespace and digest.
      Overrides:
      equals in class Object
    • computeDigest

      public static byte[] computeDigest(String setName, Value key) throws AerospikeException
      Generate unique server hash value from set name, key type and user defined key. The hash function is RIPEMD-160 (a 160 bit hash).
      Parameters:
      setName - optional set name, enter null when set does not exist
      key - record identifier, unique within set
      Returns:
      unique server hash value
      Throws:
      AerospikeException - if digest computation fails
    • toString

      public String toString()
      Overrides:
      toString in class Object