Now when you add new strings, the values are stored in an instance Azure Cache for Redis instead of the dev service. If you'd like to see the sample code used for this tutorial please see. AZURE_REDIS_DATABASE=0ĪZURE_REDIS_HOST=.netĮnvironment variable names used for dev mode services and managed service vary slightly. The console prints up values like the following example. Return to your browser and refresh the page. This command simultaneously removes the development binding and establishes the binding to the production-grade managed service. The following steps bind your application to an existing instance of Azure Cache for Redis.īind to Azure Cache for Redis. When your application is ready to move to production, you can bind your application to a managed service instead of a dev service. With the service reconnected, you can refresh the web application to see data stored in Redis. Now you can rebind the application to the Redis service, to see your previously stored data. You can now see the configuration information displayed indicates data is stored in-memory. You can verify this change by returning to your web browser and refreshing the web application. In this state, if the application scales to zero, then data is lost. The application is written so that if the environment variables aren't defined, then the text strings are stored in memory. To remove a binding from a container app, use the -unbind option. You can also remove a binding from your application. The Redis cache is responsible for storing application data, so data is available even after the application is restarted after scaling to zero. If you access the application via a browser, you can add and remove strings from the Redis database. In this case, the following environment variables are available to the application: REDIS_ENDPOINT=myredis:6379 These values are now available to the application code to use in order to create a connection to the service. The bind request gathers connection information, including credentials and connection strings, and injects it into the application as environment variables. The containerapp create command uses the -bind option to create a link between the container app and the Redis dev service. Paste this location into a web browser so you can inspect the application'e behavior throughout this tutorial. This command returns the fully qualified domain name (FQDN). image /k8se/samples/sample-service-redis:latest \ Next, create your internet-accessible container app.Ĭreate a new container app and bind it to the Redis service. The sample application manages a set of strings, either in-memory, or in Redis cache.Ĭreate the Redis dev service and name it myredis. With the CLI configured and an environment created, you can now create an application and dev service. az provider register –namespace Microsoft.ServiceLinkerĬreate a new environment. Register the Microsoft.ServiceLinker namespace. az provider register -namespace Microsoft.App az extension add -name containerapp -upgrade Upgrade the Container Apps CLI extension. Replace with the name of your container apps environment. AZURE_REDIS_DNS_NAME=Ĭreate a variable to hold your environment name. Make sure to replace with the DNS name of your instance of Azure Cache for Redis. az redis list -resource-group "$RESOURCE_GROUP" -query ".name" -o table To display a list of the Azure Cache for Redis instances, run the following command. RESOURCE_GROUP="my-services-resource-group"Ĭreate a variable for the Azure Cache for Redis DNS name. Set up resource group and location variables. Install the Azure CLI if you don't have it on your machine.Ĭreate a resource group named my-services-resource-group in the East US region.Ĭreate an instance of Azure Cache for Redis in the my-services-resource-group. If you don't have one, you can create one for free. Inspect the service running an in-memory cacheĪn active subscription is required.Disconnect the service from the application.Connect a container app to the Redis dev service.
0 Comments
Leave a Reply. |