Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录
切换导航
N
nestjs-redis
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
王智锐 (C)
nestjs-redis
Commits
100b894f
提交
100b894f
authored
3月 16, 2020
作者:
zzy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1.2.6
上级
e53907fc
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
42 行增加
和
43 行删除
+42
-43
redis-client.provider.d.ts
dist/redis-client.provider.d.ts
+2
-9
redis-client.provider.js
dist/redis-client.provider.js
+36
-31
redis.interface.d.ts
dist/redis.interface.d.ts
+2
-1
redis.service.d.ts
dist/redis.service.d.ts
+2
-2
没有找到文件。
dist/redis-client.provider.d.ts
浏览文件 @
100b894f
import
*
as
Redis
from
'ioredis'
;
import
{
Provider
}
from
'@nestjs/common'
;
import
{
RedisModuleAsyncOptions
,
RedisModuleOptions
}
from
'./redis.interface'
;
export
declare
class
RedisClientError
extends
Error
{
}
...
...
@@ -7,15 +8,7 @@ export interface RedisClient {
clients
:
Map
<
string
,
Redis
.
Redis
>
;
size
:
number
;
}
export
declare
const
createClient
:
()
=>
{
provide
:
symbol
;
useFactory
:
(
options
:
RedisModuleOptions
|
RedisModuleOptions
[])
=>
{
defaultKey
:
string
;
clients
:
Map
<
string
,
Redis
.
Redis
>
;
size
:
number
;
};
inject
:
symbol
[];
};
export
declare
const
createClient
:
()
=>
Provider
<
any
>
;
export
declare
const
createAsyncClientOptions
:
(
options
:
RedisModuleAsyncOptions
)
=>
{
provide
:
symbol
;
useFactory
:
(...
args
:
any
[])
=>
RedisModuleOptions
|
Promise
<
RedisModuleOptions
>
|
RedisModuleOptions
[]
|
Promise
<
RedisModuleOptions
[]
>
;
...
...
dist/redis-client.provider.js
浏览文件 @
100b894f
"use strict"
;
var
__awaiter
=
(
this
&&
this
.
__awaiter
)
||
function
(
thisArg
,
_arguments
,
P
,
generator
)
{
return
new
(
P
||
(
P
=
Promise
))(
function
(
resolve
,
reject
)
{
function
fulfilled
(
value
)
{
try
{
step
(
generator
.
next
(
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
rejected
(
value
)
{
try
{
step
(
generator
[
"throw"
](
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
step
(
result
)
{
result
.
done
?
resolve
(
result
.
value
)
:
new
P
(
function
(
resolve
)
{
resolve
(
result
.
value
);
}).
then
(
fulfilled
,
rejected
);
}
step
((
generator
=
generator
.
apply
(
thisArg
,
_arguments
||
[])).
next
());
});
};
var
__rest
=
(
this
&&
this
.
__rest
)
||
function
(
s
,
e
)
{
var
t
=
{};
for
(
var
p
in
s
)
if
(
Object
.
prototype
.
hasOwnProperty
.
call
(
s
,
p
)
&&
e
.
indexOf
(
p
)
<
0
)
t
[
p
]
=
s
[
p
];
if
(
s
!=
null
&&
typeof
Object
.
getOwnPropertySymbols
===
"function"
)
for
(
var
i
=
0
,
p
=
Object
.
getOwnPropertySymbols
(
s
);
i
<
p
.
length
;
i
++
)
if
(
e
.
indexOf
(
p
[
i
])
<
0
)
t
[
p
[
i
]]
=
s
[
p
[
i
]];
return
t
;
};
Object
.
defineProperty
(
exports
,
"__esModule"
,
{
value
:
true
});
const
Redis
=
require
(
"ioredis"
);
const
uuid
=
require
(
"uuid"
);
...
...
@@ -6,51 +23,39 @@ const redis_constants_1 = require("./redis.constants");
class
RedisClientError
extends
Error
{
}
exports
.
RedisClientError
=
RedisClientError
;
function
getClient
(
options
)
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
const
{
onClientReady
,
url
}
=
options
,
opt
=
__rest
(
options
,
[
"onClientReady"
,
"url"
]);
const
client
=
url
?
new
Redis
(
url
)
:
new
Redis
(
opt
);
if
(
onClientReady
)
{
onClientReady
(
client
);
}
return
client
;
});
}
exports
.
createClient
=
()
=>
({
provide
:
redis_constants_1
.
REDIS_CLIENT
,
useFactory
:
(
options
)
=>
{
useFactory
:
(
options
)
=>
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
const
clients
=
new
Map
();
const
defaultKey
=
uuid
();
if
(
Array
.
isArray
(
options
))
{
for
(
const
o
of
options
)
{
if
(
o
.
name
)
{
if
(
clients
.
has
(
o
.
name
))
{
throw
new
RedisClientError
(
`client
${
o
.
name
}
is exists`
);
}
if
(
o
.
url
)
{
clients
.
set
(
o
.
name
,
new
Redis
(
o
.
url
));
}
else
{
clients
.
set
(
o
.
name
,
new
Redis
(
o
));
}
}
else
{
if
(
clients
.
has
(
defaultKey
))
{
throw
new
RedisClientError
(
'default client is exists'
);
}
if
(
o
.
url
)
{
clients
.
set
(
defaultKey
,
new
Redis
(
o
.
url
));
}
else
{
clients
.
set
(
defaultKey
,
new
Redis
(
o
));
}
yield
Promise
.
all
(
options
.
map
((
o
)
=>
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
const
key
=
o
.
name
||
defaultKey
;
if
(
clients
.
has
(
key
))
{
throw
new
RedisClientError
(
`
${
o
.
name
||
'default'
}
client is exists`
);
}
}
clients
.
set
(
key
,
yield
getClient
(
o
));
})));
}
else
{
if
(
options
.
url
)
{
clients
.
set
(
defaultKey
,
new
Redis
(
options
.
url
));
}
else
{
clients
.
set
(
defaultKey
,
new
Redis
(
options
));
}
clients
.
set
(
defaultKey
,
yield
getClient
(
options
));
}
return
{
defaultKey
,
clients
,
size
:
clients
.
size
,
};
},
}
)
,
inject
:
[
redis_constants_1
.
REDIS_MODULE_OPTIONS
],
});
exports
.
createAsyncClientOptions
=
(
options
)
=>
({
...
...
dist/redis.interface.d.ts
浏览文件 @
100b894f
import
{
ModuleMetadata
}
from
'@nestjs/common/interfaces'
;
import
{
RedisOptions
}
from
'ioredis'
;
import
{
Redis
,
Redis
Options
}
from
'ioredis'
;
export
interface
RedisModuleOptions
extends
RedisOptions
{
name
?:
string
;
url
?:
string
;
onClientReady
?(
client
:
Redis
):
Promise
<
void
>
;
}
export
interface
RedisModuleAsyncOptions
extends
Pick
<
ModuleMetadata
,
'imports'
>
{
useFactory
?:
(...
args
:
any
[])
=>
RedisModuleOptions
|
RedisModuleOptions
[]
|
Promise
<
RedisModuleOptions
>
|
Promise
<
RedisModuleOptions
[]
>
;
...
...
dist/redis.service.d.ts
浏览文件 @
100b894f
import
*
as
Redis
from
"ioredis"
;
import
{
RedisClient
}
from
"./redis-client.provider"
;
import
*
as
Redis
from
'ioredis'
;
import
{
RedisClient
}
from
'./redis-client.provider'
;
export
declare
class
RedisService
{
private
readonly
redisClient
;
constructor
(
redisClient
:
RedisClient
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论