forked from cfadmin-cn/cfadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_Cache.lua
More file actions
139 lines (103 loc) · 3.88 KB
/
test_Cache.lua
File metadata and controls
139 lines (103 loc) · 3.88 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
-- 测试redis
local Cache = require "Cache"
local cf = require "cf"
local Log = require("logging"):new()
local opt = {
host = "localhost",
port = 6379,
auth = nil,
db = 1,
max = 1,
}
cf.fork(function ( ... )
local Cache = Cache:new(opt)
local ok, err = Cache:connect()
if not ok then
return print(err)
end
-- 测试 GET/SET/DEL 命令示例
local ok, ret = Cache:set("test", 1)
Log:DEBUG(ok, ret)
local ok, ret = Cache:get("test")
Log:DEBUG(ok, ret)
local ok, ret = Cache:del("test")
Log:DEBUG(ok, ret)
-- 测试哈希表命令示例
local ok, ret = Cache:hmset("website", "google", "www.google.com", "baidu", "www.baidu.com")
Log:DEBUG(ok, ret)
local ok, ret = Cache:hlen("website")
Log:DEBUG(ok, ret)
local ok, ret = Cache:hkeys("website")
Log:DEBUG(ok, ret)
local ok, ret = Cache:hgetall("website")
Log:DEBUG(ok, ret)
local ok, ret = Cache:hmget("website", "google", "baidu")
Log:DEBUG(ok, ret)
local ok, ret = Cache:hdel("website", "google", "baidu")
Log:DEBUG(ok, ret)
-- 测试列表命令示例
local ok, ret = Cache:lpush("language", "lua", "python", "C", "C++")
Log:DEBUG(ok, ret)
local ok, ret = Cache:rpush("language", "golang", "java", "ruby", "javascript")
Log:DEBUG(ok, ret)
local ok, ret = Cache:lrange("language", 0, -1)
Log:DEBUG(ok, ret)
local ok, ret = Cache:ltrim("language" , -1, 0)
Log:DEBUG(ok, ret)
local ok, ret = Cache:llen("language")
Log:DEBUG(ok, ret)
-- 测试有序集合命令示例
local ok, ret = Cache:smembers("bbs")
Log:DEBUG(ok, ret)
local ok, ret = Cache:sadd("bbs", "discuz.cn", "group.google.com", "oschina.net", "csdn.net")
Log:DEBUG(ok, ret)
local ok, ret = Cache:sismember("bbs", "oschina.net")
Log:DEBUG(ok, ret)
local ok, ret = Cache:srem("bbs", "discuz.cn", "group.google.com", "oschina.net", "csdn.net")
Log:DEBUG(ok, ret)
local ok, ret = Cache:sismember("bbs", "oschina.net")
Log:DEBUG(ok, ret)
local ok, ret = Cache:sadd("book1", "宝宝的C++", "宝宝的HTML", "宝宝的CSS", "C程序设计")
local ok, ret = Cache:sadd("book2", "宝宝的C++", "宝宝的HTML", "宝宝的CSS", "C++从入门到放弃")
local ok, ret = Cache:sadd("book3", "宝宝的C++", "宝宝的HTML", "宝宝的CSS", "MySQL从入门到删库跑路")
local ok, ret = Cache:sdiff("book1", "book2", "book3")
Log:DEBUG(ok, ret)
local ok, ret = Cache:del("book1", "book2", "book3")
Log:DEBUG(ok, ret)
-- 测试有序集合命令示例
local ok, ret = Cache:zadd("scores", 10, "admin", 20, "Candy", 30, "QQ", 40, "Guest")
Log:DEBUG(ok, ret)
local ok, ret = Cache:zrange("scores", 0, -1)
-- local ok, ret = Cache:zrange("scores", 0, -1, "WITHSCORES")
Log:DEBUG(ok, ret)
local ok, ret = Cache:zcount("scores", 10, 100)
Log:DEBUG(ok, ret)
local ok, ret = Cache:zscore("scores", "QQ")
Log:DEBUG(ok, ret)
local ok, ret = Cache:zrank("scores", "Candy")
Log:DEBUG(ok, ret)
local ok, ret = Cache:zrem("scores", "admin", "Candy", "QQ", "Guest")
Log:DEBUG(ok, ret)
local ok, ret = Cache:del("scores")
Log:DEBUG(ok, ret)
-- 脚本支持
local ok, ret = Cache:script_load("return 10086")
Log:DEBUG(ok, ret)
local sha = ret
local ok, ret = Cache:script_exists(sha)
Log:DEBUG(ok, ret)
local ok, ret = Cache:evalsha(sha, 0)
Log:DEBUG(ok, ret)
local ok, ret = Cache:script_flush()
Log:DEBUG(ok, ret)
-- 其它一些特殊方法支持
-- type, move, rename, keys, randomkey等等
Log:DEBUG(Cache:count())
-- 管道命令支持
local ok, ret = Cache:pipeline {
{"HMSET", "USER_INFO", "name", "Candy", "email", '869646063@qq.com', 'phone', '13000000000'},
{"HGET", "USER_INFO", "email"},
{"HGET", "USER_INFO", "phone"},
}
Log:DEBUG(ok, ret)
end)