Function ntex_redis::cmd::LPush [−][src]
pub fn LPush<T, V>(key: T, value: V) -> LPushCommand where
BulkString: From<T> + From<V>,
LPUSH redis command
Insert all the specified values at the head of the list stored at key.
use ntex_redis::{cmd, RedisConnector}; #[ntex::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { let redis = RedisConnector::new("127.0.0.1:6379").connect().await?; let key = gen_random_key(); // create list with one value redis.exec( cmd::LPush(&key, "value1") .extend(vec!["value2", "value3", "value4"]) ).await?; Ok(()) }
LPushCommand::if_exists() method changes LPUSH command to LPUSHX command
use ntex_redis::{cmd, RedisConnector}; #[ntex::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { let redis = RedisConnector::new("127.0.0.1:6379").connect().await?; let key = gen_random_key(); // create list with one value only if key already exists redis.exec( cmd::LPush(&key, "value1") .value("value2") .if_exists() ).await?; Ok(()) }