<commit_before>﻿using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Caching.Redis;
using System;
using System.Net;
using System.Threading.Tasks;

namespace Wukong.Store
{
    public class RedisCacheTicketStore : ITicketStore
    {
        private IDistributedCache _cache;

        private const string KeyPrefix = "AuthSessionStore";

        public RedisCacheTicketStore(string RedisConnection)
        {
            InitRedisConnectionAsync(RedisConnection);
        }

        async private void InitRedisConnectionAsync(string RedisConnection)
        {
            var ipAddress = (await Dns.GetHostAddressesAsync(RedisConnection.Split(':')[0]))[0];
            var resolvedRedisConnection = ipAddress + (RedisConnection.Split(':').Length == 2 ? ":" + RedisConnection.Split(':')[1] : "");

            _cache = new RedisCache(new RedisCacheOptions
            {
                Configuration = resolvedRedisConnection,
                InstanceName = "master"
            });
        }

        public Task<string> StoreAsync(AuthenticationTicket ticket)
        {
            var guid = Guid.NewGuid();
            var key = KeyPrefix + guid;
            RenewAsync(key, ticket);
            return Task.FromResult(key);
        }
<commit_msg>workaround for localhost<commit_after>﻿using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Caching.Redis;
using System;
using System.Net;
using System.Threading.Tasks;

namespace Wukong.Store
{
    public class RedisCacheTicketStore : ITicketStore
    {
        private IDistributedCache _cache;

        private const string KeyPrefix = "AuthSessionStore";

        public RedisCacheTicketStore(string RedisConnection)
        {
            InitRedisConnectionAsync(RedisConnection);
        }

        async private void InitRedisConnectionAsync(string RedisConnection)
        {
            var host = RedisConnection.Split(':')[0];
            var ipAddress = host == "localhost" ? "localhost" : (await Dns.GetHostAddressesAsync(host))[0].ToString();
            var resolvedRedisConnection = ipAddress + (RedisConnection.Split(':').Length == 2 ? ":" + RedisConnection.Split(':')[1] : "");

            _cache = new RedisCache(new RedisCacheOptions
            {
                Configuration = resolvedRedisConnection,
                InstanceName = "master"
            });
        }

        public Task<string> StoreAsync(AuthenticationTicket ticket)
        {
            var guid = Guid.NewGuid();
            var key = KeyPrefix + guid;
            RenewAsync(key, ticket);
            return Task.FromResult(key);
        }

{'fraction_non_alphanumeric': 0.09329549485633203, 'fraction_numerical': 0.002837885775097552, 'mean_word_length': 2.6528497409326426, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '654892', 'n_tokens_mistral': 732, 'n_tokens_neox': 726, 'n_words': 148}