--[[
luarocks install luasocket module 'socket' not found
https://github.com/nrk/redis-lua
最历害的是,用redis 去跑lua,分布式锁,限流,
]]--
local redis = require("redis");
local config={host="127.0.0.1",port=6379};
local client = redis.connect(config);
--项目中使用的原子操作
https://blog.csdn.net/kuishao1314aa/article/details/120367618
--eval "local val=redis.call('GET',KEYS[1]);if _G.tonumber(val)>0 then redis.call('DECR',KEYS[1]) end;return true" 1 test-key
local val=client.get('test-key');--1
if _G.tonumber(val) <1 then
print("没有库存,抢完了");
os.exit();
else
client.decr('test-key');
end
--[[
info = client:info();
for k,v in pairs(info.clients) do
print(k,v);
end
]]--
print(client:get("test-key"));
--print(cliREADMEent:del("test-key"));
--print(client:set("test-key",456));
print(client:incr("test-key"));
print(client:get("test-key"));
for k,v in pairs(redis.commands) do
print(k,v);
end
Lua + Redis 实战代码
HuntFalcon2023-08-19 10:24
相关推荐
honghongstand26 分钟前
代码随想录D52-53 图论 Python过客猫202232 分钟前
使用 deepseek实现 go语言,读取文本文件的功能,要求支持 ascii,utf-8 等多种格式自适应程序媛-徐师姐43 分钟前
基于 Python Django 的校园互助平台(附源码,文档)进击的_鹏1 小时前
【C++】list 链表的使用+模拟实现m0_738355691 小时前
java泛型大模型铲屎官1 小时前
哈希表入门到精通:从原理到 Python 实现全解析L_09072 小时前
【C】队列与栈的相互转换qq4054251972 小时前
基于python的旅客游记和轨迹分析可视化系统设计(新)C#Thread2 小时前
C#上位机--进程和线程的区别DKPT2 小时前
计算机网络之路由协议(自治系统)