Skip to content

Commit 00391ea

Browse files
committed
Documentation updates
1 parent d4a164f commit 00391ea

File tree

2 files changed

+63
-9
lines changed

2 files changed

+63
-9
lines changed

docs/KV.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ $kv = $client->KV();
1212

1313
## Actions
1414

15-
### Key Getting
15+
### Get Single KVP
1616

1717
```php
1818
list($kvp, $qm, $err) = $client->KV()->get('prefix/keyname');
@@ -22,10 +22,18 @@ if (null !== $err)
2222
var_dump($qm, $kvp);
2323
```
2424

25-
### Key Listing
25+
### List All KVP's under specified prefix
2626

27+
```php
28+
list($kvps, $qm, $err) = $client->KV()->list('prefix');
29+
if (null !== $err)
30+
die($err);
31+
32+
var_dump($qm, $kvps);
33+
```
34+
35+
### List All Keys
2736

28-
*All Keys*:
2937
```php
3038
list($keys, $qm, $err) = $client->KV()->keys();
3139
if (null !== $err)
@@ -34,7 +42,8 @@ if (null !== $err)
3442
var_dump($qm, $keys);
3543
```
3644

37-
*Only Keys with Specific Prefix*
45+
### List All Keys Under Prefix
46+
3847
```php
3948
list($keys, $qm, $err) = $client->KV()->keys('prefix');
4049
if (null !== $err)
@@ -43,7 +52,7 @@ if (null !== $err)
4352
var_dump($qm, $keys);
4453
```
4554

46-
### Key Putting
55+
### Put KVP
4756

4857
```php
4958
$kvp = new KVPair(['Key' => 'prefix/mykey', 'Value' => 'my value']);
@@ -54,7 +63,7 @@ if (null !== $err)
5463
var_dump($wm);
5564
```
5665

57-
### Key Deletion
66+
### Delete KVP
5867

5968
```php
6069
list($wm, $err) = $client->KV()->delete('prefix/mykey');
@@ -64,7 +73,7 @@ var_dump($wm);
6473

6574
```
6675

67-
### Tree Retrieval
76+
### Tree Listing
6877

6978
This is a custom feature to allow `get-tree`-like functionality with 0.6.4 (the current release as of this writing)
7079

src/KV/KVClient.php

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function get($key, QueryOptions $queryOptions = null)
4444
if (!is_string($key))
4545
{
4646
return [null, null, new Error('error', sprintf(
47-
'%s::getValue - Key expected to be string, %s seen.',
47+
'%s::get - Key expected to be string, %s seen.',
4848
get_class($this),
4949
gettype($key)
5050
))];
@@ -67,6 +67,51 @@ public function get($key, QueryOptions $queryOptions = null)
6767
return [new KVPair(reset($data)), $qm, null];
6868
}
6969

70+
/**
71+
* @param string $prefix
72+
* @param QueryOptions|null $queryOptions
73+
* @return array(
74+
* @type KVPair[]|null array of KVPair objects under specified prefix
75+
* @type QueryMeta|null query metadata
76+
* @type Error|null error, if any
77+
* )
78+
*/
79+
public function getList($prefix, QueryOptions $queryOptions = null)
80+
{
81+
if (!is_string($prefix) || '' === $prefix)
82+
{
83+
return [null, null, new Error('error', sprintf(
84+
'%s::getList - Prefix expected to be empty or string, %s seen.',
85+
get_class($this),
86+
gettype($prefix)
87+
))];
88+
}
89+
90+
$r = new Request('get', sprintf('v1/kv/%s', rawurlencode($prefix)), $this->_Config);
91+
$r->setQueryOptions($queryOptions);
92+
$r->params()->set('recurse', '');
93+
94+
list($duration, $response, $err) = $this->requireOK($this->doRequest($r));
95+
$qm = $this->buildQueryMeta($duration, $response);
96+
97+
if (null !== $err)
98+
return [null, $qm, $err];
99+
100+
list($data, $err) = $this->decodeBody($response);
101+
102+
if (null !== $err)
103+
return [null, $qm, $err];
104+
105+
$kvPairs = array();
106+
foreach($data as $v)
107+
{
108+
$kvp = new KVPair($v);
109+
$kvPairs[$kvp->getKey()] = $kvp;
110+
}
111+
112+
return [$kvPairs, $qm, null];
113+
}
114+
70115
/**
71116
* @param string $prefix Prefix to search for. Null returns all keys.
72117
* @param QueryOptions $queryOptions
@@ -81,7 +126,7 @@ public function keys($prefix = null, QueryOptions $queryOptions = null)
81126
if (null !== $prefix && !is_string($prefix))
82127
{
83128
return [null, null, new Error('error', sprintf(
84-
'%s::getKeys - Prefix expected to be empty or string, %s seen.',
129+
'%s::keys - Prefix expected to be empty or string, %s seen.',
85130
get_class($this),
86131
gettype($prefix)
87132
))];

0 commit comments

Comments
 (0)