93 lines
3.4 KiB
C#
93 lines
3.4 KiB
C#
namespace Common.Redis
|
|
{
|
|
public static class RedisKeyGenerator
|
|
{
|
|
private static readonly Dictionary<string, string> ServicePrefixes = new()
|
|
{
|
|
{ "user", "user-service" },
|
|
{ "admin", "admin-service" },
|
|
{ "game", "game-service" },
|
|
{ "fish", "game-service" },
|
|
{ "chess", "game-service" },
|
|
{ "customer", "customer-service" },
|
|
{ "common", "app-shared" }
|
|
};
|
|
|
|
public static string GetKey(string serviceName, string key, params object[] args)
|
|
{
|
|
var prefix = GetPrefix(serviceName);
|
|
var formattedKey = args.Length > 0 ? string.Format(key, args) : key;
|
|
return $"{prefix}:{formattedKey}";
|
|
}
|
|
|
|
private static string GetPrefix(string serviceName)
|
|
{
|
|
return ServicePrefixes.TryGetValue(serviceName.ToLower(), out var prefix)
|
|
? prefix
|
|
: "app-shared";
|
|
}
|
|
|
|
public static string UserKey(string key, params object[] args) =>
|
|
GetKey("user", key, args);
|
|
|
|
public static string AdminKey(string key, params object[] args) =>
|
|
GetKey("admin", key, args);
|
|
|
|
public static string GameKey(string key, params object[] args) =>
|
|
GetKey("game", key, args);
|
|
|
|
public static string CustomerKey(string key, params object[] args) =>
|
|
GetKey("customer", key, args);
|
|
|
|
public static string CommonKey(string key, params object[] args) =>
|
|
GetKey("common", key, args);
|
|
}
|
|
|
|
public static class RedisKeyConstants
|
|
{
|
|
private const string ServicePrefix = "redis0524";
|
|
|
|
public static string MatchingRoom => $"{ServicePrefix}:matching:room:level_{{0}}";
|
|
|
|
public static string UserCIDGID => $"{ServicePrefix}:user:uid_{{0}}";
|
|
|
|
public static string LoginCIDUser => $"{ServicePrefix}:user:cid_{{0}}";
|
|
|
|
public static string CIDUser => $"{ServicePrefix}:user:cid_{{0}}";
|
|
|
|
public static string VerificationCode => $"{ServicePrefix}:verification_code:{{0}}";
|
|
|
|
public static string ProductRedis => $"{ServicePrefix}:product:{{0}}";
|
|
|
|
public static string WeiXin_AccessToken => $"{ServicePrefix}:wx_access_token";
|
|
|
|
public static string WeiXinUser_AccessToken => $"{ServicePrefix}:wx_user_access_token:{{0}}";
|
|
|
|
public static string GameConfig => $"{ServicePrefix}:game_config";
|
|
|
|
public static string TodayVisitsKey => $"{ServicePrefix}:TodayVisits";
|
|
|
|
public static string MonthVisitsKey => $"{ServicePrefix}:MonthVisits";
|
|
|
|
public static string TotalVisitsKey => $"{ServicePrefix}:TotalVisits";
|
|
|
|
public static string TotalTrafficKey => $"{ServicePrefix}:TotalTraffic";
|
|
|
|
public static string TodayTrafficKey => $"{ServicePrefix}:TodayTraffic";
|
|
|
|
public static string MonthTrafficKey => $"{ServicePrefix}:MonthTraffic";
|
|
|
|
public static string GameRoomIdKey => $"{ServicePrefix}:game:room:model:{{0}}_{{1}}";
|
|
|
|
public static string DistributedLockPrefix => $"{ServicePrefix}:lock:";
|
|
|
|
public static string ChessRoomList => $"{ServicePrefix}:chess:room:list";
|
|
|
|
public static string ChessRoomKey => $"{ServicePrefix}:chess:room:{{0}}";
|
|
|
|
public static string SystemGoldDayKey => $"{ServicePrefix}:fish:gamestatic";
|
|
|
|
public static string CustomerOnlineKey => "game0524:customer:online";
|
|
}
|
|
}
|