Skip to content

Commit

Permalink
Fixes a typo in README (fixes #229).
Browse files Browse the repository at this point in the history
Signed-off-by: Tao He <sighingnow@gmail.com>
  • Loading branch information
sighingnow committed Jun 30, 2023
1 parent dd2c027 commit fcc5807
Showing 1 changed file with 52 additions and 52 deletions.
104 changes: 52 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,58 +514,58 @@ keys defined by the prefix. mkdir method is removed since etcdv3 treats everythi
2. Listing a directory:
Listing directory in etcd3 cpp client will return all keys that matched the given prefix
recursively.
```c++
etcd.set("/test/key1", "value1").wait();
etcd.set("/test/key2", "value2").wait();
etcd.set("/test/key3", "value3").wait();
etcd.set("/test/subdir/foo", "foo").wait();
etcd::Response resp = etcd.ls("/test/new_dir").get();
```

```resp.key()``` will have the following values:

```
/test/key1
/test/key2
/test/key3
/test/subdir/foo
```

Note: Regarding the returned keys when listing a directory:

+ In etcdv3 cpp client, resp.key(0) will return "/test/new_dir/key1" since everything is
treated as keys in etcdv3.
+ While in etcdv2 cpp client it will return "key1" and "/test/new_dir" directory should
be created first before you can set "key1".

When you list a directory the response object's `keys()` and `values()` methods gives
you a vector of key names and values. The `value()` method with an integer parameter also
returns with the i-th element of the values vector, so `response.values()[i] == response.value(i)`.

```c++
etcd::Client etcd("http://127.0.0.1:2379");
etcd::Response resp = etcd.ls("/test/new_dir").get();
for (int i = 0; i < resp.keys().size(); ++i)
{
std::cout << resp.keys(i);
std::cout << " = " << resp.value(i).as_string() << std::endl;
}
```
etcd-cpp-apiv3 supports lists keys only without fetching values from etcd server:
```c++
etcd::Client etcd("http://127.0.0.1:2379");
etcd::Response resp = etcd.keys("/test/new_dir").get();
for (int i = 0; i < resp.keys().size(); ++i)
{
std::cout << resp.keys(i);
}
```
Listing directory in etcd3 cpp client will return all keys that matched the given prefix
recursively.
```c++
etcd.set("/test/key1", "value1").wait();
etcd.set("/test/key2", "value2").wait();
etcd.set("/test/key3", "value3").wait();
etcd.set("/test/subdir/foo", "foo").wait();
etcd::Response resp = etcd.ls("/test").get();
```

`resp.key()` will have the following values:

```
/test/key1s
/test/key2
/test/key3
/test/subdir/foo
```

Note: Regarding the returned keys when listing a directory:

+ In etcdv3 cpp client, resp.key(0) will return "/test/new_dir/key1" since everything is
treated as keys in etcdv3.
+ While in etcdv2 cpp client it will return "key1" and "/test/new_dir" directory should
be created first before you can set "key1".

When you list a directory the response object's `keys()` and `values()` methods gives
you a vector of key names and values. The `value()` method with an integer parameter also
returns with the i-th element of the values vector, so `response.values()[i] == response.value(i)`.

```c++
etcd::Client etcd("http://127.0.0.1:2379");
etcd::Response resp = etcd.ls("/test/new_dir").get();
for (int i = 0; i < resp.keys().size(); ++i)
{
std::cout << resp.keys(i);
std::cout << " = " << resp.value(i).as_string() << std::endl;
}
```
etcd-cpp-apiv3 supports lists keys only without fetching values from etcd server:
```c++
etcd::Client etcd("http://127.0.0.1:2379");
etcd::Response resp = etcd.keys("/test/new_dir").get();
for (int i = 0; i < resp.keys().size(); ++i)
{
std::cout << resp.keys(i);
}
```

3. Removing directory:

Expand Down

0 comments on commit fcc5807

Please sign in to comment.