mm_redis 2.0.5 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +438 -441
- package/package.json +4 -6
- package/test_hmset.js +0 -91
package/package.json
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_redis",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7",
|
|
4
4
|
"description": "高效的Redis客户端封装库,提供连接池管理、数据类型操作、错误处理和批量操作优化",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "node test.js",
|
|
8
|
-
"dev": "nodemon test.js"
|
|
9
|
-
"test:compatibility": "node test_compatibility.js",
|
|
10
|
-
"test:mget_mset": "node test_mget_mset.js"
|
|
8
|
+
"dev": "nodemon test.js"
|
|
11
9
|
},
|
|
12
10
|
"repository": {
|
|
13
11
|
"type": "git",
|
|
@@ -34,8 +32,8 @@
|
|
|
34
32
|
},
|
|
35
33
|
"homepage": "https://www.npmjs.com/package/mm_redis",
|
|
36
34
|
"dependencies": {
|
|
37
|
-
"
|
|
38
|
-
"redis": "^5.
|
|
35
|
+
"mm_expand": "^1.9.7",
|
|
36
|
+
"redis": "^5.10.0"
|
|
39
37
|
},
|
|
40
38
|
"engines": {
|
|
41
39
|
"node": ">=14.0.0"
|
package/test_hmset.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
// 直接测试Redis模块的hmset功能
|
|
2
|
-
// 修改导入方式,查看实际导出的内容
|
|
3
|
-
const redisModule = require('./index.js');
|
|
4
|
-
|
|
5
|
-
// 简单的测试日志函数
|
|
6
|
-
const log = (...args) => {
|
|
7
|
-
$.log.debug(`[${new Date().toISOString()}]`, ...args);
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
// 模拟$对象
|
|
11
|
-
global.$ = {
|
|
12
|
-
log: {
|
|
13
|
-
debug: (...args) => log('[DEBUG]', ...args),
|
|
14
|
-
info: (...args) => log('[INFO]', ...args),
|
|
15
|
-
warn: (...args) => log('[WARN]', ...args),
|
|
16
|
-
error: (...args) => log('[ERROR]', ...args)
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
// 查看模块导出内容
|
|
21
|
-
log('模块导出内容:', Object.keys(redisModule));
|
|
22
|
-
const Redis = redisModule.Redis || redisModule.default || redisModule;
|
|
23
|
-
log('使用的Redis构造函数:', Redis);
|
|
24
|
-
|
|
25
|
-
// 创建测试函数
|
|
26
|
-
async function testRedisHmset() {
|
|
27
|
-
log('开始测试Redis模块的hmset方法');
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
// 创建Redis实例(使用默认配置)
|
|
31
|
-
const redis = new Redis({
|
|
32
|
-
host: 'localhost',
|
|
33
|
-
port: 6379,
|
|
34
|
-
// 其他必要配置
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// 初始化
|
|
38
|
-
await redis.init();
|
|
39
|
-
log('Redis模块初始化完成');
|
|
40
|
-
|
|
41
|
-
// 测试数据
|
|
42
|
-
const testKey = 'test_hmset_key';
|
|
43
|
-
const testObj = {
|
|
44
|
-
field1: 'v1',
|
|
45
|
-
field2: 'v2',
|
|
46
|
-
field3: { nested: 'value' }
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// 先删除测试键(如果存在)
|
|
50
|
-
await redis.del(testKey);
|
|
51
|
-
log(`已清理测试键: ${testKey}`);
|
|
52
|
-
|
|
53
|
-
// 调用hmset方法
|
|
54
|
-
log(`调用hmset方法,键: ${testKey}, 对象:`, JSON.stringify(testObj));
|
|
55
|
-
const result = await redis.hmset(testKey, testObj);
|
|
56
|
-
log(`hmset方法返回结果: ${result}`);
|
|
57
|
-
|
|
58
|
-
// 验证结果
|
|
59
|
-
log(`验证设置结果...`);
|
|
60
|
-
const field1Value = await redis.hget(testKey, 'field1');
|
|
61
|
-
const field2Value = await redis.hget(testKey, 'field2');
|
|
62
|
-
const field3Value = await redis.hget(testKey, 'field3');
|
|
63
|
-
const allFields = await redis.hgetall(testKey);
|
|
64
|
-
|
|
65
|
-
log(`field1值: ${field1Value}`);
|
|
66
|
-
log(`field2值: ${field2Value}`);
|
|
67
|
-
log(`field3值: ${field3Value}`);
|
|
68
|
-
log(`所有字段:`, JSON.stringify(allFields));
|
|
69
|
-
|
|
70
|
-
// 检查结果是否符合预期
|
|
71
|
-
const success = field1Value === 'v1' && field2Value === 'v2';
|
|
72
|
-
log(`测试${success ? '通过' : '失败'}`);
|
|
73
|
-
|
|
74
|
-
// 清理
|
|
75
|
-
await redis.del(testKey);
|
|
76
|
-
await redis.destroy();
|
|
77
|
-
log('测试完成,资源已清理');
|
|
78
|
-
|
|
79
|
-
return success;
|
|
80
|
-
|
|
81
|
-
} catch (error) {
|
|
82
|
-
log('测试过程中发生错误:', error);
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// 运行测试
|
|
88
|
-
testRedisHmset().then(result => {
|
|
89
|
-
log(`测试结束,总体结果: ${result ? '成功' : '失败'}`);
|
|
90
|
-
process.exit(result ? 0 : 1);
|
|
91
|
-
});
|