Giter Site home page Giter Site logo

redis-cache-dotnet-export-simulate-portal's Introduction

services platforms author
Azure Redis Cache
.Net
msonecode

How to export premium Redis cache by simulating as Azure portal

Introduction

Export allows you to export the data stored in Azure Redis Cache to Redis compatible RDB file(s). You can use this feature to move data from one Azure Redis Cache instance to another or to another Redis server. During the exporting process, a temporary file is created on the VM that hosts the Azure Redis Cache server instance, and the file is uploaded to the designated storage account. When the exporting operation ends in either a status of success or failure, the temporary file is deleted. Import/Export enables you to migrate between different Azure Redis Cache instances or to populate the cache with data before being used.

There are multiple methods to export redis cache (my previous post about this topic), including Azure Portal, Azure PowerShell, Azure CLI and REST API methods. Since the Azure Portal approach is the simplest one, this post I will introduce a programming method to export Redis Cache by stimulating Azure Portal approach.

Prerequisites

1. Azure Account
You need an Azure account. You can open a free Azure account or Activate Visual Studio subscriber benefits.

2. Visual Studio 2015
https://www.visualstudio.com/downloads/

3. ASP.NET MVC 5
The tutorial assumes you have worked with ASP.NET MVC and Visual Studio. If you need an introduction, see Getting Started with ASP.NET MVC 5.

4. Azure SDK
The tutorial is written for Visual Studio 2015 with the Azure SDK for .NET 2.9 or later. Download the latest Azure SDK for Visual Studio 2015. The SDK installs Visual Studio 2015 if you don't already have it.

Detailed Steps

  1. Open developer console on your browser (F12)
  2. Open the browser to Azure Portal and run the Redis exporting operation as below. To export the current contents of the cache to storage, browse to your cache in the Azure portal and click Export data from the Settings blade of your cache instance.

3. As you can see, the parameters from json file of request playload are the same as Azure CLI and RESR API methods.

  1. Select one of the invoke calls and view the headers, copy the text after "Bearer"

  1. Collect the related information from Redis Cache overview blade.
    • subscriptionId
    • resourceGroup
    • cacheName
  2. Collect related information from Storage blade.
    • storageAccountConnectionString = Settings -> Access keys -> Connection strings

  1. Fill in all the collected infos with source code you downloaded from this page.

    const string exportString = "https://management.azure.com/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Cache/Redis/{2}/export?api-version=2015-08-01";
  2. Below are some code snippets to form SAS token for Storage Container.

            public StorageWrapper(string conn)
            {
                this._storageAccount = CloudStorageAccount.Parse(conn);
            }
    
            public CloudBlobContainer GetContainer(string name)
            {
                return this._storageAccount.CreateCloudBlobClient().GetContainerReference(name);
            }
    
            public string GetContainerSas(string name, bool read = false, bool write = false, bool list = false, bool delete = false)
            {
                var container = GetContainer(name);
                container.CreateIfNotExists();
                return container.Uri + container.GetSharedAccessSignature(GetPolicy(read, write, list, delete));
            }
    
            private SharedAccessBlobPolicy GetPolicy(bool read, bool write, bool list, bool delete)
            {
                SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy();
    
                policy.Permissions =
                        (read ? SharedAccessBlobPermissions.Read : 0)
                      | (write ? SharedAccessBlobPermissions.Write : 0)
                      | (list ? SharedAccessBlobPermissions.List : 0)
                      | (delete ? SharedAccessBlobPermissions.Delete : 0);
                policy.SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(75); // Must be at least 65 minutes
    
                return policy;
            }

Reference

Below are some useful links, you will need them before your real action.

Azure Portal: Export Redis to a Blob Container.
https://docs.microsoft.com/en-us/azure/redis-cache/cache-how-to-import-export-data#export

PowerShell: Export Redis to a Blob Container.
https://docs.microsoft.com/en-us/azure/redis-cache/cache-howto-manage-redis-cache-powershell#to-export-a-redis-cache

Azure CLI: Export Redis to a Blob Container.
https://docs.microsoft.com/en-us/cli/azure/redis#export

REST API: Export Redis to a Blob Container.
https://docs.microsoft.com/en-us/rest/api/redis/redis#Redis_ExportData

Microsoft Azure Storage Explorer
http://storageexplorer.com/

redis-cache-dotnet-export-simulate-portal's People

Contributors

aliceqin12 avatar msonecode avatar vaanpan avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.