ASP.NET Core sample app illustrating how to use the Steeltoe Redis Connector to connect to a Redis or Valkey server. This sample uses StackExchange.Redis and Microsoft.Extensions.Caching.Redis to work with the same Redis service.
-
Installed .NET 8 SDK
-
Optional: Tanzu Platform for Cloud Foundry (optionally with Windows support) and one of the following service brokers:
-
Optional: Tanzu Platform for Kubernetes v1.5 or higher and Tanzu CLI
Note
Versions of ASP.NET before v9 require that Lua scripting is activated, which is disabled by default on Cloud Foundry, so check your plan settings.
- Start a Redis or Valkey docker container
- Run the sample
dotnet run
Upon startup, the app inserts a couple of key/value pairs into the bound Redis/Valkey cache using both APIs. They are displayed on the home page.
- Create a Redis service instance in an org/space
cf target -o your-org -s your-space
- When using Redis for Tanzu Application Service or Tanzu for Valkey on Cloud Foundry:
or:
cf create-service p.redis on-demand-cache sampleRedisService
cf create-service p-redis shared-vm sampleRedisService
- When using Tanzu Cloud Service Broker for Microsoft Azure:
cf create-service csb-azure-redis your-plan sampleRedisService
- When using Tanzu Cloud Service Broker for GCP:
cf create-service csb-google-redis your-plan sampleRedisService
- When using Redis for Tanzu Application Service or Tanzu for Valkey on Cloud Foundry:
- Wait for the service to become ready (you can check with
cf services
) - Run the
cf push
command to deploy from source (you can monitor logs withcf logs redis-connector-sample
)- When deploying to Windows, binaries must be built locally before push. Use the following commands instead:
dotnet publish -r win-x64 --self-contained cf push -f manifest-windows.yml -p bin/Release/net8.0/win-x64/publish
- When deploying to Windows, binaries must be built locally before push. Use the following commands instead:
- Copy the value of
routes
in the output and open in your browser
In order to connect to Redis for this sample, you must have a class claim available for the application to bind to.
The commands listed below will create the claim, and the claim will be bound to the application via the definition
in the workload.yaml
that is included in the config
folder of this project.
kubectl config set-context --current --namespace=your-namespace
tanzu service class-claim create my-postgresql-service --class postgresql-unmanaged
If you'd like to learn more about these services, see claiming services and consuming services in the documentation.
To deploy from local source code:
tanzu app workload apply --local-path . --file ./config/workload.yaml -y
Alternatively, from locally built binaries:
dotnet publish -r linux-x64 --no-self-contained
tanzu app workload apply --local-path ./bin/Release/net8.0/linux-x64/publish --file ./config/workload.yaml -y
See the Tanzu documentation for details.
See the Official Steeltoe Connectors Documentation for more detailed information.