pub struct Script { /* private fields */ }Expand description
A Lua script that can be executed on Redis
Implementations§
Source§impl Script
 
impl Script
Sourcepub fn new(source: impl Into<String>) -> Self
 
pub fn new(source: impl Into<String>) -> Self
Create a new script from Lua source code
The script is automatically hashed for use with EVALSHA.
§Examples
use redis_oxide::Script;
let script = Script::new("return redis.call('GET', KEYS[1])");
println!("Script SHA: {}", script.sha());Sourcepub async fn execute<T>(
    &self,
    client: &Client,
    keys: Vec<String>,
    args: Vec<String>,
) -> RedisResult<T>
 
pub async fn execute<T>( &self, client: &Client, keys: Vec<String>, args: Vec<String>, ) -> RedisResult<T>
Execute the script on the given client
This method will first try to use EVALSHA (if the script is cached on the server), and fall back to EVAL if the script is not cached.
§Arguments
- client- The Redis client to execute the script on
- keys- List of Redis keys that the script will access (KEYS array in Lua)
- args- List of arguments to pass to the script (ARGV array in Lua)
§Examples
let script = Script::new("return KEYS[1] .. ':' .. ARGV[1]");
let result: String = script.execute(
    &client,
    vec!["user".to_string()],
    vec!["123".to_string()]
).await?;
assert_eq!(result, "user:123");Sourcepub async fn load(&self, client: &Client) -> RedisResult<String>
 
pub async fn load(&self, client: &Client) -> RedisResult<String>
Load the script into Redis cache
This sends the script to Redis using SCRIPT LOAD, which caches it for future EVALSHA calls.
§Examples
let script = Script::new("return 'Hello, World!'");
// Preload the script
let sha = script.load(&client).await?;
println!("Script loaded with SHA: {}", sha);Trait Implementations§
Auto Trait Implementations§
impl Freeze for Script
impl RefUnwindSafe for Script
impl Send for Script
impl Sync for Script
impl Unpin for Script
impl UnwindSafe for Script
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more