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
impl Bridge
Sourcepub fn new<F>(dispatch: F) -> Self
pub fn new<F>(dispatch: F) -> Self
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.
Sourcepub fn set_instr_budget(&mut self, n: i64)
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.
Sourcepub fn with_no_dispatch() -> Self
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).
Sourcepub fn set_allowed_dialects(&mut self, versions: &[LuaVersion])
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).
Sourcepub fn eval(&mut self, script: &[u8], keys: &[&[u8]], args: &[&[u8]]) -> Reply
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.
Sourcepub fn eval_ro(
&mut self,
script: &[u8],
keys: &[&[u8]],
args: &[&[u8]],
) -> Reply
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.
Sourcepub fn evalsha_ro(
&mut self,
sha1: ScriptSha1,
keys: &[&[u8]],
args: &[&[u8]],
) -> Reply
pub fn evalsha_ro( &mut self, sha1: ScriptSha1, keys: &[&[u8]], args: &[&[u8]], ) -> Reply
Read-only variant of Bridge::evalsha. Redis 7.0+ EVALSHA_RO.
Sourcepub fn evalsha(
&mut self,
sha1: ScriptSha1,
keys: &[&[u8]],
args: &[&[u8]],
) -> Reply
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.
Sourcepub fn script_load(&mut self, script: &[u8]) -> ScriptSha1
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.
Sourcepub fn script_exists(&self, sha1s: &[ScriptSha1]) -> Vec<bool>
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.
Sourcepub fn script_flush(&mut self, _mode: FlushMode)
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.