@bejibun/redis 0.1.37 → 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,7 +3,22 @@ All notable changes to this project will be documented in this file.
3
3
 
4
4
  ---
5
5
 
6
- ## [v0.1.37](https://github.com/Bejibun-Framework/bejibun-redis/compare/v0.1.36...v0.1.37) - 2026-02-14
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
+
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
9
24
 
@@ -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,21 +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)),
19
+ keys: (pattern) => this.keys(pattern, connectionName, isNotEmpty(name)),
18
20
  pipeline: (fn) => this.pipeline(fn, connectionName, isNotEmpty(name)),
19
21
  publish: (channel, message) => this.publish(channel, message, connectionName),
20
22
  set: (key, value, ttl) => this.set(key, value, ttl, connectionName, isNotEmpty(name)),
21
23
  subscribe: (channel, listener) => this.subscribe(channel, listener, connectionName),
24
+ ttl: (key) => this.ttl(key, connectionName, isNotEmpty(name))
22
25
  };
23
26
  }
24
27
  static connection(name) {
25
28
  return {
26
29
  del: (key) => this.del(key, name),
30
+ expire: (key, value) => this.expire(key, value, name),
27
31
  get: (key) => this.get(key, name),
32
+ keys: (pattern) => this.keys(pattern, name),
28
33
  pipeline: (fn) => this.pipeline(fn, name),
29
34
  publish: (channel, message) => this.publish(channel, message, name),
30
35
  set: (key, value, ttl) => this.set(key, value, ttl, name),
31
36
  subscribe: (channel, listener) => this.subscribe(channel, listener, name),
37
+ ttl: (key) => this.ttl(key, name)
32
38
  };
33
39
  }
34
40
  static async connect(name) {
@@ -107,6 +113,30 @@ export default class RedisBuilder {
107
113
  return 0;
108
114
  }
109
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
+ }
110
140
  static async publish(channel, message, connection) {
111
141
  try {
112
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.37",
3
+ "version": "0.1.39",
4
4
  "author": "Havea Crenata <havea.crenata@gmail.com>",
5
5
  "repository": {
6
6
  "type": "git",