惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
Netflix TechBlog - Medium
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
有赞技术团队
有赞技术团队
阮一峰的网络日志
阮一峰的网络日志
WordPress大学
WordPress大学
V
Visual Studio Blog
博客园_首页
大猫的无限游戏
大猫的无限游戏
Y
Y Combinator Blog
博客园 - Franky
Vercel News
Vercel News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
U
Unit 42
IT之家
IT之家
Last Week in AI
Last Week in AI
腾讯CDC
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
量子位
I
InfoQ
T
The Blog of Author Tim Ferriss
The Cloudflare Blog
MyScale Blog
MyScale Blog
C
Check Point Blog

Redis

发现一个支持云同步的 Redis GUI 工具: RedisViewer 阿里云 Redis 命中率计算与监控的问题 Redis 运行一段时间后报错导致挂掉,有什么办法解决呢? Redis Stream 实现 MQ 的可行性 Redis 缓存数据 支持 WinXP/2003 的 Redis 服务端 怎么才能学好 redis,有什么好的教程或者 blog 推荐吗? 线上服务 redis 查询超时排查求教 有木有安卓 app 的 client 端呀? 除了 Tiny RDM 之外还有什么比较好用的 Redis GUI 工具么? Redis 支持 Hash 字段单独设置过期时间 Redis 加上密码后,整体性能下降 20%? 新学 redis 集群的疑惑 Garnet 真比 Redis 快吗? Redis 几乎每小时都出现大量超时,求助 问一下大家 redis 的配置 Redis 怎样将字节串传递给 lua 脚本? 微软 Garnet 的发展前景如何,有没有可能替代 Redis? 业内有没有把 redis 开启 aof=always 当做数据库使用的? 有谁试过 redis 的 string 自增性能吗, 我这怎么是个位数? 突然想起一个问题,你们用的 redis 有崩过吗?是什么原因崩的? 关联表查询结果的 Redis 缓存如何设计 API 请求如何方便的做并发测试? 请教兄弟们一个问题, datagrip 连接 redis 如何显示 redis 键的 过期时间呢? 关于 Redis RESP3 的想法 轻便式 Redis Monitor 面向研发人员图形可视化监控平台 Redis 中使用 pipeline 执行命令时,有单次执行数量的限制吗? [故障模拟]redis cluster 3 机 3 主 6 从,主节点都转移到了其中一台机器上,然后这台机器宕机 你们现在连接 redis 集群是用的什么工具,可以分享一下下载链接吗? 求教一下 Redis 哨兵模式下,主从延迟问题
求教大佬,线上 redis cluster 中适合使用 redis lua script ...
ryan961 · 2023-07-18 · via Redis

我将一部分逻辑代码通过 lua 脚本实现,变相的实现原子操作(如下),但之前使用 lua 脚本是遇到过 not in the same slot 的错误,感觉我的这个脚本可能与会遇到。如果我真的通过 key 加前缀的方式保证他们在同一个 slot 内是不是也会导致 cluster 处于一个不健康的集群状态。

local userAttributionKey = KEYS[1];
local humeSource = KEYS[2];
local attributeKeys = cjson.decode(KEYS[3]);

if redis.call("EXISTS", userAttributionKey) == 1 then
    -- get attribution cache
    local res = redis.call("GET", userAttributionKey);
    if res then
        return { 1, res };
    end
end

local matchResult = {};
local hits = {};
local latestTime = 0;
for i = 1, #attributeKeys do
    local indexInfoString = redis.call("GET", attributeKeys[i]);
    if indexInfoString then
        local indexInfo = cjson.decode(indexInfoString);
        local reportSource = indexInfo['report_source'];
        local uniqId = indexInfo['uniq_id'];
        local timestamp = tonumber(indexInfo['timestamp']);

        if humeSource == '' or humeSource == indexInfo['report_source'] then
            -- check attribute index info
            if reportSource ~= '' and uniqId ~= '' then
                if timestamp > latestTime then
                    indexInfo['hit'] = attributeKeys[i];
                    indexInfo['match_res'] = 'matched';
                    matchResult = indexInfo;
                    latestTime = timestamp;
                end

                table.insert(hits, attributeKeys[i]);
            else
                return redis.error_reply("Invalid Info:" .. indexInfoString);
            end
        end

        -- delete attribute key cache
        redis.call("DEL", attributeKeys[i])
    end
end

if #hits > 0 then
    matchResult['hits'] = hits;
    local matchResultStr = cjson.encode(matchResult);

    -- set attribution cache
    redis.call("SET", userAttributionKey, matchResultStr, "EX", ARGV[1]);
    return { 1, matchResultStr };
end

return { 0, cjson.encode(matchResult) };

请教下大佬和前辈,我这是不是一种错误的使用方式?以及 lua script 使用时有什么注意事项?