Skip to content

Commit 88ff109

Browse files
authored
Merge pull request #883 from Gowa2017/master
add skynet sc and mongo desc
2 parents 4f04a44 + becf15e commit 88ff109

File tree

4 files changed

+59
-35
lines changed

4 files changed

+59
-35
lines changed

meta/3rd/skynet/library/skynet/db/mongo.lua

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ end
5757
function mongo_db:auth(user, pass)
5858

5959
end
60-
---执行命令
60+
---执行命令,命令的格式需要参考 [https://docs.mongodb.com/manual/reference/command/](https://docs.mongodb.com/manual/reference/command/),
61+
---命令的键要单独分开来放,如 mongo_db:runCommand('find','account','limit','1')
6162
function mongo_db:runCommand(cmd, cmd_v, ...)
6263
end
6364
---获取集合
@@ -78,8 +79,8 @@ end
7879
---向集合安全的插入数据
7980
---@param doc table
8081
---@return boolean ok #是否成功
81-
---@return string err #错误消息
82-
---@return table r #错误返回数据
82+
---@return string|nil err #错误消息
83+
---@return table r #成功时表示返回的数据,失败时表示错误的详细信息
8384
function mongo_collection:safe_insert(doc)
8485
end
8586

@@ -91,8 +92,8 @@ end
9192
---安全插入批量数据
9293
---@param docs table[]
9394
---@return boolean ok #是否成功
94-
---@return string err #错误消息
95-
---@return table r #错误返回数据
95+
---@return string|nil err #错误消息
96+
---@return table r #成功时表示返回的数据,失败时表示错误的详细信息
9697
function mongo_collection:safe_batch_insert(docs)
9798

9899
end
@@ -107,11 +108,11 @@ end
107108
---安全更新数据
108109
---@param selector table
109110
---@param update table
110-
---@param upsert boolean
111-
---@param multi boolean
111+
---@param upsert boolean #没有数据是否插入
112+
---@param multi boolean #是否更新多行
112113
---@return boolean ok #是否成功
113-
---@return string err #错误消息
114-
---@return table r #错误返回数据
114+
---@return string|nil err #错误消息
115+
---@return table r #成功时表示返回的数据,失败时表示错误的详细信息
115116
function mongo_collection:safe_update(selector, update, upsert, multi)
116117

117118
end
@@ -131,6 +132,7 @@ end
131132
function mongo_collection:safe_delete(selector, single)
132133

133134
end
135+
---查找数据,返回的是一个游标,我们需要遍历游标才能获取所有返回
134136
---@param query table
135137
---@param selector table
136138
---@return mongo_cursor
@@ -149,7 +151,7 @@ end
149151
---* or collection:createIndex { "key1", "key2", unique = true }
150152
---* or collection:createIndex( { key1 = 1} , { unique = true } ) -- For compatibility
151153
---@param arg1 table
152-
---@param arg2 table
154+
---@param arg2? table
153155
function mongo_collection:createIndex(arg1, arg2)
154156

155157
end

meta/3rd/skynet/library/skynet/db/mysql.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ end
2525
local STMT = {}
2626
---@param sql string
2727
---@return boolean #whether ok
28-
---@return STMT # error description table or rows list
28+
---@return STMT|table # error description table or STMT
2929
function _M:prepare(sql)
3030
end
3131

meta/3rd/skynet/library/skynet/db/redis.lua

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,55 @@ local redis = {}
99
---@field db integer
1010
---@field username? string
1111

12-
---其他指令还可以动态生成
13-
---更多命令查看 https://www.redis.com.cn/commands.html
12+
---一个 Redis 连接,返回这个 Command 对象。当在此对象上执行指令时,若指令不存在,会在第一次执行的时候构造
13+
---指令对象的方法。
14+
---指令的参数的第一个可以是 nil, 也可以是 table,还可以有多个参数。
15+
---异步形式,底层用 socketchannel 进行通信,这点要注意。
16+
---更多命令查看 [https://www.redis.com.cn/commands.html](https://www.redis.com.cn/commands.html)
17+
---@see socketchannel
18+
---@class command
1419
local command = {}
15-
function command:disconnect() end
16-
function command:exists(k) end
17-
function command:sismember(key, value) end
18-
function command:pipeline(ops, resp) end
20+
function command:disconnect()
21+
end
22+
function command:exists(k)
23+
end
24+
function command:sismember(key, value)
25+
end
26+
function command:pipeline(ops, resp)
27+
end
1928

2029
--- watch mode, only can do SUBSCRIBE, PSUBSCRIBE, UNSUBSCRIBE, PUNSUBSCRIBE, PING and QUIT command.
30+
--- we can call watch:message in endless loop.
31+
---@class watch
2132
local watch = {}
22-
function watch:disconnect() end
33+
function watch:disconnect()
34+
end
2335
---阻塞模式读取消息
24-
function watch:message() end
36+
function watch:message()
37+
end
2538
---subscribe channel
26-
function watch:subscribe(...) end
39+
function watch:subscribe(...)
40+
end
2741
---pattern subscribe channels
28-
function watch:psubscribe(...) end
42+
function watch:psubscribe(...)
43+
end
2944
---unsubscribe
30-
function watch:unsubscribe(...) end
45+
function watch:unsubscribe(...)
46+
end
3147
---punsubscribe
32-
function watch:punsubscribe(...) end
48+
function watch:punsubscribe(...)
49+
end
3350

3451
---connect to redis server
3552
---@param conf redisconfig
3653
---@return command
37-
function redis.connect(conf) end
54+
function redis.connect(conf)
55+
end
3856

3957
---connect to redis server on watch mode
4058
---@param conf redisconfig
4159
---@return watch
42-
function redis.watch(conf) end
60+
function redis.watch(conf)
61+
end
4362

4463
return redis

meta/3rd/skynet/library/skynet/socketchannel.lua

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
---socket channel 在创建时,并不会立即建立连接。如果你什么都不做,那么连接建立会推迟到第一次 request 请求时。这种被动建立连接的过程会不断的尝试,即使第一次没有连接上,也会重试。
33
---@class socketchannel
44
local socket_channel = {}
5-
socket_channel.error = setmetatable(
6-
{}, {
7-
__tostring = function()
8-
return "[Error: socket]"
9-
end,
10-
})
115

126
---创建一个新的套接字频道
137
---返回结构:
@@ -30,6 +24,7 @@ socket_channel.error = setmetatable(
3024
---* __overload = false,
3125
---* }
3226
---@param desc table {host, port, backup, auth, response, nodelay, overload}
27+
---@return socketchannel
3328
function socket_channel.channel(desc)
3429

3530
end
@@ -39,15 +34,23 @@ end
3934
function socket_channel:connect(once)
4035

4136
end
37+
38+
---返回值 true 表示协议解析成功,如果为 false 表示协议出错,这会导致连接断开且让 request 的调用者也获得一个 error
39+
---在 response 函数内的任何异常以及 sock:read 或 sock:readline 读取出错,都会以 error 的形式抛给 request 的调用者。
40+
---@alias ResponseFunction fun(sock:table): boolean, string
41+
4242
---发送请求
43-
---@param request string
44-
---@param response? fun(sock:table): boolean, string
43+
---@param request string binary 请求内容,若不填写 resonse,那么只发送而不接收
44+
---@param response? ResponseFunction 返回值 true 表示协议解析成功,如果为 false 表示协议出错,这会导致连接断开且让 request 的调用者也获得一个 error
4545
---@param padding? table
46-
---@return string
46+
---@return string # 是由 response 函数返回的回应包的内容(可以是任意类型)
4747
function socket_channel:request(request, response, padding)
4848
end
4949

50-
function socket_channel:response(response)
50+
---用来单向接收一个包。
51+
---`local resp = channel:response(dispatch)` 与 `local resp = channel:request(req, dispatch)` 等价
52+
---@param dispatch any
53+
function socket_channel:response(dispatch)
5154
end
5255
---关闭频道
5356
function socket_channel:close()

0 commit comments

Comments
 (0)