forked from cloudwu/skynet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestredis.lua
67 lines (55 loc) · 1.02 KB
/
testredis.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
local skynet = require "skynet"
local redis = require "skynet.db.redis"
local conf = {
host = "127.0.0.1" ,
port = 6379 ,
db = 0
}
local function watching()
local w = redis.watch(conf)
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(conf)
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)