@bejibun/redis 0.1.38 → 0.1.39

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/CHANGELOG.md CHANGED
@@ -3,6 +3,21 @@ All notable changes to this project will be documented in this file.
3
3
 
4
4
  ---
5
5
 
6
+ ## [v0.1.39](https://github.com/Bejibun-Framework/bejibun-redis/compare/v0.1.38...v0.1.39) - 2026-03-02
7
+
8
+ ### 🩹 Fixes
9
+
10
+ ### 📖 Changes
11
+ - Added `.ttl(key: string)` to get ttl of key.
12
+ - Added `.expire(key: string, value: number)` to set key expires.
13
+
14
+ ### ❤️Contributors
15
+ - Havea Crenata ([@crenata](https://github.com/crenata))
16
+
17
+ **Full Changelog**: https://github.com/Bejibun-Framework/bejibun-redis/blob/master/CHANGELOG.md
18
+
19
+ ---
20
+
6
21
  ## [v0.1.38](https://github.com/Bejibun-Framework/bejibun-redis/compare/v0.1.36...v0.1.38) - 2026-02-14
7
22
 
8
23
  ### 🩹 Fixes
@@ -10,6 +10,8 @@ export default class RedisBuilder {
10
10
  static get(key: Bun.RedisClient.KeyLike, connection?: string, disconnectAfter?: boolean): Promise<any>;
11
11
  static set(key: Bun.RedisClient.KeyLike, value: any, ttl?: number, connection?: string, disconnectAfter?: boolean): Promise<number | "OK">;
12
12
  static del(key: Bun.RedisClient.KeyLike, connection?: string, disconnectAfter?: boolean): Promise<number>;
13
+ static ttl(key: Bun.RedisClient.KeyLike, connection?: string, disconnectAfter?: boolean): Promise<number>;
14
+ static expire(key: Bun.RedisClient.KeyLike, value: number, connection?: string, disconnectAfter?: boolean): Promise<number>;
13
15
  static publish(channel: string, message: any, connection?: string): Promise<number>;
14
16
  static subscribe(channel: string, listener: Bun.RedisClient.StringPubSubListener, connection?: string): Promise<RedisSubscribe>;
15
17
  static pipeline(fn: (pipe: RedisPipeline) => void, connection?: string, disconnectAfter?: boolean): Promise<any[]>;
@@ -14,23 +14,27 @@ export default class RedisBuilder {
14
14
  this.clients[connectionName] = this.createClient(connectionName, cfg);
15
15
  return {
16
16
  del: (key) => this.del(key, connectionName, isNotEmpty(name)),
17
+ expire: (key, value) => this.expire(key, value, connectionName, isNotEmpty(name)),
17
18
  get: (key) => this.get(key, connectionName, isNotEmpty(name)),
18
19
  keys: (pattern) => this.keys(pattern, connectionName, isNotEmpty(name)),
19
20
  pipeline: (fn) => this.pipeline(fn, connectionName, isNotEmpty(name)),
20
21
  publish: (channel, message) => this.publish(channel, message, connectionName),
21
22
  set: (key, value, ttl) => this.set(key, value, ttl, connectionName, isNotEmpty(name)),
22
23
  subscribe: (channel, listener) => this.subscribe(channel, listener, connectionName),
24
+ ttl: (key) => this.ttl(key, connectionName, isNotEmpty(name))
23
25
  };
24
26
  }
25
27
  static connection(name) {
26
28
  return {
27
29
  del: (key) => this.del(key, name),
30
+ expire: (key, value) => this.expire(key, value, name),
28
31
  get: (key) => this.get(key, name),
29
32
  keys: (pattern) => this.keys(pattern, name),
30
33
  pipeline: (fn) => this.pipeline(fn, name),
31
34
  publish: (channel, message) => this.publish(channel, message, name),
32
35
  set: (key, value, ttl) => this.set(key, value, ttl, name),
33
36
  subscribe: (channel, listener) => this.subscribe(channel, listener, name),
37
+ ttl: (key) => this.ttl(key, name)
34
38
  };
35
39
  }
36
40
  static async connect(name) {
@@ -109,6 +113,30 @@ export default class RedisBuilder {
109
113
  return 0;
110
114
  }
111
115
  }
116
+ static async ttl(key, connection, disconnectAfter) {
117
+ try {
118
+ const data = await this.getClient(connection).ttl(key);
119
+ if (disconnectAfter)
120
+ await this.disconnect(connection);
121
+ return data;
122
+ }
123
+ catch (error) {
124
+ Logger.setContext("Redis").error("Failed to fetch ttl.").trace(error);
125
+ return 0;
126
+ }
127
+ }
128
+ static async expire(key, value, connection, disconnectAfter) {
129
+ try {
130
+ const data = await this.getClient(connection).expire(key, value);
131
+ if (disconnectAfter)
132
+ await this.disconnect(connection);
133
+ return data;
134
+ }
135
+ catch (error) {
136
+ Logger.setContext("Redis").error("Failed to set expire.").trace(error);
137
+ return 0;
138
+ }
139
+ }
112
140
  static async publish(channel, message, connection) {
113
141
  try {
114
142
  const serialized = this.serialize(message);
@@ -8,6 +8,8 @@ export default class Redis {
8
8
  static get(key: Bun.RedisClient.KeyLike, connection?: string): Promise<any>;
9
9
  static set(key: Bun.RedisClient.KeyLike, value: any, ttl?: number, connection?: string): Promise<number | "OK">;
10
10
  static del(key: Bun.RedisClient.KeyLike, connection?: string): Promise<number>;
11
+ static ttl(key: Bun.RedisClient.KeyLike, connection?: string): Promise<number>;
12
+ static expire(key: Bun.RedisClient.KeyLike, value: number, connection?: string): Promise<number>;
11
13
  static publish(channel: string, message: any, connection?: string): Promise<number>;
12
14
  static subscribe(channel: string, listener: Bun.RedisClient.StringPubSubListener, connection?: string): Promise<RedisSubscribe>;
13
15
  static pipeline(fn: (pipe: RedisPipeline) => void, connection?: string): Promise<any[]>;
package/facades/Redis.js CHANGED
@@ -24,6 +24,12 @@ export default class Redis {
24
24
  static async del(key, connection) {
25
25
  return RedisBuilder.del(key, connection);
26
26
  }
27
+ static async ttl(key, connection) {
28
+ return RedisBuilder.ttl(key, connection);
29
+ }
30
+ static async expire(key, value, connection) {
31
+ return RedisBuilder.expire(key, value, connection);
32
+ }
27
33
  static async publish(channel, message, connection) {
28
34
  return RedisBuilder.publish(channel, message, connection);
29
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bejibun/redis",
3
- "version": "0.1.38",
3
+ "version": "0.1.39",
4
4
  "author": "Havea Crenata <havea.crenata@gmail.com>",
5
5
  "repository": {
6
6
  "type": "git",