Return Type Name Arguments QdbBatch QdbBatch::__construct (void) QdbBatch::compareAndSwap (string $alias, string $new_content, string $comparand [, int $expiry_time = 0 ] ) QdbBatch::get (string $alias) QdbBatch::getRemove (string $alias) QdbBatch::getUpdate (string $alias, string $content [, int $expiry_time = 0 ]) QdbBatch::put (string $alias, string $content [, int $expiry_time = 0 ]) QdbBatch::remove (string $alias) QdbBatch::removeIf (string $alias, string $comparand) QdbBatch::update (string $alias, string $content [, int $expiry_time = 0 ]) QdbCluster QdbCluster::__construct (array $nodes) string QdbCluster::compareAndSwap (string $alias, string $new_content, string $comparand [, int $expiry_time = 0 ] ) QdbCluster::expiresAt (string $alias, int $expiry_time) QdbCluster::expiresFromNow (string $alias, int $time_delta) string QdbCluster::get (string $alias) int QdbCluster::getExpiryTime (string $alias) QdbCluster::getRemove (string $alias) string QdbCluster::getUpdate (string $alias, string $content [, int $expiry_time = 0 ]) QdbCluster::put (string $alias, string $content [, int $expiry_time = 0 ]) QdbCluster::remove (string $alias) bool QdbCluster::removeIf (string $alias, string $comparand) QdbBatchResult QdbCluster::runBatch (QdbBatch $batch) QdbCluster::update (string $alias, string $content [, int $expiry_time = 0 ])
Using quasardb cluster from a PHP program is extremely straightforward, just create a QdbCluster and perform the operations.
$nodes = array(array('address' => '127.0.0.1', 'port' => 2836));
$cluster = new QdbCluster($nodes);
$cluster->put('key 0', 'value 0');
$cluster->put('key 1', 'value 1');
$value2 = $cluster->get('key 2');
Not fast enough? Try the QdbBatch class:
$batch = new QdbBatch();
$batch->put('key 0', 'value 0');
$batch->put('key 1', 'value 1');
$batch->get('key 2');
$result = $cluster->runBatch($batch);
$value2 = $result[2];
This will reduce the number of network request and it will be faster by orders of magnitudes.
Please adapt to your configuration.
Instructions:
tar xvf qdb-php-api.tar.gz
cd qdb-php-api
phpize
./configure --with-qdb=/path/to/qdb_capi
make
make install
Please adapt to your configuration.
If ‘qdb_api.dll’ is not available on the ‘PATH’, copy it to ‘C:php’.
Open a Visual Studio Developer Command Prompt (either x86 or x64).
Type:
cd /d C:\php-src\
buildconf
configure --with-qdb=C:\qdb-capi
nmake
nmake install
You may want to customize configure’s flags, for instance ‘–enable-zts’ or ‘–disable-zts’ to control thread-safety.
The following settings can be changed in php.ini:
- qdb.log_level - Specifies the log verbosity. Allowed values are detailed, debug, info, warning, error, panic. The default is panic.
Represents a collection of operations that can be executed with a single query.
Operations are executed by a call to QdbCluster::runBatch ( $batch )
Example:
$batch = new QdbBatch();
$batch->put('key 0', 'value 0');
$batch->put('key 1', 'value 1');
$batch->get('key 2');
$result = $cluster->runBatch($batch);
$value2 = $result[2];
Creates an empty batch, i.e. an empty collection of operations. Batch operations can greatly increase performance when it is necessary to run many small operations.
Operations in a QdbBatch are not executed until QdbCluster::runBatch is called.
| Returns: | An empty QdbBatch collection. |
|---|
Adds a “compare and swap” operation to the batch. When executed, the “compare and swap” operation atomically compares the entry with $comparand and updates it to $new_content if, and only if, they match. If the entry does not exist, a QdbAliasNotFoundException will be thrown when reading the value.
| Parameters: |
|
|---|---|
| Returns: | The original value of the entry is stored in the array returned by QdbCluster::runBatch. |
Adds a “get” operation to the batch. When executed, the “get” operation retrieves an entry’s content.
If the entry does not exist, a QdbAliasNotFoundException will be thrown when reading the value.
| Parameters: |
|
|---|---|
| Returns: | The value of the entry is stored in the array returned by QdbCluster::runBatch. |
Adds a “get and remove” operation to the batch. When executed, the “get and remove” operation atomically gets an entry and removes it.
If the entry does not exist, a QdbAliasNotFoundException will be thrown when reading the content.
| Parameters: |
|
|---|---|
| Returns: | The value of the entry is stored in the array returned by QdbCluster::runBatch. |
Adds a “get and update” operation to the batch. When executed, the “get and update” operation atomically gets and updates (in this order) the entry.
If the entry does not exist, a QdbAliasNotFoundException will be throw when reading the value.
| Parameters: |
|
|---|---|
| Returns: | The content of the entry (before the update) is stored in the array returned by QdbCluster::runBatch. |
Adds a “put” operation to the batch. When executed, the “put” operation adds an entry. Aliases beginning with “qdb” are reserved and cannot be used.
| Parameters: |
|
|---|
Adds a “remove” operation to the batch. When executed, the “remove” operation removes an entry.
If the entry does not exist, the operation will fail and a QdbAliasNotFoundException will be thrown when reading the matching item of the array returned by QdbCluster::runBatch.
| Parameters: |
|
|---|
Adds a “remove if” operation to the batch. When executed, the “remove if” operation removes an entry if it matches $comparand. The operation is atomic.
If the entry does not exist, the operation will fail and a QdbAliasAlreadyExistsException will be throw when reading the matching item of the array returned by QdbCluster::runBatch.
| Parameters: |
|
|---|---|
| Returns: | The result of the operation, true if the entry was actually removed or false otherwise, is stored in the array returned by QdbCluster::runBatch. |
Adds an “update” operation to the batch. When executed, the “update” operation updates an entry. If the entry already exists, the content will be updated. If the entry does not exist, it will be created.
Aliases beginning with “qdb” are reserved and cannot be used.
| Parameters: |
|
|---|
Represents a connection to a quasardb cluster.
Example:
$nodes = array(array('address' => '127.0.0.1', 'port' => 2836));
$cluster = new QdbCluster($nodes);
$cluster->put('key 0', 'value 0');
$cluster->put('key 1', 'value 1');
$value2 = $cluster->get('key 2');
Connects to a quasardb cluster through an array of arrays.
$nodes = array(
array('address'=>'192.168.0.1','port'=>'2836'),
array('address'=>'192.168.0.2','port'=>'2836')
);
Throws a QdbClusterConnectionFailedException if the connection to every node fails.
| Parameters: |
|
|---|---|
| Returns: | a QdbCluster object. |
Atomically compares the entry with $comparand and updates it to $new_content if, and only if, they match.
Throws a QdbAliasNotFoundException if the entry does not exist.
| Parameters: |
|
|---|---|
| Returns string: | Always returns the original value of the entry. |
Sets the expiry time of an existing entry. An $expiry_time of zero means the entry never expires.
Throws a QdbAliasNotFoundException if the entry does not exist.
| Parameters: |
|
|---|
Sets the expiry time of an existing entry. An $expiry_time of zero means the entry expires as soon as possible.
Throws a QdbAliasNotFoundException if the entry does not exist.
| Parameters: |
|
|---|
Retrieves an entry’s content.
Throws a QdbAliasNotFoundException if the entry does not exist.
| Parameters: |
|
|---|---|
| Returns string: | A string representing the entry’s content. |
Retrieves the expiry time of an existing entry. A value of zero means the entry never expires.
Throws a QdbAliasNotFoundException if the entry does not exist.
| Parameters: |
|
|---|---|
| Returns int: | The absolute expiry time, in seconds since epoch. |
Atomically gets an entry and removes it.
Throws a QdbAliasNotFoundException if the entry does not exist.
| Parameters: |
|
|---|---|
| Returns string: | A string representing the entry’s content. |
Atomically gets and updates (in this order) the entry.
Throws a QdbAliasNotFoundException if the entry does not exist.
| Parameters: |
|
|---|---|
| Returns string: | A string representing the entry’s content, before the update. |
Adds an entry. Aliases beginning with “qdb” are reserved and cannot be used.
Throws a QdbAliasAlreadyExistsException if the entry already exists.
| Parameters: |
|
|---|
Removes an entry.
Throws a QdbAliasNotFoundException if the entry does not exist.
| Parameters: |
|
|---|
Removes an entry if it matches $comparand.
Throws a QdbAliasNotFoundException if the entry does not exist.
| Parameters: |
|
|---|---|
| Returns bool: | true if the entry was actually removed, false if not. |
Executes operations of a QdbBatch.
An exception related to an operation will be thrown when reading the matching item from the returned array.
| Parameters: |
|
|---|---|
| Returns: | Returns an array (more exactly a class QdbBatchResult that behaves like an array) with the operation results. Operations results are stored in the order in which operations have been added to the QdbBatch, which is not necessarily the order in which operation are executed in the cluster. |
Updates an entry. Aliases beginning with “qdb” are reserved and cannot be used.
| Parameters: |
|
|---|