mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-23 11:33:09 +00:00
rewrite makefile, and remove luacode cache.
This commit is contained in:
61
test/testredis.lua
Normal file
61
test/testredis.lua
Normal file
@@ -0,0 +1,61 @@
|
||||
local skynet = require "skynet"
|
||||
local redis = require "redis"
|
||||
|
||||
local function watching()
|
||||
local w = redis.watch "main"
|
||||
w:subscribe "foo"
|
||||
w:psubscribe "hello.*"
|
||||
while true do
|
||||
print("Watch", w:message())
|
||||
end
|
||||
end
|
||||
|
||||
skynet.start(function()
|
||||
skynet.fork(watching)
|
||||
local db = redis.connect "main"
|
||||
|
||||
db:del "C"
|
||||
db:set("A", "hello")
|
||||
db:set("B", "world")
|
||||
db:sadd("C", "one")
|
||||
|
||||
print(db:get("A"))
|
||||
print(db:get("B"))
|
||||
|
||||
db:del "D"
|
||||
for i=1,10 do
|
||||
db:hset("D",i,i)
|
||||
end
|
||||
local r = db:hvals "D"
|
||||
for k,v in pairs(r) do
|
||||
print(k,v)
|
||||
end
|
||||
|
||||
db:multi()
|
||||
db:get "A"
|
||||
db:get "B"
|
||||
local t = db:exec()
|
||||
for k,v in ipairs(t) do
|
||||
print("Exec", v)
|
||||
end
|
||||
|
||||
print(db:exists "A")
|
||||
print(db:get "A")
|
||||
print(db:set("A","hello world"))
|
||||
print(db:get("A"))
|
||||
print(db:sismember("C","one"))
|
||||
print(db:sismember("C","two"))
|
||||
|
||||
print("===========publish============")
|
||||
|
||||
for i=1,10 do
|
||||
db:publish("foo", i)
|
||||
end
|
||||
for i=11,20 do
|
||||
db:publish("hello.foo", i)
|
||||
end
|
||||
|
||||
db:disconnect()
|
||||
-- skynet.exit()
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user