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

推荐订阅源

H
Hackread – Cybersecurity News, Data Breaches, AI and More
W
WeLiveSecurity
C
Check Point Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost
GbyAI
GbyAI
A
Arctic Wolf
NISL@THU
NISL@THU
N
Netflix TechBlog - Medium
The Register - Security
The Register - Security
M
MIT News - Artificial intelligence
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Microsoft Security Blog
Microsoft Security Blog
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tenable Blog
G
GRAHAM CLULEY
O
OpenAI News
S
Schneier on Security
Google Online Security Blog
Google Online Security Blog
Vercel News
Vercel News
宝玉的分享
宝玉的分享
Attack and Defense Labs
Attack and Defense Labs
T
The Blog of Author Tim Ferriss
量子位
aimingoo的专栏
aimingoo的专栏
The Cloudflare Blog
P
Privacy & Cybersecurity Law Blog
S
SegmentFault 最新的问题
MongoDB | Blog
MongoDB | Blog
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
LINUX DO - 热门话题
博客园_首页
F
Full Disclosure
Recent Commits to openclaw:main
Recent Commits to openclaw:main
D
Docker
U
Unit 42
A
About on SuperTechFans
博客园 - 司徒正美
Hacker News - Newest:
Hacker News - Newest: "LLM"
人人都是产品经理
人人都是产品经理
Application and Cybersecurity Blog
Application and Cybersecurity Blog
G
Google Developers Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
J
Java Code Geeks
云风的 BLOG
云风的 BLOG
Scott Helme
Scott Helme
TaoSecurity Blog
TaoSecurity Blog

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 使用时有什么注意事项?