@jayfong/x-server 2.21.9 → 2.21.10

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.
@@ -31,13 +31,17 @@ class CacheService {
31
31
  const ttl = ttlOrOptions == null ? this.options.ttl : typeof ttlOrOptions === 'object' ? ttlOrOptions.ttl : ttlOrOptions;
32
32
  const redisTtl = typeof ttl === 'function' ? ttl(value, this.options.ttl) : ttl;
33
33
  if (redisTtl) {
34
- const redisKey = this.toRedisKey(key);
35
- const redisValue = JSON.stringify(value);
36
- await _x.x.redis.set(redisKey, redisValue,
37
- // 毫秒
38
- 'PX', (0, _vtils.ms)(redisTtl));
39
- if (this.options.memory) {
40
- this.memoryCache.set(redisKey, value);
34
+ const redisTtlMs = (0, _vtils.ms)(redisTtl);
35
+ // Redis TTL 不能小于等于 0
36
+ if (redisTtlMs > 0) {
37
+ const redisKey = this.toRedisKey(key);
38
+ const redisValue = JSON.stringify(value);
39
+ await _x.x.redis.set(redisKey, redisValue,
40
+ // 毫秒
41
+ 'PX', redisTtlMs);
42
+ if (this.options.memory) {
43
+ this.memoryCache.set(redisKey, value);
44
+ }
41
45
  }
42
46
  }
43
47
  return value;
@@ -26,13 +26,17 @@ export class CacheService {
26
26
  const ttl = ttlOrOptions == null ? this.options.ttl : typeof ttlOrOptions === 'object' ? ttlOrOptions.ttl : ttlOrOptions;
27
27
  const redisTtl = typeof ttl === 'function' ? ttl(value, this.options.ttl) : ttl;
28
28
  if (redisTtl) {
29
- const redisKey = this.toRedisKey(key);
30
- const redisValue = JSON.stringify(value);
31
- await x.redis.set(redisKey, redisValue,
32
- // 毫秒
33
- 'PX', ms(redisTtl));
34
- if (this.options.memory) {
35
- this.memoryCache.set(redisKey, value);
29
+ const redisTtlMs = ms(redisTtl);
30
+ // Redis TTL 不能小于等于 0
31
+ if (redisTtlMs > 0) {
32
+ const redisKey = this.toRedisKey(key);
33
+ const redisValue = JSON.stringify(value);
34
+ await x.redis.set(redisKey, redisValue,
35
+ // 毫秒
36
+ 'PX', redisTtlMs);
37
+ if (this.options.memory) {
38
+ this.memoryCache.set(redisKey, value);
39
+ }
36
40
  }
37
41
  }
38
42
  return value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.21.9",
3
+ "version": "2.21.10",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",