Introduce Bun.redis - a builtin Redis client for Bun (#18812)

This commit is contained in:
Jarred Sumner
2025-04-08 03:34:00 -07:00
committed by GitHub
parent 431b28fd6b
commit ec87a27d87
53 changed files with 9164 additions and 168 deletions

View File

@@ -259,64 +259,8 @@ pub const PostgresSQLQueryResultMode = enum(u8) {
raw = 2,
};
const JSRef = union(enum) {
weak: JSC.JSValue,
strong: JSC.Strong,
const JSRef = JSC.JSRef;
pub fn initWeak(value: JSC.JSValue) @This() {
return .{ .weak = value };
}
pub fn initStrong(value: JSC.JSValue, globalThis: *JSC.JSGlobalObject) @This() {
return .{ .strong = JSC.Strong.create(value, globalThis) };
}
pub fn empty() @This() {
return .{ .weak = .zero };
}
pub fn get(this: *@This()) JSC.JSValue {
return switch (this.*) {
.weak => this.weak,
.strong => this.strong.get() orelse .zero,
};
}
pub fn setWeak(this: *@This(), value: JSC.JSValue) void {
if (this == .strong) {
this.strong.deinit();
}
this.* = .{ .weak = value };
}
pub fn setStrong(this: *@This(), value: JSC.JSValue, globalThis: *JSC.JSGlobalObject) void {
if (this == .strong) {
this.strong.set(globalThis, value);
return;
}
this.* = .{ .strong = JSC.Strong.create(value, globalThis) };
}
pub fn upgrade(this: *@This(), globalThis: *JSC.JSGlobalObject) void {
switch (this.*) {
.weak => {
bun.assert(this.weak != .zero);
this.* = .{ .strong = JSC.Strong.create(this.weak, globalThis) };
},
.strong => {},
}
}
pub fn deinit(this: *@This()) void {
switch (this.*) {
.weak => {
this.weak = .zero;
},
.strong => {
this.strong.deinit();
},
}
}
};
pub const PostgresSQLQuery = struct {
statement: ?*PostgresSQLStatement = null,
query: bun.String = bun.String.empty,