1package redis
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"github.com/Azure/go-autorest/autorest"
12	"github.com/Azure/go-autorest/autorest/azure"
13	"github.com/Azure/go-autorest/autorest/validation"
14	"github.com/Azure/go-autorest/tracing"
15	"net/http"
16)
17
18// Client is the REST API for Azure Redis Cache Service.
19type Client struct {
20	BaseClient
21}
22
23// NewClient creates an instance of the Client client.
24func NewClient(subscriptionID string) Client {
25	return NewClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewClientWithBaseURI creates an instance of the Client client using a custom endpoint.  Use this when interacting
29// with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewClientWithBaseURI(baseURI string, subscriptionID string) Client {
31	return Client{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// CheckNameAvailability checks that the redis cache name is valid and is not already in use.
35// Parameters:
36// parameters - parameters supplied to the CheckNameAvailability Redis operation. The only supported resource
37// type is 'Microsoft.Cache/redis'
38func (client Client) CheckNameAvailability(ctx context.Context, parameters CheckNameAvailabilityParameters) (result autorest.Response, err error) {
39	if tracing.IsEnabled() {
40		ctx = tracing.StartSpan(ctx, fqdn+"/Client.CheckNameAvailability")
41		defer func() {
42			sc := -1
43			if result.Response != nil {
44				sc = result.Response.StatusCode
45			}
46			tracing.EndSpan(ctx, sc, err)
47		}()
48	}
49	if err := validation.Validate([]validation.Validation{
50		{TargetValue: parameters,
51			Constraints: []validation.Constraint{{Target: "parameters.Name", Name: validation.Null, Rule: true, Chain: nil},
52				{Target: "parameters.Type", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
53		return result, validation.NewError("redis.Client", "CheckNameAvailability", err.Error())
54	}
55
56	req, err := client.CheckNameAvailabilityPreparer(ctx, parameters)
57	if err != nil {
58		err = autorest.NewErrorWithError(err, "redis.Client", "CheckNameAvailability", nil, "Failure preparing request")
59		return
60	}
61
62	resp, err := client.CheckNameAvailabilitySender(req)
63	if err != nil {
64		result.Response = resp
65		err = autorest.NewErrorWithError(err, "redis.Client", "CheckNameAvailability", resp, "Failure sending request")
66		return
67	}
68
69	result, err = client.CheckNameAvailabilityResponder(resp)
70	if err != nil {
71		err = autorest.NewErrorWithError(err, "redis.Client", "CheckNameAvailability", resp, "Failure responding to request")
72		return
73	}
74
75	return
76}
77
78// CheckNameAvailabilityPreparer prepares the CheckNameAvailability request.
79func (client Client) CheckNameAvailabilityPreparer(ctx context.Context, parameters CheckNameAvailabilityParameters) (*http.Request, error) {
80	pathParameters := map[string]interface{}{
81		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
82	}
83
84	const APIVersion = "2017-10-01"
85	queryParameters := map[string]interface{}{
86		"api-version": APIVersion,
87	}
88
89	preparer := autorest.CreatePreparer(
90		autorest.AsContentType("application/json; charset=utf-8"),
91		autorest.AsPost(),
92		autorest.WithBaseURL(client.BaseURI),
93		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Cache/CheckNameAvailability", pathParameters),
94		autorest.WithJSON(parameters),
95		autorest.WithQueryParameters(queryParameters))
96	return preparer.Prepare((&http.Request{}).WithContext(ctx))
97}
98
99// CheckNameAvailabilitySender sends the CheckNameAvailability request. The method will close the
100// http.Response Body if it receives an error.
101func (client Client) CheckNameAvailabilitySender(req *http.Request) (*http.Response, error) {
102	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
103}
104
105// CheckNameAvailabilityResponder handles the response to the CheckNameAvailability request. The method always
106// closes the http.Response Body.
107func (client Client) CheckNameAvailabilityResponder(resp *http.Response) (result autorest.Response, err error) {
108	err = autorest.Respond(
109		resp,
110		azure.WithErrorUnlessStatusCode(http.StatusOK),
111		autorest.ByClosing())
112	result.Response = resp
113	return
114}
115
116// Create create or replace (overwrite/recreate, with potential downtime) an existing Redis cache.
117// Parameters:
118// resourceGroupName - the name of the resource group.
119// name - the name of the Redis cache.
120// parameters - parameters supplied to the Create Redis operation.
121func (client Client) Create(ctx context.Context, resourceGroupName string, name string, parameters CreateParameters) (result CreateFuture, err error) {
122	if tracing.IsEnabled() {
123		ctx = tracing.StartSpan(ctx, fqdn+"/Client.Create")
124		defer func() {
125			sc := -1
126			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
127				sc = result.FutureAPI.Response().StatusCode
128			}
129			tracing.EndSpan(ctx, sc, err)
130		}()
131	}
132	if err := validation.Validate([]validation.Validation{
133		{TargetValue: parameters,
134			Constraints: []validation.Constraint{{Target: "parameters.CreateProperties", Name: validation.Null, Rule: true,
135				Chain: []validation.Constraint{{Target: "parameters.CreateProperties.Sku", Name: validation.Null, Rule: true,
136					Chain: []validation.Constraint{{Target: "parameters.CreateProperties.Sku.Capacity", Name: validation.Null, Rule: true, Chain: nil}}},
137					{Target: "parameters.CreateProperties.SubnetID", Name: validation.Null, Rule: false,
138						Chain: []validation.Constraint{{Target: "parameters.CreateProperties.SubnetID", Name: validation.Pattern, Rule: `^/subscriptions/[^/]*/resourceGroups/[^/]*/providers/Microsoft.(ClassicNetwork|Network)/virtualNetworks/[^/]*/subnets/[^/]*$`, Chain: nil}}},
139					{Target: "parameters.CreateProperties.StaticIP", Name: validation.Null, Rule: false,
140						Chain: []validation.Constraint{{Target: "parameters.CreateProperties.StaticIP", Name: validation.Pattern, Rule: `^\d+\.\d+\.\d+\.\d+$`, Chain: nil}}},
141				}},
142				{Target: "parameters.Location", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
143		return result, validation.NewError("redis.Client", "Create", err.Error())
144	}
145
146	req, err := client.CreatePreparer(ctx, resourceGroupName, name, parameters)
147	if err != nil {
148		err = autorest.NewErrorWithError(err, "redis.Client", "Create", nil, "Failure preparing request")
149		return
150	}
151
152	result, err = client.CreateSender(req)
153	if err != nil {
154		err = autorest.NewErrorWithError(err, "redis.Client", "Create", nil, "Failure sending request")
155		return
156	}
157
158	return
159}
160
161// CreatePreparer prepares the Create request.
162func (client Client) CreatePreparer(ctx context.Context, resourceGroupName string, name string, parameters CreateParameters) (*http.Request, error) {
163	pathParameters := map[string]interface{}{
164		"name":              autorest.Encode("path", name),
165		"resourceGroupName": autorest.Encode("path", resourceGroupName),
166		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
167	}
168
169	const APIVersion = "2017-10-01"
170	queryParameters := map[string]interface{}{
171		"api-version": APIVersion,
172	}
173
174	preparer := autorest.CreatePreparer(
175		autorest.AsContentType("application/json; charset=utf-8"),
176		autorest.AsPut(),
177		autorest.WithBaseURL(client.BaseURI),
178		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cache/Redis/{name}", pathParameters),
179		autorest.WithJSON(parameters),
180		autorest.WithQueryParameters(queryParameters))
181	return preparer.Prepare((&http.Request{}).WithContext(ctx))
182}
183
184// CreateSender sends the Create request. The method will close the
185// http.Response Body if it receives an error.
186func (client Client) CreateSender(req *http.Request) (future CreateFuture, err error) {
187	var resp *http.Response
188	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
189	if err != nil {
190		return
191	}
192	var azf azure.Future
193	azf, err = azure.NewFutureFromResponse(resp)
194	future.FutureAPI = &azf
195	future.Result = future.result
196	return
197}
198
199// CreateResponder handles the response to the Create request. The method always
200// closes the http.Response Body.
201func (client Client) CreateResponder(resp *http.Response) (result ResourceType, err error) {
202	err = autorest.Respond(
203		resp,
204		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
205		autorest.ByUnmarshallingJSON(&result),
206		autorest.ByClosing())
207	result.Response = autorest.Response{Response: resp}
208	return
209}
210
211// Delete deletes a Redis cache.
212// Parameters:
213// resourceGroupName - the name of the resource group.
214// name - the name of the Redis cache.
215func (client Client) Delete(ctx context.Context, resourceGroupName string, name string) (result DeleteFuture, err error) {
216	if tracing.IsEnabled() {
217		ctx = tracing.StartSpan(ctx, fqdn+"/Client.Delete")
218		defer func() {
219			sc := -1
220			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
221				sc = result.FutureAPI.Response().StatusCode
222			}
223			tracing.EndSpan(ctx, sc, err)
224		}()
225	}
226	req, err := client.DeletePreparer(ctx, resourceGroupName, name)
227	if err != nil {
228		err = autorest.NewErrorWithError(err, "redis.Client", "Delete", nil, "Failure preparing request")
229		return
230	}
231
232	result, err = client.DeleteSender(req)
233	if err != nil {
234		err = autorest.NewErrorWithError(err, "redis.Client", "Delete", nil, "Failure sending request")
235		return
236	}
237
238	return
239}
240
241// DeletePreparer prepares the Delete request.
242func (client Client) DeletePreparer(ctx context.Context, resourceGroupName string, name string) (*http.Request, error) {
243	pathParameters := map[string]interface{}{
244		"name":              autorest.Encode("path", name),
245		"resourceGroupName": autorest.Encode("path", resourceGroupName),
246		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
247	}
248
249	const APIVersion = "2017-10-01"
250	queryParameters := map[string]interface{}{
251		"api-version": APIVersion,
252	}
253
254	preparer := autorest.CreatePreparer(
255		autorest.AsDelete(),
256		autorest.WithBaseURL(client.BaseURI),
257		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cache/Redis/{name}", pathParameters),
258		autorest.WithQueryParameters(queryParameters))
259	return preparer.Prepare((&http.Request{}).WithContext(ctx))
260}
261
262// DeleteSender sends the Delete request. The method will close the
263// http.Response Body if it receives an error.
264func (client Client) DeleteSender(req *http.Request) (future DeleteFuture, err error) {
265	var resp *http.Response
266	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
267	if err != nil {
268		return
269	}
270	var azf azure.Future
271	azf, err = azure.NewFutureFromResponse(resp)
272	future.FutureAPI = &azf
273	future.Result = future.result
274	return
275}
276
277// DeleteResponder handles the response to the Delete request. The method always
278// closes the http.Response Body.
279func (client Client) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
280	err = autorest.Respond(
281		resp,
282		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
283		autorest.ByClosing())
284	result.Response = resp
285	return
286}
287
288// ExportData export data from the redis cache to blobs in a container.
289// Parameters:
290// resourceGroupName - the name of the resource group.
291// name - the name of the Redis cache.
292// parameters - parameters for Redis export operation.
293func (client Client) ExportData(ctx context.Context, resourceGroupName string, name string, parameters ExportRDBParameters) (result ExportDataFuture, err error) {
294	if tracing.IsEnabled() {
295		ctx = tracing.StartSpan(ctx, fqdn+"/Client.ExportData")
296		defer func() {
297			sc := -1
298			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
299				sc = result.FutureAPI.Response().StatusCode
300			}
301			tracing.EndSpan(ctx, sc, err)
302		}()
303	}
304	if err := validation.Validate([]validation.Validation{
305		{TargetValue: parameters,
306			Constraints: []validation.Constraint{{Target: "parameters.Prefix", Name: validation.Null, Rule: true, Chain: nil},
307				{Target: "parameters.Container", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
308		return result, validation.NewError("redis.Client", "ExportData", err.Error())
309	}
310
311	req, err := client.ExportDataPreparer(ctx, resourceGroupName, name, parameters)
312	if err != nil {
313		err = autorest.NewErrorWithError(err, "redis.Client", "ExportData", nil, "Failure preparing request")
314		return
315	}
316
317	result, err = client.ExportDataSender(req)
318	if err != nil {
319		err = autorest.NewErrorWithError(err, "redis.Client", "ExportData", nil, "Failure sending request")
320		return
321	}
322
323	return
324}
325
326// ExportDataPreparer prepares the ExportData request.
327func (client Client) ExportDataPreparer(ctx context.Context, resourceGroupName string, name string, parameters ExportRDBParameters) (*http.Request, error) {
328	pathParameters := map[string]interface{}{
329		"name":              autorest.Encode("path", name),
330		"resourceGroupName": autorest.Encode("path", resourceGroupName),
331		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
332	}
333
334	const APIVersion = "2017-10-01"
335	queryParameters := map[string]interface{}{
336		"api-version": APIVersion,
337	}
338
339	preparer := autorest.CreatePreparer(
340		autorest.AsContentType("application/json; charset=utf-8"),
341		autorest.AsPost(),
342		autorest.WithBaseURL(client.BaseURI),
343		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cache/Redis/{name}/export", pathParameters),
344		autorest.WithJSON(parameters),
345		autorest.WithQueryParameters(queryParameters))
346	return preparer.Prepare((&http.Request{}).WithContext(ctx))
347}
348
349// ExportDataSender sends the ExportData request. The method will close the
350// http.Response Body if it receives an error.
351func (client Client) ExportDataSender(req *http.Request) (future ExportDataFuture, err error) {
352	var resp *http.Response
353	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
354	if err != nil {
355		return
356	}
357	var azf azure.Future
358	azf, err = azure.NewFutureFromResponse(resp)
359	future.FutureAPI = &azf
360	future.Result = future.result
361	return
362}
363
364// ExportDataResponder handles the response to the ExportData request. The method always
365// closes the http.Response Body.
366func (client Client) ExportDataResponder(resp *http.Response) (result autorest.Response, err error) {
367	err = autorest.Respond(
368		resp,
369		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
370		autorest.ByClosing())
371	result.Response = resp
372	return
373}
374
375// ForceReboot reboot specified Redis node(s). This operation requires write permission to the cache resource. There
376// can be potential data loss.
377// Parameters:
378// resourceGroupName - the name of the resource group.
379// name - the name of the Redis cache.
380// parameters - specifies which Redis node(s) to reboot.
381func (client Client) ForceReboot(ctx context.Context, resourceGroupName string, name string, parameters RebootParameters) (result ForceRebootResponse, err error) {
382	if tracing.IsEnabled() {
383		ctx = tracing.StartSpan(ctx, fqdn+"/Client.ForceReboot")
384		defer func() {
385			sc := -1
386			if result.Response.Response != nil {
387				sc = result.Response.Response.StatusCode
388			}
389			tracing.EndSpan(ctx, sc, err)
390		}()
391	}
392	req, err := client.ForceRebootPreparer(ctx, resourceGroupName, name, parameters)
393	if err != nil {
394		err = autorest.NewErrorWithError(err, "redis.Client", "ForceReboot", nil, "Failure preparing request")
395		return
396	}
397
398	resp, err := client.ForceRebootSender(req)
399	if err != nil {
400		result.Response = autorest.Response{Response: resp}
401		err = autorest.NewErrorWithError(err, "redis.Client", "ForceReboot", resp, "Failure sending request")
402		return
403	}
404
405	result, err = client.ForceRebootResponder(resp)
406	if err != nil {
407		err = autorest.NewErrorWithError(err, "redis.Client", "ForceReboot", resp, "Failure responding to request")
408		return
409	}
410
411	return
412}
413
414// ForceRebootPreparer prepares the ForceReboot request.
415func (client Client) ForceRebootPreparer(ctx context.Context, resourceGroupName string, name string, parameters RebootParameters) (*http.Request, error) {
416	pathParameters := map[string]interface{}{
417		"name":              autorest.Encode("path", name),
418		"resourceGroupName": autorest.Encode("path", resourceGroupName),
419		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
420	}
421
422	const APIVersion = "2017-10-01"
423	queryParameters := map[string]interface{}{
424		"api-version": APIVersion,
425	}
426
427	preparer := autorest.CreatePreparer(
428		autorest.AsContentType("application/json; charset=utf-8"),
429		autorest.AsPost(),
430		autorest.WithBaseURL(client.BaseURI),
431		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cache/Redis/{name}/forceReboot", pathParameters),
432		autorest.WithJSON(parameters),
433		autorest.WithQueryParameters(queryParameters))
434	return preparer.Prepare((&http.Request{}).WithContext(ctx))
435}
436
437// ForceRebootSender sends the ForceReboot request. The method will close the
438// http.Response Body if it receives an error.
439func (client Client) ForceRebootSender(req *http.Request) (*http.Response, error) {
440	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
441}
442
443// ForceRebootResponder handles the response to the ForceReboot request. The method always
444// closes the http.Response Body.
445func (client Client) ForceRebootResponder(resp *http.Response) (result ForceRebootResponse, err error) {
446	err = autorest.Respond(
447		resp,
448		azure.WithErrorUnlessStatusCode(http.StatusOK),
449		autorest.ByUnmarshallingJSON(&result),
450		autorest.ByClosing())
451	result.Response = autorest.Response{Response: resp}
452	return
453}
454
455// Get gets a Redis cache (resource description).
456// Parameters:
457// resourceGroupName - the name of the resource group.
458// name - the name of the Redis cache.
459func (client Client) Get(ctx context.Context, resourceGroupName string, name string) (result ResourceType, err error) {
460	if tracing.IsEnabled() {
461		ctx = tracing.StartSpan(ctx, fqdn+"/Client.Get")
462		defer func() {
463			sc := -1
464			if result.Response.Response != nil {
465				sc = result.Response.Response.StatusCode
466			}
467			tracing.EndSpan(ctx, sc, err)
468		}()
469	}
470	req, err := client.GetPreparer(ctx, resourceGroupName, name)
471	if err != nil {
472		err = autorest.NewErrorWithError(err, "redis.Client", "Get", nil, "Failure preparing request")
473		return
474	}
475
476	resp, err := client.GetSender(req)
477	if err != nil {
478		result.Response = autorest.Response{Response: resp}
479		err = autorest.NewErrorWithError(err, "redis.Client", "Get", resp, "Failure sending request")
480		return
481	}
482
483	result, err = client.GetResponder(resp)
484	if err != nil {
485		err = autorest.NewErrorWithError(err, "redis.Client", "Get", resp, "Failure responding to request")
486		return
487	}
488
489	return
490}
491
492// GetPreparer prepares the Get request.
493func (client Client) GetPreparer(ctx context.Context, resourceGroupName string, name string) (*http.Request, error) {
494	pathParameters := map[string]interface{}{
495		"name":              autorest.Encode("path", name),
496		"resourceGroupName": autorest.Encode("path", resourceGroupName),
497		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
498	}
499
500	const APIVersion = "2017-10-01"
501	queryParameters := map[string]interface{}{
502		"api-version": APIVersion,
503	}
504
505	preparer := autorest.CreatePreparer(
506		autorest.AsGet(),
507		autorest.WithBaseURL(client.BaseURI),
508		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cache/Redis/{name}", pathParameters),
509		autorest.WithQueryParameters(queryParameters))
510	return preparer.Prepare((&http.Request{}).WithContext(ctx))
511}
512
513// GetSender sends the Get request. The method will close the
514// http.Response Body if it receives an error.
515func (client Client) GetSender(req *http.Request) (*http.Response, error) {
516	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
517}
518
519// GetResponder handles the response to the Get request. The method always
520// closes the http.Response Body.
521func (client Client) GetResponder(resp *http.Response) (result ResourceType, err error) {
522	err = autorest.Respond(
523		resp,
524		azure.WithErrorUnlessStatusCode(http.StatusOK),
525		autorest.ByUnmarshallingJSON(&result),
526		autorest.ByClosing())
527	result.Response = autorest.Response{Response: resp}
528	return
529}
530
531// ImportData import data into Redis cache.
532// Parameters:
533// resourceGroupName - the name of the resource group.
534// name - the name of the Redis cache.
535// parameters - parameters for Redis import operation.
536func (client Client) ImportData(ctx context.Context, resourceGroupName string, name string, parameters ImportRDBParameters) (result ImportDataFuture, err error) {
537	if tracing.IsEnabled() {
538		ctx = tracing.StartSpan(ctx, fqdn+"/Client.ImportData")
539		defer func() {
540			sc := -1
541			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
542				sc = result.FutureAPI.Response().StatusCode
543			}
544			tracing.EndSpan(ctx, sc, err)
545		}()
546	}
547	if err := validation.Validate([]validation.Validation{
548		{TargetValue: parameters,
549			Constraints: []validation.Constraint{{Target: "parameters.Files", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
550		return result, validation.NewError("redis.Client", "ImportData", err.Error())
551	}
552
553	req, err := client.ImportDataPreparer(ctx, resourceGroupName, name, parameters)
554	if err != nil {
555		err = autorest.NewErrorWithError(err, "redis.Client", "ImportData", nil, "Failure preparing request")
556		return
557	}
558
559	result, err = client.ImportDataSender(req)
560	if err != nil {
561		err = autorest.NewErrorWithError(err, "redis.Client", "ImportData", nil, "Failure sending request")
562		return
563	}
564
565	return
566}
567
568// ImportDataPreparer prepares the ImportData request.
569func (client Client) ImportDataPreparer(ctx context.Context, resourceGroupName string, name string, parameters ImportRDBParameters) (*http.Request, error) {
570	pathParameters := map[string]interface{}{
571		"name":              autorest.Encode("path", name),
572		"resourceGroupName": autorest.Encode("path", resourceGroupName),
573		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
574	}
575
576	const APIVersion = "2017-10-01"
577	queryParameters := map[string]interface{}{
578		"api-version": APIVersion,
579	}
580
581	preparer := autorest.CreatePreparer(
582		autorest.AsContentType("application/json; charset=utf-8"),
583		autorest.AsPost(),
584		autorest.WithBaseURL(client.BaseURI),
585		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cache/Redis/{name}/import", pathParameters),
586		autorest.WithJSON(parameters),
587		autorest.WithQueryParameters(queryParameters))
588	return preparer.Prepare((&http.Request{}).WithContext(ctx))
589}
590
591// ImportDataSender sends the ImportData request. The method will close the
592// http.Response Body if it receives an error.
593func (client Client) ImportDataSender(req *http.Request) (future ImportDataFuture, err error) {
594	var resp *http.Response
595	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
596	if err != nil {
597		return
598	}
599	var azf azure.Future
600	azf, err = azure.NewFutureFromResponse(resp)
601	future.FutureAPI = &azf
602	future.Result = future.result
603	return
604}
605
606// ImportDataResponder handles the response to the ImportData request. The method always
607// closes the http.Response Body.
608func (client Client) ImportDataResponder(resp *http.Response) (result autorest.Response, err error) {
609	err = autorest.Respond(
610		resp,
611		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
612		autorest.ByClosing())
613	result.Response = resp
614	return
615}
616
617// List gets all Redis caches in the specified subscription.
618func (client Client) List(ctx context.Context) (result ListResultPage, err error) {
619	if tracing.IsEnabled() {
620		ctx = tracing.StartSpan(ctx, fqdn+"/Client.List")
621		defer func() {
622			sc := -1
623			if result.lr.Response.Response != nil {
624				sc = result.lr.Response.Response.StatusCode
625			}
626			tracing.EndSpan(ctx, sc, err)
627		}()
628	}
629	result.fn = client.listNextResults
630	req, err := client.ListPreparer(ctx)
631	if err != nil {
632		err = autorest.NewErrorWithError(err, "redis.Client", "List", nil, "Failure preparing request")
633		return
634	}
635
636	resp, err := client.ListSender(req)
637	if err != nil {
638		result.lr.Response = autorest.Response{Response: resp}
639		err = autorest.NewErrorWithError(err, "redis.Client", "List", resp, "Failure sending request")
640		return
641	}
642
643	result.lr, err = client.ListResponder(resp)
644	if err != nil {
645		err = autorest.NewErrorWithError(err, "redis.Client", "List", resp, "Failure responding to request")
646		return
647	}
648	if result.lr.hasNextLink() && result.lr.IsEmpty() {
649		err = result.NextWithContext(ctx)
650		return
651	}
652
653	return
654}
655
656// ListPreparer prepares the List request.
657func (client Client) ListPreparer(ctx context.Context) (*http.Request, error) {
658	pathParameters := map[string]interface{}{
659		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
660	}
661
662	const APIVersion = "2017-10-01"
663	queryParameters := map[string]interface{}{
664		"api-version": APIVersion,
665	}
666
667	preparer := autorest.CreatePreparer(
668		autorest.AsGet(),
669		autorest.WithBaseURL(client.BaseURI),
670		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Cache/Redis", pathParameters),
671		autorest.WithQueryParameters(queryParameters))
672	return preparer.Prepare((&http.Request{}).WithContext(ctx))
673}
674
675// ListSender sends the List request. The method will close the
676// http.Response Body if it receives an error.
677func (client Client) ListSender(req *http.Request) (*http.Response, error) {
678	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
679}
680
681// ListResponder handles the response to the List request. The method always
682// closes the http.Response Body.
683func (client Client) ListResponder(resp *http.Response) (result ListResult, err error) {
684	err = autorest.Respond(
685		resp,
686		azure.WithErrorUnlessStatusCode(http.StatusOK),
687		autorest.ByUnmarshallingJSON(&result),
688		autorest.ByClosing())
689	result.Response = autorest.Response{Response: resp}
690	return
691}
692
693// listNextResults retrieves the next set of results, if any.
694func (client Client) listNextResults(ctx context.Context, lastResults ListResult) (result ListResult, err error) {
695	req, err := lastResults.listResultPreparer(ctx)
696	if err != nil {
697		return result, autorest.NewErrorWithError(err, "redis.Client", "listNextResults", nil, "Failure preparing next results request")
698	}
699	if req == nil {
700		return
701	}
702	resp, err := client.ListSender(req)
703	if err != nil {
704		result.Response = autorest.Response{Response: resp}
705		return result, autorest.NewErrorWithError(err, "redis.Client", "listNextResults", resp, "Failure sending next results request")
706	}
707	result, err = client.ListResponder(resp)
708	if err != nil {
709		err = autorest.NewErrorWithError(err, "redis.Client", "listNextResults", resp, "Failure responding to next results request")
710	}
711	return
712}
713
714// ListComplete enumerates all values, automatically crossing page boundaries as required.
715func (client Client) ListComplete(ctx context.Context) (result ListResultIterator, err error) {
716	if tracing.IsEnabled() {
717		ctx = tracing.StartSpan(ctx, fqdn+"/Client.List")
718		defer func() {
719			sc := -1
720			if result.Response().Response.Response != nil {
721				sc = result.page.Response().Response.Response.StatusCode
722			}
723			tracing.EndSpan(ctx, sc, err)
724		}()
725	}
726	result.page, err = client.List(ctx)
727	return
728}
729
730// ListByResourceGroup lists all Redis caches in a resource group.
731// Parameters:
732// resourceGroupName - the name of the resource group.
733func (client Client) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result ListResultPage, err error) {
734	if tracing.IsEnabled() {
735		ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListByResourceGroup")
736		defer func() {
737			sc := -1
738			if result.lr.Response.Response != nil {
739				sc = result.lr.Response.Response.StatusCode
740			}
741			tracing.EndSpan(ctx, sc, err)
742		}()
743	}
744	result.fn = client.listByResourceGroupNextResults
745	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
746	if err != nil {
747		err = autorest.NewErrorWithError(err, "redis.Client", "ListByResourceGroup", nil, "Failure preparing request")
748		return
749	}
750
751	resp, err := client.ListByResourceGroupSender(req)
752	if err != nil {
753		result.lr.Response = autorest.Response{Response: resp}
754		err = autorest.NewErrorWithError(err, "redis.Client", "ListByResourceGroup", resp, "Failure sending request")
755		return
756	}
757
758	result.lr, err = client.ListByResourceGroupResponder(resp)
759	if err != nil {
760		err = autorest.NewErrorWithError(err, "redis.Client", "ListByResourceGroup", resp, "Failure responding to request")
761		return
762	}
763	if result.lr.hasNextLink() && result.lr.IsEmpty() {
764		err = result.NextWithContext(ctx)
765		return
766	}
767
768	return
769}
770
771// ListByResourceGroupPreparer prepares the ListByResourceGroup request.
772func (client Client) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
773	pathParameters := map[string]interface{}{
774		"resourceGroupName": autorest.Encode("path", resourceGroupName),
775		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
776	}
777
778	const APIVersion = "2017-10-01"
779	queryParameters := map[string]interface{}{
780		"api-version": APIVersion,
781	}
782
783	preparer := autorest.CreatePreparer(
784		autorest.AsGet(),
785		autorest.WithBaseURL(client.BaseURI),
786		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cache/Redis", pathParameters),
787		autorest.WithQueryParameters(queryParameters))
788	return preparer.Prepare((&http.Request{}).WithContext(ctx))
789}
790
791// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
792// http.Response Body if it receives an error.
793func (client Client) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
794	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
795}
796
797// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
798// closes the http.Response Body.
799func (client Client) ListByResourceGroupResponder(resp *http.Response) (result ListResult, err error) {
800	err = autorest.Respond(
801		resp,
802		azure.WithErrorUnlessStatusCode(http.StatusOK),
803		autorest.ByUnmarshallingJSON(&result),
804		autorest.ByClosing())
805	result.Response = autorest.Response{Response: resp}
806	return
807}
808
809// listByResourceGroupNextResults retrieves the next set of results, if any.
810func (client Client) listByResourceGroupNextResults(ctx context.Context, lastResults ListResult) (result ListResult, err error) {
811	req, err := lastResults.listResultPreparer(ctx)
812	if err != nil {
813		return result, autorest.NewErrorWithError(err, "redis.Client", "listByResourceGroupNextResults", nil, "Failure preparing next results request")
814	}
815	if req == nil {
816		return
817	}
818	resp, err := client.ListByResourceGroupSender(req)
819	if err != nil {
820		result.Response = autorest.Response{Response: resp}
821		return result, autorest.NewErrorWithError(err, "redis.Client", "listByResourceGroupNextResults", resp, "Failure sending next results request")
822	}
823	result, err = client.ListByResourceGroupResponder(resp)
824	if err != nil {
825		err = autorest.NewErrorWithError(err, "redis.Client", "listByResourceGroupNextResults", resp, "Failure responding to next results request")
826	}
827	return
828}
829
830// ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required.
831func (client Client) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result ListResultIterator, err error) {
832	if tracing.IsEnabled() {
833		ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListByResourceGroup")
834		defer func() {
835			sc := -1
836			if result.Response().Response.Response != nil {
837				sc = result.page.Response().Response.Response.StatusCode
838			}
839			tracing.EndSpan(ctx, sc, err)
840		}()
841	}
842	result.page, err = client.ListByResourceGroup(ctx, resourceGroupName)
843	return
844}
845
846// ListKeys retrieve a Redis cache's access keys. This operation requires write permission to the cache resource.
847// Parameters:
848// resourceGroupName - the name of the resource group.
849// name - the name of the Redis cache.
850func (client Client) ListKeys(ctx context.Context, resourceGroupName string, name string) (result AccessKeys, err error) {
851	if tracing.IsEnabled() {
852		ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListKeys")
853		defer func() {
854			sc := -1
855			if result.Response.Response != nil {
856				sc = result.Response.Response.StatusCode
857			}
858			tracing.EndSpan(ctx, sc, err)
859		}()
860	}
861	req, err := client.ListKeysPreparer(ctx, resourceGroupName, name)
862	if err != nil {
863		err = autorest.NewErrorWithError(err, "redis.Client", "ListKeys", nil, "Failure preparing request")
864		return
865	}
866
867	resp, err := client.ListKeysSender(req)
868	if err != nil {
869		result.Response = autorest.Response{Response: resp}
870		err = autorest.NewErrorWithError(err, "redis.Client", "ListKeys", resp, "Failure sending request")
871		return
872	}
873
874	result, err = client.ListKeysResponder(resp)
875	if err != nil {
876		err = autorest.NewErrorWithError(err, "redis.Client", "ListKeys", resp, "Failure responding to request")
877		return
878	}
879
880	return
881}
882
883// ListKeysPreparer prepares the ListKeys request.
884func (client Client) ListKeysPreparer(ctx context.Context, resourceGroupName string, name string) (*http.Request, error) {
885	pathParameters := map[string]interface{}{
886		"name":              autorest.Encode("path", name),
887		"resourceGroupName": autorest.Encode("path", resourceGroupName),
888		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
889	}
890
891	const APIVersion = "2017-10-01"
892	queryParameters := map[string]interface{}{
893		"api-version": APIVersion,
894	}
895
896	preparer := autorest.CreatePreparer(
897		autorest.AsPost(),
898		autorest.WithBaseURL(client.BaseURI),
899		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cache/Redis/{name}/listKeys", pathParameters),
900		autorest.WithQueryParameters(queryParameters))
901	return preparer.Prepare((&http.Request{}).WithContext(ctx))
902}
903
904// ListKeysSender sends the ListKeys request. The method will close the
905// http.Response Body if it receives an error.
906func (client Client) ListKeysSender(req *http.Request) (*http.Response, error) {
907	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
908}
909
910// ListKeysResponder handles the response to the ListKeys request. The method always
911// closes the http.Response Body.
912func (client Client) ListKeysResponder(resp *http.Response) (result AccessKeys, err error) {
913	err = autorest.Respond(
914		resp,
915		azure.WithErrorUnlessStatusCode(http.StatusOK),
916		autorest.ByUnmarshallingJSON(&result),
917		autorest.ByClosing())
918	result.Response = autorest.Response{Response: resp}
919	return
920}
921
922// ListUpgradeNotifications gets any upgrade notifications for a Redis cache.
923// Parameters:
924// resourceGroupName - the name of the resource group.
925// name - the name of the Redis cache.
926// history - how many minutes in past to look for upgrade notifications
927func (client Client) ListUpgradeNotifications(ctx context.Context, resourceGroupName string, name string, history float64) (result NotificationListResponse, err error) {
928	if tracing.IsEnabled() {
929		ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListUpgradeNotifications")
930		defer func() {
931			sc := -1
932			if result.Response.Response != nil {
933				sc = result.Response.Response.StatusCode
934			}
935			tracing.EndSpan(ctx, sc, err)
936		}()
937	}
938	req, err := client.ListUpgradeNotificationsPreparer(ctx, resourceGroupName, name, history)
939	if err != nil {
940		err = autorest.NewErrorWithError(err, "redis.Client", "ListUpgradeNotifications", nil, "Failure preparing request")
941		return
942	}
943
944	resp, err := client.ListUpgradeNotificationsSender(req)
945	if err != nil {
946		result.Response = autorest.Response{Response: resp}
947		err = autorest.NewErrorWithError(err, "redis.Client", "ListUpgradeNotifications", resp, "Failure sending request")
948		return
949	}
950
951	result, err = client.ListUpgradeNotificationsResponder(resp)
952	if err != nil {
953		err = autorest.NewErrorWithError(err, "redis.Client", "ListUpgradeNotifications", resp, "Failure responding to request")
954		return
955	}
956
957	return
958}
959
960// ListUpgradeNotificationsPreparer prepares the ListUpgradeNotifications request.
961func (client Client) ListUpgradeNotificationsPreparer(ctx context.Context, resourceGroupName string, name string, history float64) (*http.Request, error) {
962	pathParameters := map[string]interface{}{
963		"name":              autorest.Encode("path", name),
964		"resourceGroupName": autorest.Encode("path", resourceGroupName),
965		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
966	}
967
968	const APIVersion = "2017-10-01"
969	queryParameters := map[string]interface{}{
970		"api-version": APIVersion,
971		"history":     autorest.Encode("query", history),
972	}
973
974	preparer := autorest.CreatePreparer(
975		autorest.AsGet(),
976		autorest.WithBaseURL(client.BaseURI),
977		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cache/Redis/{name}/listUpgradeNotifications", pathParameters),
978		autorest.WithQueryParameters(queryParameters))
979	return preparer.Prepare((&http.Request{}).WithContext(ctx))
980}
981
982// ListUpgradeNotificationsSender sends the ListUpgradeNotifications request. The method will close the
983// http.Response Body if it receives an error.
984func (client Client) ListUpgradeNotificationsSender(req *http.Request) (*http.Response, error) {
985	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
986}
987
988// ListUpgradeNotificationsResponder handles the response to the ListUpgradeNotifications request. The method always
989// closes the http.Response Body.
990func (client Client) ListUpgradeNotificationsResponder(resp *http.Response) (result NotificationListResponse, err error) {
991	err = autorest.Respond(
992		resp,
993		azure.WithErrorUnlessStatusCode(http.StatusOK),
994		autorest.ByUnmarshallingJSON(&result),
995		autorest.ByClosing())
996	result.Response = autorest.Response{Response: resp}
997	return
998}
999
1000// RegenerateKey regenerate Redis cache's access keys. This operation requires write permission to the cache resource.
1001// Parameters:
1002// resourceGroupName - the name of the resource group.
1003// name - the name of the Redis cache.
1004// parameters - specifies which key to regenerate.
1005func (client Client) RegenerateKey(ctx context.Context, resourceGroupName string, name string, parameters RegenerateKeyParameters) (result AccessKeys, err error) {
1006	if tracing.IsEnabled() {
1007		ctx = tracing.StartSpan(ctx, fqdn+"/Client.RegenerateKey")
1008		defer func() {
1009			sc := -1
1010			if result.Response.Response != nil {
1011				sc = result.Response.Response.StatusCode
1012			}
1013			tracing.EndSpan(ctx, sc, err)
1014		}()
1015	}
1016	req, err := client.RegenerateKeyPreparer(ctx, resourceGroupName, name, parameters)
1017	if err != nil {
1018		err = autorest.NewErrorWithError(err, "redis.Client", "RegenerateKey", nil, "Failure preparing request")
1019		return
1020	}
1021
1022	resp, err := client.RegenerateKeySender(req)
1023	if err != nil {
1024		result.Response = autorest.Response{Response: resp}
1025		err = autorest.NewErrorWithError(err, "redis.Client", "RegenerateKey", resp, "Failure sending request")
1026		return
1027	}
1028
1029	result, err = client.RegenerateKeyResponder(resp)
1030	if err != nil {
1031		err = autorest.NewErrorWithError(err, "redis.Client", "RegenerateKey", resp, "Failure responding to request")
1032		return
1033	}
1034
1035	return
1036}
1037
1038// RegenerateKeyPreparer prepares the RegenerateKey request.
1039func (client Client) RegenerateKeyPreparer(ctx context.Context, resourceGroupName string, name string, parameters RegenerateKeyParameters) (*http.Request, error) {
1040	pathParameters := map[string]interface{}{
1041		"name":              autorest.Encode("path", name),
1042		"resourceGroupName": autorest.Encode("path", resourceGroupName),
1043		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
1044	}
1045
1046	const APIVersion = "2017-10-01"
1047	queryParameters := map[string]interface{}{
1048		"api-version": APIVersion,
1049	}
1050
1051	preparer := autorest.CreatePreparer(
1052		autorest.AsContentType("application/json; charset=utf-8"),
1053		autorest.AsPost(),
1054		autorest.WithBaseURL(client.BaseURI),
1055		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cache/Redis/{name}/regenerateKey", pathParameters),
1056		autorest.WithJSON(parameters),
1057		autorest.WithQueryParameters(queryParameters))
1058	return preparer.Prepare((&http.Request{}).WithContext(ctx))
1059}
1060
1061// RegenerateKeySender sends the RegenerateKey request. The method will close the
1062// http.Response Body if it receives an error.
1063func (client Client) RegenerateKeySender(req *http.Request) (*http.Response, error) {
1064	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
1065}
1066
1067// RegenerateKeyResponder handles the response to the RegenerateKey request. The method always
1068// closes the http.Response Body.
1069func (client Client) RegenerateKeyResponder(resp *http.Response) (result AccessKeys, err error) {
1070	err = autorest.Respond(
1071		resp,
1072		azure.WithErrorUnlessStatusCode(http.StatusOK),
1073		autorest.ByUnmarshallingJSON(&result),
1074		autorest.ByClosing())
1075	result.Response = autorest.Response{Response: resp}
1076	return
1077}
1078
1079// Update update an existing Redis cache.
1080// Parameters:
1081// resourceGroupName - the name of the resource group.
1082// name - the name of the Redis cache.
1083// parameters - parameters supplied to the Update Redis operation.
1084func (client Client) Update(ctx context.Context, resourceGroupName string, name string, parameters UpdateParameters) (result ResourceType, err error) {
1085	if tracing.IsEnabled() {
1086		ctx = tracing.StartSpan(ctx, fqdn+"/Client.Update")
1087		defer func() {
1088			sc := -1
1089			if result.Response.Response != nil {
1090				sc = result.Response.Response.StatusCode
1091			}
1092			tracing.EndSpan(ctx, sc, err)
1093		}()
1094	}
1095	req, err := client.UpdatePreparer(ctx, resourceGroupName, name, parameters)
1096	if err != nil {
1097		err = autorest.NewErrorWithError(err, "redis.Client", "Update", nil, "Failure preparing request")
1098		return
1099	}
1100
1101	resp, err := client.UpdateSender(req)
1102	if err != nil {
1103		result.Response = autorest.Response{Response: resp}
1104		err = autorest.NewErrorWithError(err, "redis.Client", "Update", resp, "Failure sending request")
1105		return
1106	}
1107
1108	result, err = client.UpdateResponder(resp)
1109	if err != nil {
1110		err = autorest.NewErrorWithError(err, "redis.Client", "Update", resp, "Failure responding to request")
1111		return
1112	}
1113
1114	return
1115}
1116
1117// UpdatePreparer prepares the Update request.
1118func (client Client) UpdatePreparer(ctx context.Context, resourceGroupName string, name string, parameters UpdateParameters) (*http.Request, error) {
1119	pathParameters := map[string]interface{}{
1120		"name":              autorest.Encode("path", name),
1121		"resourceGroupName": autorest.Encode("path", resourceGroupName),
1122		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
1123	}
1124
1125	const APIVersion = "2017-10-01"
1126	queryParameters := map[string]interface{}{
1127		"api-version": APIVersion,
1128	}
1129
1130	preparer := autorest.CreatePreparer(
1131		autorest.AsContentType("application/json; charset=utf-8"),
1132		autorest.AsPatch(),
1133		autorest.WithBaseURL(client.BaseURI),
1134		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cache/Redis/{name}", pathParameters),
1135		autorest.WithJSON(parameters),
1136		autorest.WithQueryParameters(queryParameters))
1137	return preparer.Prepare((&http.Request{}).WithContext(ctx))
1138}
1139
1140// UpdateSender sends the Update request. The method will close the
1141// http.Response Body if it receives an error.
1142func (client Client) UpdateSender(req *http.Request) (*http.Response, error) {
1143	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
1144}
1145
1146// UpdateResponder handles the response to the Update request. The method always
1147// closes the http.Response Body.
1148func (client Client) UpdateResponder(resp *http.Response) (result ResourceType, err error) {
1149	err = autorest.Respond(
1150		resp,
1151		azure.WithErrorUnlessStatusCode(http.StatusOK),
1152		autorest.ByUnmarshallingJSON(&result),
1153		autorest.ByClosing())
1154	result.Response = autorest.Response{Response: resp}
1155	return
1156}
1157