GarnetBuilderExtensions.AddGarnet Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Adds a Garnet container to the application model.
public static Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.GarnetResource> AddGarnet (this Aspire.Hosting.IDistributedApplicationBuilder builder, string name, int? port = default);
static member AddGarnet : Aspire.Hosting.IDistributedApplicationBuilder * string * Nullable<int> -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.GarnetResource>
<Extension()>
Public Function AddGarnet (builder As IDistributedApplicationBuilder, name As String, Optional port As Nullable(Of Integer) = Nothing) As IResourceBuilder(Of GarnetResource)
Parameters
- name
- String
The name of the resource. This name will be used as the connection string name when referenced in a dependency.
Returns
A reference to the IResourceBuilder<T>.
Examples
Use in application host
var builder = DistributedApplication.CreateBuilder(args);
var garnet = builder.AddGarnet("garnet");
var api = builder.AddProject<Projects.Api>("api)
.WithReference(garnet);
builder.Build().Run();
Use in Api with Aspire.StackExchange.Redis
var builder = WebApplication.CreateBuilder(args);
builder.AddRedisClient("garnet");
var multiplexer = builder.Services.BuildServiceProvider()
.GetRequiredService<IConnectionMultiplexer>();
var db = multiplexer.GetDatabase();
db.HashSet("key", [new HashEntry("hash", "value")]);
var value = db.HashGet("key", "hash");
Remarks
This version of the package defaults to the tag of the / container image.