FreeRedis icon indicating copy to clipboard operation
FreeRedis copied to clipboard

希望RedisClient的Prifix属性公开

Open hd2y opened this issue 2 years ago • 2 comments

某些命令比如 Keys 需要使用前缀时,目前只有通过反射拿到。

hd2y avatar May 25 '22 10:05 hd2y

+1,同时希望增加一个SetPrifix()的方法。现在只能用过在连接字符串中配置。 比如说我需要根据应用Id来设置Prifix时,只有修改连接字符串或者反射去修改Prifix。

withsalt avatar Jul 05 '22 09:07 withsalt

看上去只是一时的阵痛,因为 connectionString 是分开的,每个都可能有自己的 prefix 单独设置,所以也不好公开 prefix。

之前的想法是使用者自己使用 ConnectionStringBuilder 获取 prefix 值。

2881099 avatar Jul 07 '22 01:07 2881099

推荐的解决方案:

public static class RedisClientExtensions
{
    public static string GetPrefix(this RedisClient client)
    {
        return typeof(RedisClient).GetProperty("Prefix", BindingFlags.Instance | BindingFlags.NonPublic)
            ?.GetValue(client) as string;
    }
}

hd2y avatar Dec 02 '22 10:12 hd2y