Skip to main content

Bridge

Struct Bridge 

Source
pub struct Bridge { /* private fields */ }
Expand description

kevy-lua per-shard bridge. One Bridge lives in each shard’s runtime; it owns the per-dialect VM pool, the SHA1 cache, and (P3+) the kevy-side dispatch callback that redis.call invokes.

The bridge is intentionally NOT Send / Sync — same constraint as luna’s Vm, which is !Send + !Sync by design. kevy’s thread-per-core model means every shard owns its bridge exclusively.

Implementations§

Source§

impl Bridge

Source

pub fn new<F>(dispatch: F) -> Self
where F: Fn(&[&[u8]], bool) -> Vec<u8> + 'static,

Create a fresh bridge with dispatch as the host callback behind redis.call. No Vms are spawned until the first EVAL.

The dispatch closure receives the script’s argv (&[&[u8]], command name at index 0) plus a read_only flag and must return RESP reply bytes. When read_only is true the dispatcher MUST reject write commands with -READONLY can't write against a read-only script\r\n so EVAL_RO / EVALSHA_RO deliver Redis semantics. kevy-rt owns the canonical command-flag table and does this check natively in production; tests provide a stub dispatcher hard-coding a few write commands (see tests/integration.rs).

For embedders that don’t need real keyspace access (e.g. pure-computation EVAL), Bridge::with_no_dispatch installs a default that returns -ERR redis.call: no dispatch wired for every call.

Source

pub fn set_instr_budget(&mut self, n: i64)

Override the per-Vm instruction budget (~5 s ≈ 200 M instr by default). 0 disables the cap (unlimited execution).

Setting it does NOT affect already-spawned VMs in the pool — you can pair the call with Bridge::script_flush to force a respawn under the new budget, or leave existing VMs as-is and only catch new dialects.

Source

pub fn with_no_dispatch() -> Self

Bridge with a no-op dispatcher: every redis.call returns a RESP error. Convenience for embedders that want EVAL but don’t have the host dispatch wired yet (e.g. pure-computation scripts during early development).

Source

pub fn set_allowed_dialects(&mut self, versions: &[LuaVersion])

Restrict which Lua dialects this bridge will spawn VMs for. An EVAL with #!lua version=N for a non-allowed dialect is rejected with a -ERR reply. The 5.1 default is always accessible via scripts with no shebang regardless of this setting (you can’t disable the ecosystem-default dialect without taking a different with_allowed_dialects API).

Passing an empty slice = no restriction = all five dialects permitted (the constructor default).

Source

pub fn eval(&mut self, script: &[u8], keys: &[&[u8]], args: &[&[u8]]) -> Reply

Compile-or-execute a script and marshal its first return value into a RESP reply.

P1 scope: default to Lua 5.1, ignore KEYS/ARGV (P3 binds them to globals), no redis.call (P3), no shebang parsing (P4), no SHA1 cache (P5). The point is to confirm EVAL "return 1" 0 produces :1\r\n.

Source

pub fn eval_ro( &mut self, script: &[u8], keys: &[&[u8]], args: &[&[u8]], ) -> Reply

Read-only variant of Bridge::eval. The dispatcher receives read_only = true for every redis.call from this script; kevy-rt rejects write commands with -READONLY can't write against a read-only script\r\n. Redis 7.0+ EVAL_RO.

All other semantics (KEYS / ARGV / SHA1 cache fill / dialect routing) are identical to eval.

Source

pub fn evalsha_ro( &mut self, sha1: ScriptSha1, keys: &[&[u8]], args: &[&[u8]], ) -> Reply

Read-only variant of Bridge::evalsha. Redis 7.0+ EVALSHA_RO.

Source

pub fn evalsha( &mut self, sha1: ScriptSha1, keys: &[&[u8]], args: &[&[u8]], ) -> Reply

Run a previously-cached script by SHA1 hex.

Returns -NOSCRIPT ... if the script isn’t in the cache. Identical to running eval with the cached bytes — the same shebang routing, KEYS/ARGV binding, and redis.* host plumbing apply.

Source

pub fn script_load(&mut self, script: &[u8]) -> ScriptSha1

Cache a script without running it. Returns the SHA1 digest; the operator-side wire layer hex-encodes it for the Redis SCRIPT LOAD reply.

Source

pub fn script_exists(&self, sha1s: &[ScriptSha1]) -> Vec<bool>

Test which of the given SHA1s are in the cache. Returns a vector with true/false for each input SHA1 in order.

Source

pub fn script_flush(&mut self, _mode: FlushMode)

Drop the SHA1 cache + all per-dialect VMs. ASYNC and SYNC are currently both implemented as synchronous; the tag is preserved for future differentiation.

Trait Implementations§

Source§

impl Default for Bridge

Source§

fn default() -> Self

Equivalent to Bridge::with_no_dispatch — the safe default for embedders that don’t have a host dispatch wired yet.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Bridge

§

impl !Send for Bridge

§

impl !Sync for Bridge

§

impl !UnwindSafe for Bridge

§

impl Freeze for Bridge

§

impl Unpin for Bridge

§

impl UnsafeUnpin for Bridge

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.