Fixes several typos in REAEMD.
Fixes #63. Signed-off-by: Tao He <sighingnow@gmail.com>
This commit is contained in:
parent
230ebfd08b
commit
b3a193c75e
36
README.md
36
README.md
|
|
@ -9,7 +9,7 @@ i.e., `ETCDCTL_API=3`.
|
||||||
### Supported OS environments
|
### Supported OS environments
|
||||||
|
|
||||||
+ **Linux**
|
+ **Linux**
|
||||||
- Ubuntu 18.04, requires upgrade grpc libraries (has been tested with 1.27.x).
|
- Ubuntu 18.04, requires upgrade gRPC libraries (has been tested with 1.27.x).
|
||||||
- Ubuntu 20.04
|
- Ubuntu 20.04
|
||||||
+ **MacOS**
|
+ **MacOS**
|
||||||
- MacOS 10.15
|
- MacOS 10.15
|
||||||
|
|
@ -85,11 +85,11 @@ Github when you encounter problems when working with etcd 3.x releases.
|
||||||
```
|
```
|
||||||
|
|
||||||
Methods of the etcd client object are sending the corresponding gRPC requests and are returning
|
Methods of the etcd client object are sending the corresponding gRPC requests and are returning
|
||||||
immediatelly with a ```pplx::task``` object. The task object is responsible for handling the
|
immediately with a ```pplx::task``` object. The task object is responsible for handling the
|
||||||
reception of the HTTP response as well as parsing the gRPC of the response. All of this is done
|
reception of the HTTP response as well as parsing the gRPC of the response. All of this is done
|
||||||
asynchronously in a background thread so you can continue your code to do other operations while the
|
asynchronously in a background thread so you can continue your code to do other operations while the
|
||||||
current etcd operation is executing in the background or you can wait for the response with the
|
current etcd operation is executing in the background or you can wait for the response with the
|
||||||
```wait()``` or ```get()``` methods if a synchron behaviour is enough for your needs. These methods
|
```wait()``` or ```get()``` methods if a synchronous behavior is enough for your needs. These methods
|
||||||
are blocking until the HTTP response arrives or some error situation happens. ```get()``` method
|
are blocking until the HTTP response arrives or some error situation happens. ```get()``` method
|
||||||
also returns the ```etcd::Response``` object.
|
also returns the ```etcd::Response``` object.
|
||||||
|
|
||||||
|
|
@ -101,12 +101,12 @@ also returns the ```etcd::Response``` object.
|
||||||
std::cout << response.value().as_string();
|
std::cout << response.value().as_string();
|
||||||
```
|
```
|
||||||
|
|
||||||
The pplx library allows to do even more. You can attach continuation ojects to the task if you do
|
The pplx library allows to do even more. You can attach continuation objects to the task if you do
|
||||||
not care about when the response is coming you only want to specify what to do then. This
|
not care about when the response is coming you only want to specify what to do then. This
|
||||||
can be achieved by calling the ```then``` method of the task, giving a funcion object parameter to
|
can be achieved by calling the ```then``` method of the task, giving a function object parameter to
|
||||||
it that can be used as a callback when the response is arrived and processed. The parameter of this
|
it that can be used as a callback when the response is arrived and processed. The parameter of this
|
||||||
callback should be either a ```etcd::Response``` or a ```pplx::task<etcd:Response>```. You should
|
callback should be either a ```etcd::Response``` or a ```pplx::task<etcd:Response>```. You should
|
||||||
probably use a C++ lambda funcion here as a callback.
|
probably use a C++ lambda function here as a callback.
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
etcd::Client etcd("http://127.0.0.1:4001");
|
etcd::Client etcd("http://127.0.0.1:4001");
|
||||||
|
|
@ -120,9 +120,9 @@ probably use a C++ lambda funcion here as a callback.
|
||||||
|
|
||||||
Your lambda function should have a parameter of type ```etcd::Response``` or
|
Your lambda function should have a parameter of type ```etcd::Response``` or
|
||||||
```pplx::task<etcd::Response>```. In the latter case you can get the actual ```etcd::Response```
|
```pplx::task<etcd::Response>```. In the latter case you can get the actual ```etcd::Response```
|
||||||
object with the ```get()``` function of the task. Calling get can raise exeptions so this is the way
|
object with the ```get()``` function of the task. Calling get can raise exceptions so this is the way
|
||||||
how you can catch the errors generated by the REST interface. The ```get()``` call will not block in
|
how you can catch the errors generated by the REST interface. The ```get()``` call will not block in
|
||||||
this case since the respose has been already arrived (we are inside the callback).
|
this case since the response has been already arrived (we are inside the callback).
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
etcd::Client etcd("http://127.0.0.1:4001");
|
etcd::Client etcd("http://127.0.0.1:4001");
|
||||||
|
|
@ -133,7 +133,7 @@ this case since the respose has been already arrived (we are inside the callback
|
||||||
etcd::Response response = response_task.get(); // can throw
|
etcd::Response response = response_task.get(); // can throw
|
||||||
std::cout << response.value().as_string();
|
std::cout << response.value().as_string();
|
||||||
}
|
}
|
||||||
catch (std::ecxeption const & ex)
|
catch (std::exception const & ex)
|
||||||
{
|
{
|
||||||
std::cerr << ex.what();
|
std::cerr << ex.what();
|
||||||
}
|
}
|
||||||
|
|
@ -171,7 +171,7 @@ the authentication properly.
|
||||||
etcd::Client etcd("http://127.0.0.1:2379", "root", "root");
|
etcd::Client etcd("http://127.0.0.1:2379", "root", "root");
|
||||||
```
|
```
|
||||||
|
|
||||||
Or the etcd client can be constructed explictly:
|
Or the etcd client can be constructed explicitly:
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
etcd::Client *etcd = etcd::Client::WithUser(
|
etcd::Client *etcd = etcd::Client::WithUser(
|
||||||
|
|
@ -214,7 +214,7 @@ arguments when launching etcd server).
|
||||||
"round_robin");
|
"round_robin");
|
||||||
```
|
```
|
||||||
|
|
||||||
Or the etcd client can be constructed explictly:
|
Or the etcd client can be constructed explicitly:
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
etcd::Client *etcd = etcd::Client::WithSSL(
|
etcd::Client *etcd = etcd::Client::WithSSL(
|
||||||
|
|
@ -238,7 +238,7 @@ We also provide a tool [`setup-ca.sh`](./security-config/setup-ca.sh) as a helpe
|
||||||
|
|
||||||
### Reading a value
|
### Reading a value
|
||||||
|
|
||||||
You can read a value with the ```get``` method of the clinent instance. The only parameter is the
|
You can read a value with the ```get``` method of the client instance. The only parameter is the
|
||||||
key to be read. If the read operation is successful then the value of the key can be acquired with
|
key to be read. If the read operation is successful then the value of the key can be acquired with
|
||||||
the ```value()``` method of the response. Success of the operation can be checked with the
|
the ```value()``` method of the response. Success of the operation can be checked with the
|
||||||
```is_ok()``` method of the response. In case of an error, the ```error_code()``` and
|
```is_ok()``` method of the response. In case of an error, the ```error_code()``` and
|
||||||
|
|
@ -247,12 +247,12 @@ the ```value()``` method of the response. Success of the operation can be checke
|
||||||
Please note that there can be two kind of error situations. There can be some problem with the
|
Please note that there can be two kind of error situations. There can be some problem with the
|
||||||
communication between the client and the etcd server. In this case the ```get()``` method of the
|
communication between the client and the etcd server. In this case the ```get()``` method of the
|
||||||
response task will throw an exception as shown above. If the communication is ok but there is some
|
response task will throw an exception as shown above. If the communication is ok but there is some
|
||||||
problem with the content of the actual operation, like attemp to read a non-existing key then the
|
problem with the content of the actual operation, like attempting to read a non-existing key then the
|
||||||
response object will give you all the details. Let's see this in an example.
|
response object will give you all the details. Let's see this in an example.
|
||||||
|
|
||||||
The Value object of the response also holds some extra information besides the string value of the
|
The Value object of the response also holds some extra information besides the string value of the
|
||||||
key. You can also get the index number of the creation and the last modification of this key with
|
key. You can also get the index number of the creation and the last modification of this key with
|
||||||
the ```created_index()``` and the ```modofied_index()``` methods.
|
the ```created_index()``` and the ```modified_index()``` methods.
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
etcd::Client etcd("http://127.0.0.1:4001");
|
etcd::Client etcd("http://127.0.0.1:4001");
|
||||||
|
|
@ -266,7 +266,7 @@ the ```created_index()``` and the ```modofied_index()``` methods.
|
||||||
else
|
else
|
||||||
std::cout << "operation failed, details: " << response.error_message();
|
std::cout << "operation failed, details: " << response.error_message();
|
||||||
}
|
}
|
||||||
catch (std::ecxeption const & ex)
|
catch (std::exception const & ex)
|
||||||
{
|
{
|
||||||
std::cerr << "communication problem, details: " << ex.what();
|
std::cerr << "communication problem, details: " << ex.what();
|
||||||
}
|
}
|
||||||
|
|
@ -469,7 +469,7 @@ void watch_for_changes()
|
||||||
```
|
```
|
||||||
|
|
||||||
At first glance it seems that ```watch_for_changes()``` calls itself on every value change but in
|
At first glance it seems that ```watch_for_changes()``` calls itself on every value change but in
|
||||||
fact it just sends the asynchron request, sets up a callback for the response and then returns. The
|
fact it just sends the asynchronous request, sets up a callback for the response and then returns. The
|
||||||
callback is executed by some thread from the pplx library's thread pool and the callback (in this
|
callback is executed by some thread from the pplx library's thread pool and the callback (in this
|
||||||
case a small lambda function actually) will call ```watch_for_changes``` again from there.
|
case a small lambda function actually) will call ```watch_for_changes``` again from there.
|
||||||
|
|
||||||
|
|
@ -526,13 +526,13 @@ The remaining time-to-live of a lease can be inspected by
|
||||||
|
|
||||||
#### Keep alive
|
#### Keep alive
|
||||||
|
|
||||||
Keep alive for leases is implemented using a seperate class `KeepAlive`, which can be used as:
|
Keep alive for leases is implemented using a separate class `KeepAlive`, which can be used as:
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
etcd::KeepAlive keepalive(etcd, ttl, lease_id);
|
etcd::KeepAlive keepalive(etcd, ttl, lease_id);
|
||||||
```
|
```
|
||||||
|
|
||||||
It will perform a periodly keep-alive action before it is cancelled explicitly, or destructed implicitly.
|
It will perform a period keep-alive action before it is cancelled explicitly, or destructed implicitly.
|
||||||
|
|
||||||
`KeepAlive` may fails (e.g., when the etcd server stopped unexpectedly), the constructor of `KeepAlive`
|
`KeepAlive` may fails (e.g., when the etcd server stopped unexpectedly), the constructor of `KeepAlive`
|
||||||
could accept a handler of type `std::function<std::exception_ptr>` and the handler will be invoked
|
could accept a handler of type `std::function<std::exception_ptr>` and the handler will be invoked
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue