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

推荐订阅源

N
News and Events Feed by Topic
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
T
Threat Research - Cisco Blogs
Cloudbric
Cloudbric
Recent Commits to openclaw:main
Recent Commits to openclaw:main
I
Intezer
Attack and Defense Labs
Attack and Defense Labs
P
Privacy International News Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
L
Lohrmann on Cybersecurity
C
Cybersecurity and Infrastructure Security Agency CISA
V2EX - 技术
V2EX - 技术
AWS News Blog
AWS News Blog
O
OpenAI News
L
LINUX DO - 最新话题
N
News | PayPal Newsroom
PCI Perspectives
PCI Perspectives
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Troy Hunt's Blog
Latest news
Latest news
D
Darknet – Hacking Tools, Hacker News & Cyber Security
A
Arctic Wolf
Spread Privacy
Spread Privacy
G
GRAHAM CLULEY
T
Tor Project blog
博客园_首页
Know Your Adversary
Know Your Adversary
有赞技术团队
有赞技术团队
S
Secure Thoughts
美团技术团队
Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
T
Tailwind CSS Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
V
Visual Studio Blog
J
Java Code Geeks
Cisco Talos Blog
Cisco Talos Blog
Schneier on Security
Schneier on Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Security Affairs
Jina AI
Jina AI
人人都是产品经理
人人都是产品经理
雷峰网
雷峰网
宝玉的分享
宝玉的分享
量子位
Last Week in AI
Last Week in AI
月光博客
月光博客
罗磊的独立博客
S
SegmentFault 最新的问题

Redis

发现一个支持云同步的 Redis GUI 工具: RedisViewer 阿里云 Redis 命中率计算与监控的问题 - V2EX Redis 运行一段时间后报错导致挂掉,有什么办法解决呢? - V2EX Redis Stream 实现 MQ 的可行性 - V2EX Redis 缓存数据 - V2EX 支持 WinXP/2003 的 Redis 服务端 - V2EX 怎么才能学好 redis,有什么好的教程或者 blog 推荐吗? - V2EX 线上服务 redis 查询超时排查求教 - V2EX 有木有安卓 app 的 client 端呀? - V2EX 除了 Tiny RDM 之外还有什么比较好用的 Redis GUI 工具么? - V2EX Redis 支持 Hash 字段单独设置过期时间 - V2EX Redis 加上密码后,整体性能下降 20%? - V2EX 新学 redis 集群的疑惑 - V2EX Garnet 真比 Redis 快吗? - V2EX Redis 几乎每小时都出现大量超时,求助 - V2EX 问一下大家 redis 的配置 - V2EX Redis 怎样将字节串传递给 lua 脚本? - V2EX 微软 Garnet 的发展前景如何,有没有可能替代 Redis? - V2EX 业内有没有把 redis 开启 aof=always 当做数据库使用的? - V2EX 有谁试过 redis 的 string 自增性能吗, 我这怎么是个位数? - V2EX 突然想起一个问题,你们用的 redis 有崩过吗?是什么原因崩的? - V2EX 关联表查询结果的 Redis 缓存如何设计 API 请求如何方便的做并发测试? - V2EX 请教兄弟们一个问题, datagrip 连接 redis 如何显示 redis 键的 过期时间呢? 关于 Redis RESP3 的想法 - V2EX 轻便式 Redis Monitor 面向研发人员图形可视化监控平台 Redis 中使用 pipeline 执行命令时,有单次执行数量的限制吗? - V2EX [故障模拟]redis cluster 3 机 3 主 6 从,主节点都转移到了其中一台机器上,然后这台机器宕机 你们现在连接 redis 集群是用的什么工具,可以分享一下下载链接吗? - V2EX 求教一下 Redis 哨兵模式下,主从延迟问题 - V2EX 想问下大佬 40M 的字符串适合放到 redis 缓存吗? - V2EX redis 有时取不到值 - V2EX redis 集群中 执行事务 或者 lua 脚本 涉及到多个 key 时,这些 key 要求在同一个节点还是同一个 slot? - V2EX redis 7 所有命令都是原子的吗? - V2EX Redis 是鸡肋吗? - V2EX Redis 服务挂了,一段时间后又恢复,不会造成缓存与数据库不一致吗? - V2EX 为什么 MySQL 有缓存,还要使用 Redis? - V2EX 关于缓存一致性问题,不知道我这个方案是否可行 - V2EX redis 集群获取不到连接 - V2EX 用 redis 直接替换 app/物联网的 mq 服务器的可行性大吗?怎么对客户端进行限制 - V2EX redis 怎么裁剪 zset 只保留排名前 100 的数据 - V2EX 缓存失效后先返回再触发更新的场景要怎么处理? - V2EX 关于 redis 一个小问题(随机性) - V2EX 怎么使用命令批量删除匹配的 key 值? - V2EX 对 redis 的 zset 做分片的时候怎么选择分片个数 - V2EX 关于消息推送方案的讨论 - V2EX Redis 的 zset 按 score 排序做分页的时候怎么保证数据不丢失? - V2EX redis 的 zset 如果打散成多个 zset 的话,如果要分页查询怎么处理呢? - V2EX 关于社区场景下,用户已读文章不再推荐这种需求实现方案的探讨 - V2EX 一个 abtest 实验中 redis 设计的思考
求教大佬,线上 redis cluster 中适合使用 redis lua script 吗?以及使用时有什么注意事项? - V2EX
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 使用时有什么注意事项?