-
Notifications
You must be signed in to change notification settings - Fork 166
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
[Discuss] client-side-cachin #15
Comments
该功能涉及到统计业务甚至动态逻辑,实时与定时等等维度,暂且想到设计之初仅提供 O(option)CURD 数据接口。
赞同 KV 模式保存,并发字典查询性能在 us 以下尚且可行,.NET5 中官方对字典以及字符串Key有特别优化。 目前最快的 KV 构建算法是 BTFTree 属于指针和动态代码的结合,使用 Emit 极难实现,除了实现树遍历和返回数据之外还需要对 if 分支做二分查找优化,此方案优先级极低。Swifter.Json 作者有实现 HashCode 版的二分查找,可提升性能。
暂无好建议,更像是开放设置。
待调研,想到用守护线程来管理。 |
还需要评估一下 Tracking 和 广播 两种模式的使用场景和实现方式。 |
广播处理起来太麻烦了,每个正在发送命令的 RedisSocket 都有可能收到消息,容易造成消息不对称。 目前是 client tracking redirect 1 同一个连接来完成这件事。 |
1、广播需要客户端来甄别数据。 看样子组播会好一点,如果官方能提供 UDP 客户端驱动来管理密钥和过期更新策略则极好。另外密钥传输场景像TFO的样子,目测有升级的余地,或许可以问问官方后期计划。 |
已完成如下功能,解决:
交给外部处理,如下 KeyFilter 委托
使用并发字典
交给外部处理,如下 Capacity 设置
交给外部处理,如下 CheckExpired 委托
内部已处理,本地执行命令之后,AOP 会删本地缓存,再次执行命令就不会从本地缓存读取了
待续 如下测试,缓存目前主要解决 GET/MGET 的使用:cli.UseClientSideCaching(new ClientSideCachingOptions
{
//本地缓存的容量
Capacity = 3,
//过滤哪些键能被本地缓存
KeyFilter = key => key.StartsWith("Interceptor"),
//检查长期未使用的缓存
CheckExpired = (key, dt) => DateTime.Now.Subtract(dt) > TimeSpan.FromSeconds(2)
});
cli.Set("Interceptor01", "123123"); //redis-server
var val1 = cli.Get("Interceptor01"); //redis-server
var val2 = cli.Get("Interceptor01"); //本地
var val3 = cli.Get("Interceptor01"); //断点等3秒 redis-server
cli.Set("Interceptor01", "234567"); //redis-server
var val4 = cli.Get("Interceptor01"); //redis-server
var val5 = cli.Get("Interceptor01"); //本地
var val6 = cli.MGet("Interceptor01", "Interceptor02", "Interceptor03"); //redis-server
var val7 = cli.MGet("Interceptor01", "Interceptor02", "Interceptor03"); //本地
var val8 = cli.MGet("Interceptor01", "Interceptor02", "Interceptor03"); //本地
cli.MSet("Interceptor01", "Interceptor01Value", "Interceptor02", "Interceptor02Value", "Interceptor03", "Interceptor03Value"); //redis-server
var val9 = cli.MGet("Interceptor01", "Interceptor02", "Interceptor03"); //redis-server
var val10 = cli.MGet("Interceptor01", "Interceptor02", "Interceptor03"); //本地
//以下 KeyFilter 返回 false,从而不使用本地缓存
cli.Set("123Interceptor01", "123123"); //redis-server
var val11 = cli.Get("123Interceptor01"); //redis-server
var val12 = cli.Get("123Interceptor01"); //redis-server
var val23 = cli.Get("123Interceptor01"); //redis-server 设置 cli.Notice 事件在控制台输出内容: Not connected 代表没有经过 redis-server 192.168.164.10:6379 > CLIENT TRACKING ON REDIRECT 46
FreeRedis.RedisResult
(0ms)
192.168.164.10:6379 > SET Interceptor01 123123
OK
(24ms)
192.168.164.10:6379 > GET Interceptor01
123123
(2ms)
Not connected > GET Interceptor01
123123
(0ms)
192.168.164.10:6379 > GET Interceptor01
123123
(0ms)
192.168.164.10:6379 > SET Interceptor01 234567
OK
(0ms)
192.168.164.10:6379 > GET Interceptor01
234567
(0ms)
Not connected > GET Interceptor01
234567
(0ms)
192.168.164.10:6379 > MGET Interceptor01 Interceptor02 Interceptor03
[234567, Interceptor02Value, Interceptor03Value]
(0ms)
Not connected > MGET Interceptor01 Interceptor02 Interceptor03
[234567, Interceptor02Value, Interceptor03Value]
(0ms)
Not connected > MGET Interceptor01 Interceptor02 Interceptor03
[234567, Interceptor02Value, Interceptor03Value]
(0ms)
192.168.164.10:6379 > MSET Interceptor01 Interceptor01Value Interceptor02 Interceptor02Value Interceptor03 Interceptor03Value
False
(3ms)
192.168.164.10:6379 > MGET Interceptor01 Interceptor02 Interceptor03
[Interceptor01Value, Interceptor02Value, Interceptor03Value]
(1ms)
Not connected > MGET Interceptor01 Interceptor02 Interceptor03
[Interceptor01Value, Interceptor02Value, Interceptor03Value]
(0ms)
192.168.164.10:6379 > SET 123Interceptor01 123123
OK
(0ms)
192.168.164.10:6379 > GET 123Interceptor01
123123
(0ms)
192.168.164.10:6379 > GET 123Interceptor01
123123
(0ms)
192.168.164.10:6379 > GET 123Interceptor01
123123
(0ms) |
官方文档:https://redis.io/topics/client-side-caching
客户端缓存是一种用于创建高性能的技术。利用应用程序的可用内存,将 redis-server 信息的某些数据直接存储在应用程序端。
使用客户端缓存时,而无需再次请求 redis-server
FreeRedis 怎样提供 API 给使用者
第一次从 redis-server 读取数据缓存到本地,后面的三次直接从本地内存读出来的数据。
因为本地内存有限,不能无限制将内容缓存起来。主要解决缓存条件。
伪代码:
欢迎踊跃发表意见
The text was updated successfully, but these errors were encountered: