setnx

Sets a value on a key, only if it does not already exist.

[Redis documentation]


setnx(key, value, [options], [callback])

Arguments Type Description
key string Key identifier
value string Value to store
options JSON Object Optional parameters
callback function Callback

Options

Option Type Description Default
queuable boolean Make this request queuable or not true

Return Value

Returns the MemoryStorage object to allow chaining.


Callback Response

Returns a boolean specifying if the operation was successful or not.

Usage

Copied to clipboard!

<?php

use \Kuzzle\Kuzzle;


$kuzzle = new Kuzzle('localhost');

try {
  $status = $kuzzle->memoryStorage()->setnx('key', 'value');
}
catch (ErrorException $e) {

}

Callback response:

Copied to clipboard!
true