Table Of Contents

6.13. PHP

6.13.1. qdb\QdbAliasAlreadyExistsException

class QdbAliasAlreadyExistsException

Thrown when an entry with the same alias is already present in the database.

6.13.2. qdb\QdbAliasNotFoundException

class QdbAliasNotFoundException

Thrown when an entry cannot be found in the database.

6.13.3. qdb\QdbBatch

class QdbBatch

A collection of operation that can be executed with a single query.

Operation are executed by a call to {@link QdbCluster::runBatch()}

$result = $cluster->runBatch($batch);

$value2 = $result[2]; </code>

__construct()

Creates an empty batch, i.e. an empty collection of operation.

compareAndSwap($alias, $new_content, $comparand, $expiry_time = 0)

Adds a “compare and swap” operation to the batch.

When executed, the “compare and swap” operation atomically compares a blob with $comparand and updates it to $new_content if, and only if, they match.

Parameters:
  • $alias (string) – The blob’s alias.
  • $new_content (string) – The new content of the blob in case of match.
  • $comparand (string) – The content to be compared to.
  • $expiry_time (int) – The absolute expiration time, in seconds since epoch (0 means “never expires”).
get($alias)

Adds a “get” operation to the batch.

When executed, the “get” operation reads the content of a blob.

Parameters:
  • $alias (string) – The blob’s alias.
getAndRemove($alias)

Adds a “get and remove” operation to the batch.

When executed, the “get and remove” operation atomically reads a blob and removes it.

Parameters:
  • $alias (string) – The blob’s alias.
getAndUpdate($alias, $content, $expiry_time = 0)

Adds a “get and remove” operation to the batch.

When executed, the “get and remove” operation atomically reads a blob’s content and replaces it.

Parameters:
  • $alias (string) – The blob’s alias.
  • $content (string) – The new content of the blob.
  • $expiry_time (int) – The absolute expiration time, in seconds since epoch (0 means “never expires”).
put($alias, $content, $expiry_time = 0)

Adds a “put” operation to the batch.

When executed, the “put” operation creates a blob.

Parameters:
  • $alias (string) – The blob’s alias.
  • $content (string) – The initial content of the blob.
  • $expiry_time (int) – The absolute expiration time, in seconds since epoch (0 means “never expires”).
remove($alias)

Adds a “remove” operation to the batch. When executed, the “remove” operation removes an entry.

Parameters:
  • $alias (string) – The entry’s alias.
removeIf($alias, $comparand)

Adds a “remove if” operation to the batch.

When executed, the “remove if” operation removes a blob if it matches $comparand. The operation is atomic.

Parameters:
  • $alias (string) – The blob’s alias.
  • $comparand (string) – The content to be compared to.
update($alias, $content, $expiry_time = 0)

Adds an “update” operation to the batch.

When executed, the “update” operation sets the content of a blob. It will create the blob if needed.

Parameters:
  • $alias (string) – The blob’s alias.
  • $content (string) – The new content of the blob.
  • $expiry_time (int) – The absolute expiration time, in seconds since epoch (0 means “never expires”).

6.13.4. qdb\QdbBatchResult

class QdbBatchResult

A result of a batch query.

A QdbBatchResult is returned by {@link QdbCluster::runBatch()}.

This class behaves like an array containing the operation results. Operations results are stored in the order in which operations have been added to the {@link QdbBatch}, which is not necessarily the order in which operation are executed in the cluster.

An exception will be thrown when reading the result of an operation that failed. The exception type will match the failure of that particular operation, like {@link QdbAliasAlreadyExistsException}, {@link QdbAliasNotFoundException}, {@link QdbContainerEmptyException} or {@link QdbIncompatibleTypeException}.

// then, execute it $result = $cluster->runBatch($batch);

// finally, read the results // (the following line may throw QdbAliasNotFoundException or QdbIncompatibleTypeException) $value2 = $result[2]; </code>

6.13.5. qdb\QdbBlob

class QdbBlob

A blob in the database.

Blob stands for Binary Large Object, meaning that you can store arbitrary data in this blob.

compareAndSwap($new_content, $comparand, $expiry_time)

Atomically compares the blob’s content with $comparand and updates it to $new_content if, and only if, they match.

Parameters:
  • $new_content (string) – The new content of the blob in case of a match.
  • $comparand (string) – The content to be compared to.
  • $expiry_time (int) – The absolute expiration time, in seconds since epoch (0 means “never expires”).
Returns:

string The original content of the blob if it didn’t match $comparand; null if it matched.

get()

Reads the blob’s content.

Returns:string The blob’s content.
getAndRemove()

Atomically gets blob’s content and removes it.

Returns:string The blob’s content.
getAndUpdate($content, $expiry_time = 0)

Atomically gets the blob’s content and replaces it.

Parameters:
  • $content (string) – The new content of the blob.
  • $expiry_time (int) – The absolute expiration time, in seconds since epoch (0 means “never expires”).
Returns:

string The blob’s content.

put($content, $expiry_time = 0)

Sets the blob’s content, fails if it already exists.

Parameters:
  • $content (string) – The initial content of the blob.
  • $expiry_time (int) – The absolute expiration time, in seconds since epoch (0 means “never expires”).
removeIf()

Removes the blob if content matches.

Returns:bool true if the blob was actually removed; false if not.
update($content, $expiry_time)

Sets the blob’s content, creates the blob if needed.

Parameters:
  • $content (string) – The new content of the blob.
  • $expiry_time (int) – The absolute expiration time, in seconds since epoch (0 means “never expires”).
Returns:

bool true if the integer was created; false if it was updated.

expiresAt($expiry_time)

Sets the absolute expiration time of the entry.

Parameters:
  • $expiry_time (int) – The absolute expiration time, in seconds since epoch (0 means “never expires”).
expiresFromNow($time_delta)

Sets the relative expiration time of the entry.

Parameters:
  • $time_delta (int) – The relative expiration time, in seconds.
getExpiryTime()

Gets the expiration time of the entry.

Returns:int The absolute expiration time, in seconds since epoch (0 means “never expires”).
attachTag($tag)

Attachs a tag to the entry

Parameters:
  • $tag (QdbTag|string) – The tag to add to the entry, or its alias.
Returns:

bool true if the tag was added, or false it the entry already had this tag.

attachTags($tags)

Attachs one or more tags to the entry

Parameters:
  • $tags
Returns:

void

alias()

Gets the alias (i.e. its “key”) of the entry.

Alias starting with qdb are reserved.

Returns:string The alias of the entry.
getTags($tag)

Enumerates the tags attached to the entry.

Parameters:
  • $tag (QdbTag|string) – The tag to the entry, or it’s alias.
Returns:

QdbTagCollection A traversable collection of {@link QdbTag}

hasTag($tag)

Checks if a tag is attached to the entry.

Parameters:
  • $tag (QdbTag|string) – The tag to check for, or its alias.
Returns:

bool true if the entry is tagged with the given tag, false otherwise.

remove()

Deletes the entry.

detachTag($tag)

Detaches a tag from the entry.

Parameters:
  • $tag (QdbTag|string) – The tag to the entry, or its alias.
Returns:

bool true if the tag was added, or false it the entry already had this tag.

6.13.6. qdb\QdbCluster

class QdbCluster

A connection to a quasardb cluster.

$cluster->blob(‘key 0’)->put(‘value 0’); $cluster->deque(‘key 1’)->pushBack(‘value 1’); $cluster->integer(‘key 2’)->add(42); </code>

__construct($uri)

Connects to a quasardb cluster through the specified URI.

The URI contains the addresses of the bootstraping nodes, other nodes are discovered during the first connection. Having more than one node in the URI allows to connect to the cluster even if the first node is down.

Parameters:
  • $uri (string) – A quasardb URI, in the form of qdb://<address1>:<port1>[,<address2:<port2>…].
blob($alias)

Creates a {@link QdbBlob} associated with the specified alias.

No query is performed at this point.

Parameters:
  • $alias (string) – The alias of the blob (alias starting with qdb are reserved).
Returns:

QdbBlob

deque($alias)

Creates a {@link QdbDeque} associated with the specified alias.

No query is performed at this point.

Parameters:
  • $alias (string) – The alias of the queue (alias starting with qdb are reserved).
Returns:

QdbDeque

entry($alias)

Create a {@link QdbBlob}, a {@link QdbDeque}, a {@link QdbInteger} or a {@link QdbTag} depending on the actual type of the entry.

The entry must exist in the database.

$entry1 = $cluster->entry(‘alias1’); // $entry1 is a QdbBlob $entry2 = $cluster->entry(‘alias2’); // $entry2 is a QdbDeque </code>

Parameters:
  • $alias (string) – The alias of the entry (alias starting with qdb are reserved).
Returns:

QdbEntry

integer($alias)

Creates a {@link QdbInteger} associated with the specified alias.

No query is performed at this point.

Parameters:
  • $alias (string) – The alias of the integer (alias starting with qdb are reserved).
Returns:

QdbInteger

purgeAll($timeout = 300)

Removes all the entries on all the nodes of the quasardb cluster.

This operation is not allowed by default, it must be enabled in the server configuration.

Parameters:
  • $timeout (int) – The maximim number of seconds for the command to execute.
runBatch($batch)

Executes operations of a QdbBatch.

Parameters:
  • $batch (QdbBatch) – The batch to run.
Returns:

QdbBatchResult

tag($alias)

Creates a {@link QdbTag} associated with the specified alias.

No query is performed at this point.

Parameters:
  • $alias (string) – The alias of the tag (alias starting with qdb are reserved).
Returns:

QdbTag

6.13.7. qdb\QdbConnectionException

class QdbConnectionException

Thrown when the connection to the cluster failed.

6.13.8. qdb\QdbContainerEmptyException

class QdbContainerEmptyException

Thrown when the container is empty.

6.13.9. qdb\QdbDeque

class QdbDeque

A queue of blob in the database.

It’s a double-ended queue, you can both enqueue and dequeue from the front and the back.

back()

Gets the element at the end of the queue.

Returns:string The last element of the queue.
front()

Gets the element at the beginning of the queue.

Returns:string The first element of the queue.
popBack()

Dequeues from the end of the queue and returns the value.

Returns:string The last element of the queue.
popFront()

Dequeues from the beginning of the queue and returns the value.

Returns:string The first element of the queue.
pushBack($content)

Enqueues the specified value at the end of the queue. Creates the queue if needed.

Parameters:
  • $content (string) – The value to enqueue.
pushFront($content)

Enqueues the specified value at the beginning of the queue. Creates the queue if needed.

Parameters:
  • $content (string) – The value to enqueue.
size()

Gets the length of the queue.

Returns:int The number of elements in the queue.
attachTag($tag)

Attachs a tag to the entry

Parameters:
  • $tag (QdbTag|string) – The tag to add to the entry, or its alias.
Returns:

bool true if the tag was added, or false it the entry already had this tag.

attachTags($tags)

Attachs one or more tags to the entry

Parameters:
  • $tags
Returns:

void

alias()

Gets the alias (i.e. its “key”) of the entry.

Alias starting with qdb are reserved.

Returns:string The alias of the entry.
getTags($tag)

Enumerates the tags attached to the entry.

Parameters:
  • $tag (QdbTag|string) – The tag to the entry, or it’s alias.
Returns:

QdbTagCollection A traversable collection of {@link QdbTag}

hasTag($tag)

Checks if a tag is attached to the entry.

Parameters:
  • $tag (QdbTag|string) – The tag to check for, or its alias.
Returns:

bool true if the entry is tagged with the given tag, false otherwise.

remove()

Deletes the entry.

detachTag($tag)

Detaches a tag from the entry.

Parameters:
  • $tag (QdbTag|string) – The tag to the entry, or its alias.
Returns:

bool true if the tag was added, or false it the entry already had this tag.

6.13.10. qdb\QdbEntry

class QdbEntry

An entry in the database

attachTag($tag)

Attachs a tag to the entry

Parameters:
  • $tag (QdbTag|string) – The tag to add to the entry, or its alias.
Returns:

bool true if the tag was added, or false it the entry already had this tag.

attachTags($tags)

Attachs one or more tags to the entry

Parameters:
  • $tags
Returns:

void

alias()

Gets the alias (i.e. its “key”) of the entry.

Alias starting with qdb are reserved.

Returns:string The alias of the entry.
getTags($tag)

Enumerates the tags attached to the entry.

Parameters:
  • $tag (QdbTag|string) – The tag to the entry, or it’s alias.
Returns:

QdbTagCollection A traversable collection of {@link QdbTag}

hasTag($tag)

Checks if a tag is attached to the entry.

Parameters:
  • $tag (QdbTag|string) – The tag to check for, or its alias.
Returns:

bool true if the entry is tagged with the given tag, false otherwise.

remove()

Deletes the entry.

detachTag($tag)

Detaches a tag from the entry.

Parameters:
  • $tag (QdbTag|string) – The tag to the entry, or its alias.
Returns:

bool true if the tag was added, or false it the entry already had this tag.

6.13.11. qdb\QdbEntryCollection

class QdbEntryCollection

A traversable collection of {@link QdbEntry}.

A QdbEntryCollection is returned by {@link QdbTag::getEntries()}.

Entries in the collection have a concrete type like {@link QdbBlob}, {@link QdbInteger}, {@link QdbDeque} or {@link QdbTag}

6.13.12. qdb\QdbException

class QdbException

Base class of all quasardb exceptions.

6.13.13. qdb\QdbExpirableEntry

class QdbExpirableEntry

An entry which can expire.

expiresAt($expiry_time)

Sets the absolute expiration time of the entry.

Parameters:
  • $expiry_time (int) – The absolute expiration time, in seconds since epoch (0 means “never expires”).
expiresFromNow($time_delta)

Sets the relative expiration time of the entry.

Parameters:
  • $time_delta (int) – The relative expiration time, in seconds.
getExpiryTime()

Gets the expiration time of the entry.

Returns:int The absolute expiration time, in seconds since epoch (0 means “never expires”).
attachTag($tag)

Attachs a tag to the entry

Parameters:
  • $tag (QdbTag|string) – The tag to add to the entry, or its alias.
Returns:

bool true if the tag was added, or false it the entry already had this tag.

attachTags($tags)

Attachs one or more tags to the entry

Parameters:
  • $tags
Returns:

void

alias()

Gets the alias (i.e. its “key”) of the entry.

Alias starting with qdb are reserved.

Returns:string The alias of the entry.
getTags($tag)

Enumerates the tags attached to the entry.

Parameters:
  • $tag (QdbTag|string) – The tag to the entry, or it’s alias.
Returns:

QdbTagCollection A traversable collection of {@link QdbTag}

hasTag($tag)

Checks if a tag is attached to the entry.

Parameters:
  • $tag (QdbTag|string) – The tag to check for, or its alias.
Returns:

bool true if the entry is tagged with the given tag, false otherwise.

remove()

Deletes the entry.

detachTag($tag)

Detaches a tag from the entry.

Parameters:
  • $tag (QdbTag|string) – The tag to the entry, or its alias.
Returns:

bool true if the tag was added, or false it the entry already had this tag.

6.13.14. qdb\QdbIncompatibleTypeException

class QdbIncompatibleTypeException

Thrown when an operation cannot be perform because the existing entry do not have the appropriate type.

6.13.15. qdb\QdbInputException

class QdbInputException

Thrown when user input causes an error.

6.13.16. qdb\QdbInteger

class QdbInteger

A signed 64-bit integer in the database.

add($value)

Atomically increment the value in the database.

Parameters:
  • $value (int) – The value to add to the integer.
Returns:

int The new value (i.e. after the addition) of the integer.

get()

Reads the integer’s value.

Returns:int The value of the integer.
put($value, $expiry_time = 0)

Creates the integer, fails if it already exists.

Parameters:
  • $value (int) – The initial value of the integer.
  • $expiry_time (int) – The absolute expiration time, in seconds since epoch (0 means “never expires”).
update($value, $expiry_time = 0)

Sets the integer’s value. Creates the integer if needed.

Parameters:
  • $value (int) – The new value of the integer.
  • $expiry_time (int) – The absolute expiration time, in seconds since epoch (0 means “never expires”).
Returns:

bool true if the integer was created; false if it was updated.

expiresAt($expiry_time)

Sets the absolute expiration time of the entry.

Parameters:
  • $expiry_time (int) – The absolute expiration time, in seconds since epoch (0 means “never expires”).
expiresFromNow($time_delta)

Sets the relative expiration time of the entry.

Parameters:
  • $time_delta (int) – The relative expiration time, in seconds.
getExpiryTime()

Gets the expiration time of the entry.

Returns:int The absolute expiration time, in seconds since epoch (0 means “never expires”).
attachTag($tag)

Attachs a tag to the entry

Parameters:
  • $tag (QdbTag|string) – The tag to add to the entry, or its alias.
Returns:

bool true if the tag was added, or false it the entry already had this tag.

attachTags($tags)

Attachs one or more tags to the entry

Parameters:
  • $tags
Returns:

void

alias()

Gets the alias (i.e. its “key”) of the entry.

Alias starting with qdb are reserved.

Returns:string The alias of the entry.
getTags($tag)

Enumerates the tags attached to the entry.

Parameters:
  • $tag (QdbTag|string) – The tag to the entry, or it’s alias.
Returns:

QdbTagCollection A traversable collection of {@link QdbTag}

hasTag($tag)

Checks if a tag is attached to the entry.

Parameters:
  • $tag (QdbTag|string) – The tag to check for, or its alias.
Returns:

bool true if the entry is tagged with the given tag, false otherwise.

remove()

Deletes the entry.

detachTag($tag)

Detaches a tag from the entry.

Parameters:
  • $tag (QdbTag|string) – The tag to the entry, or its alias.
Returns:

bool true if the tag was added, or false it the entry already had this tag.

6.13.17. qdb\QdbOperationDisabledException

class QdbOperationDisabledException

Thrown when an operation cannot be perform because it has been disabled in the cluster configuration.

6.13.18. qdb\QdbOperationException

class QdbOperationException

Thrown when a database operation failed.

6.13.19. qdb\QdbProtocolException

class QdbProtocolException

Thrown when an error is detected in the quasardb protocol.

6.13.20. qdb\QdbSystemException

class QdbSystemException

Thrown when an error is returned by the operating system.

6.13.21. qdb\QdbTag

class QdbTag

A tag in the database.

A tag is a lightweight means of finding entries in the database.

attachEntry($entry)

Attaches the tag to an entry.

Parameters:
  • $entry (QdbEntry|string) – The entry to add the tag to, or its alias.
Returns:

bool true if the tag was added, or false it the entry already had this tag.

getEntries()

Enumerates tagged entries.

Returns:QdbEntryCollection A traversable collection of {@link QdbEntry}.
hasEntry($entry)

Checks if an entry is attached with the tag.

Parameters:
  • $entry (QdbEntry|string) – The entry to check, or its alias.
Returns:

bool true if the entry is tagged with the given tag, false otherwise.

detachEntry($entry)

Detachs the tag from an entry.

Parameters:
  • $entry (QdbEntry|string) – The entry to remove the tag from, or its alias.
Returns:

bool true if the tag was removed, or false it the entry already didn’t have this tag.

attachTag($tag)

Attachs a tag to the entry

Parameters:
  • $tag (QdbTag|string) – The tag to add to the entry, or its alias.
Returns:

bool true if the tag was added, or false it the entry already had this tag.

attachTags($tags)

Attachs one or more tags to the entry

Parameters:
  • $tags
Returns:

void

alias()

Gets the alias (i.e. its “key”) of the entry.

Alias starting with qdb are reserved.

Returns:string The alias of the entry.
getTags($tag)

Enumerates the tags attached to the entry.

Parameters:
  • $tag (QdbTag|string) – The tag to the entry, or it’s alias.
Returns:

QdbTagCollection A traversable collection of {@link QdbTag}

hasTag($tag)

Checks if a tag is attached to the entry.

Parameters:
  • $tag (QdbTag|string) – The tag to check for, or its alias.
Returns:

bool true if the entry is tagged with the given tag, false otherwise.

remove()

Deletes the entry.

detachTag($tag)

Detaches a tag from the entry.

Parameters:
  • $tag (QdbTag|string) – The tag to the entry, or its alias.
Returns:

bool true if the tag was added, or false it the entry already had this tag.

6.13.22. qdb\QdbTagCollection

class QdbTagCollection

A traversable collection of {@link QdbTag}.

A QdbTagCollection is returned by {@link QdbEntry::getTags()}.