listDir() public method

Retrieve a directory
public listDir ( string $key = '/', boolean $recursive = false ) : mixed
$key string
$recursive boolean
return mixed
Example #1
0
 /**
  * @covers LinkORB\Component\Etcd\Client::listDir
  */
 public function testListDir()
 {
     $data = $this->client->listDir();
     $this->assertEquals($this->dirname, $data['node']['key']);
     $this->assertTrue($data['node']['dir'] == 1);
 }
Example #2
0
 * We then refresh the original lock, increasing the timeout by another 3 seconds
 *
 * We then try to create a new lock, which should fail
 */
$pid = getmypid();
$hostname = gethostname();
$jobPid = $hostname . ':' . $pid;
echo "PID: {$jobPid}\n";
$client = new Client();
$client->setRoot("{$account_id}");
echo "Setting initial lock, timeout of 3 seconds\n";
$result1 = $client->set("/{$connector_id}", $jobPid, 3);
print_r($result1);
echo "\n";
echo "Printing directory tree\n";
print_r($client->listDir('/', true));
echo "\n";
echo "Attemping to set value\n";
$result2 = $client->set("/{$connector_id}", $jobPid . "-next", 3, ['prevExist' => 'false']);
print_r($result2);
echo "\n";
echo "Refreshing lock, timeout of 3 seconds\n";
$result1 = $client->set("/{$connector_id}", $jobPid, 3, ['prevValue' => $jobPid]);
print_r($result1);
echo "\n";
// get key value
echo "Checking if key has expired\n";
try {
    echo "Key Value: " . $client->get("/{$connector_id}") . "\n\n";
} catch (Exception $e) {
    echo "Key Not Found: {$connector_id}\n\n";