Skip to main content

RespValue

Enum RespValue 

Source
pub enum RespValue {
    Simple(String),
    Error(String),
    Integer(i64),
    Bulk(Vec<u8>),
    Array(Vec<RespValue>),
    Null,
}
Expand description

One RESP2 value.

Variants§

§

Simple(String)

A simple string, such as OK.

§

Error(String)

An error reply. crate::Client::execute returns this as crate::Error::Server.

§

Integer(i64)

A signed integer.

§

Bulk(Vec<u8>)

A bulk string, including the empty bulk.

§

Array(Vec<RespValue>)

An array of values.

§

Null

A null bulk or a null array.

Implementations§

Source§

impl RespValue

Source

pub fn as_string(&self) -> Result<Option<String>, Error>

UTF-8 text of a simple string, error, or bulk string. An integer is its decimal form. None when the value is null or an array (including a Pub/Sub push).

Examples found in repository?
examples/tour.rs (line 472)
457fn transactions(db: &mut Client) -> Result<(), ruvio_client::Error> {
458    db.watch_key("{tour}:w")?;
459    db.watch(&["{tour}:w"])?;
460    db.multi()?;
461    db.execute(&["SET", "{tour}:w", "1"])?;
462    db.execute(&["INCR", "{tour}:w"])?;
463    println!(
464        "exec {} replies",
465        db.exec()?.map(|replies| replies.len()).unwrap_or(0)
466    );
467    db.unwatch()?;
468    db.multi()?;
469    db.discard()?;
470    println!(
471        "eval {:?}",
472        db.eval("return ARGV[1]", &[], &["hi"])?.as_string()?
473    );
474    let sha = db.script_load("return ruvio.call('GET', KEYS[1])")?;
475
476    println!("script_exists {:?}", db.script_exists(&[&sha, "0000"])?);
477    println!(
478        "evalsha {:?}",
479        db.evalsha(&sha, &["{tour}:w"], &[])?.as_string()?
480    );
481    db.function_load("tour_echo", "return ARGV[1]")?;
482    println!(
483        "fcall {:?}",
484        db.fcall("tour_echo", &[], &["x"])?.as_string()?
485    );
486    println!(
487        "function_list array {}",
488        db.function_list()?.as_array().is_some()
489    );
490    println!("function_delete {}", db.function_delete("tour_echo")?);
491    db.script_flush()?;
492    match db.script_kill() {
493        Ok(()) => println!("script_kill ok"),
494        Err(error) => println!("script_kill {error}"),
495    }
496
497    if !db.is_cluster() {
498        db.set("{tour}:move", "v")?;
499        println!("move {}", db.move_key("{tour}:move", 14)?);
500        db.swapdb(14, 15)?;
501        println!("swapdb back");
502        db.swapdb(14, 15)?;
503    }
504
505    Ok(())
506}
Source

pub fn as_integer(&self) -> Option<i64>

The integer, or None for any other kind.

Source

pub fn as_array(&self) -> Option<&[RespValue]>

The array items, or None for any other kind.

Examples found in repository?
examples/tour.rs (line 421)
383fn streams(db: &mut Client) -> Result<(), ruvio_client::Error> {
384    let key = "{tour}:stream";
385    let first = db.xadd(key, "*", &[("f", "1")])?;
386
387    db.xadd(key, "*", &[("f", "2")])?;
388    println!(
389        "xadd_maxlen {}",
390        db.xadd_maxlen(key, 10, "*", &[("f", "3")])?
391    );
392    println!(
393        "xadd_delay {}",
394        db.xadd_delay(key, 60_000, "*", &[("f", "later")])?
395    );
396    println!("xlen {}", db.xlen(key)?);
397    println!("xrange {}", db.xrange(key, "-", "+", None)?[0].id);
398    println!(
399        "xrevrange {}",
400        db.xrevrange(key, "+", "-", Some(1))?[0].fields[0].1
401    );
402    let read = db.xread(
403        &StreamReadOptions {
404            count: Some(2),
405            ..StreamReadOptions::default()
406        },
407        &[(key, "0")],
408    )?;
409
410    println!("xread {}", read[0].entries.len());
411    db.xgroup_create(key, "g", "0", false)?;
412    db.xgroup_create("{tour}:fresh", "g", "$", true)?;
413    let delivered = db.xreadgroup("g", "c1", &StreamReadOptions::default(), &[(key, ">")])?;
414
415    println!("xreadgroup {}", delivered[0].entries.len());
416    let pending = db.xpending(key, "g", "-", "+", 10, &StreamPendingFilter::default())?;
417
418    println!(
419        "xpending {} summary-array {}",
420        pending.len(),
421        db.xpending_summary(key, "g")?.as_array().is_some()
422    );
423    let claimed = db.xclaim(
424        key,
425        "g",
426        "c2",
427        Duration::ZERO,
428        &[&first],
429        &StreamClaimOptions::default(),
430    )?;
431
432    println!("xclaim {}", claimed[0].id);
433    println!(
434        "xclaim_ids {:?}",
435        db.xclaim_ids(
436            key,
437            "g",
438            "c2",
439            Duration::ZERO,
440            &[&first],
441            &StreamClaimOptions::default()
442        )?
443    );
444    println!("xack {}", db.xack(key, "g", &[&first])?);
445    println!(
446        "xgroup_delconsumer {}",
447        db.xgroup_delconsumer(key, "g", "c1")?
448    );
449    db.xgroup_setid(key, "g", "0")?;
450    println!("xgroup_destroy {}", db.xgroup_destroy(key, "g")?);
451    println!("xdel {}", db.xdel(key, &[&first])?);
452    println!("xtrim {}", db.xtrim_maxlen(key, 1)?);
453
454    Ok(())
455}
456
457fn transactions(db: &mut Client) -> Result<(), ruvio_client::Error> {
458    db.watch_key("{tour}:w")?;
459    db.watch(&["{tour}:w"])?;
460    db.multi()?;
461    db.execute(&["SET", "{tour}:w", "1"])?;
462    db.execute(&["INCR", "{tour}:w"])?;
463    println!(
464        "exec {} replies",
465        db.exec()?.map(|replies| replies.len()).unwrap_or(0)
466    );
467    db.unwatch()?;
468    db.multi()?;
469    db.discard()?;
470    println!(
471        "eval {:?}",
472        db.eval("return ARGV[1]", &[], &["hi"])?.as_string()?
473    );
474    let sha = db.script_load("return ruvio.call('GET', KEYS[1])")?;
475
476    println!("script_exists {:?}", db.script_exists(&[&sha, "0000"])?);
477    println!(
478        "evalsha {:?}",
479        db.evalsha(&sha, &["{tour}:w"], &[])?.as_string()?
480    );
481    db.function_load("tour_echo", "return ARGV[1]")?;
482    println!(
483        "fcall {:?}",
484        db.fcall("tour_echo", &[], &["x"])?.as_string()?
485    );
486    println!(
487        "function_list array {}",
488        db.function_list()?.as_array().is_some()
489    );
490    println!("function_delete {}", db.function_delete("tour_echo")?);
491    db.script_flush()?;
492    match db.script_kill() {
493        Ok(()) => println!("script_kill ok"),
494        Err(error) => println!("script_kill {error}"),
495    }
496
497    if !db.is_cluster() {
498        db.set("{tour}:move", "v")?;
499        println!("move {}", db.move_key("{tour}:move", 14)?);
500        db.swapdb(14, 15)?;
501        println!("swapdb back");
502        db.swapdb(14, 15)?;
503    }
504
505    Ok(())
506}
507
508fn server(db: &mut Client) -> Result<(), ruvio_client::Error> {
509    println!("ping {}", db.ping()?);
510    println!("ping_message {}", db.ping_message("tour")?);
511    println!("info has ruvio {}", db.info(None)?.contains("ruvio"));
512    println!("info server {}", db.info(Some("server"))?.len());
513    println!("config_get {}", db.config_get("databases")?.len());
514    println!("whoami {}", db.acl_whoami()?);
515    println!("acl_users {:?}", db.acl_users()?);
516    println!("acl_list {}", db.acl_list()?.len());
517    println!("acl_cat {}", db.acl_cat()?.len());
518    println!("acl_getuser null {}", db.acl_getuser("default")?.is_null());
519    db.acl_setuser("tour-reader", &["on", "~{tour}:*", "+get"])?;
520    db.client_setname("ruvio-tour")?;
521    println!("client_getname {:?}", db.client_getname()?);
522    db.client_tracking(false)?;
523    println!("cluster_keyslot {}", db.cluster_keyslot("{tour}")?);
524
525    if db.is_cluster() {
526        println!(
527            "cluster_nodes {}",
528            db.cluster_nodes()?.chars().take(40).collect::<String>()
529        );
530        println!(
531            "cluster_slots array {}",
532            db.cluster_slots()?.as_array().is_some()
533        );
534        println!(
535            "cluster_shards array {}",
536            db.cluster_shards()?.as_array().is_some()
537        );
538        println!("cluster_info {}", db.cluster_info()?.len());
539        println!("cluster_myid {}", db.cluster_myid()?);
540        db.readonly()?;
541        db.readwrite()?;
542    }
543
544    db.save()?;
545    db.bgsave()?;
546    println!("hello array {}", db.hello(2)?.as_array().is_some());
547    db.execute_many(&[&["PING"], &["PING"]])?;
548
549    Ok(())
550}
Source

pub fn is_null(&self) -> bool

True for a null bulk or a null array.

Examples found in repository?
examples/tour.rs (line 518)
508fn server(db: &mut Client) -> Result<(), ruvio_client::Error> {
509    println!("ping {}", db.ping()?);
510    println!("ping_message {}", db.ping_message("tour")?);
511    println!("info has ruvio {}", db.info(None)?.contains("ruvio"));
512    println!("info server {}", db.info(Some("server"))?.len());
513    println!("config_get {}", db.config_get("databases")?.len());
514    println!("whoami {}", db.acl_whoami()?);
515    println!("acl_users {:?}", db.acl_users()?);
516    println!("acl_list {}", db.acl_list()?.len());
517    println!("acl_cat {}", db.acl_cat()?.len());
518    println!("acl_getuser null {}", db.acl_getuser("default")?.is_null());
519    db.acl_setuser("tour-reader", &["on", "~{tour}:*", "+get"])?;
520    db.client_setname("ruvio-tour")?;
521    println!("client_getname {:?}", db.client_getname()?);
522    db.client_tracking(false)?;
523    println!("cluster_keyslot {}", db.cluster_keyslot("{tour}")?);
524
525    if db.is_cluster() {
526        println!(
527            "cluster_nodes {}",
528            db.cluster_nodes()?.chars().take(40).collect::<String>()
529        );
530        println!(
531            "cluster_slots array {}",
532            db.cluster_slots()?.as_array().is_some()
533        );
534        println!(
535            "cluster_shards array {}",
536            db.cluster_shards()?.as_array().is_some()
537        );
538        println!("cluster_info {}", db.cluster_info()?.len());
539        println!("cluster_myid {}", db.cluster_myid()?);
540        db.readonly()?;
541        db.readwrite()?;
542    }
543
544    db.save()?;
545    db.bgsave()?;
546    println!("hello array {}", db.hello(2)?.as_array().is_some());
547    db.execute_many(&[&["PING"], &["PING"]])?;
548
549    Ok(())
550}

Trait Implementations§

Source§

impl Clone for RespValue

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RespValue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for RespValue

Source§

impl PartialEq for RespValue

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RespValue

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.