google_cloud_redis_v1/client.rs
1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Code generated by sidekick. DO NOT EDIT.
16#![allow(rustdoc::redundant_explicit_links)]
17#![allow(rustdoc::broken_intra_doc_links)]
18
19/// Implements a client for the Google Cloud Memorystore for Redis API.
20///
21/// # Example
22/// ```
23/// # tokio_test::block_on(async {
24/// # use google_cloud_redis_v1::client::CloudRedis;
25/// let client = CloudRedis::builder().build().await?;
26/// // use `client` to make requests to the Google Cloud Memorystore for Redis API.
27/// # gax::client_builder::Result::<()>::Ok(()) });
28/// ```
29///
30/// # Service Description
31///
32/// Configures and manages Cloud Memorystore for Redis instances
33///
34/// Google Cloud Memorystore for Redis v1
35///
36/// The `redis.googleapis.com` service implements the Google Cloud Memorystore
37/// for Redis API and defines the following resource model for managing Redis
38/// instances:
39///
40/// * The service works with a collection of cloud projects, named: `/projects/*`
41/// * Each project has a collection of available locations, named: `/locations/*`
42/// * Each location has a collection of Redis instances, named: `/instances/*`
43/// * As such, Redis instances are resources of the form:
44/// `/projects/{project_id}/locations/{location_id}/instances/{instance_id}`
45///
46/// Note that location_id must be referring to a GCP `region`; for example:
47///
48/// * `projects/redpepper-1290/locations/us-central1/instances/my-redis`
49///
50/// # Configuration
51///
52/// To configure `CloudRedis` use the `with_*` methods in the type returned
53/// by [builder()][CloudRedis::builder]. The default configuration should
54/// work for most applications. Common configuration changes include
55///
56/// * [with_endpoint()]: by default this client uses the global default endpoint
57/// (`https://redis.googleapis.com`). Applications using regional
58/// endpoints or running in restricted networks (e.g. a network configured
59// with [Private Google Access with VPC Service Controls]) may want to
60/// override this default.
61/// * [with_credentials()]: by default this client uses
62/// [Application Default Credentials]. Applications using custom
63/// authentication may need to override this default.
64///
65/// [with_endpoint()]: super::builder::cloud_redis::ClientBuilder::with_endpoint
66/// [with_credentials()]: super::builder::cloud_redis::ClientBuilder::credentials
67/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
68/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
69///
70/// # Pooling and Cloning
71///
72/// `CloudRedis` holds a connection pool internally, it is advised to
73/// create one and the reuse it. You do not need to wrap `CloudRedis` in
74/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
75/// already uses an `Arc` internally.
76#[derive(Clone, Debug)]
77pub struct CloudRedis {
78 inner: std::sync::Arc<dyn super::stub::dynamic::CloudRedis>,
79}
80
81impl CloudRedis {
82 /// Returns a builder for [CloudRedis].
83 ///
84 /// ```
85 /// # tokio_test::block_on(async {
86 /// # use google_cloud_redis_v1::client::CloudRedis;
87 /// let client = CloudRedis::builder().build().await?;
88 /// # gax::client_builder::Result::<()>::Ok(()) });
89 /// ```
90 pub fn builder() -> super::builder::cloud_redis::ClientBuilder {
91 gax::client_builder::internal::new_builder(super::builder::cloud_redis::client::Factory)
92 }
93
94 /// Creates a new client from the provided stub.
95 ///
96 /// The most common case for calling this function is in tests mocking the
97 /// client's behavior.
98 pub fn from_stub<T>(stub: T) -> Self
99 where
100 T: super::stub::CloudRedis + 'static,
101 {
102 Self {
103 inner: std::sync::Arc::new(stub),
104 }
105 }
106
107 pub(crate) async fn new(
108 config: gaxi::options::ClientConfig,
109 ) -> gax::client_builder::Result<Self> {
110 let inner = Self::build_inner(config).await?;
111 Ok(Self { inner })
112 }
113
114 async fn build_inner(
115 conf: gaxi::options::ClientConfig,
116 ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::CloudRedis>> {
117 if gaxi::options::tracing_enabled(&conf) {
118 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
119 }
120 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
121 }
122
123 async fn build_transport(
124 conf: gaxi::options::ClientConfig,
125 ) -> gax::client_builder::Result<impl super::stub::CloudRedis> {
126 super::transport::CloudRedis::new(conf).await
127 }
128
129 async fn build_with_tracing(
130 conf: gaxi::options::ClientConfig,
131 ) -> gax::client_builder::Result<impl super::stub::CloudRedis> {
132 Self::build_transport(conf)
133 .await
134 .map(super::tracing::CloudRedis::new)
135 }
136
137 /// Lists all Redis instances owned by a project in either the specified
138 /// location (region) or all locations.
139 ///
140 /// The location should have the following format:
141 ///
142 /// * `projects/{project_id}/locations/{location_id}`
143 ///
144 /// If `location_id` is specified as `-` (wildcard), then all regions
145 /// available to the project are queried, and the results are aggregated.
146 pub fn list_instances(&self) -> super::builder::cloud_redis::ListInstances {
147 super::builder::cloud_redis::ListInstances::new(self.inner.clone())
148 }
149
150 /// Gets the details of a specific Redis instance.
151 pub fn get_instance(&self) -> super::builder::cloud_redis::GetInstance {
152 super::builder::cloud_redis::GetInstance::new(self.inner.clone())
153 }
154
155 /// Gets the AUTH string for a Redis instance. If AUTH is not enabled for the
156 /// instance the response will be empty. This information is not included in
157 /// the details returned to GetInstance.
158 pub fn get_instance_auth_string(&self) -> super::builder::cloud_redis::GetInstanceAuthString {
159 super::builder::cloud_redis::GetInstanceAuthString::new(self.inner.clone())
160 }
161
162 /// Creates a Redis instance based on the specified tier and memory size.
163 ///
164 /// By default, the instance is accessible from the project's
165 /// [default network](https://cloud.google.com/vpc/docs/vpc).
166 ///
167 /// The creation is executed asynchronously and callers may check the returned
168 /// operation to track its progress. Once the operation is completed the Redis
169 /// instance will be fully functional. Completed longrunning.Operation will
170 /// contain the new instance object in the response field.
171 ///
172 /// The returned operation is automatically deleted after a few hours, so there
173 /// is no need to call DeleteOperation.
174 ///
175 /// # Long running operations
176 ///
177 /// This method is used to start, and/or poll a [long-running Operation].
178 /// The [Working with long-running operations] chapter in the [user guide]
179 /// covers these operations in detail.
180 ///
181 /// [long-running operation]: https://google.aip.dev/151
182 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
183 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
184 pub fn create_instance(&self) -> super::builder::cloud_redis::CreateInstance {
185 super::builder::cloud_redis::CreateInstance::new(self.inner.clone())
186 }
187
188 /// Updates the metadata and configuration of a specific Redis instance.
189 ///
190 /// Completed longrunning.Operation will contain the new instance object
191 /// in the response field. The returned operation is automatically deleted
192 /// after a few hours, so there is no need to call DeleteOperation.
193 ///
194 /// # Long running operations
195 ///
196 /// This method is used to start, and/or poll a [long-running Operation].
197 /// The [Working with long-running operations] chapter in the [user guide]
198 /// covers these operations in detail.
199 ///
200 /// [long-running operation]: https://google.aip.dev/151
201 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
202 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
203 pub fn update_instance(&self) -> super::builder::cloud_redis::UpdateInstance {
204 super::builder::cloud_redis::UpdateInstance::new(self.inner.clone())
205 }
206
207 /// Upgrades Redis instance to the newer Redis version specified in the
208 /// request.
209 ///
210 /// # Long running operations
211 ///
212 /// This method is used to start, and/or poll a [long-running Operation].
213 /// The [Working with long-running operations] chapter in the [user guide]
214 /// covers these operations in detail.
215 ///
216 /// [long-running operation]: https://google.aip.dev/151
217 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
218 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
219 pub fn upgrade_instance(&self) -> super::builder::cloud_redis::UpgradeInstance {
220 super::builder::cloud_redis::UpgradeInstance::new(self.inner.clone())
221 }
222
223 /// Import a Redis RDB snapshot file from Cloud Storage into a Redis instance.
224 ///
225 /// Redis may stop serving during this operation. Instance state will be
226 /// IMPORTING for entire operation. When complete, the instance will contain
227 /// only data from the imported file.
228 ///
229 /// The returned operation is automatically deleted after a few hours, so
230 /// there is no need to call DeleteOperation.
231 ///
232 /// # Long running operations
233 ///
234 /// This method is used to start, and/or poll a [long-running Operation].
235 /// The [Working with long-running operations] chapter in the [user guide]
236 /// covers these operations in detail.
237 ///
238 /// [long-running operation]: https://google.aip.dev/151
239 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
240 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
241 pub fn import_instance(&self) -> super::builder::cloud_redis::ImportInstance {
242 super::builder::cloud_redis::ImportInstance::new(self.inner.clone())
243 }
244
245 /// Export Redis instance data into a Redis RDB format file in Cloud Storage.
246 ///
247 /// Redis will continue serving during this operation.
248 ///
249 /// The returned operation is automatically deleted after a few hours, so
250 /// there is no need to call DeleteOperation.
251 ///
252 /// # Long running operations
253 ///
254 /// This method is used to start, and/or poll a [long-running Operation].
255 /// The [Working with long-running operations] chapter in the [user guide]
256 /// covers these operations in detail.
257 ///
258 /// [long-running operation]: https://google.aip.dev/151
259 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
260 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
261 pub fn export_instance(&self) -> super::builder::cloud_redis::ExportInstance {
262 super::builder::cloud_redis::ExportInstance::new(self.inner.clone())
263 }
264
265 /// Initiates a failover of the primary node to current replica node for a
266 /// specific STANDARD tier Cloud Memorystore for Redis instance.
267 ///
268 /// # Long running operations
269 ///
270 /// This method is used to start, and/or poll a [long-running Operation].
271 /// The [Working with long-running operations] chapter in the [user guide]
272 /// covers these operations in detail.
273 ///
274 /// [long-running operation]: https://google.aip.dev/151
275 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
276 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
277 pub fn failover_instance(&self) -> super::builder::cloud_redis::FailoverInstance {
278 super::builder::cloud_redis::FailoverInstance::new(self.inner.clone())
279 }
280
281 /// Deletes a specific Redis instance. Instance stops serving and data is
282 /// deleted.
283 ///
284 /// # Long running operations
285 ///
286 /// This method is used to start, and/or poll a [long-running Operation].
287 /// The [Working with long-running operations] chapter in the [user guide]
288 /// covers these operations in detail.
289 ///
290 /// [long-running operation]: https://google.aip.dev/151
291 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
292 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
293 pub fn delete_instance(&self) -> super::builder::cloud_redis::DeleteInstance {
294 super::builder::cloud_redis::DeleteInstance::new(self.inner.clone())
295 }
296
297 /// Reschedule maintenance for a given instance in a given project and
298 /// location.
299 ///
300 /// # Long running operations
301 ///
302 /// This method is used to start, and/or poll a [long-running Operation].
303 /// The [Working with long-running operations] chapter in the [user guide]
304 /// covers these operations in detail.
305 ///
306 /// [long-running operation]: https://google.aip.dev/151
307 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
308 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
309 pub fn reschedule_maintenance(&self) -> super::builder::cloud_redis::RescheduleMaintenance {
310 super::builder::cloud_redis::RescheduleMaintenance::new(self.inner.clone())
311 }
312
313 /// Lists information about the supported locations for this service.
314 pub fn list_locations(&self) -> super::builder::cloud_redis::ListLocations {
315 super::builder::cloud_redis::ListLocations::new(self.inner.clone())
316 }
317
318 /// Gets information about a location.
319 pub fn get_location(&self) -> super::builder::cloud_redis::GetLocation {
320 super::builder::cloud_redis::GetLocation::new(self.inner.clone())
321 }
322
323 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
324 ///
325 /// [google.longrunning.Operations]: longrunning::client::Operations
326 pub fn list_operations(&self) -> super::builder::cloud_redis::ListOperations {
327 super::builder::cloud_redis::ListOperations::new(self.inner.clone())
328 }
329
330 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
331 ///
332 /// [google.longrunning.Operations]: longrunning::client::Operations
333 pub fn get_operation(&self) -> super::builder::cloud_redis::GetOperation {
334 super::builder::cloud_redis::GetOperation::new(self.inner.clone())
335 }
336
337 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
338 ///
339 /// [google.longrunning.Operations]: longrunning::client::Operations
340 pub fn delete_operation(&self) -> super::builder::cloud_redis::DeleteOperation {
341 super::builder::cloud_redis::DeleteOperation::new(self.inner.clone())
342 }
343
344 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
345 ///
346 /// [google.longrunning.Operations]: longrunning::client::Operations
347 pub fn cancel_operation(&self) -> super::builder::cloud_redis::CancelOperation {
348 super::builder::cloud_redis::CancelOperation::new(self.inner.clone())
349 }
350}