Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IRedisClient add async method #148

Open
tky753 opened this issue May 31, 2023 · 3 comments
Open

IRedisClient add async method #148

tky753 opened this issue May 31, 2023 · 3 comments

Comments

@tky753
Copy link

tky753 commented May 31, 2023

IRedisClient doesn't have async methods witch are implemnted in RedisClient, it makes IRedisClient a little 鸡肋.

@2881099
Copy link
Owner

2881099 commented May 31, 2023

IRedisClient 是社区 PR 的,不完整

@2881099
Copy link
Owner

2881099 commented May 31, 2023

var sb = new StringBuilder(@"using System;
using System.Collections.Generic;
using System.IO;

namespace FreeRedis
{
    public partial interface IRedisClient
    {
        List<Func<IInterceptor>> Interceptors { get; }

        event EventHandler<ConnectedEventArgs> Connected;
        event EventHandler<NoticeEventArgs> Notice;
        event EventHandler<UnavailableEventArgs> Unavailable;
");
            var methods = typeof(RedisClient).GetMethods().OrderBy(a =>
                a.ReturnType.IsAssignableFrom(typeof(Task)) ||
                a.ReturnType.IsGenericType && a.ReturnType.GetGenericTypeDefinition() == typeof(Task<>)).ToArray();

            foreach (var method in methods)
            {
                var mstr = method.DisplayCsharp(false);
                mstr = mstr.Replace("public ", "")
                    .Replace("virtual ", "")
                    .Replace("System.IO.", "")
                    .Replace("System.Object.", "object")
                    .Replace("System.", "")
                    .Replace("Threading.Tasks.", "")
                    .Replace("Collections.Generic.", "")
                    .Replace("FreeRedis.Internal.", "")
                    .Replace("FreeRedis.", "")
                    .Replace("Boolean", "bool")
                    .Replace("String", "string")
                    .Replace("Int32", "int")
                    .Replace("Int64", "long")
                    .Replace("Decimal", "decimal");
                mstr = Regex.Replace(mstr, @"Nullable<(\w+)>", "$1?");
                //        sb.Append($@"
                //{method.ReturnType.DisplayCsharp(false)} {method.Name}({string.Join(", ", method.GetParameters().Select(a => a.ParameterType.DisplayCsharp(false) + " " + a.Name))})");
                sb.Append($@"
        {mstr};");
            }

            sb.Append(@"
    }
}");
            string redisInterface = sb.ToString();

2881099 added a commit that referenced this issue May 31, 2023
2881099 added a commit that referenced this issue May 31, 2023
@2881099
Copy link
Owner

2881099 commented May 31, 2023

v1.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants