< Summary - Kestrun — Combined Coverage

Information
Class: Public.Session.Add-KrDistributedRedisCache
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Session/Add-KrDistributedRedisCache.ps1
Tag: Kestrun/Kestrun@2d87023b37eb91155071c91dd3d6a2eeb3004705
Line coverage
0%
Covered lines: 0
Uncovered lines: 12
Coverable lines: 12
Total lines: 86
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 10/13/2025 - 16:52:37 Line coverage: 0% (0/12) Total lines: 86 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Session/Add-KrDistributedRedisCache.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Adds StackExchange.Redis distributed cache services to the Kestrun server.
 4    .DESCRIPTION
 5        Configures the Kestrun server to use StackExchange.Redis as the distributed cache for session state.
 6    .PARAMETER Server
 7        The Kestrun server instance to configure. If not specified, the current server instance is used.
 8    .PARAMETER Options
 9        The Redis cache options to configure. If not specified, default options are used.
 10    .PARAMETER ConfigurationOptions
 11        The StackExchange.Redis configuration options to use. If not specified, the default configuration is used.
 12        This parameter is mutually exclusive with the Configuration parameter.
 13    .PARAMETER Configuration
 14        The configuration string to use for connecting to the Redis server. If not specified, the default configuration 
 15        This parameter is mutually exclusive with the ConfigurationOptions parameter.
 16    .PARAMETER InstanceName
 17        The instance name to use for the Redis cache. If not specified, the default instance name is used.
 18    .PARAMETER PassThru
 19        If specified, the cmdlet returns the modified server instance after configuration.
 20    .EXAMPLE
 21        Add-KrDistributedRedisCache -Server $myServer -Options $myRedisOptions
 22        Adds StackExchange.Redis distributed cache services to the specified Kestrun server with the provided options.
 23    .EXAMPLE
 24        Add-KrDistributedRedisCache -Configuration "localhost:6379" -InstanceName "MyApp"
 25        Configures StackExchange.Redis distributed cache with the specified configuration string and instance name.
 26    .EXAMPLE
 27        $configOptions = [StackExchange.Redis.ConfigurationOptions]::Parse("localhost:6379")
 28        $configOptions.AbortOnConnectFail = $false
 29        Add-KrDistributedRedisCache -ConfigurationOptions $configOptions
 30        Configures StackExchange.Redis distributed cache with the specified configuration options.
 31    .NOTES
 32        This cmdlet is part of the Kestrun PowerShell module and is used to configure StackExchange.Redis distributed ca
 33    .LINK
 34        https://docs.kestrun.dev/docs/powershell/kestrun/middleware
 35 #>
 36function Add-KrDistributedRedisCache {
 37    [KestrunRuntimeApi('Definition')]
 38    [CmdletBinding(defaultParameterSetName = 'Items')]
 39    [OutputType([Kestrun.Hosting.KestrunHost])]
 40    param(
 41        [Parameter(Mandatory = $false, ValueFromPipeline = $true)]
 42        [Kestrun.Hosting.KestrunHost]$Server,
 43
 44        [Parameter(Mandatory = $true, ParameterSetName = 'Options')]
 45        [Microsoft.Extensions.Caching.StackExchangeRedis.RedisCacheOptions]$Options,
 46
 47        [Parameter(ParameterSetName = 'Items')]
 48        [StackExchange.Redis.ConfigurationOptions]$ConfigurationOptions,
 49
 50        [Parameter(ParameterSetName = 'Items')]
 51        [string]$Configuration,
 52
 53        [Parameter(ParameterSetName = 'Items')]
 54        [string]$InstanceName,
 55
 56        [Parameter()]
 57        [switch]$PassThru
 58    )
 59    begin {
 60        # Ensure the server instance is resolved
 061        $Server = Resolve-KestrunServer -Server $Server
 62    }
 63    process {
 064        if ($PSCmdlet.ParameterSetName -eq 'Items') {
 65            # Build Redis cache options from individual parameters
 066            $Options = [Microsoft.Extensions.Caching.StackExchangeRedis.RedisCacheOptions]::new()
 67
 068            if ($PsBoundParameters.ContainsKey('ConfigurationOptions')) {
 069                $Options.ConfigurationOptions = $ConfigurationOptions
 70            }
 071            if ($PsBoundParameters.ContainsKey('Configuration')) {
 072                $Options.Configuration = $Configuration
 73            }
 074            if ($PsBoundParameters.ContainsKey('InstanceName')) {
 075                $Options.InstanceName = $InstanceName
 76            }
 77        }
 78        # Add StackExchange.Redis distributed cache to the Kestrun server
 079        [Kestrun.Hosting.KestrunHostSessionExtensions]::AddStackExchangeRedisCache($Server, $Options) | Out-Null
 80
 081        if ($PassThru.IsPresent) {
 82            # if the PassThru switch is specified, return the modified server instance
 083            return $Server
 84        }
 85    }
 86}

Methods/Properties

Add-KrDistributedRedisCache()