本次封装Redis应用,用的是免费的ServiceStack,通过NuGet查找应用,该Demo需要特别应用的还有Newtonsoft.Json、Unity,均是最新版本便可
Demo通过Redis数据库提供者(RedisCacheDatabaseProvider),Redis配置类(RedisCacheOptions),Redis基本功能类(RedisCacheBase),这里的RedisCacheOptions归属配置,我这里将它写成静态类。
RedisCacheOptions
该类是Redis数据库配置,像连接数据库字符串,特定字符前缀,因为Redis可以做到分布式,所以不同的Redis端,用不同的前缀名,还有要连接的数据库编号,默认0-16
连接数据库字符串
private static stringGetDefaultConnectionString()
{var connStr =ConfigurationManager.ConnectionStrings[ConnectionStringKey];if (connStr==null|| string.IsNullOrWhiteSpace(connStr.ConnectionString))
{return "localhost";
}returnconnStr.ConnectionString;
}
特定