mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 04:33:05 +00:00
add socket.response to support redis watch mode
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user