mm_redis 2.1.7 → 2.3.0

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.
@@ -0,0 +1,40 @@
1
+ /**
2
+ * mm_redis 最小可运行示例
3
+ * @description 演示 Redis 类的实例化、工厂获取实例与核心方法存在性。
4
+ * 注意:不会真正连接 Redis 服务;host/port/password 为示例假值,实际使用时请替换为真实配置。
5
+ */
6
+ const { Redis, redisAdmin } = require('../index.js');
7
+
8
+ /** 示例假配置(实际使用时替换为真实 Redis 连接信息) */
9
+ const CONFIG = {
10
+ host: 'localhost',
11
+ port: 6379,
12
+ password: 'change_me',
13
+ database: 0
14
+ };
15
+
16
+ /**
17
+ * 主函数
18
+ */
19
+ function main() {
20
+ console.log('== mm_redis 示例开始 ==');
21
+
22
+ // 实例化(仅初始化连接池属性,不建立真实连接)
23
+ const redis = new Redis(CONFIG);
24
+ console.log('实例化 Redis 成功');
25
+ console.log('连接标识:', redis.identifier);
26
+
27
+ // 通过工厂函数获取按作用域缓存的实例
28
+ const cache = redisAdmin('example', CONFIG);
29
+ console.log('redisAdmin 获取实例:', cache instanceof Redis);
30
+
31
+ // 核心方法存在性检查(不真正执行,避免连接外部服务)
32
+ const METHODS = ['open', 'close', 'set', 'get', 'del', 'exists', 'keys', 'hset', 'hget',
33
+ 'mset', 'mget', 'incr', 'decr', 'sadd', 'smembers', 'zadd', 'zrange', 'subscribe', 'publish'];
34
+ const missing = METHODS.filter((name) => typeof cache[name] !== 'function');
35
+ console.log('核心方法检查:', missing.length === 0 ? '全部存在' : '缺失: ' + missing.join(','));
36
+
37
+ console.log('== mm_redis 示例结束 ==');
38
+ }
39
+
40
+ main();