add socket.response to support redis watch mode

This commit is contained in:
Cloud Wu
2014-03-23 19:46:21 +08:00
parent 2e1de9a64a
commit 90c947047c
3 changed files with 149 additions and 49 deletions

View File

@@ -1,8 +1,19 @@
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")
@@ -12,7 +23,7 @@ skynet.start(function()
print(db:get("B"))
db:del "D"
for i=1,1000 do
for i=1,10 do
db:hset("D",i,i)
end
local r = db:hvals "D"
@@ -20,7 +31,6 @@ skynet.start(function()
print(k,v)
end
--[[
db:multi()
db:get "A"
db:get "B"
@@ -28,14 +38,24 @@ skynet.start(function()
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()
-- skynet.exit()
end)