Struct etcd_client::Client
source · pub struct Client { /* private fields */ }
Expand description
Asynchronous etcd
client using v3 API.
Implementations§
source§impl Client
impl Client
sourcepub async fn connect<E: AsRef<str>, S: AsRef<[E]>>(
endpoints: S,
options: Option<ConnectOptions>,
) -> Result<Self, Error>
pub async fn connect<E: AsRef<str>, S: AsRef<[E]>>( endpoints: S, options: Option<ConnectOptions>, ) -> Result<Self, Error>
Connect to etcd
servers from given endpoints
.
sourcepub async fn add_endpoint<E: AsRef<str>>(
&self,
endpoint: E,
) -> Result<(), Error>
pub async fn add_endpoint<E: AsRef<str>>( &self, endpoint: E, ) -> Result<(), Error>
Dynamically add an endpoint to the client.
Which can be used to add a new member to the underlying balance cache. The typical scenario is that application can use a services discovery to discover the member list changes and add/remove them to/from the client.
Note that the Client
doesn’t check the authentication before added.
So the etcd member of the added endpoint REQUIRES to use the same auth
token as when create the client. Otherwise, the underlying balance
services will not be able to connect to the new endpoint.
sourcepub async fn remove_endpoint<E: AsRef<str>>(
&self,
endpoint: E,
) -> Result<(), Error>
pub async fn remove_endpoint<E: AsRef<str>>( &self, endpoint: E, ) -> Result<(), Error>
Dynamically remove an endpoint from the client.
Note that the endpoint
str should be the same as it was added.
And the underlying balance services cache used the hash from the Uri,
which was parsed from endpoint
str, to do the equality comparisons.
sourcepub fn watch_client(&self) -> WatchClient
pub fn watch_client(&self) -> WatchClient
Gets a watch client.
sourcepub fn lease_client(&self) -> LeaseClient
pub fn lease_client(&self) -> LeaseClient
Gets a lease client.
sourcepub fn auth_client(&self) -> AuthClient
pub fn auth_client(&self) -> AuthClient
Gets an auth client.
sourcepub fn maintenance_client(&self) -> MaintenanceClient
pub fn maintenance_client(&self) -> MaintenanceClient
Gets a maintenance client.
sourcepub fn cluster_client(&self) -> ClusterClient
pub fn cluster_client(&self) -> ClusterClient
Gets a cluster client.
sourcepub fn lock_client(&self) -> LockClient
pub fn lock_client(&self) -> LockClient
Gets a lock client.
sourcepub fn election_client(&self) -> ElectionClient
pub fn election_client(&self) -> ElectionClient
Gets a election client.
sourcepub async fn put(
&mut self,
key: impl Into<Vec<u8>>,
value: impl Into<Vec<u8>>,
options: Option<PutOptions>,
) -> Result<PutResponse, Error>
pub async fn put( &mut self, key: impl Into<Vec<u8>>, value: impl Into<Vec<u8>>, options: Option<PutOptions>, ) -> Result<PutResponse, Error>
Put the given key into the key-value store. A put request increments the revision of the key-value store and generates one event in the event history.
sourcepub async fn get(
&mut self,
key: impl Into<Vec<u8>>,
options: Option<GetOptions>,
) -> Result<GetResponse, Error>
pub async fn get( &mut self, key: impl Into<Vec<u8>>, options: Option<GetOptions>, ) -> Result<GetResponse, Error>
Gets the key from the key-value store.
sourcepub async fn delete(
&mut self,
key: impl Into<Vec<u8>>,
options: Option<DeleteOptions>,
) -> Result<DeleteResponse, Error>
pub async fn delete( &mut self, key: impl Into<Vec<u8>>, options: Option<DeleteOptions>, ) -> Result<DeleteResponse, Error>
Deletes the given key from the key-value store.
sourcepub async fn compact(
&mut self,
revision: i64,
options: Option<CompactionOptions>,
) -> Result<CompactionResponse, Error>
pub async fn compact( &mut self, revision: i64, options: Option<CompactionOptions>, ) -> Result<CompactionResponse, Error>
Compacts the event history in the etcd key-value store. The key-value store should be periodically compacted or the event history will continue to grow indefinitely.
sourcepub async fn txn(&mut self, txn: Txn) -> Result<TxnResponse, Error>
pub async fn txn(&mut self, txn: Txn) -> Result<TxnResponse, Error>
Processes multiple operations in a single transaction. A txn request increments the revision of the key-value store and generates events with the same revision for every completed operation. It is not allowed to modify the same key several times within one txn.
sourcepub async fn watch(
&mut self,
key: impl Into<Vec<u8>>,
options: Option<WatchOptions>,
) -> Result<(Watcher, WatchStream), Error>
pub async fn watch( &mut self, key: impl Into<Vec<u8>>, options: Option<WatchOptions>, ) -> Result<(Watcher, WatchStream), Error>
Watches for events happening or that have happened. Both input and output are streams; the input stream is for creating and canceling watcher and the output stream sends events. The entire event history can be watched starting from the last compaction revision.
sourcepub async fn lease_grant(
&mut self,
ttl: i64,
options: Option<LeaseGrantOptions>,
) -> Result<LeaseGrantResponse, Error>
pub async fn lease_grant( &mut self, ttl: i64, options: Option<LeaseGrantOptions>, ) -> Result<LeaseGrantResponse, Error>
Creates a lease which expires if the server does not receive a keepAlive within a given time to live period. All keys attached to the lease will be expired and deleted if the lease expires. Each expired key generates a delete event in the event history.
sourcepub async fn lease_revoke(
&mut self,
id: i64,
) -> Result<LeaseRevokeResponse, Error>
pub async fn lease_revoke( &mut self, id: i64, ) -> Result<LeaseRevokeResponse, Error>
Revokes a lease. All keys attached to the lease will expire and be deleted.
sourcepub async fn lease_keep_alive(
&mut self,
id: i64,
) -> Result<(LeaseKeeper, LeaseKeepAliveStream), Error>
pub async fn lease_keep_alive( &mut self, id: i64, ) -> Result<(LeaseKeeper, LeaseKeepAliveStream), Error>
Keeps the lease alive by streaming keep alive requests from the client to the server and streaming keep alive responses from the server to the client.
sourcepub async fn lease_time_to_live(
&mut self,
id: i64,
options: Option<LeaseTimeToLiveOptions>,
) -> Result<LeaseTimeToLiveResponse, Error>
pub async fn lease_time_to_live( &mut self, id: i64, options: Option<LeaseTimeToLiveOptions>, ) -> Result<LeaseTimeToLiveResponse, Error>
Retrieves lease information.
sourcepub async fn leases(&mut self) -> Result<LeaseLeasesResponse, Error>
pub async fn leases(&mut self) -> Result<LeaseLeasesResponse, Error>
Lists all existing leases.
sourcepub async fn lock(
&mut self,
name: impl Into<Vec<u8>>,
options: Option<LockOptions>,
) -> Result<LockResponse, Error>
pub async fn lock( &mut self, name: impl Into<Vec<u8>>, options: Option<LockOptions>, ) -> Result<LockResponse, Error>
Lock acquires a distributed shared lock on a given named lock. On success, it will return a unique key that exists so long as the lock is held by the caller. This key can be used in conjunction with transactions to safely ensure updates to etcd only occur while holding lock ownership. The lock is held until Unlock is called on the key or the lease associate with the owner expires.
sourcepub async fn unlock(
&mut self,
key: impl Into<Vec<u8>>,
) -> Result<UnlockResponse, Error>
pub async fn unlock( &mut self, key: impl Into<Vec<u8>>, ) -> Result<UnlockResponse, Error>
Unlock takes a key returned by Lock and releases the hold on lock. The next Lock caller waiting for the lock will then be woken up and given ownership of the lock.
sourcepub async fn auth_enable(&mut self) -> Result<AuthEnableResponse, Error>
pub async fn auth_enable(&mut self) -> Result<AuthEnableResponse, Error>
Enables authentication.
sourcepub async fn auth_disable(&mut self) -> Result<AuthDisableResponse, Error>
pub async fn auth_disable(&mut self) -> Result<AuthDisableResponse, Error>
Disables authentication.
sourcepub async fn role_add(
&mut self,
name: impl Into<String>,
) -> Result<RoleAddResponse, Error>
pub async fn role_add( &mut self, name: impl Into<String>, ) -> Result<RoleAddResponse, Error>
Adds role.
sourcepub async fn role_delete(
&mut self,
name: impl Into<String>,
) -> Result<RoleDeleteResponse, Error>
pub async fn role_delete( &mut self, name: impl Into<String>, ) -> Result<RoleDeleteResponse, Error>
Deletes role.
sourcepub async fn role_get(
&mut self,
name: impl Into<String>,
) -> Result<RoleGetResponse, Error>
pub async fn role_get( &mut self, name: impl Into<String>, ) -> Result<RoleGetResponse, Error>
Gets role.
sourcepub async fn role_list(&mut self) -> Result<RoleListResponse, Error>
pub async fn role_list(&mut self) -> Result<RoleListResponse, Error>
Lists role.
sourcepub async fn role_grant_permission(
&mut self,
name: impl Into<String>,
perm: Permission,
) -> Result<RoleGrantPermissionResponse, Error>
pub async fn role_grant_permission( &mut self, name: impl Into<String>, perm: Permission, ) -> Result<RoleGrantPermissionResponse, Error>
Grants role permission.
sourcepub async fn role_revoke_permission(
&mut self,
name: impl Into<String>,
key: impl Into<Vec<u8>>,
options: Option<RoleRevokePermissionOptions>,
) -> Result<RoleRevokePermissionResponse, Error>
pub async fn role_revoke_permission( &mut self, name: impl Into<String>, key: impl Into<Vec<u8>>, options: Option<RoleRevokePermissionOptions>, ) -> Result<RoleRevokePermissionResponse, Error>
Revokes role permission.
sourcepub async fn user_add(
&mut self,
name: impl Into<String>,
password: impl Into<String>,
options: Option<UserAddOptions>,
) -> Result<UserAddResponse, Error>
pub async fn user_add( &mut self, name: impl Into<String>, password: impl Into<String>, options: Option<UserAddOptions>, ) -> Result<UserAddResponse, Error>
Add an user.
sourcepub async fn user_get(
&mut self,
name: impl Into<String>,
) -> Result<UserGetResponse, Error>
pub async fn user_get( &mut self, name: impl Into<String>, ) -> Result<UserGetResponse, Error>
Gets the user info by the user name.
sourcepub async fn user_list(&mut self) -> Result<UserListResponse, Error>
pub async fn user_list(&mut self) -> Result<UserListResponse, Error>
Lists all users.
sourcepub async fn user_delete(
&mut self,
name: impl Into<String>,
) -> Result<UserDeleteResponse, Error>
pub async fn user_delete( &mut self, name: impl Into<String>, ) -> Result<UserDeleteResponse, Error>
Deletes the given key from the key-value store.
sourcepub async fn user_change_password(
&mut self,
name: impl Into<String>,
password: impl Into<String>,
) -> Result<UserChangePasswordResponse, Error>
pub async fn user_change_password( &mut self, name: impl Into<String>, password: impl Into<String>, ) -> Result<UserChangePasswordResponse, Error>
Change password for an user.
sourcepub async fn user_grant_role(
&mut self,
user: impl Into<String>,
role: impl Into<String>,
) -> Result<UserGrantRoleResponse, Error>
pub async fn user_grant_role( &mut self, user: impl Into<String>, role: impl Into<String>, ) -> Result<UserGrantRoleResponse, Error>
Grant role for an user.
sourcepub async fn user_revoke_role(
&mut self,
user: impl Into<String>,
role: impl Into<String>,
) -> Result<UserRevokeRoleResponse, Error>
pub async fn user_revoke_role( &mut self, user: impl Into<String>, role: impl Into<String>, ) -> Result<UserRevokeRoleResponse, Error>
Revoke role for an user.
sourcepub async fn alarm(
&mut self,
alarm_action: AlarmAction,
alarm_type: AlarmType,
options: Option<AlarmOptions>,
) -> Result<AlarmResponse, Error>
pub async fn alarm( &mut self, alarm_action: AlarmAction, alarm_type: AlarmType, options: Option<AlarmOptions>, ) -> Result<AlarmResponse, Error>
Maintain(get, active or inactive) alarms of members.
sourcepub async fn status(&mut self) -> Result<StatusResponse, Error>
pub async fn status(&mut self) -> Result<StatusResponse, Error>
Gets the status of a member.
sourcepub async fn defragment(&mut self) -> Result<DefragmentResponse, Error>
pub async fn defragment(&mut self) -> Result<DefragmentResponse, Error>
Defragments a member’s backend database to recover storage space.
sourcepub async fn hash(&mut self) -> Result<HashResponse, Error>
pub async fn hash(&mut self) -> Result<HashResponse, Error>
Computes the hash of whole backend keyspace. including key, lease, and other buckets in storage. This is designed for testing ONLY!
sourcepub async fn hash_kv(&mut self, revision: i64) -> Result<HashKvResponse, Error>
pub async fn hash_kv(&mut self, revision: i64) -> Result<HashKvResponse, Error>
Computes the hash of all MVCC keys up to a given revision. It only iterates "key" bucket in backend storage.
sourcepub async fn snapshot(&mut self) -> Result<SnapshotStreaming, Error>
pub async fn snapshot(&mut self) -> Result<SnapshotStreaming, Error>
Gets a snapshot of the entire backend from a member over a stream to a client.
sourcepub async fn member_add<E: AsRef<str>, S: AsRef<[E]>>(
&mut self,
urls: S,
options: Option<MemberAddOptions>,
) -> Result<MemberAddResponse, Error>
pub async fn member_add<E: AsRef<str>, S: AsRef<[E]>>( &mut self, urls: S, options: Option<MemberAddOptions>, ) -> Result<MemberAddResponse, Error>
Adds current connected server as a member.
sourcepub async fn member_remove(
&mut self,
id: u64,
) -> Result<MemberRemoveResponse, Error>
pub async fn member_remove( &mut self, id: u64, ) -> Result<MemberRemoveResponse, Error>
Remove a member.
sourcepub async fn member_update(
&mut self,
id: u64,
url: impl Into<Vec<String>>,
) -> Result<MemberUpdateResponse, Error>
pub async fn member_update( &mut self, id: u64, url: impl Into<Vec<String>>, ) -> Result<MemberUpdateResponse, Error>
Updates the member.
sourcepub async fn member_promote(
&mut self,
id: u64,
) -> Result<MemberPromoteResponse, Error>
pub async fn member_promote( &mut self, id: u64, ) -> Result<MemberPromoteResponse, Error>
Promotes the member.
sourcepub async fn member_list(&mut self) -> Result<MemberListResponse, Error>
pub async fn member_list(&mut self) -> Result<MemberListResponse, Error>
Lists members.
sourcepub async fn move_leader(
&mut self,
target_id: u64,
) -> Result<MoveLeaderResponse, Error>
pub async fn move_leader( &mut self, target_id: u64, ) -> Result<MoveLeaderResponse, Error>
Moves the current leader node to target node.
sourcepub async fn campaign(
&mut self,
name: impl Into<Vec<u8>>,
value: impl Into<Vec<u8>>,
lease: i64,
) -> Result<CampaignResponse, Error>
pub async fn campaign( &mut self, name: impl Into<Vec<u8>>, value: impl Into<Vec<u8>>, lease: i64, ) -> Result<CampaignResponse, Error>
Puts a value as eligible for the election on the prefix key. Multiple sessions can participate in the election for the same prefix, but only one can be the leader at a time.
sourcepub async fn proclaim(
&mut self,
value: impl Into<Vec<u8>>,
options: Option<ProclaimOptions>,
) -> Result<ProclaimResponse, Error>
pub async fn proclaim( &mut self, value: impl Into<Vec<u8>>, options: Option<ProclaimOptions>, ) -> Result<ProclaimResponse, Error>
Lets the leader announce a new value without another election.
sourcepub async fn leader(
&mut self,
name: impl Into<Vec<u8>>,
) -> Result<LeaderResponse, Error>
pub async fn leader( &mut self, name: impl Into<Vec<u8>>, ) -> Result<LeaderResponse, Error>
Returns the leader value for the current election.
sourcepub async fn observe(
&mut self,
name: impl Into<Vec<u8>>,
) -> Result<ObserveStream, Error>
pub async fn observe( &mut self, name: impl Into<Vec<u8>>, ) -> Result<ObserveStream, Error>
Returns a channel that reliably observes ordered leader proposals as GetResponse values on every current elected leader key.
sourcepub async fn resign(
&mut self,
option: Option<ResignOptions>,
) -> Result<ResignResponse, Error>
pub async fn resign( &mut self, option: Option<ResignOptions>, ) -> Result<ResignResponse, Error>
Releases election leadership and then start a new election
sourcepub async fn set_client_auth(
&mut self,
name: String,
password: String,
) -> Result<(), Error>
pub async fn set_client_auth( &mut self, name: String, password: String, ) -> Result<(), Error>
Sets client-side authentication.
sourcepub fn remove_client_auth(&mut self)
pub fn remove_client_auth(&mut self)
Removes client-side authentication.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request