Add "limit" support on "ls" command.
Signed-off-by: Tao He <linzhu.ht@alibaba-inc.com>
This commit is contained in:
parent
b3f6b826cd
commit
fa30281a19
|
|
@ -157,6 +157,15 @@ namespace etcd
|
|||
pplx::task<Response> ls(std::string const & key);
|
||||
|
||||
|
||||
/**
|
||||
* Gets a directory listing of the directory identified by the key.
|
||||
* @param key is the key to be listed
|
||||
* @param limit is the size limit of results to be listed, we don't use default parameters
|
||||
* to ensure backwards binary compatibility.
|
||||
*/
|
||||
pplx::task<Response> ls(std::string const & key, size_t const limit);
|
||||
|
||||
|
||||
/**
|
||||
* Removes a directory node. Fails if the parent directory dos not exists or not a directory.
|
||||
* @param key is the directory to be created to be listed
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ namespace etcdv3
|
|||
int old_revision;
|
||||
int64_t lease_id;
|
||||
int ttl;
|
||||
int limit;
|
||||
std::string key;
|
||||
std::string value;
|
||||
std::string old_value;
|
||||
|
|
|
|||
|
|
@ -339,6 +339,18 @@ pplx::task<etcd::Response> etcd::Client::ls(std::string const & key)
|
|||
etcdv3::ActionParameters params;
|
||||
params.key.assign(key);
|
||||
params.withPrefix = true;
|
||||
params.limit = 0; // default no limit.
|
||||
params.kv_stub = stub_.get();
|
||||
std::shared_ptr<etcdv3::AsyncGetAction> call(new etcdv3::AsyncGetAction(params));
|
||||
return Response::create(call);
|
||||
}
|
||||
|
||||
pplx::task<etcd::Response> etcd::Client::ls(std::string const & key, size_t const limit)
|
||||
{
|
||||
etcdv3::ActionParameters params;
|
||||
params.key.assign(key);
|
||||
params.withPrefix = true;
|
||||
params.limit = limit;
|
||||
params.kv_stub = stub_.get();
|
||||
std::shared_ptr<etcdv3::AsyncGetAction> call(new etcdv3::AsyncGetAction(params));
|
||||
return Response::create(call);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ etcdv3::AsyncGetAction::AsyncGetAction(etcdv3::ActionParameters param)
|
|||
{
|
||||
RangeRequest get_request;
|
||||
get_request.set_key(parameters.key);
|
||||
get_request.set_limit(param.limit);
|
||||
if(parameters.withPrefix)
|
||||
{
|
||||
std::string range_end(parameters.key);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ void etcdv3::AsyncRangeResponse::ParseResponse(RangeResponse& resp, bool prefix)
|
|||
{
|
||||
action = etcdv3::GET_ACTION;
|
||||
index = resp.header().revision();
|
||||
if(resp.kvs_size() == 0)
|
||||
if(resp.kvs_size() == 0 && !prefix)
|
||||
{
|
||||
error_code=100;
|
||||
error_message="Key not found";
|
||||
|
|
|
|||
Loading…
Reference in New Issue