mm_redis 1.9.8 → 1.9.9
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/LICENSE +15 -0
- package/README.md +64 -25
- package/index.js +1832 -521
- package/package.json +2 -2
- package/test.js +20 -20
- package/test_hmset.js +91 -0
- package/compatibility_table.md +0 -103
- package/verify_compatibility.js +0 -175
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_redis",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.9",
|
|
4
4
|
"description": "高效的Redis客户端封装库,提供连接池管理、数据类型操作、错误处理和批量操作优化",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"homepage": "https://www.npmjs.com/package/mm_redis",
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"
|
|
37
|
+
"mm_base_service": "^1.0.0",
|
|
38
38
|
"redis": "^5.8.3"
|
|
39
39
|
},
|
|
40
40
|
"engines": {
|
package/test.js
CHANGED
|
@@ -43,40 +43,40 @@ async function test() {
|
|
|
43
43
|
// 测试3: 数值增加相关 (addInt, incr, decr, incrby, decrby, addFloat)
|
|
44
44
|
$.log.debug('[Redis] \n测试3: 数值增加相关');
|
|
45
45
|
await rs.set("counter", 10);
|
|
46
|
-
var
|
|
47
|
-
$.log.debug('[Redis] addInt增加后的值:',
|
|
46
|
+
var new_count = await rs.addInt("counter", 5);
|
|
47
|
+
$.log.debug('[Redis] addInt增加后的值:', new_count);
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
$.log.debug('[Redis] incr增加后的值:',
|
|
49
|
+
new_count = await rs.incr("counter");
|
|
50
|
+
$.log.debug('[Redis] incr增加后的值:', new_count);
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
$.log.debug('[Redis] decr减少后的值:',
|
|
52
|
+
new_count = await rs.decr("counter");
|
|
53
|
+
$.log.debug('[Redis] decr减少后的值:', new_count);
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
$.log.debug('[Redis] incrby增加后的值:',
|
|
55
|
+
new_count = await rs.incrby("counter", 10);
|
|
56
|
+
$.log.debug('[Redis] incrby增加后的值:', new_count);
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
$.log.debug('[Redis] decrby减少后的值:',
|
|
58
|
+
new_count = await rs.decrby("counter", 5);
|
|
59
|
+
$.log.debug('[Redis] decrby减少后的值:', new_count);
|
|
60
60
|
|
|
61
61
|
await rs.set("float_counter", 10.5);
|
|
62
|
-
var
|
|
63
|
-
$.log.debug('[Redis] addFloat增加后的值:',
|
|
62
|
+
var new_float = await rs.addFloat("float_counter", 2.3);
|
|
63
|
+
$.log.debug('[Redis] addFloat增加后的值:', new_float);
|
|
64
64
|
|
|
65
65
|
// 测试4: 字符串操作 (addStr)
|
|
66
66
|
$.log.debug('[Redis] \n测试4: 字符串操作');
|
|
67
67
|
await rs.set("test_str", "Hello");
|
|
68
|
-
var
|
|
69
|
-
$.log.debug('[Redis] addStr追加后长度:',
|
|
70
|
-
var
|
|
71
|
-
$.log.debug('[Redis] 完整字符串:',
|
|
68
|
+
var str_len = await rs.addStr("test_str", " World");
|
|
69
|
+
$.log.debug('[Redis] addStr追加后长度:', str_len);
|
|
70
|
+
var full_str = await rs.get("test_str");
|
|
71
|
+
$.log.debug('[Redis] 完整字符串:', full_str);
|
|
72
72
|
|
|
73
73
|
// 测试5: 条件设置 (add - 仅当键不存在时设置)
|
|
74
74
|
$.log.debug('[Redis] \n测试5: 条件设置');
|
|
75
75
|
await rs.set("exists_key", "已存在的值");
|
|
76
|
-
var
|
|
77
|
-
var
|
|
78
|
-
$.log.debug('[Redis] 已有键add结果(false):',
|
|
79
|
-
$.log.debug('[Redis] 新键add结果(true):',
|
|
76
|
+
var add_result1 = await rs.add("exists_key", "这不会被设置");
|
|
77
|
+
var add_result2 = await rs.add("new_key", "新键值");
|
|
78
|
+
$.log.debug('[Redis] 已有键add结果(false):', add_result1);
|
|
79
|
+
$.log.debug('[Redis] 新键add结果(true):', add_result2);
|
|
80
80
|
$.log.debug('[Redis] 新键值:', await rs.get("new_key"));
|
|
81
81
|
|
|
82
82
|
// 测试6: 键检查 (has, exists)
|
package/test_hmset.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// 直接测试Redis模块的hmset功能
|
|
2
|
+
// 修改导入方式,查看实际导出的内容
|
|
3
|
+
const redisModule = require('./index.js');
|
|
4
|
+
|
|
5
|
+
// 简单的测试日志函数
|
|
6
|
+
const log = (...args) => {
|
|
7
|
+
console.log(`[${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
|
+
});
|
package/compatibility_table.md
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
# 四种缓存方式方法兼容性对比表格
|
|
2
|
-
|
|
3
|
-
## 核心缓存方法
|
|
4
|
-
|
|
5
|
-
| 方法名 | Redis | MongoDB | CacheBase | Memory | 状态说明 |
|
|
6
|
-
|-------|-------|---------|-----------|--------|----------|
|
|
7
|
-
| set | ✅ | ✅ | ⚠️ | ⚠️ | Redis和MongoDB正常工作,CacheBase和Memory行为不一致 |
|
|
8
|
-
| get | ✅ | ✅ | ✅ | ✅ | 所有方式均正常工作 |
|
|
9
|
-
| del | ✅ | ✅ | ⚠️ | ⚠️ | Redis和MongoDB正常工作,CacheBase和Memory行为不一致 |
|
|
10
|
-
| has | ✅ | ✅ | ✅ | ✅ | 所有方式都支持 |
|
|
11
|
-
| clear | ✅ | ✅ | ⚠️ | ⚠️ | Redis和MongoDB正常工作,CacheBase和Memory行为不一致 |
|
|
12
|
-
| keys | ✅ | ✅ | ✅ | ✅ | 所有方式都支持 |
|
|
13
|
-
| ttl | ⚠️ | ⚠️ | ⚠️ | ⚠️ | 所有方式行为不一致,需要依赖底层实现 |
|
|
14
|
-
| add | ✅ | ✅ | ✅ | ✅ | 所有方式均正常工作 |
|
|
15
|
-
| addInt | ✅ | ❌ | ❌ | ❌ | 仅Redis支持 |
|
|
16
|
-
| addStr | ✅ | ❌ | ❌ | ❌ | 仅Redis支持 |
|
|
17
|
-
| sort | ✅ | ✅ | ❌ | ❌ | Redis和MongoDB支持,其他方式不支持 |
|
|
18
|
-
| exists | ✅ | ✅ | ⚠️ | ⚠️ | Redis和MongoDB正常工作,CacheBase和Memory行为不一致 |
|
|
19
|
-
| incrby | ✅ | ❌ | ❌ | ❌ | 仅Redis支持 |
|
|
20
|
-
| decrby | ✅ | ❌ | ❌ | ❌ | 仅Redis支持 |
|
|
21
|
-
| addFloat | ✅ | ❌ | ❌ | ❌ | 仅Redis支持 |
|
|
22
|
-
|
|
23
|
-
## Redis兼容方法 - 哈希表操作
|
|
24
|
-
|
|
25
|
-
| 方法名 | Redis | MongoDB | CacheBase | Memory | 状态说明 |
|
|
26
|
-
|-------|-------|---------|-----------|--------|----------|
|
|
27
|
-
| hset | ✅ | ✅ | ⚠️ | ⚠️ | Redis和MongoDB正常工作,CacheBase和Memory行为不一致 |
|
|
28
|
-
| hget | ✅ | ✅ | ✅ | ✅ | 所有方式均正常工作 |
|
|
29
|
-
| hgetall | ✅ | ✅ | ✅ | ✅ | 所有方式都支持 |
|
|
30
|
-
| hdel | ✅ | ✅ | ✅ | ✅ | 所有方式都支持 |
|
|
31
|
-
| hmset | ✅ | ✅ | ❌ | ❌ | Redis和MongoDB支持,其他方式不支持 |
|
|
32
|
-
| hmget | ❌ | ✅ | ❌ | ❌ | 仅MongoDB支持 |
|
|
33
|
-
| hlen | ✅ | ✅ | ❌ | ❌ | Redis和MongoDB支持,其他方式不支持 |
|
|
34
|
-
|
|
35
|
-
## Redis兼容方法 - 其他常用命令
|
|
36
|
-
|
|
37
|
-
| 方法名 | Redis | MongoDB | CacheBase | Memory | 状态说明 |
|
|
38
|
-
|-------|-------|---------|-----------|--------|----------|
|
|
39
|
-
| expire | ✅ | ✅ | ✅ | ✅ | 所有方式都支持 |
|
|
40
|
-
| incr | ✅ | ✅ | ✅ | ✅ | 所有方式都支持 |
|
|
41
|
-
| decr | ✅ | ❌ | ❌ | ❌ | 仅Redis支持 |
|
|
42
|
-
| mget | ✅ | ✅ | ❌ | ❌ | Redis和MongoDB支持,其他方式不支持 |
|
|
43
|
-
| mset | ✅ | ✅ | ❌ | ❌ | Redis和MongoDB支持,其他方式不支持 |
|
|
44
|
-
| pexpire | ❌ | ❌ | ❌ | ❌ | 所有方式都不支持 |
|
|
45
|
-
| persist | ✅ | ❌ | ✅ | ✅ | Redis、CacheBase和Memory支持,MongoDB不支持 |
|
|
46
|
-
| strlen | ✅ | ❌ | ✅ | ❌ | Redis和CacheBase支持,其他方式不支持 |
|
|
47
|
-
| type | ❌ | ❌ | ❌ | ❌ | 所有方式都不支持 |
|
|
48
|
-
| rename | ❌ | ❌ | ❌ | ❌ | 所有方式都不支持 |
|
|
49
|
-
|
|
50
|
-
## Redis兼容方法 - 集合操作
|
|
51
|
-
|
|
52
|
-
| 方法名 | Redis | MongoDB | CacheBase | Memory | 状态说明 |
|
|
53
|
-
|-------|-------|---------|-----------|--------|----------|
|
|
54
|
-
| sadd | ✅ | ❌ | ❌ | ❌ | 仅Redis支持 |
|
|
55
|
-
| srem | ✅ | ❌ | ❌ | ❌ | 仅Redis支持 |
|
|
56
|
-
| sismember | ✅ | ✅ | ❌ | ❌ | Redis和MongoDB支持,其他方式不支持 |
|
|
57
|
-
| smembers | ✅ | ✅ | ❌ | ❌ | Redis和MongoDB支持,其他方式不支持 |
|
|
58
|
-
|
|
59
|
-
## 数组/列表操作方法
|
|
60
|
-
|
|
61
|
-
| 方法名 | Redis | MongoDB | CacheBase | Memory | 状态说明 |
|
|
62
|
-
|-------|-------|---------|-----------|--------|----------|
|
|
63
|
-
| list_set | ✅ | ❌ | ⚠️ | ⚠️ | Redis正常工作,CacheBase和Memory行为不一致,MongoDB不支持 |
|
|
64
|
-
| list_add | ✅ | ❌ | ⚠️ | ⚠️ | Redis正常工作,CacheBase和Memory行为不一致,MongoDB不支持 |
|
|
65
|
-
| list_has | ✅ | ❌ | ⚠️ | ⚠️ | Redis正常工作,CacheBase和Memory行为不一致,MongoDB不支持 |
|
|
66
|
-
| list_get | ✅ | ❌ | ⚠️ | ⚠️ | Redis正常工作,CacheBase和Memory行为不一致,MongoDB不支持 |
|
|
67
|
-
| list_clear | ✅ | ❌ | ✅ | ✅ | MongoDB不支持,其他方式支持 |
|
|
68
|
-
|
|
69
|
-
## 兼容性报告总结
|
|
70
|
-
|
|
71
|
-
基于实际功能测试,以下是四种缓存方式的兼容性报告:
|
|
72
|
-
|
|
73
|
-
| 方法类别 | CacheBase | Redis | MongoDB | Memory | 状态说明 |
|
|
74
|
-
|---------|-----------|-------|---------|--------|----------|
|
|
75
|
-
| 基础键值操作 | ⚠️ | ✅ | ✅ | ⚠️ | Redis和MongoDB正常工作,CacheBase和Memory部分方法行为不一致 |
|
|
76
|
-
| 数组操作 | ⚠️ | ✅ | ❌ | ⚠️ | Redis完全支持,CacheBase和Memory行为不一致,MongoDB不支持 |
|
|
77
|
-
| 过期时间操作 | ✅ | ✅ | ✅ | ✅ | 基本过期时间操作支持,但MongoDB不支持persist |
|
|
78
|
-
| 原子递增操作 | ✅ | ✅ | ✅ | ✅ | incr支持,但decr、incrby、decrby只有Redis支持 |
|
|
79
|
-
| 批量操作 | ❌ | ✅ | ✅ | ❌ | Redis和MongoDB支持,其他方式不支持 |
|
|
80
|
-
| 哈希表基本操作 | ✅ | ✅ | ✅ | ✅ | 基本操作均支持 |
|
|
81
|
-
| 哈希表批量操作 | ❌ | ✅ | ✅ | ❌ | Redis和MongoDB支持,其他方式不支持 |
|
|
82
|
-
| 集合操作 | ❌ | ✅ | ⚠️ | ❌ | Redis完整支持,MongoDB支持部分方法,其他方式不支持 |
|
|
83
|
-
| 字符串操作 | ⚠️ | ✅ | ❌ | ❌ | Redis完全支持,CacheBase支持部分方法,其他方式不支持 |
|
|
84
|
-
| 类型检测 | ❌ | ❌ | ❌ | ❌ | 所有方式都不支持 |
|
|
85
|
-
| 键重命名 | ❌ | ❌ | ❌ | ❌ | 所有方式都不支持 |
|
|
86
|
-
| 清理操作 | ✅ | ✅ | ✅ | ✅ | clear操作正常工作 |
|
|
87
|
-
|
|
88
|
-
### 测试统计
|
|
89
|
-
|
|
90
|
-
- **总测试用例**:43个方法
|
|
91
|
-
- **通过数**:不同缓存方式通过数量不同(Redis最多,MongoDB次之)
|
|
92
|
-
- **整体支持情况**:
|
|
93
|
-
- Redis:支持28个方法,不支持9个,行为不一致6个
|
|
94
|
-
- MongoDB:支持23个方法,不支持15个,行为不一致0个
|
|
95
|
-
- CacheBase:支持15个方法,不支持17个,行为不一致7个
|
|
96
|
-
- Memory:支持15个方法,不支持17个,行为不一致7个
|
|
97
|
-
- **注意事项**:
|
|
98
|
-
1. CacheBase和Memory的行为完全一致
|
|
99
|
-
2. Redis完全支持列表操作方法
|
|
100
|
-
3. MongoDB完全不支持列表操作方法(list_*)
|
|
101
|
-
4. addInt、addStr、incrby、decrby和addFloat仅Redis支持
|
|
102
|
-
5. 基础键值操作在Redis和MongoDB中表现最佳
|
|
103
|
-
6. 集合操作只有Redis完整支持
|
package/verify_compatibility.js
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
const { redis_admin } = require('./index.js');
|
|
2
|
-
|
|
3
|
-
async function verifyCompatibility() {
|
|
4
|
-
try {
|
|
5
|
-
var config = './config.json'.loadJson(__dirname);
|
|
6
|
-
var rs = redis_admin('sys', config);
|
|
7
|
-
await rs.open();
|
|
8
|
-
|
|
9
|
-
console.log('开始验证兼容性表格中的所有方法...');
|
|
10
|
-
|
|
11
|
-
// 1. 测试核心缓存方法
|
|
12
|
-
console.log('\n=== 核心缓存方法验证 ===');
|
|
13
|
-
await testBasicMethods(rs);
|
|
14
|
-
|
|
15
|
-
// 2. 测试已标记为移除的方法
|
|
16
|
-
console.log('\n=== 已标记为移除的方法验证 ===');
|
|
17
|
-
await testRemovedMethods(rs);
|
|
18
|
-
|
|
19
|
-
// 3. 测试列表操作方法
|
|
20
|
-
console.log('\n=== 列表操作方法验证 ===');
|
|
21
|
-
await testListMethods(rs);
|
|
22
|
-
|
|
23
|
-
// 4. 测试哈希表相关方法
|
|
24
|
-
console.log('\n=== 哈希表方法验证 ===');
|
|
25
|
-
await testHashMethods(rs);
|
|
26
|
-
|
|
27
|
-
// 5. 清理并关闭连接
|
|
28
|
-
console.log('\n清理测试数据...');
|
|
29
|
-
await rs.del(["list_test_key", "hash_test_key", "test_counter", "test_string"]);
|
|
30
|
-
|
|
31
|
-
await rs.close();
|
|
32
|
-
console.log('\n所有验证完成!');
|
|
33
|
-
process.exit(0);
|
|
34
|
-
} catch (error) {
|
|
35
|
-
console.error('验证过程中出现错误:', error);
|
|
36
|
-
process.exit(1);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async function testBasicMethods(rs) {
|
|
41
|
-
try {
|
|
42
|
-
// 测试核心方法
|
|
43
|
-
const methods = [
|
|
44
|
-
{ name: 'set', result: await rs.set('temp_key', 'test_value') },
|
|
45
|
-
{ name: 'get', result: await rs.get('temp_key') },
|
|
46
|
-
{ name: 'has', result: await rs.has('temp_key') },
|
|
47
|
-
{ name: 'exists', result: await rs.exists('temp_key') },
|
|
48
|
-
{ name: 'ttl', result: await rs.ttl('temp_key') },
|
|
49
|
-
{ name: 'persist', result: await rs.persist('temp_key') },
|
|
50
|
-
{ name: 'add', result: await rs.add('new_temp_key', 'new_value') },
|
|
51
|
-
{ name: 'addInt', result: await rs.addInt('test_counter', 10) },
|
|
52
|
-
{ name: 'addStr', result: await rs.addStr('test_string', 'text') },
|
|
53
|
-
{ name: 'keys', result: await rs.keys('*') },
|
|
54
|
-
{ name: 'clear', result: await rs.clear('temp_key') },
|
|
55
|
-
{ name: 'del', result: await rs.del('new_temp_key') },
|
|
56
|
-
{ name: 'incr', result: await rs.incr('test_counter') },
|
|
57
|
-
{ name: 'decr', result: await rs.decr('test_counter') },
|
|
58
|
-
{ name: 'mget', result: await rs.mget(['test_counter', 'test_string']) },
|
|
59
|
-
{ name: 'mset', result: await rs.mset({batch1: 'value1', batch2: 'value2'}) },
|
|
60
|
-
{ name: 'expire', result: await rs.expire('test_counter', 60) },
|
|
61
|
-
{ name: 'sort', result: await rs.sort('temp_sort', {order: 'asc'}) },
|
|
62
|
-
{ name: 'decrby', result: await rs.decrby('test_counter', 5) },
|
|
63
|
-
{ name: 'incrby', result: await rs.incrby('test_counter', 10) },
|
|
64
|
-
{ name: 'addFloat', result: await rs.addFloat('test_counter', 0.5) }
|
|
65
|
-
];
|
|
66
|
-
|
|
67
|
-
console.log('所有核心方法测试结果:');
|
|
68
|
-
methods.forEach(method => {
|
|
69
|
-
console.log(`- ${method.name}: ${typeof method.result !== 'undefined' ? '✅ 可用' : '❌ 不可用'}`);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
} catch (error) {
|
|
73
|
-
console.error('核心方法测试失败:', error);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async function testRemovedMethods(rs) {
|
|
78
|
-
try {
|
|
79
|
-
// 测试文档中标记为❌的方法
|
|
80
|
-
const removedMethods = ['hexists', 'hkeys', 'hvals'];
|
|
81
|
-
|
|
82
|
-
console.log('移除方法测试结果:');
|
|
83
|
-
for (const method of removedMethods) {
|
|
84
|
-
try {
|
|
85
|
-
// 尝试调用移除的方法
|
|
86
|
-
if (typeof rs[method] === 'function') {
|
|
87
|
-
// 方法存在,尝试调用它
|
|
88
|
-
const result = await rs[method]('hash_key', 'field1');
|
|
89
|
-
console.log(`- ${method}: ⚠️ 方法存在,但根据兼容性表格应被移除`);
|
|
90
|
-
} else {
|
|
91
|
-
console.log(`- ${method}: ✅ 正确移除,方法不存在`);
|
|
92
|
-
}
|
|
93
|
-
} catch (err) {
|
|
94
|
-
console.log(`- ${method}: ✅ 调用失败,符合移除预期:`, err.message);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
} catch (error) {
|
|
98
|
-
console.error('移除方法测试失败:', error);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async function testListMethods(rs) {
|
|
103
|
-
try {
|
|
104
|
-
// 测试列表操作方法
|
|
105
|
-
const listKey = 'list_test_key';
|
|
106
|
-
|
|
107
|
-
console.log('列表操作方法测试结果:');
|
|
108
|
-
|
|
109
|
-
// 测试list_set
|
|
110
|
-
const listSetResult = await rs.list_set(listKey, ["item1", "item2", "item3"]);
|
|
111
|
-
console.log(`- list_set: ${listSetResult ? '✅ 成功' : '❌ 失败'}`);
|
|
112
|
-
|
|
113
|
-
// 测试list_get
|
|
114
|
-
const listGetResult = await rs.list_get(listKey);
|
|
115
|
-
console.log(`- list_get: ${Array.isArray(listGetResult) ? '✅ 成功' : '❌ 失败'}`, listGetResult);
|
|
116
|
-
|
|
117
|
-
// 测试list_add
|
|
118
|
-
const listAddResult = await rs.list_add(listKey, "item4");
|
|
119
|
-
console.log(`- list_add: ${listAddResult ? '✅ 成功' : '❌ 失败'}`);
|
|
120
|
-
|
|
121
|
-
// 测试list_has
|
|
122
|
-
const listHasResult = await rs.list_has(listKey, "item2");
|
|
123
|
-
console.log(`- list_has: ${typeof listHasResult === 'boolean' ? '✅ 成功' : '❌ 失败'}`, listHasResult);
|
|
124
|
-
|
|
125
|
-
// 测试list_clear
|
|
126
|
-
const listClearResult = await rs.list_clear(listKey);
|
|
127
|
-
console.log(`- list_clear: ${listClearResult ? '✅ 成功' : '❌ 失败'}`);
|
|
128
|
-
|
|
129
|
-
} catch (error) {
|
|
130
|
-
console.error('列表操作方法测试失败:', error);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
async function testHashMethods(rs) {
|
|
135
|
-
try {
|
|
136
|
-
// 测试哈希表方法
|
|
137
|
-
const hashKey = 'hash_test_key';
|
|
138
|
-
|
|
139
|
-
console.log('哈希表方法测试结果:');
|
|
140
|
-
|
|
141
|
-
// 测试hset
|
|
142
|
-
const hsetResult = await rs.hset(hashKey, 'field1', 'value1');
|
|
143
|
-
console.log(`- hset: ${typeof hsetResult !== 'undefined' ? '✅ 可用' : '❌ 不可用'}`);
|
|
144
|
-
|
|
145
|
-
// 测试hget
|
|
146
|
-
const hgetResult = await rs.hget(hashKey, 'field1');
|
|
147
|
-
console.log(`- hget: ${hgetResult === 'value1' ? '✅ 可用' : '❌ 不可用'}`);
|
|
148
|
-
|
|
149
|
-
// 测试hmset
|
|
150
|
-
const hmsetResult = await rs.hmset(hashKey, {field2: 'value2', field3: 'value3'});
|
|
151
|
-
console.log(`- hmset: ${typeof hmsetResult !== 'undefined' ? '✅ 可用' : '❌ 不可用'}`);
|
|
152
|
-
|
|
153
|
-
// 测试hgetall
|
|
154
|
-
const hgetallResult = await rs.hgetall(hashKey);
|
|
155
|
-
console.log(`- hgetall: ${typeof hgetallResult === 'object' ? '✅ 可用' : '❌ 不可用'}`);
|
|
156
|
-
|
|
157
|
-
// 测试hdel
|
|
158
|
-
const hdelResult = await rs.hdel(hashKey, 'field1');
|
|
159
|
-
console.log(`- hdel: ${typeof hdelResult !== 'undefined' ? '✅ 可用' : '❌ 不可用'}`);
|
|
160
|
-
|
|
161
|
-
// 测试hlen
|
|
162
|
-
const hlenResult = await rs.hlen(hashKey);
|
|
163
|
-
console.log(`- hlen: ${typeof hlenResult === 'number' ? '✅ 可用' : '❌ 不可用'}`);
|
|
164
|
-
|
|
165
|
-
} catch (error) {
|
|
166
|
-
console.error('哈希表方法测试失败:', error);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
verifyCompatibility();
|
|
171
|
-
|
|
172
|
-
setTimeout(() => {
|
|
173
|
-
console.error('验证超时');
|
|
174
|
-
process.exit(1);
|
|
175
|
-
}, 15000); // 延长超时时间
|