@better-auth/redis-storage 1.6.10 → 1.6.12

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/dist/index.d.mts CHANGED
@@ -35,6 +35,7 @@ interface RedisStorageConfig {
35
35
  */
36
36
  declare function redisStorage(config: RedisStorageConfig): {
37
37
  get(key: string): Promise<string | null>;
38
+ getAndDelete(key: string): Promise<unknown>;
38
39
  set(key: string, value: string, ttl?: number | undefined): Promise<void>;
39
40
  delete(key: string): Promise<void>;
40
41
  listKeys(): Promise<string[]>;
package/dist/index.mjs CHANGED
@@ -22,13 +22,32 @@
22
22
  */
23
23
  function redisStorage(config) {
24
24
  const { client, keyPrefix = "better-auth:" } = config;
25
+ let supportsGetDel = true;
26
+ const getAndDeleteScript = `
27
+ local value = redis.call("GET", KEYS[1])
28
+ if value ~= false then
29
+ redis.call("DEL", KEYS[1])
30
+ end
31
+ return value
32
+ `;
25
33
  const prefixKey = (key) => {
26
34
  return `${keyPrefix}${key}`;
27
35
  };
36
+ const isUnknownCommandError = (error) => error instanceof Error && error.message.toLowerCase().includes("unknown command");
28
37
  return {
29
38
  async get(key) {
30
39
  return client.get(prefixKey(key));
31
40
  },
41
+ async getAndDelete(key) {
42
+ const prefixedKey = prefixKey(key);
43
+ if (supportsGetDel) try {
44
+ return await client.call("GETDEL", prefixedKey);
45
+ } catch (error) {
46
+ if (!isUnknownCommandError(error)) throw error;
47
+ supportsGetDel = false;
48
+ }
49
+ return client.eval(getAndDeleteScript, 1, prefixedKey);
50
+ },
32
51
  async set(key, value, ttl) {
33
52
  const prefixedKey = prefixKey(key);
34
53
  if (ttl !== void 0 && ttl > 0) await client.setex(prefixedKey, ttl, value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-auth/redis-storage",
3
- "version": "1.6.10",
3
+ "version": "1.6.12",
4
4
  "description": "Redis storage for Better Auth secondary storage",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "peerDependencies": {
37
37
  "ioredis": "^5.0.0",
38
- "@better-auth/core": "^1.6.10"
38
+ "@better-auth/core": "^1.6.12"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/node": "^25.3.2",
@@ -43,7 +43,7 @@
43
43
  "tsdown": "0.21.1",
44
44
  "typescript": "^5.9.3",
45
45
  "vitest": "^4.1.5",
46
- "@better-auth/core": "1.6.10"
46
+ "@better-auth/core": "1.6.12"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "tsdown",