@Generated(value="by gapic-generator") @BetaApi public class CloudRedisClient extends Object implements BackgroundResource
Google Cloud Memorystore for Redis v1beta1
The `redis.googleapis.com` service implements the Google Cloud Memorystore for Redis API and defines the following resource model for managing Redis instances: * The service works with a collection of cloud projects, named: `/projects/*` * Each project has a collection of available locations, named: `/locations/*` * Each location has a collection of Redis instances, named: `/instances/*` * As such, Redis instances are resources of the form: `/projects/{project_id}/locations/{location_id}/instances/{instance_id}`
Note that location_id must be refering to a GCP `region`; for example: * `projects/redpepper-1290/locations/us-central1/instances/my-redis`
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
Instance response = cloudRedisClient.getInstance(name);
}
Note: close() needs to be called on the cloudRedisClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of CloudRedisSettings to create(). For example:
To customize credentials:
CloudRedisSettings cloudRedisSettings =
CloudRedisSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
CloudRedisClient cloudRedisClient =
CloudRedisClient.create(cloudRedisSettings);
To customize the endpoint:
CloudRedisSettings cloudRedisSettings =
CloudRedisSettings.newBuilder().setEndpoint(myEndpoint).build();
CloudRedisClient cloudRedisClient =
CloudRedisClient.create(cloudRedisSettings);
Modifier and Type | Class and Description |
---|---|
static class |
CloudRedisClient.ListInstancesFixedSizeCollection |
static class |
CloudRedisClient.ListInstancesPage |
static class |
CloudRedisClient.ListInstancesPagedResponse |
Modifier | Constructor and Description |
---|---|
protected |
CloudRedisClient(CloudRedisSettings settings)
Constructs an instance of CloudRedisClient, using the given settings.
|
protected |
CloudRedisClient(CloudRedisStub stub) |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static CloudRedisClient |
create()
Constructs an instance of CloudRedisClient with default settings.
|
static CloudRedisClient |
create(CloudRedisSettings settings)
Constructs an instance of CloudRedisClient, using the given settings.
|
static CloudRedisClient |
create(CloudRedisStub stub)
Constructs an instance of CloudRedisClient, using the given stub for making calls.
|
OperationFuture<com.google.cloud.redis.v1beta1.Instance,Any> |
createInstanceAsync(com.google.cloud.redis.v1beta1.CreateInstanceRequest request)
Creates a Redis instance based on the specified tier and memory size.
|
OperationFuture<com.google.cloud.redis.v1beta1.Instance,Any> |
createInstanceAsync(com.google.cloud.redis.v1beta1.LocationName parent,
String instanceId,
com.google.cloud.redis.v1beta1.Instance instance)
Creates a Redis instance based on the specified tier and memory size.
|
OperationFuture<com.google.cloud.redis.v1beta1.Instance,Any> |
createInstanceAsync(String parent,
String instanceId,
com.google.cloud.redis.v1beta1.Instance instance)
Creates a Redis instance based on the specified tier and memory size.
|
UnaryCallable<com.google.cloud.redis.v1beta1.CreateInstanceRequest,Operation> |
createInstanceCallable()
Creates a Redis instance based on the specified tier and memory size.
|
OperationCallable<com.google.cloud.redis.v1beta1.CreateInstanceRequest,com.google.cloud.redis.v1beta1.Instance,Any> |
createInstanceOperationCallable()
Creates a Redis instance based on the specified tier and memory size.
|
OperationFuture<Empty,Any> |
deleteInstanceAsync(com.google.cloud.redis.v1beta1.DeleteInstanceRequest request)
Deletes a specific Redis instance.
|
OperationFuture<Empty,Any> |
deleteInstanceAsync(com.google.cloud.redis.v1beta1.InstanceName name)
Deletes a specific Redis instance.
|
OperationFuture<Empty,Any> |
deleteInstanceAsync(String name)
Deletes a specific Redis instance.
|
UnaryCallable<com.google.cloud.redis.v1beta1.DeleteInstanceRequest,Operation> |
deleteInstanceCallable()
Deletes a specific Redis instance.
|
OperationCallable<com.google.cloud.redis.v1beta1.DeleteInstanceRequest,Empty,Any> |
deleteInstanceOperationCallable()
Deletes a specific Redis instance.
|
OperationFuture<com.google.cloud.redis.v1beta1.Instance,Any> |
failoverInstanceAsync(com.google.cloud.redis.v1beta1.FailoverInstanceRequest request)
Failover the master role to current replica node against a specific STANDARD tier redis
instance.
|
OperationFuture<com.google.cloud.redis.v1beta1.Instance,Any> |
failoverInstanceAsync(String name,
com.google.cloud.redis.v1beta1.FailoverInstanceRequest.DataProtectionMode dataProtectionMode)
Failover the master role to current replica node against a specific STANDARD tier redis
instance.
|
UnaryCallable<com.google.cloud.redis.v1beta1.FailoverInstanceRequest,Operation> |
failoverInstanceCallable()
Failover the master role to current replica node against a specific STANDARD tier redis
instance.
|
OperationCallable<com.google.cloud.redis.v1beta1.FailoverInstanceRequest,com.google.cloud.redis.v1beta1.Instance,Any> |
failoverInstanceOperationCallable()
Failover the master role to current replica node against a specific STANDARD tier redis
instance.
|
com.google.cloud.redis.v1beta1.Instance |
getInstance(com.google.cloud.redis.v1beta1.GetInstanceRequest request)
Gets the details of a specific Redis instance.
|
com.google.cloud.redis.v1beta1.Instance |
getInstance(com.google.cloud.redis.v1beta1.InstanceName name)
Gets the details of a specific Redis instance.
|
com.google.cloud.redis.v1beta1.Instance |
getInstance(String name)
Gets the details of a specific Redis instance.
|
UnaryCallable<com.google.cloud.redis.v1beta1.GetInstanceRequest,com.google.cloud.redis.v1beta1.Instance> |
getInstanceCallable()
Gets the details of a specific Redis instance.
|
OperationsClient |
getOperationsClient()
Returns the OperationsClient that can be used to query the status of a long-running operation
returned by another API method call.
|
CloudRedisSettings |
getSettings() |
CloudRedisStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
CloudRedisClient.ListInstancesPagedResponse |
listInstances(com.google.cloud.redis.v1beta1.ListInstancesRequest request)
Lists all Redis instances owned by a project in either the specified location (region) or all
locations.
|
CloudRedisClient.ListInstancesPagedResponse |
listInstances(com.google.cloud.redis.v1beta1.LocationName parent)
Lists all Redis instances owned by a project in either the specified location (region) or all
locations.
|
CloudRedisClient.ListInstancesPagedResponse |
listInstances(String parent)
Lists all Redis instances owned by a project in either the specified location (region) or all
locations.
|
UnaryCallable<com.google.cloud.redis.v1beta1.ListInstancesRequest,com.google.cloud.redis.v1beta1.ListInstancesResponse> |
listInstancesCallable()
Lists all Redis instances owned by a project in either the specified location (region) or all
locations.
|
UnaryCallable<com.google.cloud.redis.v1beta1.ListInstancesRequest,CloudRedisClient.ListInstancesPagedResponse> |
listInstancesPagedCallable()
Lists all Redis instances owned by a project in either the specified location (region) or all
locations.
|
void |
shutdown() |
void |
shutdownNow() |
OperationFuture<com.google.cloud.redis.v1beta1.Instance,Any> |
updateInstanceAsync(FieldMask updateMask,
com.google.cloud.redis.v1beta1.Instance instance)
Updates the metadata and configuration of a specific Redis instance.
|
OperationFuture<com.google.cloud.redis.v1beta1.Instance,Any> |
updateInstanceAsync(com.google.cloud.redis.v1beta1.UpdateInstanceRequest request)
Updates the metadata and configuration of a specific Redis instance.
|
UnaryCallable<com.google.cloud.redis.v1beta1.UpdateInstanceRequest,Operation> |
updateInstanceCallable()
Updates the metadata and configuration of a specific Redis instance.
|
OperationCallable<com.google.cloud.redis.v1beta1.UpdateInstanceRequest,com.google.cloud.redis.v1beta1.Instance,Any> |
updateInstanceOperationCallable()
Updates the metadata and configuration of a specific Redis instance.
|
protected CloudRedisClient(CloudRedisSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected CloudRedisClient(CloudRedisStub stub)
public static final CloudRedisClient create() throws IOException
IOException
public static final CloudRedisClient create(CloudRedisSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final CloudRedisClient create(CloudRedisStub stub)
public final CloudRedisSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public CloudRedisStub getStub()
@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationsClient getOperationsClient()
public final CloudRedisClient.ListInstancesPagedResponse listInstances(com.google.cloud.redis.v1beta1.LocationName parent)
The location should have the following format: * `projects/{project_id}/locations/{location_id}`
If `location_id` is specified as `-` (wildcard), then all regions available to the project are queried, and the results are aggregated.
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
for (Instance element : cloudRedisClient.listInstances(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent
- Required. The resource name of the instance location using the form:
`projects/{project_id}/locations/{location_id}` where `location_id` refers to a GCP regionApiException
- if the remote call failspublic final CloudRedisClient.ListInstancesPagedResponse listInstances(String parent)
The location should have the following format: * `projects/{project_id}/locations/{location_id}`
If `location_id` is specified as `-` (wildcard), then all regions available to the project are queried, and the results are aggregated.
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
for (Instance element : cloudRedisClient.listInstances(parent.toString()).iterateAll()) {
// doThingsWith(element);
}
}
parent
- Required. The resource name of the instance location using the form:
`projects/{project_id}/locations/{location_id}` where `location_id` refers to a GCP regionApiException
- if the remote call failspublic final CloudRedisClient.ListInstancesPagedResponse listInstances(com.google.cloud.redis.v1beta1.ListInstancesRequest request)
The location should have the following format: * `projects/{project_id}/locations/{location_id}`
If `location_id` is specified as `-` (wildcard), then all regions available to the project are queried, and the results are aggregated.
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
ListInstancesRequest request = ListInstancesRequest.newBuilder()
.setParent(parent.toString())
.build();
for (Instance element : cloudRedisClient.listInstances(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.cloud.redis.v1beta1.ListInstancesRequest,CloudRedisClient.ListInstancesPagedResponse> listInstancesPagedCallable()
The location should have the following format: * `projects/{project_id}/locations/{location_id}`
If `location_id` is specified as `-` (wildcard), then all regions available to the project are queried, and the results are aggregated.
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
ListInstancesRequest request = ListInstancesRequest.newBuilder()
.setParent(parent.toString())
.build();
ApiFuture<ListInstancesPagedResponse> future = cloudRedisClient.listInstancesPagedCallable().futureCall(request);
// Do something
for (Instance element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final UnaryCallable<com.google.cloud.redis.v1beta1.ListInstancesRequest,com.google.cloud.redis.v1beta1.ListInstancesResponse> listInstancesCallable()
The location should have the following format: * `projects/{project_id}/locations/{location_id}`
If `location_id` is specified as `-` (wildcard), then all regions available to the project are queried, and the results are aggregated.
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
ListInstancesRequest request = ListInstancesRequest.newBuilder()
.setParent(parent.toString())
.build();
while (true) {
ListInstancesResponse response = cloudRedisClient.listInstancesCallable().call(request);
for (Instance element : response.getInstancesList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final com.google.cloud.redis.v1beta1.Instance getInstance(com.google.cloud.redis.v1beta1.InstanceName name)
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
Instance response = cloudRedisClient.getInstance(name);
}
name
- Required. Redis instance resource name using the form:
`projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id`
refers to a GCP regionApiException
- if the remote call failspublic final com.google.cloud.redis.v1beta1.Instance getInstance(String name)
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
Instance response = cloudRedisClient.getInstance(name.toString());
}
name
- Required. Redis instance resource name using the form:
`projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id`
refers to a GCP regionApiException
- if the remote call failspublic final com.google.cloud.redis.v1beta1.Instance getInstance(com.google.cloud.redis.v1beta1.GetInstanceRequest request)
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
GetInstanceRequest request = GetInstanceRequest.newBuilder()
.setName(name.toString())
.build();
Instance response = cloudRedisClient.getInstance(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.cloud.redis.v1beta1.GetInstanceRequest,com.google.cloud.redis.v1beta1.Instance> getInstanceCallable()
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
GetInstanceRequest request = GetInstanceRequest.newBuilder()
.setName(name.toString())
.build();
ApiFuture<Instance> future = cloudRedisClient.getInstanceCallable().futureCall(request);
// Do something
Instance response = future.get();
}
@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<com.google.cloud.redis.v1beta1.Instance,Any> createInstanceAsync(com.google.cloud.redis.v1beta1.LocationName parent, String instanceId, com.google.cloud.redis.v1beta1.Instance instance)
By default, the instance is accessible from the project's [default network](/compute/docs/networks-and-firewalls#networks).
The creation is executed asynchronously and callers may check the returned operation to track its progress. Once the operation is completed the Redis instance will be fully functional. Completed longrunning.Operation will contain the new instance object in the response field.
The returned operation is automatically deleted after a few hours, so there is no need to call DeleteOperation.
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
String instanceId = "test_instance";
Instance.Tier tier = Instance.Tier.BASIC;
int memorySizeGb = 1;
Instance instance = Instance.newBuilder()
.setTier(tier)
.setMemorySizeGb(memorySizeGb)
.build();
Instance response = cloudRedisClient.createInstanceAsync(parent, instanceId, instance).get();
}
parent
- Required. The resource name of the instance location using the form:
`projects/{project_id}/locations/{location_id}` where `location_id` refers to a GCP regioninstanceId
- Required. The logical name of the Redis instance in the customer project with
the following restrictions:
* Must contain only lowercase letters, numbers, and hyphens. * Must start with a letter. * Must be between 1-40 characters. * Must end with a number or a letter. * Must be unique within the customer project / location
instance
- Required. A Redis [Instance] resourceApiException
- if the remote call fails@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<com.google.cloud.redis.v1beta1.Instance,Any> createInstanceAsync(String parent, String instanceId, com.google.cloud.redis.v1beta1.Instance instance)
By default, the instance is accessible from the project's [default network](/compute/docs/networks-and-firewalls#networks).
The creation is executed asynchronously and callers may check the returned operation to track its progress. Once the operation is completed the Redis instance will be fully functional. Completed longrunning.Operation will contain the new instance object in the response field.
The returned operation is automatically deleted after a few hours, so there is no need to call DeleteOperation.
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
String instanceId = "test_instance";
Instance.Tier tier = Instance.Tier.BASIC;
int memorySizeGb = 1;
Instance instance = Instance.newBuilder()
.setTier(tier)
.setMemorySizeGb(memorySizeGb)
.build();
Instance response = cloudRedisClient.createInstanceAsync(parent.toString(), instanceId, instance).get();
}
parent
- Required. The resource name of the instance location using the form:
`projects/{project_id}/locations/{location_id}` where `location_id` refers to a GCP regioninstanceId
- Required. The logical name of the Redis instance in the customer project with
the following restrictions:
* Must contain only lowercase letters, numbers, and hyphens. * Must start with a letter. * Must be between 1-40 characters. * Must end with a number or a letter. * Must be unique within the customer project / location
instance
- Required. A Redis [Instance] resourceApiException
- if the remote call fails@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<com.google.cloud.redis.v1beta1.Instance,Any> createInstanceAsync(com.google.cloud.redis.v1beta1.CreateInstanceRequest request)
By default, the instance is accessible from the project's [default network](/compute/docs/networks-and-firewalls#networks).
The creation is executed asynchronously and callers may check the returned operation to track its progress. Once the operation is completed the Redis instance will be fully functional. Completed longrunning.Operation will contain the new instance object in the response field.
The returned operation is automatically deleted after a few hours, so there is no need to call DeleteOperation.
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
String instanceId = "test_instance";
Instance.Tier tier = Instance.Tier.BASIC;
int memorySizeGb = 1;
Instance instance = Instance.newBuilder()
.setTier(tier)
.setMemorySizeGb(memorySizeGb)
.build();
CreateInstanceRequest request = CreateInstanceRequest.newBuilder()
.setParent(parent.toString())
.setInstanceId(instanceId)
.setInstance(instance)
.build();
Instance response = cloudRedisClient.createInstanceAsync(request).get();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call fails@BetaApi(value="The surface for use by generated code is not stable yet and may change in the future.") public final OperationCallable<com.google.cloud.redis.v1beta1.CreateInstanceRequest,com.google.cloud.redis.v1beta1.Instance,Any> createInstanceOperationCallable()
By default, the instance is accessible from the project's [default network](/compute/docs/networks-and-firewalls#networks).
The creation is executed asynchronously and callers may check the returned operation to track its progress. Once the operation is completed the Redis instance will be fully functional. Completed longrunning.Operation will contain the new instance object in the response field.
The returned operation is automatically deleted after a few hours, so there is no need to call DeleteOperation.
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
String instanceId = "test_instance";
Instance.Tier tier = Instance.Tier.BASIC;
int memorySizeGb = 1;
Instance instance = Instance.newBuilder()
.setTier(tier)
.setMemorySizeGb(memorySizeGb)
.build();
CreateInstanceRequest request = CreateInstanceRequest.newBuilder()
.setParent(parent.toString())
.setInstanceId(instanceId)
.setInstance(instance)
.build();
OperationFuture<Instance, Any> future = cloudRedisClient.createInstanceOperationCallable().futureCall(request);
// Do something
Instance response = future.get();
}
public final UnaryCallable<com.google.cloud.redis.v1beta1.CreateInstanceRequest,Operation> createInstanceCallable()
By default, the instance is accessible from the project's [default network](/compute/docs/networks-and-firewalls#networks).
The creation is executed asynchronously and callers may check the returned operation to track its progress. Once the operation is completed the Redis instance will be fully functional. Completed longrunning.Operation will contain the new instance object in the response field.
The returned operation is automatically deleted after a few hours, so there is no need to call DeleteOperation.
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
String instanceId = "test_instance";
Instance.Tier tier = Instance.Tier.BASIC;
int memorySizeGb = 1;
Instance instance = Instance.newBuilder()
.setTier(tier)
.setMemorySizeGb(memorySizeGb)
.build();
CreateInstanceRequest request = CreateInstanceRequest.newBuilder()
.setParent(parent.toString())
.setInstanceId(instanceId)
.setInstance(instance)
.build();
ApiFuture<Operation> future = cloudRedisClient.createInstanceCallable().futureCall(request);
// Do something
Operation response = future.get();
}
@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<com.google.cloud.redis.v1beta1.Instance,Any> updateInstanceAsync(FieldMask updateMask, com.google.cloud.redis.v1beta1.Instance instance)
Completed longrunning.Operation will contain the new instance object in the response field. The returned operation is automatically deleted after a few hours, so there is no need to call DeleteOperation.
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
String pathsElement = "display_name";
String pathsElement2 = "memory_size_gb";
List<String> paths = Arrays.asList(pathsElement, pathsElement2);
FieldMask updateMask = FieldMask.newBuilder()
.addAllPaths(paths)
.build();
String displayName = "UpdatedDisplayName";
int memorySizeGb = 4;
Instance instance = Instance.newBuilder()
.setDisplayName(displayName)
.setMemorySizeGb(memorySizeGb)
.build();
Instance response = cloudRedisClient.updateInstanceAsync(updateMask, instance).get();
}
updateMask
- Required. Mask of fields to update. At least one path must be supplied in
this field. The elements of the repeated paths field may only include these fields from
[Instance][google.cloud.redis.v1beta1.Instance]:
* `displayName` * `labels` * `memorySizeGb` * `redisConfig`
instance
- Required. Update description. Only fields specified in update_mask are updated.ApiException
- if the remote call fails@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<com.google.cloud.redis.v1beta1.Instance,Any> updateInstanceAsync(com.google.cloud.redis.v1beta1.UpdateInstanceRequest request)
Completed longrunning.Operation will contain the new instance object in the response field. The returned operation is automatically deleted after a few hours, so there is no need to call DeleteOperation.
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
String pathsElement = "display_name";
String pathsElement2 = "memory_size_gb";
List<String> paths = Arrays.asList(pathsElement, pathsElement2);
FieldMask updateMask = FieldMask.newBuilder()
.addAllPaths(paths)
.build();
String displayName = "UpdatedDisplayName";
int memorySizeGb = 4;
Instance instance = Instance.newBuilder()
.setDisplayName(displayName)
.setMemorySizeGb(memorySizeGb)
.build();
UpdateInstanceRequest request = UpdateInstanceRequest.newBuilder()
.setUpdateMask(updateMask)
.setInstance(instance)
.build();
Instance response = cloudRedisClient.updateInstanceAsync(request).get();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call fails@BetaApi(value="The surface for use by generated code is not stable yet and may change in the future.") public final OperationCallable<com.google.cloud.redis.v1beta1.UpdateInstanceRequest,com.google.cloud.redis.v1beta1.Instance,Any> updateInstanceOperationCallable()
Completed longrunning.Operation will contain the new instance object in the response field. The returned operation is automatically deleted after a few hours, so there is no need to call DeleteOperation.
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
String pathsElement = "display_name";
String pathsElement2 = "memory_size_gb";
List<String> paths = Arrays.asList(pathsElement, pathsElement2);
FieldMask updateMask = FieldMask.newBuilder()
.addAllPaths(paths)
.build();
String displayName = "UpdatedDisplayName";
int memorySizeGb = 4;
Instance instance = Instance.newBuilder()
.setDisplayName(displayName)
.setMemorySizeGb(memorySizeGb)
.build();
UpdateInstanceRequest request = UpdateInstanceRequest.newBuilder()
.setUpdateMask(updateMask)
.setInstance(instance)
.build();
OperationFuture<Instance, Any> future = cloudRedisClient.updateInstanceOperationCallable().futureCall(request);
// Do something
Instance response = future.get();
}
public final UnaryCallable<com.google.cloud.redis.v1beta1.UpdateInstanceRequest,Operation> updateInstanceCallable()
Completed longrunning.Operation will contain the new instance object in the response field. The returned operation is automatically deleted after a few hours, so there is no need to call DeleteOperation.
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
String pathsElement = "display_name";
String pathsElement2 = "memory_size_gb";
List<String> paths = Arrays.asList(pathsElement, pathsElement2);
FieldMask updateMask = FieldMask.newBuilder()
.addAllPaths(paths)
.build();
String displayName = "UpdatedDisplayName";
int memorySizeGb = 4;
Instance instance = Instance.newBuilder()
.setDisplayName(displayName)
.setMemorySizeGb(memorySizeGb)
.build();
UpdateInstanceRequest request = UpdateInstanceRequest.newBuilder()
.setUpdateMask(updateMask)
.setInstance(instance)
.build();
ApiFuture<Operation> future = cloudRedisClient.updateInstanceCallable().futureCall(request);
// Do something
Operation response = future.get();
}
@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Empty,Any> deleteInstanceAsync(com.google.cloud.redis.v1beta1.InstanceName name)
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
cloudRedisClient.deleteInstanceAsync(name).get();
}
name
- Required. Redis instance resource name using the form:
`projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id`
refers to a GCP regionApiException
- if the remote call fails@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Empty,Any> deleteInstanceAsync(String name)
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
cloudRedisClient.deleteInstanceAsync(name.toString()).get();
}
name
- Required. Redis instance resource name using the form:
`projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id`
refers to a GCP regionApiException
- if the remote call fails@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Empty,Any> deleteInstanceAsync(com.google.cloud.redis.v1beta1.DeleteInstanceRequest request)
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder()
.setName(name.toString())
.build();
cloudRedisClient.deleteInstanceAsync(request).get();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call fails@BetaApi(value="The surface for use by generated code is not stable yet and may change in the future.") public final OperationCallable<com.google.cloud.redis.v1beta1.DeleteInstanceRequest,Empty,Any> deleteInstanceOperationCallable()
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder()
.setName(name.toString())
.build();
OperationFuture<Empty, Any> future = cloudRedisClient.deleteInstanceOperationCallable().futureCall(request);
// Do something
future.get();
}
public final UnaryCallable<com.google.cloud.redis.v1beta1.DeleteInstanceRequest,Operation> deleteInstanceCallable()
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]");
DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder()
.setName(name.toString())
.build();
ApiFuture<Operation> future = cloudRedisClient.deleteInstanceCallable().futureCall(request);
// Do something
future.get();
}
@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<com.google.cloud.redis.v1beta1.Instance,Any> failoverInstanceAsync(String name, com.google.cloud.redis.v1beta1.FailoverInstanceRequest.DataProtectionMode dataProtectionMode)
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
String formattedName = InstanceName.format("[PROJECT]", "[LOCATION]", "[INSTANCE]");
FailoverInstanceRequest.DataProtectionMode dataProtectionMode = FailoverInstanceRequest.DataProtectionMode.DATA_PROTECTION_MODE_UNSPECIFIED;
Instance response = cloudRedisClient.failoverInstanceAsync(formattedName, dataProtectionMode).get();
}
name
- Required. Redis instance resource name using the form:
`projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id`
refers to a GCP regiondataProtectionMode
- Optional. Available data protection modes that the user can choose.
If it's unspecified, data protection mode will be LIMITED_DATA_LOSS by default.ApiException
- if the remote call fails@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<com.google.cloud.redis.v1beta1.Instance,Any> failoverInstanceAsync(com.google.cloud.redis.v1beta1.FailoverInstanceRequest request)
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
String formattedName = InstanceName.format("[PROJECT]", "[LOCATION]", "[INSTANCE]");
FailoverInstanceRequest.DataProtectionMode dataProtectionMode = FailoverInstanceRequest.DataProtectionMode.DATA_PROTECTION_MODE_UNSPECIFIED;
FailoverInstanceRequest request = FailoverInstanceRequest.newBuilder()
.setName(formattedName)
.setDataProtectionMode(dataProtectionMode)
.build();
Instance response = cloudRedisClient.failoverInstanceAsync(request).get();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call fails@BetaApi(value="The surface for use by generated code is not stable yet and may change in the future.") public final OperationCallable<com.google.cloud.redis.v1beta1.FailoverInstanceRequest,com.google.cloud.redis.v1beta1.Instance,Any> failoverInstanceOperationCallable()
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
String formattedName = InstanceName.format("[PROJECT]", "[LOCATION]", "[INSTANCE]");
FailoverInstanceRequest.DataProtectionMode dataProtectionMode = FailoverInstanceRequest.DataProtectionMode.DATA_PROTECTION_MODE_UNSPECIFIED;
FailoverInstanceRequest request = FailoverInstanceRequest.newBuilder()
.setName(formattedName)
.setDataProtectionMode(dataProtectionMode)
.build();
OperationFuture<Instance, Any> future = cloudRedisClient.failoverInstanceOperationCallable().futureCall(request);
// Do something
Instance response = future.get();
}
public final UnaryCallable<com.google.cloud.redis.v1beta1.FailoverInstanceRequest,Operation> failoverInstanceCallable()
Sample code:
try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) {
String formattedName = InstanceName.format("[PROJECT]", "[LOCATION]", "[INSTANCE]");
FailoverInstanceRequest.DataProtectionMode dataProtectionMode = FailoverInstanceRequest.DataProtectionMode.DATA_PROTECTION_MODE_UNSPECIFIED;
FailoverInstanceRequest request = FailoverInstanceRequest.newBuilder()
.setName(formattedName)
.setDataProtectionMode(dataProtectionMode)
.build();
ApiFuture<Operation> future = cloudRedisClient.failoverInstanceCallable().futureCall(request);
// Do something
Operation response = future.get();
}
public final void close()
close
in interface AutoCloseable
public void shutdown()
shutdown
in interface BackgroundResource
public boolean isShutdown()
isShutdown
in interface BackgroundResource
public boolean isTerminated()
isTerminated
in interface BackgroundResource
public void shutdownNow()
shutdownNow
in interface BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface BackgroundResource
InterruptedException
Copyright © 2019 Google LLC. All rights reserved.