Skip to main content

Client

Struct Client 

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

A Ruvio client. Against a single server it is one TCP connection. Against a sharded server it opens one connection per shard and sends each command to the shard that owns its key.

Subscribe commands open a second TCP socket, the same way Ruvio.Client does. GET, SET, PING, and PUBLISH stay on the command sockets.

The client speaks RESP2 and does not send CLIENT SETINFO or HELLO.

Implementations§

Source§

impl Client

Source

pub fn connect(host: impl Into<String>, port: u16) -> Result<Self, Error>

Opens a connection. Sends CLUSTER SLOTS so a sharded server is routed automatically.

Examples found in repository?
examples/tour.rs (line 25)
17fn main() -> Result<(), ruvio_client::Error> {
18    let host = std::env::args()
19        .nth(1)
20        .unwrap_or_else(|| "127.0.0.1".to_owned());
21    let port = std::env::args()
22        .nth(2)
23        .and_then(|text| text.parse().ok())
24        .unwrap_or(6379);
25    let mut db = Client::connect(&host, port)?;
26
27    db.on_connection_lost(|notice| {
28        println!(
29            "connection lost {}:{} subscriber={}",
30            notice.host, notice.port, notice.subscriber
31        );
32    });
33
34    db.on_connection_restored(|notice| {
35        println!(
36            "connection restored {}:{} subscriber={}",
37            notice.host, notice.port, notice.subscriber
38        );
39    });
40
41    db.set_reconnect_delay(|attempt| {
42        if attempt >= 8 {
43            None
44        } else {
45            Some(Duration::from_millis(100 * 2u64.pow(attempt - 1)))
46        }
47    });
48
49    println!(
50        "connected cluster={} shards={} slot={}",
51        db.is_cluster(),
52        db.shard_count(),
53        ruvio_client::hash_slot("{tour}")
54    );
55    println!("reconnect armed; the command that sees a drop fails, the next one opens the socket");
56
57    if !db.is_cluster() {
58        db.select(15)?;
59        db.flushdb()?;
60        println!("selected database {}", db.database());
61    }
62
63    strings(&mut db)?;
64    owned(&mut db)?;
65    lists(&mut db)?;
66    sets(&mut db)?;
67    hashes(&mut db)?;
68    sorted_sets(&mut db)?;
69    bloom(&mut db)?;
70    streams(&mut db)?;
71    transactions(&mut db)?;
72    server(&mut db)?;
73    pubsub(&host, port)?;
74
75    println!("tour finished");
76
77    Ok(())
78}
79
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
129
130fn owned(db: &mut Client) -> Result<(), ruvio_client::Error> {
131    let first = db.lease("{tour}:lock", 30_000)?;
132
133    println!(
134        "lease {:?} held {:?} release {}",
135        first,
136        db.lease("{tour}:lock", 30_000)?,
137        db.release("{tour}:lock", first.unwrap_or(0) as u64)?
138    );
139    let permit = db.semaphore("{tour}:workers", 1, 30_000)?;
140
141    println!(
142        "semaphore {:?} full {:?} release {}",
143        permit,
144        db.semaphore("{tour}:workers", 1, 30_000)?,
145        db.release("{tour}:workers", permit.unwrap_or(0) as u64)?
146    );
147    println!(
148        "incr_by_max {:?} over {:?}",
149        db.incr_by_max("{tour}:seats", 3, 4)?,
150        db.incr_by_max("{tour}:seats", 2, 4)?
151    );
152    let created = db.setv("{tour}:doc", "12", None)?;
153    let next = db.setv("{tour}:doc", "11", Some(created as u64))?;
154
155    println!("setv {created} then {next}");
156    println!(
157        "setv mismatch {}",
158        db.setv("{tour}:doc", "10", Some(created as u64))
159            .err()
160            .map(|error| error.to_string())
161            .unwrap_or_else(|| "accepted".to_owned())
162    );
163    let cursor = db.changes_start()?;
164
165    db.set("{tour}:note", "paid")?;
166    let notes = db.changes(cursor as u64)?;
167
168    println!(
169        "changes cursor={cursor} notes={} {}",
170        notes.len(),
171        notes.first().map(|(_, text)| text.as_str()).unwrap_or("")
172    );
173    println!(
174        "limit {:?} {:?}",
175        db.limit("{tour}:login", 2, 60_000)?,
176        db.limit("{tour}:login", 2, 60_000)?
177    );
178    println!(
179        "once {} {}",
180        db.once("{tour}:pay", 60_000)?,
181        db.once("{tour}:pay", 60_000)?
182    );
183    db.set("{tour}:seats", "5")?;
184    println!(
185        "take {:?} {:?}",
186        db.take("{tour}:seats", 2)?,
187        db.take("{tour}:seats", 9)?
188    );
189    println!("getex {:?}", db.getex("{tour}:seats", 60_000)?);
190
191    Ok(())
192}
193
194fn lists(db: &mut Client) -> Result<(), ruvio_client::Error> {
195    let key = "{tour}:l";
196
197    println!("rpush {}", db.rpush(key, &["a", "b", "c", "d"])?);
198    println!("lpush {}", db.lpush(key, &["z"])?);
199    println!("lpop {:?}", db.lpop(key)?);
200    println!("rpop_count {:?}", db.rpop_count(key, 2)?);
201    println!("llen {}", db.llen(key)?);
202    println!("lindex {:?}", db.lindex(key, 0)?);
203    println!("lrange {:?}", db.lrange(key, 0, -1)?);
204    db.ltrim(key, 0, 0)?;
205    println!("lpop_count {:?}", db.lpop_count(key, 1)?);
206    db.rpush(key, &["only"])?;
207    println!("blpop {:?}", db.blpop_key(key, Duration::from_millis(200))?);
208    db.rpush(key, &["right"])?;
209    println!("brpop {:?}", db.brpop(&[key], Duration::from_millis(200))?);
210    println!(
211        "brpop empty {:?}",
212        db.brpop_key(key, Duration::from_millis(1))?
213    );
214
215    Ok(())
216}
217
218fn sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
219    println!("sadd {}", db.sadd("{tour}:s1", &["a", "b", "c"])?);
220    db.sadd("{tour}:s2", &["b", "c", "d"])?;
221    println!("sismember {}", db.sismember("{tour}:s1", "a")?);
222    println!("scard {}", db.scard("{tour}:s1")?);
223    println!("smembers {:?}", db.smembers("{tour}:s1")?);
224    println!("sinter {:?}", db.sinter(&["{tour}:s1", "{tour}:s2"])?);
225    println!("sunion {:?}", db.sunion(&["{tour}:s1", "{tour}:s2"])?);
226    println!("sdiff {:?}", db.sdiff(&["{tour}:s1", "{tour}:s2"])?);
227    println!(
228        "sinterstore {}",
229        db.sinterstore("{tour}:s3", &["{tour}:s1", "{tour}:s2"])?
230    );
231    println!(
232        "sunionstore {}",
233        db.sunionstore("{tour}:s4", &["{tour}:s1", "{tour}:s2"])?
234    );
235    println!(
236        "sdiffstore {}",
237        db.sdiffstore("{tour}:s5", &["{tour}:s1", "{tour}:s2"])?
238    );
239    println!("smove {}", db.smove("{tour}:s1", "{tour}:s3", "a")?);
240    println!("srem {}", db.srem("{tour}:s3", &["a"])?);
241    println!("srandmember {:?}", db.srandmember("{tour}:s2")?);
242    println!(
243        "srandmember_count {:?}",
244        db.srandmember_count("{tour}:s2", 2)?
245    );
246    println!("spop_count {:?}", db.spop_count("{tour}:s5", 5)?);
247    println!("spop {:?}", db.spop("{tour}:s4")?);
248
249    Ok(())
250}
251
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
299
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
370
371fn bloom(db: &mut Client) -> Result<(), ruvio_client::Error> {
372    db.bf_reserve("{tour}:bf", 0.01, 1000)?;
373    println!("bf_add {}", db.bf_add("{tour}:bf", "x")?);
374    println!(
375        "bf_exists {} {}",
376        db.bf_exists("{tour}:bf", "x")?,
377        db.bf_exists("{tour}:bf", "y")?
378    );
379
380    Ok(())
381}
382
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}
551
552fn pubsub(host: &str, port: u16) -> Result<(), ruvio_client::Error> {
553    let mut commands = Client::connect(host, port)?;
554    let mut listener = commands.subscriber()?;
555
556    listener.subscribe(&["{tour}:news"])?;
557    listener.psubscribe(&["{tour}:n*"])?;
558    listener.set_read_timeout(Some(Duration::from_secs(2)))?;
559    println!("publish {}", commands.publish("{tour}:news", "hello-tour")?);
560
561    let exact = listener.next_message()?;
562    let pattern = listener.next_message()?;
563
564    println!(
565        "message {} {:?}",
566        exact.channel,
567        String::from_utf8_lossy(&exact.payload)
568    );
569    println!("pmessage {:?}", pattern.pattern);
570    listener.unsubscribe(&["{tour}:news"])?;
571    listener.punsubscribe(&["{tour}:n*"])?;
572    listener.ssubscribe(&["{tour}:shard"])?;
573    println!("spublish {}", commands.spublish("{tour}:shard", "sharded")?);
574    println!("smessage {}", listener.next_message()?.kind);
575    listener.sunsubscribe(&["{tour}:shard"])?;
576    println!("ping after subscribe {}", commands.ping()?);
577
578    Ok(())
579}
Source

pub fn connect_database( host: impl Into<String>, port: u16, database: u32, ) -> Result<Self, Error>

Opens a connection bound to one logical database. Sends SELECT when database is not 0.

The returned client is the database handle: every command on it runs in database.

Source

pub fn connect_ip(ip: IpAddr, port: u16, database: u32) -> Result<Self, Error>

Opens a connection to an IP address and port. Sends SELECT when database is not 0.

Source

pub fn connect_addr(address: SocketAddr, database: u32) -> Result<Self, Error>

Opens a connection to a socket address. Sends SELECT when database is not 0.

Source

pub fn connect_with(options: ClientOptions) -> Result<Self, Error>

Opens a connection. When ClientOptions::password is set, sends AUTH. When ClientOptions::discover_cluster is on, sends CLUSTER SLOTS. When ClientOptions::database is not 0, a standalone server then gets SELECT.

Source

pub fn is_cluster(&self) -> bool

True when the server reported a slot map and commands are routed by slot.

Examples found in repository?
examples/tour.rs (line 51)
17fn main() -> Result<(), ruvio_client::Error> {
18    let host = std::env::args()
19        .nth(1)
20        .unwrap_or_else(|| "127.0.0.1".to_owned());
21    let port = std::env::args()
22        .nth(2)
23        .and_then(|text| text.parse().ok())
24        .unwrap_or(6379);
25    let mut db = Client::connect(&host, port)?;
26
27    db.on_connection_lost(|notice| {
28        println!(
29            "connection lost {}:{} subscriber={}",
30            notice.host, notice.port, notice.subscriber
31        );
32    });
33
34    db.on_connection_restored(|notice| {
35        println!(
36            "connection restored {}:{} subscriber={}",
37            notice.host, notice.port, notice.subscriber
38        );
39    });
40
41    db.set_reconnect_delay(|attempt| {
42        if attempt >= 8 {
43            None
44        } else {
45            Some(Duration::from_millis(100 * 2u64.pow(attempt - 1)))
46        }
47    });
48
49    println!(
50        "connected cluster={} shards={} slot={}",
51        db.is_cluster(),
52        db.shard_count(),
53        ruvio_client::hash_slot("{tour}")
54    );
55    println!("reconnect armed; the command that sees a drop fails, the next one opens the socket");
56
57    if !db.is_cluster() {
58        db.select(15)?;
59        db.flushdb()?;
60        println!("selected database {}", db.database());
61    }
62
63    strings(&mut db)?;
64    owned(&mut db)?;
65    lists(&mut db)?;
66    sets(&mut db)?;
67    hashes(&mut db)?;
68    sorted_sets(&mut db)?;
69    bloom(&mut db)?;
70    streams(&mut db)?;
71    transactions(&mut db)?;
72    server(&mut db)?;
73    pubsub(&host, port)?;
74
75    println!("tour finished");
76
77    Ok(())
78}
79
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
129
130fn owned(db: &mut Client) -> Result<(), ruvio_client::Error> {
131    let first = db.lease("{tour}:lock", 30_000)?;
132
133    println!(
134        "lease {:?} held {:?} release {}",
135        first,
136        db.lease("{tour}:lock", 30_000)?,
137        db.release("{tour}:lock", first.unwrap_or(0) as u64)?
138    );
139    let permit = db.semaphore("{tour}:workers", 1, 30_000)?;
140
141    println!(
142        "semaphore {:?} full {:?} release {}",
143        permit,
144        db.semaphore("{tour}:workers", 1, 30_000)?,
145        db.release("{tour}:workers", permit.unwrap_or(0) as u64)?
146    );
147    println!(
148        "incr_by_max {:?} over {:?}",
149        db.incr_by_max("{tour}:seats", 3, 4)?,
150        db.incr_by_max("{tour}:seats", 2, 4)?
151    );
152    let created = db.setv("{tour}:doc", "12", None)?;
153    let next = db.setv("{tour}:doc", "11", Some(created as u64))?;
154
155    println!("setv {created} then {next}");
156    println!(
157        "setv mismatch {}",
158        db.setv("{tour}:doc", "10", Some(created as u64))
159            .err()
160            .map(|error| error.to_string())
161            .unwrap_or_else(|| "accepted".to_owned())
162    );
163    let cursor = db.changes_start()?;
164
165    db.set("{tour}:note", "paid")?;
166    let notes = db.changes(cursor as u64)?;
167
168    println!(
169        "changes cursor={cursor} notes={} {}",
170        notes.len(),
171        notes.first().map(|(_, text)| text.as_str()).unwrap_or("")
172    );
173    println!(
174        "limit {:?} {:?}",
175        db.limit("{tour}:login", 2, 60_000)?,
176        db.limit("{tour}:login", 2, 60_000)?
177    );
178    println!(
179        "once {} {}",
180        db.once("{tour}:pay", 60_000)?,
181        db.once("{tour}:pay", 60_000)?
182    );
183    db.set("{tour}:seats", "5")?;
184    println!(
185        "take {:?} {:?}",
186        db.take("{tour}:seats", 2)?,
187        db.take("{tour}:seats", 9)?
188    );
189    println!("getex {:?}", db.getex("{tour}:seats", 60_000)?);
190
191    Ok(())
192}
193
194fn lists(db: &mut Client) -> Result<(), ruvio_client::Error> {
195    let key = "{tour}:l";
196
197    println!("rpush {}", db.rpush(key, &["a", "b", "c", "d"])?);
198    println!("lpush {}", db.lpush(key, &["z"])?);
199    println!("lpop {:?}", db.lpop(key)?);
200    println!("rpop_count {:?}", db.rpop_count(key, 2)?);
201    println!("llen {}", db.llen(key)?);
202    println!("lindex {:?}", db.lindex(key, 0)?);
203    println!("lrange {:?}", db.lrange(key, 0, -1)?);
204    db.ltrim(key, 0, 0)?;
205    println!("lpop_count {:?}", db.lpop_count(key, 1)?);
206    db.rpush(key, &["only"])?;
207    println!("blpop {:?}", db.blpop_key(key, Duration::from_millis(200))?);
208    db.rpush(key, &["right"])?;
209    println!("brpop {:?}", db.brpop(&[key], Duration::from_millis(200))?);
210    println!(
211        "brpop empty {:?}",
212        db.brpop_key(key, Duration::from_millis(1))?
213    );
214
215    Ok(())
216}
217
218fn sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
219    println!("sadd {}", db.sadd("{tour}:s1", &["a", "b", "c"])?);
220    db.sadd("{tour}:s2", &["b", "c", "d"])?;
221    println!("sismember {}", db.sismember("{tour}:s1", "a")?);
222    println!("scard {}", db.scard("{tour}:s1")?);
223    println!("smembers {:?}", db.smembers("{tour}:s1")?);
224    println!("sinter {:?}", db.sinter(&["{tour}:s1", "{tour}:s2"])?);
225    println!("sunion {:?}", db.sunion(&["{tour}:s1", "{tour}:s2"])?);
226    println!("sdiff {:?}", db.sdiff(&["{tour}:s1", "{tour}:s2"])?);
227    println!(
228        "sinterstore {}",
229        db.sinterstore("{tour}:s3", &["{tour}:s1", "{tour}:s2"])?
230    );
231    println!(
232        "sunionstore {}",
233        db.sunionstore("{tour}:s4", &["{tour}:s1", "{tour}:s2"])?
234    );
235    println!(
236        "sdiffstore {}",
237        db.sdiffstore("{tour}:s5", &["{tour}:s1", "{tour}:s2"])?
238    );
239    println!("smove {}", db.smove("{tour}:s1", "{tour}:s3", "a")?);
240    println!("srem {}", db.srem("{tour}:s3", &["a"])?);
241    println!("srandmember {:?}", db.srandmember("{tour}:s2")?);
242    println!(
243        "srandmember_count {:?}",
244        db.srandmember_count("{tour}:s2", 2)?
245    );
246    println!("spop_count {:?}", db.spop_count("{tour}:s5", 5)?);
247    println!("spop {:?}", db.spop("{tour}:s4")?);
248
249    Ok(())
250}
251
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
299
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
370
371fn bloom(db: &mut Client) -> Result<(), ruvio_client::Error> {
372    db.bf_reserve("{tour}:bf", 0.01, 1000)?;
373    println!("bf_add {}", db.bf_add("{tour}:bf", "x")?);
374    println!(
375        "bf_exists {} {}",
376        db.bf_exists("{tour}:bf", "x")?,
377        db.bf_exists("{tour}:bf", "y")?
378    );
379
380    Ok(())
381}
382
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 shard_count(&self) -> usize

How many shards the client routes to. 1 for a single server.

Examples found in repository?
examples/tour.rs (line 52)
17fn main() -> Result<(), ruvio_client::Error> {
18    let host = std::env::args()
19        .nth(1)
20        .unwrap_or_else(|| "127.0.0.1".to_owned());
21    let port = std::env::args()
22        .nth(2)
23        .and_then(|text| text.parse().ok())
24        .unwrap_or(6379);
25    let mut db = Client::connect(&host, port)?;
26
27    db.on_connection_lost(|notice| {
28        println!(
29            "connection lost {}:{} subscriber={}",
30            notice.host, notice.port, notice.subscriber
31        );
32    });
33
34    db.on_connection_restored(|notice| {
35        println!(
36            "connection restored {}:{} subscriber={}",
37            notice.host, notice.port, notice.subscriber
38        );
39    });
40
41    db.set_reconnect_delay(|attempt| {
42        if attempt >= 8 {
43            None
44        } else {
45            Some(Duration::from_millis(100 * 2u64.pow(attempt - 1)))
46        }
47    });
48
49    println!(
50        "connected cluster={} shards={} slot={}",
51        db.is_cluster(),
52        db.shard_count(),
53        ruvio_client::hash_slot("{tour}")
54    );
55    println!("reconnect armed; the command that sees a drop fails, the next one opens the socket");
56
57    if !db.is_cluster() {
58        db.select(15)?;
59        db.flushdb()?;
60        println!("selected database {}", db.database());
61    }
62
63    strings(&mut db)?;
64    owned(&mut db)?;
65    lists(&mut db)?;
66    sets(&mut db)?;
67    hashes(&mut db)?;
68    sorted_sets(&mut db)?;
69    bloom(&mut db)?;
70    streams(&mut db)?;
71    transactions(&mut db)?;
72    server(&mut db)?;
73    pubsub(&host, port)?;
74
75    println!("tour finished");
76
77    Ok(())
78}
Source

pub fn ping(&mut self) -> Result<String, Error>

Sends PING and returns the simple-string reply.

Examples found in repository?
examples/tour.rs (line 509)
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}
551
552fn pubsub(host: &str, port: u16) -> Result<(), ruvio_client::Error> {
553    let mut commands = Client::connect(host, port)?;
554    let mut listener = commands.subscriber()?;
555
556    listener.subscribe(&["{tour}:news"])?;
557    listener.psubscribe(&["{tour}:n*"])?;
558    listener.set_read_timeout(Some(Duration::from_secs(2)))?;
559    println!("publish {}", commands.publish("{tour}:news", "hello-tour")?);
560
561    let exact = listener.next_message()?;
562    let pattern = listener.next_message()?;
563
564    println!(
565        "message {} {:?}",
566        exact.channel,
567        String::from_utf8_lossy(&exact.payload)
568    );
569    println!("pmessage {:?}", pattern.pattern);
570    listener.unsubscribe(&["{tour}:news"])?;
571    listener.punsubscribe(&["{tour}:n*"])?;
572    listener.ssubscribe(&["{tour}:shard"])?;
573    println!("spublish {}", commands.spublish("{tour}:shard", "sharded")?);
574    println!("smessage {}", listener.next_message()?.kind);
575    listener.sunsubscribe(&["{tour}:shard"])?;
576    println!("ping after subscribe {}", commands.ping()?);
577
578    Ok(())
579}
Source

pub fn ping_message(&mut self, message: &str) -> Result<String, Error>

Sends PING message and returns the echoed message.

Examples found in repository?
examples/tour.rs (line 510)
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 database(&self) -> u32

The logical database this connection last selected.

Examples found in repository?
examples/tour.rs (line 60)
17fn main() -> Result<(), ruvio_client::Error> {
18    let host = std::env::args()
19        .nth(1)
20        .unwrap_or_else(|| "127.0.0.1".to_owned());
21    let port = std::env::args()
22        .nth(2)
23        .and_then(|text| text.parse().ok())
24        .unwrap_or(6379);
25    let mut db = Client::connect(&host, port)?;
26
27    db.on_connection_lost(|notice| {
28        println!(
29            "connection lost {}:{} subscriber={}",
30            notice.host, notice.port, notice.subscriber
31        );
32    });
33
34    db.on_connection_restored(|notice| {
35        println!(
36            "connection restored {}:{} subscriber={}",
37            notice.host, notice.port, notice.subscriber
38        );
39    });
40
41    db.set_reconnect_delay(|attempt| {
42        if attempt >= 8 {
43            None
44        } else {
45            Some(Duration::from_millis(100 * 2u64.pow(attempt - 1)))
46        }
47    });
48
49    println!(
50        "connected cluster={} shards={} slot={}",
51        db.is_cluster(),
52        db.shard_count(),
53        ruvio_client::hash_slot("{tour}")
54    );
55    println!("reconnect armed; the command that sees a drop fails, the next one opens the socket");
56
57    if !db.is_cluster() {
58        db.select(15)?;
59        db.flushdb()?;
60        println!("selected database {}", db.database());
61    }
62
63    strings(&mut db)?;
64    owned(&mut db)?;
65    lists(&mut db)?;
66    sets(&mut db)?;
67    hashes(&mut db)?;
68    sorted_sets(&mut db)?;
69    bloom(&mut db)?;
70    streams(&mut db)?;
71    transactions(&mut db)?;
72    server(&mut db)?;
73    pubsub(&host, port)?;
74
75    println!("tour finished");
76
77    Ok(())
78}
Source

pub fn subscriber(&self) -> Result<Self, Error>

Opens a second socket for Pub/Sub. subscribe on this client already does that automatically; use this when you want the socket in hand.

Examples found in repository?
examples/tour.rs (line 554)
552fn pubsub(host: &str, port: u16) -> Result<(), ruvio_client::Error> {
553    let mut commands = Client::connect(host, port)?;
554    let mut listener = commands.subscriber()?;
555
556    listener.subscribe(&["{tour}:news"])?;
557    listener.psubscribe(&["{tour}:n*"])?;
558    listener.set_read_timeout(Some(Duration::from_secs(2)))?;
559    println!("publish {}", commands.publish("{tour}:news", "hello-tour")?);
560
561    let exact = listener.next_message()?;
562    let pattern = listener.next_message()?;
563
564    println!(
565        "message {} {:?}",
566        exact.channel,
567        String::from_utf8_lossy(&exact.payload)
568    );
569    println!("pmessage {:?}", pattern.pattern);
570    listener.unsubscribe(&["{tour}:news"])?;
571    listener.punsubscribe(&["{tour}:n*"])?;
572    listener.ssubscribe(&["{tour}:shard"])?;
573    println!("spublish {}", commands.spublish("{tour}:shard", "sharded")?);
574    println!("smessage {}", listener.next_message()?.kind);
575    listener.sunsubscribe(&["{tour}:shard"])?;
576    println!("ping after subscribe {}", commands.ping()?);
577
578    Ok(())
579}
Source

pub fn select(&mut self, database: u32) -> Result<(), Error>

Sends SELECT. Indexes run from 0 to the server’s databases setting minus one (16 by default).

Examples found in repository?
examples/tour.rs (line 58)
17fn main() -> Result<(), ruvio_client::Error> {
18    let host = std::env::args()
19        .nth(1)
20        .unwrap_or_else(|| "127.0.0.1".to_owned());
21    let port = std::env::args()
22        .nth(2)
23        .and_then(|text| text.parse().ok())
24        .unwrap_or(6379);
25    let mut db = Client::connect(&host, port)?;
26
27    db.on_connection_lost(|notice| {
28        println!(
29            "connection lost {}:{} subscriber={}",
30            notice.host, notice.port, notice.subscriber
31        );
32    });
33
34    db.on_connection_restored(|notice| {
35        println!(
36            "connection restored {}:{} subscriber={}",
37            notice.host, notice.port, notice.subscriber
38        );
39    });
40
41    db.set_reconnect_delay(|attempt| {
42        if attempt >= 8 {
43            None
44        } else {
45            Some(Duration::from_millis(100 * 2u64.pow(attempt - 1)))
46        }
47    });
48
49    println!(
50        "connected cluster={} shards={} slot={}",
51        db.is_cluster(),
52        db.shard_count(),
53        ruvio_client::hash_slot("{tour}")
54    );
55    println!("reconnect armed; the command that sees a drop fails, the next one opens the socket");
56
57    if !db.is_cluster() {
58        db.select(15)?;
59        db.flushdb()?;
60        println!("selected database {}", db.database());
61    }
62
63    strings(&mut db)?;
64    owned(&mut db)?;
65    lists(&mut db)?;
66    sets(&mut db)?;
67    hashes(&mut db)?;
68    sorted_sets(&mut db)?;
69    bloom(&mut db)?;
70    streams(&mut db)?;
71    transactions(&mut db)?;
72    server(&mut db)?;
73    pubsub(&host, port)?;
74
75    println!("tour finished");
76
77    Ok(())
78}
Source

pub fn into_database(self, database: u32) -> Result<Self, Error>

Sends SELECT and returns the same connection.

This is not a second TCP socket: every later command on the client uses the new database.

Source

pub fn set_read_timeout( &mut self, timeout: Option<Duration>, ) -> Result<(), Error>

Sets how long a read may block. None waits forever.

A timed-out read returns Error::Io, and the reply may still arrive later, so drop the client unless it was only waiting in Self::read_message.

Examples found in repository?
examples/tour.rs (line 558)
552fn pubsub(host: &str, port: u16) -> Result<(), ruvio_client::Error> {
553    let mut commands = Client::connect(host, port)?;
554    let mut listener = commands.subscriber()?;
555
556    listener.subscribe(&["{tour}:news"])?;
557    listener.psubscribe(&["{tour}:n*"])?;
558    listener.set_read_timeout(Some(Duration::from_secs(2)))?;
559    println!("publish {}", commands.publish("{tour}:news", "hello-tour")?);
560
561    let exact = listener.next_message()?;
562    let pattern = listener.next_message()?;
563
564    println!(
565        "message {} {:?}",
566        exact.channel,
567        String::from_utf8_lossy(&exact.payload)
568    );
569    println!("pmessage {:?}", pattern.pattern);
570    listener.unsubscribe(&["{tour}:news"])?;
571    listener.punsubscribe(&["{tour}:n*"])?;
572    listener.ssubscribe(&["{tour}:shard"])?;
573    println!("spublish {}", commands.spublish("{tour}:shard", "sharded")?);
574    println!("smessage {}", listener.next_message()?.kind);
575    listener.sunsubscribe(&["{tour}:shard"])?;
576    println!("ping after subscribe {}", commands.ping()?);
577
578    Ok(())
579}
Source

pub fn get(&mut self, key: &str) -> Result<Option<Vec<u8>>, Error>

Sends GET and returns the raw bulk, or None when the key is missing.

Source

pub fn get_string(&mut self, key: &str) -> Result<Option<String>, Error>

Sends GET and decodes the bulk as UTF-8. None when the key is missing.

Examples found in repository?
examples/tour.rs (line 84)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn set(&mut self, key: &str, value: &str) -> Result<bool, Error>

Sends SET. Returns false when NX or XX skips the write.

Examples found in repository?
examples/tour.rs (line 83)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
129
130fn owned(db: &mut Client) -> Result<(), ruvio_client::Error> {
131    let first = db.lease("{tour}:lock", 30_000)?;
132
133    println!(
134        "lease {:?} held {:?} release {}",
135        first,
136        db.lease("{tour}:lock", 30_000)?,
137        db.release("{tour}:lock", first.unwrap_or(0) as u64)?
138    );
139    let permit = db.semaphore("{tour}:workers", 1, 30_000)?;
140
141    println!(
142        "semaphore {:?} full {:?} release {}",
143        permit,
144        db.semaphore("{tour}:workers", 1, 30_000)?,
145        db.release("{tour}:workers", permit.unwrap_or(0) as u64)?
146    );
147    println!(
148        "incr_by_max {:?} over {:?}",
149        db.incr_by_max("{tour}:seats", 3, 4)?,
150        db.incr_by_max("{tour}:seats", 2, 4)?
151    );
152    let created = db.setv("{tour}:doc", "12", None)?;
153    let next = db.setv("{tour}:doc", "11", Some(created as u64))?;
154
155    println!("setv {created} then {next}");
156    println!(
157        "setv mismatch {}",
158        db.setv("{tour}:doc", "10", Some(created as u64))
159            .err()
160            .map(|error| error.to_string())
161            .unwrap_or_else(|| "accepted".to_owned())
162    );
163    let cursor = db.changes_start()?;
164
165    db.set("{tour}:note", "paid")?;
166    let notes = db.changes(cursor as u64)?;
167
168    println!(
169        "changes cursor={cursor} notes={} {}",
170        notes.len(),
171        notes.first().map(|(_, text)| text.as_str()).unwrap_or("")
172    );
173    println!(
174        "limit {:?} {:?}",
175        db.limit("{tour}:login", 2, 60_000)?,
176        db.limit("{tour}:login", 2, 60_000)?
177    );
178    println!(
179        "once {} {}",
180        db.once("{tour}:pay", 60_000)?,
181        db.once("{tour}:pay", 60_000)?
182    );
183    db.set("{tour}:seats", "5")?;
184    println!(
185        "take {:?} {:?}",
186        db.take("{tour}:seats", 2)?,
187        db.take("{tour}:seats", 9)?
188    );
189    println!("getex {:?}", db.getex("{tour}:seats", 60_000)?);
190
191    Ok(())
192}
193
194fn lists(db: &mut Client) -> Result<(), ruvio_client::Error> {
195    let key = "{tour}:l";
196
197    println!("rpush {}", db.rpush(key, &["a", "b", "c", "d"])?);
198    println!("lpush {}", db.lpush(key, &["z"])?);
199    println!("lpop {:?}", db.lpop(key)?);
200    println!("rpop_count {:?}", db.rpop_count(key, 2)?);
201    println!("llen {}", db.llen(key)?);
202    println!("lindex {:?}", db.lindex(key, 0)?);
203    println!("lrange {:?}", db.lrange(key, 0, -1)?);
204    db.ltrim(key, 0, 0)?;
205    println!("lpop_count {:?}", db.lpop_count(key, 1)?);
206    db.rpush(key, &["only"])?;
207    println!("blpop {:?}", db.blpop_key(key, Duration::from_millis(200))?);
208    db.rpush(key, &["right"])?;
209    println!("brpop {:?}", db.brpop(&[key], Duration::from_millis(200))?);
210    println!(
211        "brpop empty {:?}",
212        db.brpop_key(key, Duration::from_millis(1))?
213    );
214
215    Ok(())
216}
217
218fn sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
219    println!("sadd {}", db.sadd("{tour}:s1", &["a", "b", "c"])?);
220    db.sadd("{tour}:s2", &["b", "c", "d"])?;
221    println!("sismember {}", db.sismember("{tour}:s1", "a")?);
222    println!("scard {}", db.scard("{tour}:s1")?);
223    println!("smembers {:?}", db.smembers("{tour}:s1")?);
224    println!("sinter {:?}", db.sinter(&["{tour}:s1", "{tour}:s2"])?);
225    println!("sunion {:?}", db.sunion(&["{tour}:s1", "{tour}:s2"])?);
226    println!("sdiff {:?}", db.sdiff(&["{tour}:s1", "{tour}:s2"])?);
227    println!(
228        "sinterstore {}",
229        db.sinterstore("{tour}:s3", &["{tour}:s1", "{tour}:s2"])?
230    );
231    println!(
232        "sunionstore {}",
233        db.sunionstore("{tour}:s4", &["{tour}:s1", "{tour}:s2"])?
234    );
235    println!(
236        "sdiffstore {}",
237        db.sdiffstore("{tour}:s5", &["{tour}:s1", "{tour}:s2"])?
238    );
239    println!("smove {}", db.smove("{tour}:s1", "{tour}:s3", "a")?);
240    println!("srem {}", db.srem("{tour}:s3", &["a"])?);
241    println!("srandmember {:?}", db.srandmember("{tour}:s2")?);
242    println!(
243        "srandmember_count {:?}",
244        db.srandmember_count("{tour}:s2", 2)?
245    );
246    println!("spop_count {:?}", db.spop_count("{tour}:s5", 5)?);
247    println!("spop {:?}", db.spop("{tour}:s4")?);
248
249    Ok(())
250}
251
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
299
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
370
371fn bloom(db: &mut Client) -> Result<(), ruvio_client::Error> {
372    db.bf_reserve("{tour}:bf", 0.01, 1000)?;
373    println!("bf_add {}", db.bf_add("{tour}:bf", "x")?);
374    println!(
375        "bf_exists {} {}",
376        db.bf_exists("{tour}:bf", "x")?,
377        db.bf_exists("{tour}:bf", "y")?
378    );
379
380    Ok(())
381}
382
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}
Source

pub fn set_with( &mut self, key: &str, value: &str, expiry: Option<Duration>, mode: SetMode, ) -> Result<bool, Error>

Sends SET with an optional millisecond expiry and NX or XX.

Examples found in repository?
examples/tour.rs (line 85)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn set_expires_at( &mut self, key: &str, value: &str, expires_at: SystemTime, mode: SetMode, ) -> Result<bool, Error>

Sends SET ... PXAT: the key expires at expires_at.

Examples found in repository?
examples/tour.rs (lines 86-91)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn set_keep_ttl( &mut self, key: &str, value: &str, mode: SetMode, ) -> Result<bool, Error>

Sends SET ... KEEPTTL: the key keeps its current expiry.

Examples found in repository?
examples/tour.rs (line 92)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn set_and_get( &mut self, key: &str, value: &str, expiry: Option<Duration>, mode: SetMode, ) -> Result<Option<String>, Error>

Sends SET ... GET and returns the previous string, or None when the key was missing. With NX or XX the previous value is returned even when the write is skipped.

Examples found in repository?
examples/tour.rs (line 95)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn incr(&mut self, key: &str) -> Result<i64, Error>

Sends INCR.

Examples found in repository?
examples/tour.rs (line 105)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn expire(&mut self, key: &str, ttl: Duration) -> Result<bool, Error>

Sends EXPIRE, or PEXPIRE when ttl is not whole seconds. False when the key does not exist.

Examples found in repository?
examples/tour.rs (line 115)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn del_key(&mut self, key: &str) -> Result<i64, Error>

Sends DEL for one key.

Examples found in repository?
examples/tour.rs (line 125)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn del(&mut self, keys: &[&str]) -> Result<i64, Error>

Sends DEL and returns how many keys were removed.

Examples found in repository?
examples/tour.rs (line 124)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn read_message(&mut self) -> Result<RespValue, Error>

Reads the next reply without sending a command. Use this after a subscribe for message, pmessage, and smessage pushes.

Source

pub fn on_connection_lost<F>(&mut self, hook: F)
where F: Fn(ConnectionNotice) + Send + Sync + 'static,

Called when a command or subscriber socket drops.

Examples found in repository?
examples/tour.rs (lines 27-32)
17fn main() -> Result<(), ruvio_client::Error> {
18    let host = std::env::args()
19        .nth(1)
20        .unwrap_or_else(|| "127.0.0.1".to_owned());
21    let port = std::env::args()
22        .nth(2)
23        .and_then(|text| text.parse().ok())
24        .unwrap_or(6379);
25    let mut db = Client::connect(&host, port)?;
26
27    db.on_connection_lost(|notice| {
28        println!(
29            "connection lost {}:{} subscriber={}",
30            notice.host, notice.port, notice.subscriber
31        );
32    });
33
34    db.on_connection_restored(|notice| {
35        println!(
36            "connection restored {}:{} subscriber={}",
37            notice.host, notice.port, notice.subscriber
38        );
39    });
40
41    db.set_reconnect_delay(|attempt| {
42        if attempt >= 8 {
43            None
44        } else {
45            Some(Duration::from_millis(100 * 2u64.pow(attempt - 1)))
46        }
47    });
48
49    println!(
50        "connected cluster={} shards={} slot={}",
51        db.is_cluster(),
52        db.shard_count(),
53        ruvio_client::hash_slot("{tour}")
54    );
55    println!("reconnect armed; the command that sees a drop fails, the next one opens the socket");
56
57    if !db.is_cluster() {
58        db.select(15)?;
59        db.flushdb()?;
60        println!("selected database {}", db.database());
61    }
62
63    strings(&mut db)?;
64    owned(&mut db)?;
65    lists(&mut db)?;
66    sets(&mut db)?;
67    hashes(&mut db)?;
68    sorted_sets(&mut db)?;
69    bloom(&mut db)?;
70    streams(&mut db)?;
71    transactions(&mut db)?;
72    server(&mut db)?;
73    pubsub(&host, port)?;
74
75    println!("tour finished");
76
77    Ok(())
78}
Source

pub fn on_connection_restored<F>(&mut self, hook: F)
where F: Fn(ConnectionNotice) + Send + Sync + 'static,

Called after a dropped socket is open again.

Examples found in repository?
examples/tour.rs (lines 34-39)
17fn main() -> Result<(), ruvio_client::Error> {
18    let host = std::env::args()
19        .nth(1)
20        .unwrap_or_else(|| "127.0.0.1".to_owned());
21    let port = std::env::args()
22        .nth(2)
23        .and_then(|text| text.parse().ok())
24        .unwrap_or(6379);
25    let mut db = Client::connect(&host, port)?;
26
27    db.on_connection_lost(|notice| {
28        println!(
29            "connection lost {}:{} subscriber={}",
30            notice.host, notice.port, notice.subscriber
31        );
32    });
33
34    db.on_connection_restored(|notice| {
35        println!(
36            "connection restored {}:{} subscriber={}",
37            notice.host, notice.port, notice.subscriber
38        );
39    });
40
41    db.set_reconnect_delay(|attempt| {
42        if attempt >= 8 {
43            None
44        } else {
45            Some(Duration::from_millis(100 * 2u64.pow(attempt - 1)))
46        }
47    });
48
49    println!(
50        "connected cluster={} shards={} slot={}",
51        db.is_cluster(),
52        db.shard_count(),
53        ruvio_client::hash_slot("{tour}")
54    );
55    println!("reconnect armed; the command that sees a drop fails, the next one opens the socket");
56
57    if !db.is_cluster() {
58        db.select(15)?;
59        db.flushdb()?;
60        println!("selected database {}", db.database());
61    }
62
63    strings(&mut db)?;
64    owned(&mut db)?;
65    lists(&mut db)?;
66    sets(&mut db)?;
67    hashes(&mut db)?;
68    sorted_sets(&mut db)?;
69    bloom(&mut db)?;
70    streams(&mut db)?;
71    transactions(&mut db)?;
72    server(&mut db)?;
73    pubsub(&host, port)?;
74
75    println!("tour finished");
76
77    Ok(())
78}
Source

pub fn set_reconnect_delay<F>(&mut self, delay: F)
where F: Fn(u32) -> Option<Duration> + Send + Sync + 'static,

Replaces the built-in exponential wait. The attempt starts at 1 after the first failure. Return None to stop. When set, max_reconnect_attempts is not applied.

Examples found in repository?
examples/tour.rs (lines 41-47)
17fn main() -> Result<(), ruvio_client::Error> {
18    let host = std::env::args()
19        .nth(1)
20        .unwrap_or_else(|| "127.0.0.1".to_owned());
21    let port = std::env::args()
22        .nth(2)
23        .and_then(|text| text.parse().ok())
24        .unwrap_or(6379);
25    let mut db = Client::connect(&host, port)?;
26
27    db.on_connection_lost(|notice| {
28        println!(
29            "connection lost {}:{} subscriber={}",
30            notice.host, notice.port, notice.subscriber
31        );
32    });
33
34    db.on_connection_restored(|notice| {
35        println!(
36            "connection restored {}:{} subscriber={}",
37            notice.host, notice.port, notice.subscriber
38        );
39    });
40
41    db.set_reconnect_delay(|attempt| {
42        if attempt >= 8 {
43            None
44        } else {
45            Some(Duration::from_millis(100 * 2u64.pow(attempt - 1)))
46        }
47    });
48
49    println!(
50        "connected cluster={} shards={} slot={}",
51        db.is_cluster(),
52        db.shard_count(),
53        ruvio_client::hash_slot("{tour}")
54    );
55    println!("reconnect armed; the command that sees a drop fails, the next one opens the socket");
56
57    if !db.is_cluster() {
58        db.select(15)?;
59        db.flushdb()?;
60        println!("selected database {}", db.database());
61    }
62
63    strings(&mut db)?;
64    owned(&mut db)?;
65    lists(&mut db)?;
66    sets(&mut db)?;
67    hashes(&mut db)?;
68    sorted_sets(&mut db)?;
69    bloom(&mut db)?;
70    streams(&mut db)?;
71    transactions(&mut db)?;
72    server(&mut db)?;
73    pubsub(&host, port)?;
74
75    println!("tour finished");
76
77    Ok(())
78}
Source

pub fn reconnect(&mut self) -> Result<(), Error>

Opens a dropped command socket again. With ClientOptions::reconnect on, the next command does this itself.

Source

pub fn execute(&mut self, arguments: &[&str]) -> Result<RespValue, Error>

Sends one command. A RESP error becomes Error::Server and the connection stays open.

Examples found in repository?
examples/tour.rs (line 461)
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 execute_many( &mut self, commands: &[&[&str]], ) -> Result<Vec<RespValue>, Error>

Writes every command, then reads one reply each. Error replies stay as RespValue::Error. On a cluster the commands are grouped by shard; replies keep command order.

Examples found in repository?
examples/tour.rs (line 547)
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§

impl Client

Source

pub fn mget(&mut self, keys: &[&str]) -> Result<Vec<Option<String>>, Error>

Sends MGET. A missing key is None.

Examples found in repository?
examples/tour.rs (line 100)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn limit( &mut self, key: &str, max: u64, window_ms: u64, ) -> Result<Option<i64>, Error>

Sends LIMIT. None means this call did not fit in the window. Some is how many calls remain after this one.

Examples found in repository?
examples/tour.rs (line 175)
130fn owned(db: &mut Client) -> Result<(), ruvio_client::Error> {
131    let first = db.lease("{tour}:lock", 30_000)?;
132
133    println!(
134        "lease {:?} held {:?} release {}",
135        first,
136        db.lease("{tour}:lock", 30_000)?,
137        db.release("{tour}:lock", first.unwrap_or(0) as u64)?
138    );
139    let permit = db.semaphore("{tour}:workers", 1, 30_000)?;
140
141    println!(
142        "semaphore {:?} full {:?} release {}",
143        permit,
144        db.semaphore("{tour}:workers", 1, 30_000)?,
145        db.release("{tour}:workers", permit.unwrap_or(0) as u64)?
146    );
147    println!(
148        "incr_by_max {:?} over {:?}",
149        db.incr_by_max("{tour}:seats", 3, 4)?,
150        db.incr_by_max("{tour}:seats", 2, 4)?
151    );
152    let created = db.setv("{tour}:doc", "12", None)?;
153    let next = db.setv("{tour}:doc", "11", Some(created as u64))?;
154
155    println!("setv {created} then {next}");
156    println!(
157        "setv mismatch {}",
158        db.setv("{tour}:doc", "10", Some(created as u64))
159            .err()
160            .map(|error| error.to_string())
161            .unwrap_or_else(|| "accepted".to_owned())
162    );
163    let cursor = db.changes_start()?;
164
165    db.set("{tour}:note", "paid")?;
166    let notes = db.changes(cursor as u64)?;
167
168    println!(
169        "changes cursor={cursor} notes={} {}",
170        notes.len(),
171        notes.first().map(|(_, text)| text.as_str()).unwrap_or("")
172    );
173    println!(
174        "limit {:?} {:?}",
175        db.limit("{tour}:login", 2, 60_000)?,
176        db.limit("{tour}:login", 2, 60_000)?
177    );
178    println!(
179        "once {} {}",
180        db.once("{tour}:pay", 60_000)?,
181        db.once("{tour}:pay", 60_000)?
182    );
183    db.set("{tour}:seats", "5")?;
184    println!(
185        "take {:?} {:?}",
186        db.take("{tour}:seats", 2)?,
187        db.take("{tour}:seats", 9)?
188    );
189    println!("getex {:?}", db.getex("{tour}:seats", 60_000)?);
190
191    Ok(())
192}
Source

pub fn once(&mut self, key: &str, ttl_ms: u64) -> Result<i64, Error>

Sends ONCE. 1 is the first call. 0 means the key is already taken.

Examples found in repository?
examples/tour.rs (line 180)
130fn owned(db: &mut Client) -> Result<(), ruvio_client::Error> {
131    let first = db.lease("{tour}:lock", 30_000)?;
132
133    println!(
134        "lease {:?} held {:?} release {}",
135        first,
136        db.lease("{tour}:lock", 30_000)?,
137        db.release("{tour}:lock", first.unwrap_or(0) as u64)?
138    );
139    let permit = db.semaphore("{tour}:workers", 1, 30_000)?;
140
141    println!(
142        "semaphore {:?} full {:?} release {}",
143        permit,
144        db.semaphore("{tour}:workers", 1, 30_000)?,
145        db.release("{tour}:workers", permit.unwrap_or(0) as u64)?
146    );
147    println!(
148        "incr_by_max {:?} over {:?}",
149        db.incr_by_max("{tour}:seats", 3, 4)?,
150        db.incr_by_max("{tour}:seats", 2, 4)?
151    );
152    let created = db.setv("{tour}:doc", "12", None)?;
153    let next = db.setv("{tour}:doc", "11", Some(created as u64))?;
154
155    println!("setv {created} then {next}");
156    println!(
157        "setv mismatch {}",
158        db.setv("{tour}:doc", "10", Some(created as u64))
159            .err()
160            .map(|error| error.to_string())
161            .unwrap_or_else(|| "accepted".to_owned())
162    );
163    let cursor = db.changes_start()?;
164
165    db.set("{tour}:note", "paid")?;
166    let notes = db.changes(cursor as u64)?;
167
168    println!(
169        "changes cursor={cursor} notes={} {}",
170        notes.len(),
171        notes.first().map(|(_, text)| text.as_str()).unwrap_or("")
172    );
173    println!(
174        "limit {:?} {:?}",
175        db.limit("{tour}:login", 2, 60_000)?,
176        db.limit("{tour}:login", 2, 60_000)?
177    );
178    println!(
179        "once {} {}",
180        db.once("{tour}:pay", 60_000)?,
181        db.once("{tour}:pay", 60_000)?
182    );
183    db.set("{tour}:seats", "5")?;
184    println!(
185        "take {:?} {:?}",
186        db.take("{tour}:seats", 2)?,
187        db.take("{tour}:seats", 9)?
188    );
189    println!("getex {:?}", db.getex("{tour}:seats", 60_000)?);
190
191    Ok(())
192}
Source

pub fn idempotency_begin( &mut self, key: &str, fingerprint: &str, owner: &str, ttl_ms: u64, ) -> Result<RespValue, Error>

Native reservation: [acquired], [pending], [conflict], or [completed, binary result].

Source

pub fn idempotency_complete( &mut self, key: &str, fingerprint: &str, owner: &str, result: &str, ) -> Result<i64, Error>

Publishes a result only for the matching live owner, without renewing retention.

Source

pub fn take(&mut self, key: &str, count: i64) -> Result<Option<i64>, Error>

Sends TAKE. None means the key did not hold enough and was left unchanged.

Examples found in repository?
examples/tour.rs (line 186)
130fn owned(db: &mut Client) -> Result<(), ruvio_client::Error> {
131    let first = db.lease("{tour}:lock", 30_000)?;
132
133    println!(
134        "lease {:?} held {:?} release {}",
135        first,
136        db.lease("{tour}:lock", 30_000)?,
137        db.release("{tour}:lock", first.unwrap_or(0) as u64)?
138    );
139    let permit = db.semaphore("{tour}:workers", 1, 30_000)?;
140
141    println!(
142        "semaphore {:?} full {:?} release {}",
143        permit,
144        db.semaphore("{tour}:workers", 1, 30_000)?,
145        db.release("{tour}:workers", permit.unwrap_or(0) as u64)?
146    );
147    println!(
148        "incr_by_max {:?} over {:?}",
149        db.incr_by_max("{tour}:seats", 3, 4)?,
150        db.incr_by_max("{tour}:seats", 2, 4)?
151    );
152    let created = db.setv("{tour}:doc", "12", None)?;
153    let next = db.setv("{tour}:doc", "11", Some(created as u64))?;
154
155    println!("setv {created} then {next}");
156    println!(
157        "setv mismatch {}",
158        db.setv("{tour}:doc", "10", Some(created as u64))
159            .err()
160            .map(|error| error.to_string())
161            .unwrap_or_else(|| "accepted".to_owned())
162    );
163    let cursor = db.changes_start()?;
164
165    db.set("{tour}:note", "paid")?;
166    let notes = db.changes(cursor as u64)?;
167
168    println!(
169        "changes cursor={cursor} notes={} {}",
170        notes.len(),
171        notes.first().map(|(_, text)| text.as_str()).unwrap_or("")
172    );
173    println!(
174        "limit {:?} {:?}",
175        db.limit("{tour}:login", 2, 60_000)?,
176        db.limit("{tour}:login", 2, 60_000)?
177    );
178    println!(
179        "once {} {}",
180        db.once("{tour}:pay", 60_000)?,
181        db.once("{tour}:pay", 60_000)?
182    );
183    db.set("{tour}:seats", "5")?;
184    println!(
185        "take {:?} {:?}",
186        db.take("{tour}:seats", 2)?,
187        db.take("{tour}:seats", 9)?
188    );
189    println!("getex {:?}", db.getex("{tour}:seats", 60_000)?);
190
191    Ok(())
192}
Source

pub fn getex(&mut self, key: &str, ttl_ms: u64) -> Result<Option<String>, Error>

Sends GETEX. Returns the string and sets its TTL to ttl_ms.

Examples found in repository?
examples/tour.rs (line 189)
130fn owned(db: &mut Client) -> Result<(), ruvio_client::Error> {
131    let first = db.lease("{tour}:lock", 30_000)?;
132
133    println!(
134        "lease {:?} held {:?} release {}",
135        first,
136        db.lease("{tour}:lock", 30_000)?,
137        db.release("{tour}:lock", first.unwrap_or(0) as u64)?
138    );
139    let permit = db.semaphore("{tour}:workers", 1, 30_000)?;
140
141    println!(
142        "semaphore {:?} full {:?} release {}",
143        permit,
144        db.semaphore("{tour}:workers", 1, 30_000)?,
145        db.release("{tour}:workers", permit.unwrap_or(0) as u64)?
146    );
147    println!(
148        "incr_by_max {:?} over {:?}",
149        db.incr_by_max("{tour}:seats", 3, 4)?,
150        db.incr_by_max("{tour}:seats", 2, 4)?
151    );
152    let created = db.setv("{tour}:doc", "12", None)?;
153    let next = db.setv("{tour}:doc", "11", Some(created as u64))?;
154
155    println!("setv {created} then {next}");
156    println!(
157        "setv mismatch {}",
158        db.setv("{tour}:doc", "10", Some(created as u64))
159            .err()
160            .map(|error| error.to_string())
161            .unwrap_or_else(|| "accepted".to_owned())
162    );
163    let cursor = db.changes_start()?;
164
165    db.set("{tour}:note", "paid")?;
166    let notes = db.changes(cursor as u64)?;
167
168    println!(
169        "changes cursor={cursor} notes={} {}",
170        notes.len(),
171        notes.first().map(|(_, text)| text.as_str()).unwrap_or("")
172    );
173    println!(
174        "limit {:?} {:?}",
175        db.limit("{tour}:login", 2, 60_000)?,
176        db.limit("{tour}:login", 2, 60_000)?
177    );
178    println!(
179        "once {} {}",
180        db.once("{tour}:pay", 60_000)?,
181        db.once("{tour}:pay", 60_000)?
182    );
183    db.set("{tour}:seats", "5")?;
184    println!(
185        "take {:?} {:?}",
186        db.take("{tour}:seats", 2)?,
187        db.take("{tour}:seats", 9)?
188    );
189    println!("getex {:?}", db.getex("{tour}:seats", 60_000)?);
190
191    Ok(())
192}
Source

pub fn lease(&mut self, key: &str, ttl_ms: u64) -> Result<Option<i64>, Error>

Sends LEASE. None means another holder still has the lease.

Examples found in repository?
examples/tour.rs (line 131)
130fn owned(db: &mut Client) -> Result<(), ruvio_client::Error> {
131    let first = db.lease("{tour}:lock", 30_000)?;
132
133    println!(
134        "lease {:?} held {:?} release {}",
135        first,
136        db.lease("{tour}:lock", 30_000)?,
137        db.release("{tour}:lock", first.unwrap_or(0) as u64)?
138    );
139    let permit = db.semaphore("{tour}:workers", 1, 30_000)?;
140
141    println!(
142        "semaphore {:?} full {:?} release {}",
143        permit,
144        db.semaphore("{tour}:workers", 1, 30_000)?,
145        db.release("{tour}:workers", permit.unwrap_or(0) as u64)?
146    );
147    println!(
148        "incr_by_max {:?} over {:?}",
149        db.incr_by_max("{tour}:seats", 3, 4)?,
150        db.incr_by_max("{tour}:seats", 2, 4)?
151    );
152    let created = db.setv("{tour}:doc", "12", None)?;
153    let next = db.setv("{tour}:doc", "11", Some(created as u64))?;
154
155    println!("setv {created} then {next}");
156    println!(
157        "setv mismatch {}",
158        db.setv("{tour}:doc", "10", Some(created as u64))
159            .err()
160            .map(|error| error.to_string())
161            .unwrap_or_else(|| "accepted".to_owned())
162    );
163    let cursor = db.changes_start()?;
164
165    db.set("{tour}:note", "paid")?;
166    let notes = db.changes(cursor as u64)?;
167
168    println!(
169        "changes cursor={cursor} notes={} {}",
170        notes.len(),
171        notes.first().map(|(_, text)| text.as_str()).unwrap_or("")
172    );
173    println!(
174        "limit {:?} {:?}",
175        db.limit("{tour}:login", 2, 60_000)?,
176        db.limit("{tour}:login", 2, 60_000)?
177    );
178    println!(
179        "once {} {}",
180        db.once("{tour}:pay", 60_000)?,
181        db.once("{tour}:pay", 60_000)?
182    );
183    db.set("{tour}:seats", "5")?;
184    println!(
185        "take {:?} {:?}",
186        db.take("{tour}:seats", 2)?,
187        db.take("{tour}:seats", 9)?
188    );
189    println!("getex {:?}", db.getex("{tour}:seats", 60_000)?);
190
191    Ok(())
192}
Source

pub fn semaphore( &mut self, key: &str, max: u64, ttl_ms: u64, ) -> Result<Option<i64>, Error>

Sends SEMAPHORE key max ttl_ms. Some(token) while fewer than max holders are live; None when full. Pass the token to Client::release.

Examples found in repository?
examples/tour.rs (line 139)
130fn owned(db: &mut Client) -> Result<(), ruvio_client::Error> {
131    let first = db.lease("{tour}:lock", 30_000)?;
132
133    println!(
134        "lease {:?} held {:?} release {}",
135        first,
136        db.lease("{tour}:lock", 30_000)?,
137        db.release("{tour}:lock", first.unwrap_or(0) as u64)?
138    );
139    let permit = db.semaphore("{tour}:workers", 1, 30_000)?;
140
141    println!(
142        "semaphore {:?} full {:?} release {}",
143        permit,
144        db.semaphore("{tour}:workers", 1, 30_000)?,
145        db.release("{tour}:workers", permit.unwrap_or(0) as u64)?
146    );
147    println!(
148        "incr_by_max {:?} over {:?}",
149        db.incr_by_max("{tour}:seats", 3, 4)?,
150        db.incr_by_max("{tour}:seats", 2, 4)?
151    );
152    let created = db.setv("{tour}:doc", "12", None)?;
153    let next = db.setv("{tour}:doc", "11", Some(created as u64))?;
154
155    println!("setv {created} then {next}");
156    println!(
157        "setv mismatch {}",
158        db.setv("{tour}:doc", "10", Some(created as u64))
159            .err()
160            .map(|error| error.to_string())
161            .unwrap_or_else(|| "accepted".to_owned())
162    );
163    let cursor = db.changes_start()?;
164
165    db.set("{tour}:note", "paid")?;
166    let notes = db.changes(cursor as u64)?;
167
168    println!(
169        "changes cursor={cursor} notes={} {}",
170        notes.len(),
171        notes.first().map(|(_, text)| text.as_str()).unwrap_or("")
172    );
173    println!(
174        "limit {:?} {:?}",
175        db.limit("{tour}:login", 2, 60_000)?,
176        db.limit("{tour}:login", 2, 60_000)?
177    );
178    println!(
179        "once {} {}",
180        db.once("{tour}:pay", 60_000)?,
181        db.once("{tour}:pay", 60_000)?
182    );
183    db.set("{tour}:seats", "5")?;
184    println!(
185        "take {:?} {:?}",
186        db.take("{tour}:seats", 2)?,
187        db.take("{tour}:seats", 9)?
188    );
189    println!("getex {:?}", db.getex("{tour}:seats", 60_000)?);
190
191    Ok(())
192}
Source

pub fn incr_by_max( &mut self, key: &str, delta: i64, limit: i64, ) -> Result<Option<i64>, Error>

Sends INCRBY key delta MAX limit. None means the result would pass limit, and the key was left unchanged.

Examples found in repository?
examples/tour.rs (line 149)
130fn owned(db: &mut Client) -> Result<(), ruvio_client::Error> {
131    let first = db.lease("{tour}:lock", 30_000)?;
132
133    println!(
134        "lease {:?} held {:?} release {}",
135        first,
136        db.lease("{tour}:lock", 30_000)?,
137        db.release("{tour}:lock", first.unwrap_or(0) as u64)?
138    );
139    let permit = db.semaphore("{tour}:workers", 1, 30_000)?;
140
141    println!(
142        "semaphore {:?} full {:?} release {}",
143        permit,
144        db.semaphore("{tour}:workers", 1, 30_000)?,
145        db.release("{tour}:workers", permit.unwrap_or(0) as u64)?
146    );
147    println!(
148        "incr_by_max {:?} over {:?}",
149        db.incr_by_max("{tour}:seats", 3, 4)?,
150        db.incr_by_max("{tour}:seats", 2, 4)?
151    );
152    let created = db.setv("{tour}:doc", "12", None)?;
153    let next = db.setv("{tour}:doc", "11", Some(created as u64))?;
154
155    println!("setv {created} then {next}");
156    println!(
157        "setv mismatch {}",
158        db.setv("{tour}:doc", "10", Some(created as u64))
159            .err()
160            .map(|error| error.to_string())
161            .unwrap_or_else(|| "accepted".to_owned())
162    );
163    let cursor = db.changes_start()?;
164
165    db.set("{tour}:note", "paid")?;
166    let notes = db.changes(cursor as u64)?;
167
168    println!(
169        "changes cursor={cursor} notes={} {}",
170        notes.len(),
171        notes.first().map(|(_, text)| text.as_str()).unwrap_or("")
172    );
173    println!(
174        "limit {:?} {:?}",
175        db.limit("{tour}:login", 2, 60_000)?,
176        db.limit("{tour}:login", 2, 60_000)?
177    );
178    println!(
179        "once {} {}",
180        db.once("{tour}:pay", 60_000)?,
181        db.once("{tour}:pay", 60_000)?
182    );
183    db.set("{tour}:seats", "5")?;
184    println!(
185        "take {:?} {:?}",
186        db.take("{tour}:seats", 2)?,
187        db.take("{tour}:seats", 9)?
188    );
189    println!("getex {:?}", db.getex("{tour}:seats", 60_000)?);
190
191    Ok(())
192}
Source

pub fn release(&mut self, key: &str, token: u64) -> Result<i64, Error>

Sends RELEASE. Returns 1 when the token matched the holder of a lease or a semaphore.

Examples found in repository?
examples/tour.rs (line 137)
130fn owned(db: &mut Client) -> Result<(), ruvio_client::Error> {
131    let first = db.lease("{tour}:lock", 30_000)?;
132
133    println!(
134        "lease {:?} held {:?} release {}",
135        first,
136        db.lease("{tour}:lock", 30_000)?,
137        db.release("{tour}:lock", first.unwrap_or(0) as u64)?
138    );
139    let permit = db.semaphore("{tour}:workers", 1, 30_000)?;
140
141    println!(
142        "semaphore {:?} full {:?} release {}",
143        permit,
144        db.semaphore("{tour}:workers", 1, 30_000)?,
145        db.release("{tour}:workers", permit.unwrap_or(0) as u64)?
146    );
147    println!(
148        "incr_by_max {:?} over {:?}",
149        db.incr_by_max("{tour}:seats", 3, 4)?,
150        db.incr_by_max("{tour}:seats", 2, 4)?
151    );
152    let created = db.setv("{tour}:doc", "12", None)?;
153    let next = db.setv("{tour}:doc", "11", Some(created as u64))?;
154
155    println!("setv {created} then {next}");
156    println!(
157        "setv mismatch {}",
158        db.setv("{tour}:doc", "10", Some(created as u64))
159            .err()
160            .map(|error| error.to_string())
161            .unwrap_or_else(|| "accepted".to_owned())
162    );
163    let cursor = db.changes_start()?;
164
165    db.set("{tour}:note", "paid")?;
166    let notes = db.changes(cursor as u64)?;
167
168    println!(
169        "changes cursor={cursor} notes={} {}",
170        notes.len(),
171        notes.first().map(|(_, text)| text.as_str()).unwrap_or("")
172    );
173    println!(
174        "limit {:?} {:?}",
175        db.limit("{tour}:login", 2, 60_000)?,
176        db.limit("{tour}:login", 2, 60_000)?
177    );
178    println!(
179        "once {} {}",
180        db.once("{tour}:pay", 60_000)?,
181        db.once("{tour}:pay", 60_000)?
182    );
183    db.set("{tour}:seats", "5")?;
184    println!(
185        "take {:?} {:?}",
186        db.take("{tour}:seats", 2)?,
187        db.take("{tour}:seats", 9)?
188    );
189    println!("getex {:?}", db.getex("{tour}:seats", 60_000)?);
190
191    Ok(())
192}
Source

pub fn setv( &mut self, key: &str, value: &str, version: Option<u64>, ) -> Result<i64, Error>

Sends SETV. Omit version to create version 1.

Examples found in repository?
examples/tour.rs (line 152)
130fn owned(db: &mut Client) -> Result<(), ruvio_client::Error> {
131    let first = db.lease("{tour}:lock", 30_000)?;
132
133    println!(
134        "lease {:?} held {:?} release {}",
135        first,
136        db.lease("{tour}:lock", 30_000)?,
137        db.release("{tour}:lock", first.unwrap_or(0) as u64)?
138    );
139    let permit = db.semaphore("{tour}:workers", 1, 30_000)?;
140
141    println!(
142        "semaphore {:?} full {:?} release {}",
143        permit,
144        db.semaphore("{tour}:workers", 1, 30_000)?,
145        db.release("{tour}:workers", permit.unwrap_or(0) as u64)?
146    );
147    println!(
148        "incr_by_max {:?} over {:?}",
149        db.incr_by_max("{tour}:seats", 3, 4)?,
150        db.incr_by_max("{tour}:seats", 2, 4)?
151    );
152    let created = db.setv("{tour}:doc", "12", None)?;
153    let next = db.setv("{tour}:doc", "11", Some(created as u64))?;
154
155    println!("setv {created} then {next}");
156    println!(
157        "setv mismatch {}",
158        db.setv("{tour}:doc", "10", Some(created as u64))
159            .err()
160            .map(|error| error.to_string())
161            .unwrap_or_else(|| "accepted".to_owned())
162    );
163    let cursor = db.changes_start()?;
164
165    db.set("{tour}:note", "paid")?;
166    let notes = db.changes(cursor as u64)?;
167
168    println!(
169        "changes cursor={cursor} notes={} {}",
170        notes.len(),
171        notes.first().map(|(_, text)| text.as_str()).unwrap_or("")
172    );
173    println!(
174        "limit {:?} {:?}",
175        db.limit("{tour}:login", 2, 60_000)?,
176        db.limit("{tour}:login", 2, 60_000)?
177    );
178    println!(
179        "once {} {}",
180        db.once("{tour}:pay", 60_000)?,
181        db.once("{tour}:pay", 60_000)?
182    );
183    db.set("{tour}:seats", "5")?;
184    println!(
185        "take {:?} {:?}",
186        db.take("{tour}:seats", 2)?,
187        db.take("{tour}:seats", 9)?
188    );
189    println!("getex {:?}", db.getex("{tour}:seats", 60_000)?);
190
191    Ok(())
192}
Source

pub fn changes_start(&mut self) -> Result<i64, Error>

Sends CHANGES START and returns the cursor to read after.

Examples found in repository?
examples/tour.rs (line 163)
130fn owned(db: &mut Client) -> Result<(), ruvio_client::Error> {
131    let first = db.lease("{tour}:lock", 30_000)?;
132
133    println!(
134        "lease {:?} held {:?} release {}",
135        first,
136        db.lease("{tour}:lock", 30_000)?,
137        db.release("{tour}:lock", first.unwrap_or(0) as u64)?
138    );
139    let permit = db.semaphore("{tour}:workers", 1, 30_000)?;
140
141    println!(
142        "semaphore {:?} full {:?} release {}",
143        permit,
144        db.semaphore("{tour}:workers", 1, 30_000)?,
145        db.release("{tour}:workers", permit.unwrap_or(0) as u64)?
146    );
147    println!(
148        "incr_by_max {:?} over {:?}",
149        db.incr_by_max("{tour}:seats", 3, 4)?,
150        db.incr_by_max("{tour}:seats", 2, 4)?
151    );
152    let created = db.setv("{tour}:doc", "12", None)?;
153    let next = db.setv("{tour}:doc", "11", Some(created as u64))?;
154
155    println!("setv {created} then {next}");
156    println!(
157        "setv mismatch {}",
158        db.setv("{tour}:doc", "10", Some(created as u64))
159            .err()
160            .map(|error| error.to_string())
161            .unwrap_or_else(|| "accepted".to_owned())
162    );
163    let cursor = db.changes_start()?;
164
165    db.set("{tour}:note", "paid")?;
166    let notes = db.changes(cursor as u64)?;
167
168    println!(
169        "changes cursor={cursor} notes={} {}",
170        notes.len(),
171        notes.first().map(|(_, text)| text.as_str()).unwrap_or("")
172    );
173    println!(
174        "limit {:?} {:?}",
175        db.limit("{tour}:login", 2, 60_000)?,
176        db.limit("{tour}:login", 2, 60_000)?
177    );
178    println!(
179        "once {} {}",
180        db.once("{tour}:pay", 60_000)?,
181        db.once("{tour}:pay", 60_000)?
182    );
183    db.set("{tour}:seats", "5")?;
184    println!(
185        "take {:?} {:?}",
186        db.take("{tour}:seats", 2)?,
187        db.take("{tour}:seats", 9)?
188    );
189    println!("getex {:?}", db.getex("{tour}:seats", 60_000)?);
190
191    Ok(())
192}
Source

pub fn changes(&mut self, cursor: u64) -> Result<Vec<(i64, String)>, Error>

Sends CHANGES and returns (sequence, text) notes after cursor.

Examples found in repository?
examples/tour.rs (line 166)
130fn owned(db: &mut Client) -> Result<(), ruvio_client::Error> {
131    let first = db.lease("{tour}:lock", 30_000)?;
132
133    println!(
134        "lease {:?} held {:?} release {}",
135        first,
136        db.lease("{tour}:lock", 30_000)?,
137        db.release("{tour}:lock", first.unwrap_or(0) as u64)?
138    );
139    let permit = db.semaphore("{tour}:workers", 1, 30_000)?;
140
141    println!(
142        "semaphore {:?} full {:?} release {}",
143        permit,
144        db.semaphore("{tour}:workers", 1, 30_000)?,
145        db.release("{tour}:workers", permit.unwrap_or(0) as u64)?
146    );
147    println!(
148        "incr_by_max {:?} over {:?}",
149        db.incr_by_max("{tour}:seats", 3, 4)?,
150        db.incr_by_max("{tour}:seats", 2, 4)?
151    );
152    let created = db.setv("{tour}:doc", "12", None)?;
153    let next = db.setv("{tour}:doc", "11", Some(created as u64))?;
154
155    println!("setv {created} then {next}");
156    println!(
157        "setv mismatch {}",
158        db.setv("{tour}:doc", "10", Some(created as u64))
159            .err()
160            .map(|error| error.to_string())
161            .unwrap_or_else(|| "accepted".to_owned())
162    );
163    let cursor = db.changes_start()?;
164
165    db.set("{tour}:note", "paid")?;
166    let notes = db.changes(cursor as u64)?;
167
168    println!(
169        "changes cursor={cursor} notes={} {}",
170        notes.len(),
171        notes.first().map(|(_, text)| text.as_str()).unwrap_or("")
172    );
173    println!(
174        "limit {:?} {:?}",
175        db.limit("{tour}:login", 2, 60_000)?,
176        db.limit("{tour}:login", 2, 60_000)?
177    );
178    println!(
179        "once {} {}",
180        db.once("{tour}:pay", 60_000)?,
181        db.once("{tour}:pay", 60_000)?
182    );
183    db.set("{tour}:seats", "5")?;
184    println!(
185        "take {:?} {:?}",
186        db.take("{tour}:seats", 2)?,
187        db.take("{tour}:seats", 9)?
188    );
189    println!("getex {:?}", db.getex("{tour}:seats", 60_000)?);
190
191    Ok(())
192}
Source

pub fn mset(&mut self, pairs: &[(&str, &str)]) -> Result<(), Error>

Sends MSET.

Examples found in repository?
examples/tour.rs (line 97)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn getset( &mut self, key: &str, value: &str, ) -> Result<Option<String>, Error>

Sends GETSET and returns the previous value.

Examples found in repository?
examples/tour.rs (line 102)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn append(&mut self, key: &str, value: &str) -> Result<i64, Error>

Sends APPEND and returns the new length.

Examples found in repository?
examples/tour.rs (line 103)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn strlen(&mut self, key: &str) -> Result<i64, Error>

Sends STRLEN.

Examples found in repository?
examples/tour.rs (line 104)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn decr(&mut self, key: &str) -> Result<i64, Error>

Sends DECR.

Examples found in repository?
examples/tour.rs (line 107)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn incr_by(&mut self, key: &str, delta: i64) -> Result<i64, Error>

Sends INCRBY.

Examples found in repository?
examples/tour.rs (line 106)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn decr_by(&mut self, key: &str, delta: i64) -> Result<i64, Error>

Sends DECRBY.

Examples found in repository?
examples/tour.rs (line 108)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}

Sends UNLINK for one key.

Examples found in repository?
examples/tour.rs (line 114)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}

Sends UNLINK and returns how many keys were removed.

Examples found in repository?
examples/tour.rs (line 113)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn exists_key(&mut self, key: &str) -> Result<i64, Error>

Sends EXISTS for one key.

Examples found in repository?
examples/tour.rs (line 110)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn exists(&mut self, keys: &[&str]) -> Result<i64, Error>

Sends EXISTS and returns how many of the keys exist.

Examples found in repository?
examples/tour.rs (line 109)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn key_type(&mut self, key: &str) -> Result<String, Error>

Sends TYPE: string, list, set, hash, zset, stream, or none.

Examples found in repository?
examples/tour.rs (line 111)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn rename(&mut self, key: &str, new_key: &str) -> Result<(), Error>

Sends RENAME.

Examples found in repository?
examples/tour.rs (line 112)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn scan( &mut self, cursor: u64, pattern: Option<&str>, count: Option<u64>, ) -> Result<ScanPage, Error>

Sends SCAN with an optional MATCH pattern and COUNT hint.

Examples found in repository?
examples/tour.rs (line 120)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn dbsize(&mut self) -> Result<i64, Error>

Sends DBSIZE for the selected database.

Examples found in repository?
examples/tour.rs (line 123)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn expire_at(&mut self, key: &str, when: SystemTime) -> Result<bool, Error>

Sends EXPIREAT, or PEXPIREAT when when is not a whole second.

Examples found in repository?
examples/tour.rs (line 117)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn pexpire(&mut self, key: &str, ttl: Duration) -> Result<bool, Error>

Sends PEXPIRE. False when the key does not exist.

Examples found in repository?
examples/tour.rs (line 116)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn ttl(&mut self, key: &str) -> Result<i64, Error>

Sends TTL: seconds left, -1 without an expiry, -2 when the key is missing.

Examples found in repository?
examples/tour.rs (line 118)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn pttl(&mut self, key: &str) -> Result<i64, Error>

Sends PTTL: milliseconds left, -1 without an expiry, -2 when the key is missing.

Examples found in repository?
examples/tour.rs (line 118)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn persist(&mut self, key: &str) -> Result<bool, Error>

Sends PERSIST. False when the key is missing or has no expiry.

Examples found in repository?
examples/tour.rs (line 119)
80fn strings(db: &mut Client) -> Result<(), ruvio_client::Error> {
81    let key = "{tour}:s";
82
83    db.set(key, "hello")?;
84    println!("get {:?}", db.get_string(key)?);
85    db.set_with(key, "nx", None, SetMode::IfNotExists)?;
86    db.set_expires_at(
87        key,
88        "later",
89        SystemTime::now() + Duration::from_secs(120),
90        SetMode::Always,
91    )?;
92    db.set_keep_ttl(key, "kept", SetMode::Always)?;
93    println!(
94        "set_and_get {:?}",
95        db.set_and_get(key, "now", None, SetMode::Always)?
96    );
97    db.mset(&[("{tour}:a", "1"), ("{tour}:b", "2")])?;
98    println!(
99        "mget {:?}",
100        db.mget(&["{tour}:a", "{tour}:missing", "{tour}:b"])?
101    );
102    println!("getset {:?}", db.getset(key, "10")?);
103    println!("append {}", db.append(key, "0")?);
104    println!("strlen {}", db.strlen(key)?);
105    println!("incr {}", db.incr("{tour}:n")?);
106    println!("incr_by {}", db.incr_by("{tour}:n", 5)?);
107    println!("decr {}", db.decr("{tour}:n")?);
108    println!("decr_by {}", db.decr_by("{tour}:n", 2)?);
109    println!("exists {}", db.exists(&["{tour}:a", "{tour}:b"])?);
110    println!("exists_key {}", db.exists_key(key)?);
111    println!("type {}", db.key_type(key)?);
112    db.rename("{tour}:b", "{tour}:c")?;
113    println!("unlink {}", db.unlink(&["{tour}:c"])?);
114    println!("unlink_key {}", db.unlink_key("{tour}:gone")?);
115    db.expire(key, Duration::from_secs(30))?;
116    db.pexpire("{tour}:a", Duration::from_millis(30_000))?;
117    db.expire_at("{tour}:a", SystemTime::now() + Duration::from_secs(60))?;
118    println!("ttl {} pttl {}", db.ttl(key)?, db.pttl(key)?);
119    println!("persist {}", db.persist(key)?);
120    let page = db.scan(0, Some("{tour}:*"), Some(20))?;
121
122    println!("scan cursor={} keys={}", page.cursor, page.keys.len());
123    println!("dbsize {}", db.dbsize()?);
124    println!("del {}", db.del(&["{tour}:a"])?);
125    println!("del_key {}", db.del_key("{tour}:n")?);
126
127    Ok(())
128}
Source

pub fn lpush(&mut self, key: &str, values: &[&str]) -> Result<i64, Error>

Sends LPUSH and returns the new length.

Examples found in repository?
examples/tour.rs (line 198)
194fn lists(db: &mut Client) -> Result<(), ruvio_client::Error> {
195    let key = "{tour}:l";
196
197    println!("rpush {}", db.rpush(key, &["a", "b", "c", "d"])?);
198    println!("lpush {}", db.lpush(key, &["z"])?);
199    println!("lpop {:?}", db.lpop(key)?);
200    println!("rpop_count {:?}", db.rpop_count(key, 2)?);
201    println!("llen {}", db.llen(key)?);
202    println!("lindex {:?}", db.lindex(key, 0)?);
203    println!("lrange {:?}", db.lrange(key, 0, -1)?);
204    db.ltrim(key, 0, 0)?;
205    println!("lpop_count {:?}", db.lpop_count(key, 1)?);
206    db.rpush(key, &["only"])?;
207    println!("blpop {:?}", db.blpop_key(key, Duration::from_millis(200))?);
208    db.rpush(key, &["right"])?;
209    println!("brpop {:?}", db.brpop(&[key], Duration::from_millis(200))?);
210    println!(
211        "brpop empty {:?}",
212        db.brpop_key(key, Duration::from_millis(1))?
213    );
214
215    Ok(())
216}
Source

pub fn rpush(&mut self, key: &str, values: &[&str]) -> Result<i64, Error>

Sends RPUSH and returns the new length.

Examples found in repository?
examples/tour.rs (line 197)
194fn lists(db: &mut Client) -> Result<(), ruvio_client::Error> {
195    let key = "{tour}:l";
196
197    println!("rpush {}", db.rpush(key, &["a", "b", "c", "d"])?);
198    println!("lpush {}", db.lpush(key, &["z"])?);
199    println!("lpop {:?}", db.lpop(key)?);
200    println!("rpop_count {:?}", db.rpop_count(key, 2)?);
201    println!("llen {}", db.llen(key)?);
202    println!("lindex {:?}", db.lindex(key, 0)?);
203    println!("lrange {:?}", db.lrange(key, 0, -1)?);
204    db.ltrim(key, 0, 0)?;
205    println!("lpop_count {:?}", db.lpop_count(key, 1)?);
206    db.rpush(key, &["only"])?;
207    println!("blpop {:?}", db.blpop_key(key, Duration::from_millis(200))?);
208    db.rpush(key, &["right"])?;
209    println!("brpop {:?}", db.brpop(&[key], Duration::from_millis(200))?);
210    println!(
211        "brpop empty {:?}",
212        db.brpop_key(key, Duration::from_millis(1))?
213    );
214
215    Ok(())
216}
Source

pub fn lpop(&mut self, key: &str) -> Result<Option<String>, Error>

Sends LPOP for one element.

Examples found in repository?
examples/tour.rs (line 199)
194fn lists(db: &mut Client) -> Result<(), ruvio_client::Error> {
195    let key = "{tour}:l";
196
197    println!("rpush {}", db.rpush(key, &["a", "b", "c", "d"])?);
198    println!("lpush {}", db.lpush(key, &["z"])?);
199    println!("lpop {:?}", db.lpop(key)?);
200    println!("rpop_count {:?}", db.rpop_count(key, 2)?);
201    println!("llen {}", db.llen(key)?);
202    println!("lindex {:?}", db.lindex(key, 0)?);
203    println!("lrange {:?}", db.lrange(key, 0, -1)?);
204    db.ltrim(key, 0, 0)?;
205    println!("lpop_count {:?}", db.lpop_count(key, 1)?);
206    db.rpush(key, &["only"])?;
207    println!("blpop {:?}", db.blpop_key(key, Duration::from_millis(200))?);
208    db.rpush(key, &["right"])?;
209    println!("brpop {:?}", db.brpop(&[key], Duration::from_millis(200))?);
210    println!(
211        "brpop empty {:?}",
212        db.brpop_key(key, Duration::from_millis(1))?
213    );
214
215    Ok(())
216}
Source

pub fn lpop_count( &mut self, key: &str, count: u64, ) -> Result<Vec<String>, Error>

Sends LPOP with a count. A missing list returns an empty vector.

Examples found in repository?
examples/tour.rs (line 205)
194fn lists(db: &mut Client) -> Result<(), ruvio_client::Error> {
195    let key = "{tour}:l";
196
197    println!("rpush {}", db.rpush(key, &["a", "b", "c", "d"])?);
198    println!("lpush {}", db.lpush(key, &["z"])?);
199    println!("lpop {:?}", db.lpop(key)?);
200    println!("rpop_count {:?}", db.rpop_count(key, 2)?);
201    println!("llen {}", db.llen(key)?);
202    println!("lindex {:?}", db.lindex(key, 0)?);
203    println!("lrange {:?}", db.lrange(key, 0, -1)?);
204    db.ltrim(key, 0, 0)?;
205    println!("lpop_count {:?}", db.lpop_count(key, 1)?);
206    db.rpush(key, &["only"])?;
207    println!("blpop {:?}", db.blpop_key(key, Duration::from_millis(200))?);
208    db.rpush(key, &["right"])?;
209    println!("brpop {:?}", db.brpop(&[key], Duration::from_millis(200))?);
210    println!(
211        "brpop empty {:?}",
212        db.brpop_key(key, Duration::from_millis(1))?
213    );
214
215    Ok(())
216}
Source

pub fn rpop(&mut self, key: &str) -> Result<Option<String>, Error>

Sends RPOP for one element.

Source

pub fn rpop_count( &mut self, key: &str, count: u64, ) -> Result<Vec<String>, Error>

Sends RPOP with a count. A missing list returns an empty vector.

Examples found in repository?
examples/tour.rs (line 200)
194fn lists(db: &mut Client) -> Result<(), ruvio_client::Error> {
195    let key = "{tour}:l";
196
197    println!("rpush {}", db.rpush(key, &["a", "b", "c", "d"])?);
198    println!("lpush {}", db.lpush(key, &["z"])?);
199    println!("lpop {:?}", db.lpop(key)?);
200    println!("rpop_count {:?}", db.rpop_count(key, 2)?);
201    println!("llen {}", db.llen(key)?);
202    println!("lindex {:?}", db.lindex(key, 0)?);
203    println!("lrange {:?}", db.lrange(key, 0, -1)?);
204    db.ltrim(key, 0, 0)?;
205    println!("lpop_count {:?}", db.lpop_count(key, 1)?);
206    db.rpush(key, &["only"])?;
207    println!("blpop {:?}", db.blpop_key(key, Duration::from_millis(200))?);
208    db.rpush(key, &["right"])?;
209    println!("brpop {:?}", db.brpop(&[key], Duration::from_millis(200))?);
210    println!(
211        "brpop empty {:?}",
212        db.brpop_key(key, Duration::from_millis(1))?
213    );
214
215    Ok(())
216}
Source

pub fn llen(&mut self, key: &str) -> Result<i64, Error>

Sends LLEN.

Examples found in repository?
examples/tour.rs (line 201)
194fn lists(db: &mut Client) -> Result<(), ruvio_client::Error> {
195    let key = "{tour}:l";
196
197    println!("rpush {}", db.rpush(key, &["a", "b", "c", "d"])?);
198    println!("lpush {}", db.lpush(key, &["z"])?);
199    println!("lpop {:?}", db.lpop(key)?);
200    println!("rpop_count {:?}", db.rpop_count(key, 2)?);
201    println!("llen {}", db.llen(key)?);
202    println!("lindex {:?}", db.lindex(key, 0)?);
203    println!("lrange {:?}", db.lrange(key, 0, -1)?);
204    db.ltrim(key, 0, 0)?;
205    println!("lpop_count {:?}", db.lpop_count(key, 1)?);
206    db.rpush(key, &["only"])?;
207    println!("blpop {:?}", db.blpop_key(key, Duration::from_millis(200))?);
208    db.rpush(key, &["right"])?;
209    println!("brpop {:?}", db.brpop(&[key], Duration::from_millis(200))?);
210    println!(
211        "brpop empty {:?}",
212        db.brpop_key(key, Duration::from_millis(1))?
213    );
214
215    Ok(())
216}
Source

pub fn lindex(&mut self, key: &str, index: i64) -> Result<Option<String>, Error>

Sends LINDEX.

Examples found in repository?
examples/tour.rs (line 202)
194fn lists(db: &mut Client) -> Result<(), ruvio_client::Error> {
195    let key = "{tour}:l";
196
197    println!("rpush {}", db.rpush(key, &["a", "b", "c", "d"])?);
198    println!("lpush {}", db.lpush(key, &["z"])?);
199    println!("lpop {:?}", db.lpop(key)?);
200    println!("rpop_count {:?}", db.rpop_count(key, 2)?);
201    println!("llen {}", db.llen(key)?);
202    println!("lindex {:?}", db.lindex(key, 0)?);
203    println!("lrange {:?}", db.lrange(key, 0, -1)?);
204    db.ltrim(key, 0, 0)?;
205    println!("lpop_count {:?}", db.lpop_count(key, 1)?);
206    db.rpush(key, &["only"])?;
207    println!("blpop {:?}", db.blpop_key(key, Duration::from_millis(200))?);
208    db.rpush(key, &["right"])?;
209    println!("brpop {:?}", db.brpop(&[key], Duration::from_millis(200))?);
210    println!(
211        "brpop empty {:?}",
212        db.brpop_key(key, Duration::from_millis(1))?
213    );
214
215    Ok(())
216}
Source

pub fn lrange( &mut self, key: &str, start: i64, stop: i64, ) -> Result<Vec<String>, Error>

Sends LRANGE. stop is inclusive and negative indexes count from the tail.

Examples found in repository?
examples/tour.rs (line 203)
194fn lists(db: &mut Client) -> Result<(), ruvio_client::Error> {
195    let key = "{tour}:l";
196
197    println!("rpush {}", db.rpush(key, &["a", "b", "c", "d"])?);
198    println!("lpush {}", db.lpush(key, &["z"])?);
199    println!("lpop {:?}", db.lpop(key)?);
200    println!("rpop_count {:?}", db.rpop_count(key, 2)?);
201    println!("llen {}", db.llen(key)?);
202    println!("lindex {:?}", db.lindex(key, 0)?);
203    println!("lrange {:?}", db.lrange(key, 0, -1)?);
204    db.ltrim(key, 0, 0)?;
205    println!("lpop_count {:?}", db.lpop_count(key, 1)?);
206    db.rpush(key, &["only"])?;
207    println!("blpop {:?}", db.blpop_key(key, Duration::from_millis(200))?);
208    db.rpush(key, &["right"])?;
209    println!("brpop {:?}", db.brpop(&[key], Duration::from_millis(200))?);
210    println!(
211        "brpop empty {:?}",
212        db.brpop_key(key, Duration::from_millis(1))?
213    );
214
215    Ok(())
216}
Source

pub fn ltrim(&mut self, key: &str, start: i64, stop: i64) -> Result<(), Error>

Sends LTRIM.

Examples found in repository?
examples/tour.rs (line 204)
194fn lists(db: &mut Client) -> Result<(), ruvio_client::Error> {
195    let key = "{tour}:l";
196
197    println!("rpush {}", db.rpush(key, &["a", "b", "c", "d"])?);
198    println!("lpush {}", db.lpush(key, &["z"])?);
199    println!("lpop {:?}", db.lpop(key)?);
200    println!("rpop_count {:?}", db.rpop_count(key, 2)?);
201    println!("llen {}", db.llen(key)?);
202    println!("lindex {:?}", db.lindex(key, 0)?);
203    println!("lrange {:?}", db.lrange(key, 0, -1)?);
204    db.ltrim(key, 0, 0)?;
205    println!("lpop_count {:?}", db.lpop_count(key, 1)?);
206    db.rpush(key, &["only"])?;
207    println!("blpop {:?}", db.blpop_key(key, Duration::from_millis(200))?);
208    db.rpush(key, &["right"])?;
209    println!("brpop {:?}", db.brpop(&[key], Duration::from_millis(200))?);
210    println!(
211        "brpop empty {:?}",
212        db.brpop_key(key, Duration::from_millis(1))?
213    );
214
215    Ok(())
216}
Source

pub fn blpop_key( &mut self, key: &str, timeout: Duration, ) -> Result<Option<(String, String)>, Error>

Sends BLPOP for one key. Returns (key, value), or None when timeout passes. Duration::ZERO waits forever.

Examples found in repository?
examples/tour.rs (line 207)
194fn lists(db: &mut Client) -> Result<(), ruvio_client::Error> {
195    let key = "{tour}:l";
196
197    println!("rpush {}", db.rpush(key, &["a", "b", "c", "d"])?);
198    println!("lpush {}", db.lpush(key, &["z"])?);
199    println!("lpop {:?}", db.lpop(key)?);
200    println!("rpop_count {:?}", db.rpop_count(key, 2)?);
201    println!("llen {}", db.llen(key)?);
202    println!("lindex {:?}", db.lindex(key, 0)?);
203    println!("lrange {:?}", db.lrange(key, 0, -1)?);
204    db.ltrim(key, 0, 0)?;
205    println!("lpop_count {:?}", db.lpop_count(key, 1)?);
206    db.rpush(key, &["only"])?;
207    println!("blpop {:?}", db.blpop_key(key, Duration::from_millis(200))?);
208    db.rpush(key, &["right"])?;
209    println!("brpop {:?}", db.brpop(&[key], Duration::from_millis(200))?);
210    println!(
211        "brpop empty {:?}",
212        db.brpop_key(key, Duration::from_millis(1))?
213    );
214
215    Ok(())
216}
Source

pub fn blpop( &mut self, keys: &[&str], timeout: Duration, ) -> Result<Option<(String, String)>, Error>

Sends BLPOP. Returns (key, value), or None when timeout passes. Duration::ZERO waits forever. The timeout rounds up to whole seconds.

Source

pub fn brpop_key( &mut self, key: &str, timeout: Duration, ) -> Result<Option<(String, String)>, Error>

Sends BRPOP for one key. Returns (key, value), or None when timeout passes.

Examples found in repository?
examples/tour.rs (line 212)
194fn lists(db: &mut Client) -> Result<(), ruvio_client::Error> {
195    let key = "{tour}:l";
196
197    println!("rpush {}", db.rpush(key, &["a", "b", "c", "d"])?);
198    println!("lpush {}", db.lpush(key, &["z"])?);
199    println!("lpop {:?}", db.lpop(key)?);
200    println!("rpop_count {:?}", db.rpop_count(key, 2)?);
201    println!("llen {}", db.llen(key)?);
202    println!("lindex {:?}", db.lindex(key, 0)?);
203    println!("lrange {:?}", db.lrange(key, 0, -1)?);
204    db.ltrim(key, 0, 0)?;
205    println!("lpop_count {:?}", db.lpop_count(key, 1)?);
206    db.rpush(key, &["only"])?;
207    println!("blpop {:?}", db.blpop_key(key, Duration::from_millis(200))?);
208    db.rpush(key, &["right"])?;
209    println!("brpop {:?}", db.brpop(&[key], Duration::from_millis(200))?);
210    println!(
211        "brpop empty {:?}",
212        db.brpop_key(key, Duration::from_millis(1))?
213    );
214
215    Ok(())
216}
Source

pub fn brpop( &mut self, keys: &[&str], timeout: Duration, ) -> Result<Option<(String, String)>, Error>

Sends BRPOP. Returns (key, value), or None when timeout passes.

Examples found in repository?
examples/tour.rs (line 209)
194fn lists(db: &mut Client) -> Result<(), ruvio_client::Error> {
195    let key = "{tour}:l";
196
197    println!("rpush {}", db.rpush(key, &["a", "b", "c", "d"])?);
198    println!("lpush {}", db.lpush(key, &["z"])?);
199    println!("lpop {:?}", db.lpop(key)?);
200    println!("rpop_count {:?}", db.rpop_count(key, 2)?);
201    println!("llen {}", db.llen(key)?);
202    println!("lindex {:?}", db.lindex(key, 0)?);
203    println!("lrange {:?}", db.lrange(key, 0, -1)?);
204    db.ltrim(key, 0, 0)?;
205    println!("lpop_count {:?}", db.lpop_count(key, 1)?);
206    db.rpush(key, &["only"])?;
207    println!("blpop {:?}", db.blpop_key(key, Duration::from_millis(200))?);
208    db.rpush(key, &["right"])?;
209    println!("brpop {:?}", db.brpop(&[key], Duration::from_millis(200))?);
210    println!(
211        "brpop empty {:?}",
212        db.brpop_key(key, Duration::from_millis(1))?
213    );
214
215    Ok(())
216}
Source

pub fn sadd(&mut self, key: &str, members: &[&str]) -> Result<i64, Error>

Sends SADD and returns how many members were new.

Examples found in repository?
examples/tour.rs (line 219)
218fn sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
219    println!("sadd {}", db.sadd("{tour}:s1", &["a", "b", "c"])?);
220    db.sadd("{tour}:s2", &["b", "c", "d"])?;
221    println!("sismember {}", db.sismember("{tour}:s1", "a")?);
222    println!("scard {}", db.scard("{tour}:s1")?);
223    println!("smembers {:?}", db.smembers("{tour}:s1")?);
224    println!("sinter {:?}", db.sinter(&["{tour}:s1", "{tour}:s2"])?);
225    println!("sunion {:?}", db.sunion(&["{tour}:s1", "{tour}:s2"])?);
226    println!("sdiff {:?}", db.sdiff(&["{tour}:s1", "{tour}:s2"])?);
227    println!(
228        "sinterstore {}",
229        db.sinterstore("{tour}:s3", &["{tour}:s1", "{tour}:s2"])?
230    );
231    println!(
232        "sunionstore {}",
233        db.sunionstore("{tour}:s4", &["{tour}:s1", "{tour}:s2"])?
234    );
235    println!(
236        "sdiffstore {}",
237        db.sdiffstore("{tour}:s5", &["{tour}:s1", "{tour}:s2"])?
238    );
239    println!("smove {}", db.smove("{tour}:s1", "{tour}:s3", "a")?);
240    println!("srem {}", db.srem("{tour}:s3", &["a"])?);
241    println!("srandmember {:?}", db.srandmember("{tour}:s2")?);
242    println!(
243        "srandmember_count {:?}",
244        db.srandmember_count("{tour}:s2", 2)?
245    );
246    println!("spop_count {:?}", db.spop_count("{tour}:s5", 5)?);
247    println!("spop {:?}", db.spop("{tour}:s4")?);
248
249    Ok(())
250}
Source

pub fn srem(&mut self, key: &str, members: &[&str]) -> Result<i64, Error>

Sends SREM and returns how many members were removed.

Examples found in repository?
examples/tour.rs (line 240)
218fn sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
219    println!("sadd {}", db.sadd("{tour}:s1", &["a", "b", "c"])?);
220    db.sadd("{tour}:s2", &["b", "c", "d"])?;
221    println!("sismember {}", db.sismember("{tour}:s1", "a")?);
222    println!("scard {}", db.scard("{tour}:s1")?);
223    println!("smembers {:?}", db.smembers("{tour}:s1")?);
224    println!("sinter {:?}", db.sinter(&["{tour}:s1", "{tour}:s2"])?);
225    println!("sunion {:?}", db.sunion(&["{tour}:s1", "{tour}:s2"])?);
226    println!("sdiff {:?}", db.sdiff(&["{tour}:s1", "{tour}:s2"])?);
227    println!(
228        "sinterstore {}",
229        db.sinterstore("{tour}:s3", &["{tour}:s1", "{tour}:s2"])?
230    );
231    println!(
232        "sunionstore {}",
233        db.sunionstore("{tour}:s4", &["{tour}:s1", "{tour}:s2"])?
234    );
235    println!(
236        "sdiffstore {}",
237        db.sdiffstore("{tour}:s5", &["{tour}:s1", "{tour}:s2"])?
238    );
239    println!("smove {}", db.smove("{tour}:s1", "{tour}:s3", "a")?);
240    println!("srem {}", db.srem("{tour}:s3", &["a"])?);
241    println!("srandmember {:?}", db.srandmember("{tour}:s2")?);
242    println!(
243        "srandmember_count {:?}",
244        db.srandmember_count("{tour}:s2", 2)?
245    );
246    println!("spop_count {:?}", db.spop_count("{tour}:s5", 5)?);
247    println!("spop {:?}", db.spop("{tour}:s4")?);
248
249    Ok(())
250}
Source

pub fn sismember(&mut self, key: &str, member: &str) -> Result<bool, Error>

Sends SISMEMBER.

Examples found in repository?
examples/tour.rs (line 221)
218fn sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
219    println!("sadd {}", db.sadd("{tour}:s1", &["a", "b", "c"])?);
220    db.sadd("{tour}:s2", &["b", "c", "d"])?;
221    println!("sismember {}", db.sismember("{tour}:s1", "a")?);
222    println!("scard {}", db.scard("{tour}:s1")?);
223    println!("smembers {:?}", db.smembers("{tour}:s1")?);
224    println!("sinter {:?}", db.sinter(&["{tour}:s1", "{tour}:s2"])?);
225    println!("sunion {:?}", db.sunion(&["{tour}:s1", "{tour}:s2"])?);
226    println!("sdiff {:?}", db.sdiff(&["{tour}:s1", "{tour}:s2"])?);
227    println!(
228        "sinterstore {}",
229        db.sinterstore("{tour}:s3", &["{tour}:s1", "{tour}:s2"])?
230    );
231    println!(
232        "sunionstore {}",
233        db.sunionstore("{tour}:s4", &["{tour}:s1", "{tour}:s2"])?
234    );
235    println!(
236        "sdiffstore {}",
237        db.sdiffstore("{tour}:s5", &["{tour}:s1", "{tour}:s2"])?
238    );
239    println!("smove {}", db.smove("{tour}:s1", "{tour}:s3", "a")?);
240    println!("srem {}", db.srem("{tour}:s3", &["a"])?);
241    println!("srandmember {:?}", db.srandmember("{tour}:s2")?);
242    println!(
243        "srandmember_count {:?}",
244        db.srandmember_count("{tour}:s2", 2)?
245    );
246    println!("spop_count {:?}", db.spop_count("{tour}:s5", 5)?);
247    println!("spop {:?}", db.spop("{tour}:s4")?);
248
249    Ok(())
250}
Source

pub fn scard(&mut self, key: &str) -> Result<i64, Error>

Sends SCARD.

Examples found in repository?
examples/tour.rs (line 222)
218fn sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
219    println!("sadd {}", db.sadd("{tour}:s1", &["a", "b", "c"])?);
220    db.sadd("{tour}:s2", &["b", "c", "d"])?;
221    println!("sismember {}", db.sismember("{tour}:s1", "a")?);
222    println!("scard {}", db.scard("{tour}:s1")?);
223    println!("smembers {:?}", db.smembers("{tour}:s1")?);
224    println!("sinter {:?}", db.sinter(&["{tour}:s1", "{tour}:s2"])?);
225    println!("sunion {:?}", db.sunion(&["{tour}:s1", "{tour}:s2"])?);
226    println!("sdiff {:?}", db.sdiff(&["{tour}:s1", "{tour}:s2"])?);
227    println!(
228        "sinterstore {}",
229        db.sinterstore("{tour}:s3", &["{tour}:s1", "{tour}:s2"])?
230    );
231    println!(
232        "sunionstore {}",
233        db.sunionstore("{tour}:s4", &["{tour}:s1", "{tour}:s2"])?
234    );
235    println!(
236        "sdiffstore {}",
237        db.sdiffstore("{tour}:s5", &["{tour}:s1", "{tour}:s2"])?
238    );
239    println!("smove {}", db.smove("{tour}:s1", "{tour}:s3", "a")?);
240    println!("srem {}", db.srem("{tour}:s3", &["a"])?);
241    println!("srandmember {:?}", db.srandmember("{tour}:s2")?);
242    println!(
243        "srandmember_count {:?}",
244        db.srandmember_count("{tour}:s2", 2)?
245    );
246    println!("spop_count {:?}", db.spop_count("{tour}:s5", 5)?);
247    println!("spop {:?}", db.spop("{tour}:s4")?);
248
249    Ok(())
250}
Source

pub fn smembers(&mut self, key: &str) -> Result<Vec<String>, Error>

Sends SMEMBERS.

Examples found in repository?
examples/tour.rs (line 223)
218fn sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
219    println!("sadd {}", db.sadd("{tour}:s1", &["a", "b", "c"])?);
220    db.sadd("{tour}:s2", &["b", "c", "d"])?;
221    println!("sismember {}", db.sismember("{tour}:s1", "a")?);
222    println!("scard {}", db.scard("{tour}:s1")?);
223    println!("smembers {:?}", db.smembers("{tour}:s1")?);
224    println!("sinter {:?}", db.sinter(&["{tour}:s1", "{tour}:s2"])?);
225    println!("sunion {:?}", db.sunion(&["{tour}:s1", "{tour}:s2"])?);
226    println!("sdiff {:?}", db.sdiff(&["{tour}:s1", "{tour}:s2"])?);
227    println!(
228        "sinterstore {}",
229        db.sinterstore("{tour}:s3", &["{tour}:s1", "{tour}:s2"])?
230    );
231    println!(
232        "sunionstore {}",
233        db.sunionstore("{tour}:s4", &["{tour}:s1", "{tour}:s2"])?
234    );
235    println!(
236        "sdiffstore {}",
237        db.sdiffstore("{tour}:s5", &["{tour}:s1", "{tour}:s2"])?
238    );
239    println!("smove {}", db.smove("{tour}:s1", "{tour}:s3", "a")?);
240    println!("srem {}", db.srem("{tour}:s3", &["a"])?);
241    println!("srandmember {:?}", db.srandmember("{tour}:s2")?);
242    println!(
243        "srandmember_count {:?}",
244        db.srandmember_count("{tour}:s2", 2)?
245    );
246    println!("spop_count {:?}", db.spop_count("{tour}:s5", 5)?);
247    println!("spop {:?}", db.spop("{tour}:s4")?);
248
249    Ok(())
250}
Source

pub fn sinter(&mut self, keys: &[&str]) -> Result<Vec<String>, Error>

Sends SINTER.

Examples found in repository?
examples/tour.rs (line 224)
218fn sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
219    println!("sadd {}", db.sadd("{tour}:s1", &["a", "b", "c"])?);
220    db.sadd("{tour}:s2", &["b", "c", "d"])?;
221    println!("sismember {}", db.sismember("{tour}:s1", "a")?);
222    println!("scard {}", db.scard("{tour}:s1")?);
223    println!("smembers {:?}", db.smembers("{tour}:s1")?);
224    println!("sinter {:?}", db.sinter(&["{tour}:s1", "{tour}:s2"])?);
225    println!("sunion {:?}", db.sunion(&["{tour}:s1", "{tour}:s2"])?);
226    println!("sdiff {:?}", db.sdiff(&["{tour}:s1", "{tour}:s2"])?);
227    println!(
228        "sinterstore {}",
229        db.sinterstore("{tour}:s3", &["{tour}:s1", "{tour}:s2"])?
230    );
231    println!(
232        "sunionstore {}",
233        db.sunionstore("{tour}:s4", &["{tour}:s1", "{tour}:s2"])?
234    );
235    println!(
236        "sdiffstore {}",
237        db.sdiffstore("{tour}:s5", &["{tour}:s1", "{tour}:s2"])?
238    );
239    println!("smove {}", db.smove("{tour}:s1", "{tour}:s3", "a")?);
240    println!("srem {}", db.srem("{tour}:s3", &["a"])?);
241    println!("srandmember {:?}", db.srandmember("{tour}:s2")?);
242    println!(
243        "srandmember_count {:?}",
244        db.srandmember_count("{tour}:s2", 2)?
245    );
246    println!("spop_count {:?}", db.spop_count("{tour}:s5", 5)?);
247    println!("spop {:?}", db.spop("{tour}:s4")?);
248
249    Ok(())
250}
Source

pub fn sunion(&mut self, keys: &[&str]) -> Result<Vec<String>, Error>

Sends SUNION.

Examples found in repository?
examples/tour.rs (line 225)
218fn sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
219    println!("sadd {}", db.sadd("{tour}:s1", &["a", "b", "c"])?);
220    db.sadd("{tour}:s2", &["b", "c", "d"])?;
221    println!("sismember {}", db.sismember("{tour}:s1", "a")?);
222    println!("scard {}", db.scard("{tour}:s1")?);
223    println!("smembers {:?}", db.smembers("{tour}:s1")?);
224    println!("sinter {:?}", db.sinter(&["{tour}:s1", "{tour}:s2"])?);
225    println!("sunion {:?}", db.sunion(&["{tour}:s1", "{tour}:s2"])?);
226    println!("sdiff {:?}", db.sdiff(&["{tour}:s1", "{tour}:s2"])?);
227    println!(
228        "sinterstore {}",
229        db.sinterstore("{tour}:s3", &["{tour}:s1", "{tour}:s2"])?
230    );
231    println!(
232        "sunionstore {}",
233        db.sunionstore("{tour}:s4", &["{tour}:s1", "{tour}:s2"])?
234    );
235    println!(
236        "sdiffstore {}",
237        db.sdiffstore("{tour}:s5", &["{tour}:s1", "{tour}:s2"])?
238    );
239    println!("smove {}", db.smove("{tour}:s1", "{tour}:s3", "a")?);
240    println!("srem {}", db.srem("{tour}:s3", &["a"])?);
241    println!("srandmember {:?}", db.srandmember("{tour}:s2")?);
242    println!(
243        "srandmember_count {:?}",
244        db.srandmember_count("{tour}:s2", 2)?
245    );
246    println!("spop_count {:?}", db.spop_count("{tour}:s5", 5)?);
247    println!("spop {:?}", db.spop("{tour}:s4")?);
248
249    Ok(())
250}
Source

pub fn sdiff(&mut self, keys: &[&str]) -> Result<Vec<String>, Error>

Sends SDIFF.

Examples found in repository?
examples/tour.rs (line 226)
218fn sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
219    println!("sadd {}", db.sadd("{tour}:s1", &["a", "b", "c"])?);
220    db.sadd("{tour}:s2", &["b", "c", "d"])?;
221    println!("sismember {}", db.sismember("{tour}:s1", "a")?);
222    println!("scard {}", db.scard("{tour}:s1")?);
223    println!("smembers {:?}", db.smembers("{tour}:s1")?);
224    println!("sinter {:?}", db.sinter(&["{tour}:s1", "{tour}:s2"])?);
225    println!("sunion {:?}", db.sunion(&["{tour}:s1", "{tour}:s2"])?);
226    println!("sdiff {:?}", db.sdiff(&["{tour}:s1", "{tour}:s2"])?);
227    println!(
228        "sinterstore {}",
229        db.sinterstore("{tour}:s3", &["{tour}:s1", "{tour}:s2"])?
230    );
231    println!(
232        "sunionstore {}",
233        db.sunionstore("{tour}:s4", &["{tour}:s1", "{tour}:s2"])?
234    );
235    println!(
236        "sdiffstore {}",
237        db.sdiffstore("{tour}:s5", &["{tour}:s1", "{tour}:s2"])?
238    );
239    println!("smove {}", db.smove("{tour}:s1", "{tour}:s3", "a")?);
240    println!("srem {}", db.srem("{tour}:s3", &["a"])?);
241    println!("srandmember {:?}", db.srandmember("{tour}:s2")?);
242    println!(
243        "srandmember_count {:?}",
244        db.srandmember_count("{tour}:s2", 2)?
245    );
246    println!("spop_count {:?}", db.spop_count("{tour}:s5", 5)?);
247    println!("spop {:?}", db.spop("{tour}:s4")?);
248
249    Ok(())
250}
Source

pub fn sinterstore( &mut self, destination: &str, keys: &[&str], ) -> Result<i64, Error>

Sends SINTERSTORE and returns the size of destination.

Examples found in repository?
examples/tour.rs (line 229)
218fn sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
219    println!("sadd {}", db.sadd("{tour}:s1", &["a", "b", "c"])?);
220    db.sadd("{tour}:s2", &["b", "c", "d"])?;
221    println!("sismember {}", db.sismember("{tour}:s1", "a")?);
222    println!("scard {}", db.scard("{tour}:s1")?);
223    println!("smembers {:?}", db.smembers("{tour}:s1")?);
224    println!("sinter {:?}", db.sinter(&["{tour}:s1", "{tour}:s2"])?);
225    println!("sunion {:?}", db.sunion(&["{tour}:s1", "{tour}:s2"])?);
226    println!("sdiff {:?}", db.sdiff(&["{tour}:s1", "{tour}:s2"])?);
227    println!(
228        "sinterstore {}",
229        db.sinterstore("{tour}:s3", &["{tour}:s1", "{tour}:s2"])?
230    );
231    println!(
232        "sunionstore {}",
233        db.sunionstore("{tour}:s4", &["{tour}:s1", "{tour}:s2"])?
234    );
235    println!(
236        "sdiffstore {}",
237        db.sdiffstore("{tour}:s5", &["{tour}:s1", "{tour}:s2"])?
238    );
239    println!("smove {}", db.smove("{tour}:s1", "{tour}:s3", "a")?);
240    println!("srem {}", db.srem("{tour}:s3", &["a"])?);
241    println!("srandmember {:?}", db.srandmember("{tour}:s2")?);
242    println!(
243        "srandmember_count {:?}",
244        db.srandmember_count("{tour}:s2", 2)?
245    );
246    println!("spop_count {:?}", db.spop_count("{tour}:s5", 5)?);
247    println!("spop {:?}", db.spop("{tour}:s4")?);
248
249    Ok(())
250}
Source

pub fn sunionstore( &mut self, destination: &str, keys: &[&str], ) -> Result<i64, Error>

Sends SUNIONSTORE and returns the size of destination.

Examples found in repository?
examples/tour.rs (line 233)
218fn sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
219    println!("sadd {}", db.sadd("{tour}:s1", &["a", "b", "c"])?);
220    db.sadd("{tour}:s2", &["b", "c", "d"])?;
221    println!("sismember {}", db.sismember("{tour}:s1", "a")?);
222    println!("scard {}", db.scard("{tour}:s1")?);
223    println!("smembers {:?}", db.smembers("{tour}:s1")?);
224    println!("sinter {:?}", db.sinter(&["{tour}:s1", "{tour}:s2"])?);
225    println!("sunion {:?}", db.sunion(&["{tour}:s1", "{tour}:s2"])?);
226    println!("sdiff {:?}", db.sdiff(&["{tour}:s1", "{tour}:s2"])?);
227    println!(
228        "sinterstore {}",
229        db.sinterstore("{tour}:s3", &["{tour}:s1", "{tour}:s2"])?
230    );
231    println!(
232        "sunionstore {}",
233        db.sunionstore("{tour}:s4", &["{tour}:s1", "{tour}:s2"])?
234    );
235    println!(
236        "sdiffstore {}",
237        db.sdiffstore("{tour}:s5", &["{tour}:s1", "{tour}:s2"])?
238    );
239    println!("smove {}", db.smove("{tour}:s1", "{tour}:s3", "a")?);
240    println!("srem {}", db.srem("{tour}:s3", &["a"])?);
241    println!("srandmember {:?}", db.srandmember("{tour}:s2")?);
242    println!(
243        "srandmember_count {:?}",
244        db.srandmember_count("{tour}:s2", 2)?
245    );
246    println!("spop_count {:?}", db.spop_count("{tour}:s5", 5)?);
247    println!("spop {:?}", db.spop("{tour}:s4")?);
248
249    Ok(())
250}
Source

pub fn sdiffstore( &mut self, destination: &str, keys: &[&str], ) -> Result<i64, Error>

Sends SDIFFSTORE and returns the size of destination.

Examples found in repository?
examples/tour.rs (line 237)
218fn sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
219    println!("sadd {}", db.sadd("{tour}:s1", &["a", "b", "c"])?);
220    db.sadd("{tour}:s2", &["b", "c", "d"])?;
221    println!("sismember {}", db.sismember("{tour}:s1", "a")?);
222    println!("scard {}", db.scard("{tour}:s1")?);
223    println!("smembers {:?}", db.smembers("{tour}:s1")?);
224    println!("sinter {:?}", db.sinter(&["{tour}:s1", "{tour}:s2"])?);
225    println!("sunion {:?}", db.sunion(&["{tour}:s1", "{tour}:s2"])?);
226    println!("sdiff {:?}", db.sdiff(&["{tour}:s1", "{tour}:s2"])?);
227    println!(
228        "sinterstore {}",
229        db.sinterstore("{tour}:s3", &["{tour}:s1", "{tour}:s2"])?
230    );
231    println!(
232        "sunionstore {}",
233        db.sunionstore("{tour}:s4", &["{tour}:s1", "{tour}:s2"])?
234    );
235    println!(
236        "sdiffstore {}",
237        db.sdiffstore("{tour}:s5", &["{tour}:s1", "{tour}:s2"])?
238    );
239    println!("smove {}", db.smove("{tour}:s1", "{tour}:s3", "a")?);
240    println!("srem {}", db.srem("{tour}:s3", &["a"])?);
241    println!("srandmember {:?}", db.srandmember("{tour}:s2")?);
242    println!(
243        "srandmember_count {:?}",
244        db.srandmember_count("{tour}:s2", 2)?
245    );
246    println!("spop_count {:?}", db.spop_count("{tour}:s5", 5)?);
247    println!("spop {:?}", db.spop("{tour}:s4")?);
248
249    Ok(())
250}
Source

pub fn smove( &mut self, source: &str, destination: &str, member: &str, ) -> Result<bool, Error>

Sends SMOVE. False when member was not in source.

Examples found in repository?
examples/tour.rs (line 239)
218fn sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
219    println!("sadd {}", db.sadd("{tour}:s1", &["a", "b", "c"])?);
220    db.sadd("{tour}:s2", &["b", "c", "d"])?;
221    println!("sismember {}", db.sismember("{tour}:s1", "a")?);
222    println!("scard {}", db.scard("{tour}:s1")?);
223    println!("smembers {:?}", db.smembers("{tour}:s1")?);
224    println!("sinter {:?}", db.sinter(&["{tour}:s1", "{tour}:s2"])?);
225    println!("sunion {:?}", db.sunion(&["{tour}:s1", "{tour}:s2"])?);
226    println!("sdiff {:?}", db.sdiff(&["{tour}:s1", "{tour}:s2"])?);
227    println!(
228        "sinterstore {}",
229        db.sinterstore("{tour}:s3", &["{tour}:s1", "{tour}:s2"])?
230    );
231    println!(
232        "sunionstore {}",
233        db.sunionstore("{tour}:s4", &["{tour}:s1", "{tour}:s2"])?
234    );
235    println!(
236        "sdiffstore {}",
237        db.sdiffstore("{tour}:s5", &["{tour}:s1", "{tour}:s2"])?
238    );
239    println!("smove {}", db.smove("{tour}:s1", "{tour}:s3", "a")?);
240    println!("srem {}", db.srem("{tour}:s3", &["a"])?);
241    println!("srandmember {:?}", db.srandmember("{tour}:s2")?);
242    println!(
243        "srandmember_count {:?}",
244        db.srandmember_count("{tour}:s2", 2)?
245    );
246    println!("spop_count {:?}", db.spop_count("{tour}:s5", 5)?);
247    println!("spop {:?}", db.spop("{tour}:s4")?);
248
249    Ok(())
250}
Source

pub fn spop(&mut self, key: &str) -> Result<Option<String>, Error>

Sends SPOP for one member.

Examples found in repository?
examples/tour.rs (line 247)
218fn sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
219    println!("sadd {}", db.sadd("{tour}:s1", &["a", "b", "c"])?);
220    db.sadd("{tour}:s2", &["b", "c", "d"])?;
221    println!("sismember {}", db.sismember("{tour}:s1", "a")?);
222    println!("scard {}", db.scard("{tour}:s1")?);
223    println!("smembers {:?}", db.smembers("{tour}:s1")?);
224    println!("sinter {:?}", db.sinter(&["{tour}:s1", "{tour}:s2"])?);
225    println!("sunion {:?}", db.sunion(&["{tour}:s1", "{tour}:s2"])?);
226    println!("sdiff {:?}", db.sdiff(&["{tour}:s1", "{tour}:s2"])?);
227    println!(
228        "sinterstore {}",
229        db.sinterstore("{tour}:s3", &["{tour}:s1", "{tour}:s2"])?
230    );
231    println!(
232        "sunionstore {}",
233        db.sunionstore("{tour}:s4", &["{tour}:s1", "{tour}:s2"])?
234    );
235    println!(
236        "sdiffstore {}",
237        db.sdiffstore("{tour}:s5", &["{tour}:s1", "{tour}:s2"])?
238    );
239    println!("smove {}", db.smove("{tour}:s1", "{tour}:s3", "a")?);
240    println!("srem {}", db.srem("{tour}:s3", &["a"])?);
241    println!("srandmember {:?}", db.srandmember("{tour}:s2")?);
242    println!(
243        "srandmember_count {:?}",
244        db.srandmember_count("{tour}:s2", 2)?
245    );
246    println!("spop_count {:?}", db.spop_count("{tour}:s5", 5)?);
247    println!("spop {:?}", db.spop("{tour}:s4")?);
248
249    Ok(())
250}
Source

pub fn spop_count( &mut self, key: &str, count: u64, ) -> Result<Vec<String>, Error>

Sends SPOP with a count and returns the removed members.

Examples found in repository?
examples/tour.rs (line 246)
218fn sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
219    println!("sadd {}", db.sadd("{tour}:s1", &["a", "b", "c"])?);
220    db.sadd("{tour}:s2", &["b", "c", "d"])?;
221    println!("sismember {}", db.sismember("{tour}:s1", "a")?);
222    println!("scard {}", db.scard("{tour}:s1")?);
223    println!("smembers {:?}", db.smembers("{tour}:s1")?);
224    println!("sinter {:?}", db.sinter(&["{tour}:s1", "{tour}:s2"])?);
225    println!("sunion {:?}", db.sunion(&["{tour}:s1", "{tour}:s2"])?);
226    println!("sdiff {:?}", db.sdiff(&["{tour}:s1", "{tour}:s2"])?);
227    println!(
228        "sinterstore {}",
229        db.sinterstore("{tour}:s3", &["{tour}:s1", "{tour}:s2"])?
230    );
231    println!(
232        "sunionstore {}",
233        db.sunionstore("{tour}:s4", &["{tour}:s1", "{tour}:s2"])?
234    );
235    println!(
236        "sdiffstore {}",
237        db.sdiffstore("{tour}:s5", &["{tour}:s1", "{tour}:s2"])?
238    );
239    println!("smove {}", db.smove("{tour}:s1", "{tour}:s3", "a")?);
240    println!("srem {}", db.srem("{tour}:s3", &["a"])?);
241    println!("srandmember {:?}", db.srandmember("{tour}:s2")?);
242    println!(
243        "srandmember_count {:?}",
244        db.srandmember_count("{tour}:s2", 2)?
245    );
246    println!("spop_count {:?}", db.spop_count("{tour}:s5", 5)?);
247    println!("spop {:?}", db.spop("{tour}:s4")?);
248
249    Ok(())
250}
Source

pub fn srandmember(&mut self, key: &str) -> Result<Option<String>, Error>

Sends SRANDMEMBER for one member.

Examples found in repository?
examples/tour.rs (line 241)
218fn sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
219    println!("sadd {}", db.sadd("{tour}:s1", &["a", "b", "c"])?);
220    db.sadd("{tour}:s2", &["b", "c", "d"])?;
221    println!("sismember {}", db.sismember("{tour}:s1", "a")?);
222    println!("scard {}", db.scard("{tour}:s1")?);
223    println!("smembers {:?}", db.smembers("{tour}:s1")?);
224    println!("sinter {:?}", db.sinter(&["{tour}:s1", "{tour}:s2"])?);
225    println!("sunion {:?}", db.sunion(&["{tour}:s1", "{tour}:s2"])?);
226    println!("sdiff {:?}", db.sdiff(&["{tour}:s1", "{tour}:s2"])?);
227    println!(
228        "sinterstore {}",
229        db.sinterstore("{tour}:s3", &["{tour}:s1", "{tour}:s2"])?
230    );
231    println!(
232        "sunionstore {}",
233        db.sunionstore("{tour}:s4", &["{tour}:s1", "{tour}:s2"])?
234    );
235    println!(
236        "sdiffstore {}",
237        db.sdiffstore("{tour}:s5", &["{tour}:s1", "{tour}:s2"])?
238    );
239    println!("smove {}", db.smove("{tour}:s1", "{tour}:s3", "a")?);
240    println!("srem {}", db.srem("{tour}:s3", &["a"])?);
241    println!("srandmember {:?}", db.srandmember("{tour}:s2")?);
242    println!(
243        "srandmember_count {:?}",
244        db.srandmember_count("{tour}:s2", 2)?
245    );
246    println!("spop_count {:?}", db.spop_count("{tour}:s5", 5)?);
247    println!("spop {:?}", db.spop("{tour}:s4")?);
248
249    Ok(())
250}
Source

pub fn srandmember_count( &mut self, key: &str, count: i64, ) -> Result<Vec<String>, Error>

Sends SRANDMEMBER with a count. A positive count returns distinct members; a negative count may repeat members.

Examples found in repository?
examples/tour.rs (line 244)
218fn sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
219    println!("sadd {}", db.sadd("{tour}:s1", &["a", "b", "c"])?);
220    db.sadd("{tour}:s2", &["b", "c", "d"])?;
221    println!("sismember {}", db.sismember("{tour}:s1", "a")?);
222    println!("scard {}", db.scard("{tour}:s1")?);
223    println!("smembers {:?}", db.smembers("{tour}:s1")?);
224    println!("sinter {:?}", db.sinter(&["{tour}:s1", "{tour}:s2"])?);
225    println!("sunion {:?}", db.sunion(&["{tour}:s1", "{tour}:s2"])?);
226    println!("sdiff {:?}", db.sdiff(&["{tour}:s1", "{tour}:s2"])?);
227    println!(
228        "sinterstore {}",
229        db.sinterstore("{tour}:s3", &["{tour}:s1", "{tour}:s2"])?
230    );
231    println!(
232        "sunionstore {}",
233        db.sunionstore("{tour}:s4", &["{tour}:s1", "{tour}:s2"])?
234    );
235    println!(
236        "sdiffstore {}",
237        db.sdiffstore("{tour}:s5", &["{tour}:s1", "{tour}:s2"])?
238    );
239    println!("smove {}", db.smove("{tour}:s1", "{tour}:s3", "a")?);
240    println!("srem {}", db.srem("{tour}:s3", &["a"])?);
241    println!("srandmember {:?}", db.srandmember("{tour}:s2")?);
242    println!(
243        "srandmember_count {:?}",
244        db.srandmember_count("{tour}:s2", 2)?
245    );
246    println!("spop_count {:?}", db.spop_count("{tour}:s5", 5)?);
247    println!("spop {:?}", db.spop("{tour}:s4")?);
248
249    Ok(())
250}
Source

pub fn hset(&mut self, key: &str, fields: &[(&str, &str)]) -> Result<i64, Error>

Sends HSET and returns how many fields were new.

Examples found in repository?
examples/tour.rs (line 255)
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
Source

pub fn hget(&mut self, key: &str, field: &str) -> Result<Option<String>, Error>

Sends HGET.

Examples found in repository?
examples/tour.rs (line 256)
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
Source

pub fn hdel(&mut self, key: &str, fields: &[&str]) -> Result<i64, Error>

Sends HDEL and returns how many fields were removed.

Examples found in repository?
examples/tour.rs (line 295)
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
Source

pub fn hlen(&mut self, key: &str) -> Result<i64, Error>

Sends HLEN.

Examples found in repository?
examples/tour.rs (line 260)
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
Source

pub fn hgetall(&mut self, key: &str) -> Result<HashMap<String, String>, Error>

Sends HGETALL.

Examples found in repository?
examples/tour.rs (line 264)
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
Source

pub fn hmget( &mut self, key: &str, fields: &[&str], ) -> Result<Vec<Option<String>>, Error>

Sends HMGET. A missing field is None.

Examples found in repository?
examples/tour.rs (line 265)
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
Source

pub fn hexists(&mut self, key: &str, field: &str) -> Result<bool, Error>

Sends HEXISTS.

Examples found in repository?
examples/tour.rs (line 261)
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
Source

pub fn hkeys(&mut self, key: &str) -> Result<Vec<String>, Error>

Sends HKEYS.

Examples found in repository?
examples/tour.rs (line 262)
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
Source

pub fn hvals(&mut self, key: &str) -> Result<Vec<String>, Error>

Sends HVALS.

Examples found in repository?
examples/tour.rs (line 263)
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
Source

pub fn hincr_by( &mut self, key: &str, field: &str, delta: i64, ) -> Result<i64, Error>

Sends HINCRBY and returns the new value.

Examples found in repository?
examples/tour.rs (line 257)
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
Source

pub fn hsetnx( &mut self, key: &str, field: &str, value: &str, ) -> Result<bool, Error>

Sends HSETNX. False when the field already existed.

Examples found in repository?
examples/tour.rs (line 258)
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
Source

pub fn hstrlen(&mut self, key: &str, field: &str) -> Result<i64, Error>

Sends HSTRLEN.

Examples found in repository?
examples/tour.rs (line 259)
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
Source

pub fn hexpire( &mut self, key: &str, ttl: Duration, fields: &[&str], ) -> Result<Vec<i64>, Error>

Sets a TTL on hash fields. Sends HEXPIRE for whole seconds, otherwise HPEXPIRE. One reply per field: 1 set, 0 condition not met, 2 deleted by a zero TTL, -2 no such field or key.

db.hset("session:42", &[("token", "abc"), ("user", "ada")])?;
db.hexpire("session:42", Duration::from_secs(900), &["token"])?;
Examples found in repository?
examples/tour.rs (line 271)
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
Source

pub fn hexpire_with( &mut self, key: &str, ttl: Duration, condition: FieldExpireCondition, fields: &[&str], ) -> Result<Vec<i64>, Error>

Like Client::hexpire with NX, XX, GT, or LT.

Examples found in repository?
examples/tour.rs (lines 275-280)
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
Source

pub fn hpexpire( &mut self, key: &str, ttl: Duration, fields: &[&str], ) -> Result<Vec<i64>, Error>

Sends HPEXPIRE: a TTL in milliseconds on hash fields.

Examples found in repository?
examples/tour.rs (line 284)
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
Source

pub fn hexpire_at( &mut self, key: &str, when: SystemTime, fields: &[&str], ) -> Result<Vec<i64>, Error>

Sets an absolute deadline on hash fields. Sends HEXPIREAT for a whole second, otherwise HPEXPIREAT. A time in the past deletes the field (reply 2).

Examples found in repository?
examples/tour.rs (line 290)
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
Source

pub fn httl(&mut self, key: &str, fields: &[&str]) -> Result<Vec<i64>, Error>

Sends HTTL: seconds left per field, -1 without a TTL, -2 when missing.

Examples found in repository?
examples/tour.rs (line 286)
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
Source

pub fn hpttl(&mut self, key: &str, fields: &[&str]) -> Result<Vec<i64>, Error>

Sends HPTTL: milliseconds left per field, -1 without a TTL, -2 when missing.

Examples found in repository?
examples/tour.rs (line 287)
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
Source

pub fn hexpiretime( &mut self, key: &str, fields: &[&str], ) -> Result<Vec<i64>, Error>

Sends HEXPIRETIME: the Unix second each field expires at, -1 or -2 as HTTL.

Examples found in repository?
examples/tour.rs (line 292)
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
Source

pub fn hpexpiretime( &mut self, key: &str, fields: &[&str], ) -> Result<Vec<i64>, Error>

Sends HPEXPIRETIME: the Unix millisecond each field expires at.

Examples found in repository?
examples/tour.rs (line 293)
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
Source

pub fn hpersist( &mut self, key: &str, fields: &[&str], ) -> Result<Vec<i64>, Error>

Sends HPERSIST: 1 removed a TTL, -1 the field had none, -2 it is missing.

Examples found in repository?
examples/tour.rs (line 294)
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
Source

pub fn hscan( &mut self, key: &str, cursor: u64, pattern: Option<&str>, count: Option<u64>, ) -> Result<HashScanPage, Error>

Sends HSCAN with an optional MATCH pattern and COUNT hint.

Examples found in repository?
examples/tour.rs (line 266)
252fn hashes(db: &mut Client) -> Result<(), ruvio_client::Error> {
253    let key = "{tour}:h";
254
255    println!("hset {}", db.hset(key, &[("f1", "1"), ("f2", "two")])?);
256    println!("hget {:?}", db.hget(key, "f2")?);
257    println!("hincr_by {}", db.hincr_by(key, "f1", 4)?);
258    println!("hsetnx {}", db.hsetnx(key, "f1", "9")?);
259    println!("hstrlen {}", db.hstrlen(key, "f2")?);
260    println!("hlen {}", db.hlen(key)?);
261    println!("hexists {}", db.hexists(key, "f1")?);
262    println!("hkeys {:?}", db.hkeys(key)?);
263    println!("hvals {:?}", db.hvals(key)?);
264    println!("hgetall {:?}", db.hgetall(key)?);
265    println!("hmget {:?}", db.hmget(key, &["f2", "nope"])?);
266    let page = db.hscan(key, 0, Some("f*"), Some(10))?;
267
268    println!("hscan cursor={} fields={}", page.cursor, page.fields.len());
269    println!(
270        "hexpire {:?}",
271        db.hexpire(key, Duration::from_secs(60), &["f1", "nope"])?
272    );
273    println!(
274        "hexpire_with GT {:?}",
275        db.hexpire_with(
276            key,
277            Duration::from_secs(120),
278            FieldExpireCondition::IfGreater,
279            &["f1"]
280        )?
281    );
282    println!(
283        "hpexpire {:?}",
284        db.hpexpire(key, Duration::from_millis(90_500), &["f2"])?
285    );
286    println!("httl {:?}", db.httl(key, &["f1", "f2"])?);
287    println!("hpttl {:?}", db.hpttl(key, &["f1"])?);
288    println!(
289        "hexpire_at {:?}",
290        db.hexpire_at(key, SystemTime::now() + Duration::from_secs(300), &["f2"])?
291    );
292    println!("hexpiretime {:?}", db.hexpiretime(key, &["f2"])?);
293    println!("hpexpiretime {:?}", db.hpexpiretime(key, &["f2"])?);
294    println!("hpersist {:?}", db.hpersist(key, &["f1", "f2"])?);
295    println!("hdel {}", db.hdel(key, &["f1"])?);
296
297    Ok(())
298}
Source

pub fn zadd(&mut self, key: &str, entries: &[(&str, f64)]) -> Result<i64, Error>

Sends ZADD with (member, score) pairs and returns how many members were new.

db.zadd("board", &[("ada", 100.0), ("bob", 50.0)])?;
Examples found in repository?
examples/tour.rs (line 303)
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
Source

pub fn zadd_with( &mut self, key: &str, options: SortedSetAddOptions, entries: &[(&str, f64)], ) -> Result<i64, Error>

Sends ZADD with NX, XX, GT, LT, or CH. Without SortedSetAddOptions::changed the reply counts new members.

Examples found in repository?
examples/tour.rs (line 320)
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
Source

pub fn zadd_incr( &mut self, key: &str, member: &str, delta: f64, options: SortedSetAddOptions, ) -> Result<Option<f64>, Error>

Sends ZADD ... INCR. Returns the new score, or None when an option skipped the update.

Examples found in repository?
examples/tour.rs (line 325)
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
Source

pub fn zincr_by( &mut self, key: &str, member: &str, delta: f64, ) -> Result<f64, Error>

Sends ZINCRBY and returns the new score.

Examples found in repository?
examples/tour.rs (line 322)
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
Source

pub fn geo_add( &mut self, key: &str, places: &[(f64, f64, &str)], ) -> Result<i64, Error>

Sends GEOADD. Each place is longitude, latitude, then member.

Examples found in repository?
examples/tour.rs (line 306)
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
Source

pub fn geo_dist( &mut self, key: &str, from: &str, to: &str, unit: Option<&str>, ) -> Result<Option<f64>, Error>

Sends GEODIST. unit is m, km, ft, or mi. None asks for meters.

Source

pub fn geo_hash( &mut self, key: &str, members: &[&str], ) -> Result<Vec<Option<String>>, Error>

Sends GEOHASH. A missing member is None.

Source

pub fn geo_pos( &mut self, key: &str, members: &[&str], ) -> Result<Vec<Option<(f64, f64)>>, Error>

Sends GEOPOS. A missing member is None.

Sends GEOSEARCH ... FROMLONLAT ... BYRADIUS ... ASC.

Examples found in repository?
examples/tour.rs (line 310)
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
Source

pub fn geo_search_store( &mut self, destination: &str, source: &str, member: &str, radius: f64, unit: &str, ) -> Result<i64, Error>

Sends GEOSEARCHSTORE from a member and a radius. Returns how many members were stored.

Source

pub fn geo_radius_by_member( &mut self, key: &str, member: &str, radius: f64, unit: &str, ) -> Result<Vec<String>, Error>

Sends GEORADIUSBYMEMBER ... ASC.

Source

pub fn geo_radius( &mut self, key: &str, longitude: f64, latitude: f64, radius: f64, unit: &str, ) -> Result<Vec<String>, Error>

Sends GEORADIUS ... ASC.

Source

pub fn zrange( &mut self, key: &str, start: i64, stop: i64, ) -> Result<Vec<String>, Error>

Sends ZRANGE by rank. stop is inclusive.

Examples found in repository?
examples/tour.rs (line 327)
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
Source

pub fn zrevrange( &mut self, key: &str, start: i64, stop: i64, ) -> Result<Vec<String>, Error>

Sends ZREVRANGE by rank. stop is inclusive.

Examples found in repository?
examples/tour.rs (line 328)
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
Source

pub fn zrange_with_scores( &mut self, key: &str, start: i64, stop: i64, ) -> Result<Vec<SortedSetEntry>, Error>

Sends ZRANGE ... WITHSCORES.

Examples found in repository?
examples/tour.rs (line 329)
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
Source

pub fn zrevrange_with_scores( &mut self, key: &str, start: i64, stop: i64, ) -> Result<Vec<SortedSetEntry>, Error>

Sends ZREVRANGE ... WITHSCORES.

Examples found in repository?
examples/tour.rs (line 332)
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
Source

pub fn zrange_by_lex( &mut self, key: &str, min: &str, max: &str, ) -> Result<Vec<String>, Error>

Sends ZRANGE min max BYLEX. Bounds are -, +, [member, or (member.

Source

pub fn zrange_by_score_with_scores( &mut self, key: &str, min: &str, max: &str, ) -> Result<Vec<SortedSetEntry>, Error>

Sends ZRANGEBYSCORE ... WITHSCORES. min and max accept -inf, +inf, and ( for exclusive bounds.

Examples found in repository?
examples/tour.rs (line 336)
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
Source

pub fn zrem(&mut self, key: &str, members: &[&str]) -> Result<i64, Error>

Sends ZREM and returns how many members were removed.

Examples found in repository?
examples/tour.rs (line 341)
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
Source

pub fn zpopmin( &mut self, key: &str, count: u64, ) -> Result<Vec<SortedSetEntry>, Error>

Sends ZPOPMIN key count: removes and returns up to count lowest-scored members.

Examples found in repository?
examples/tour.rs (line 350)
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
Source

pub fn zpopmax( &mut self, key: &str, count: u64, ) -> Result<Vec<SortedSetEntry>, Error>

Sends ZPOPMAX key count: removes and returns up to count highest-scored members.

Examples found in repository?
examples/tour.rs (line 351)
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
Source

pub fn bzpopmin( &mut self, keys: &[&str], timeout: Duration, ) -> Result<Option<(String, SortedSetEntry)>, Error>

Sends BZPOPMIN. Returns the key and the popped member, or None when timeout passes. Duration::ZERO waits forever. The timeout rounds up to whole seconds.

Examples found in repository?
examples/tour.rs (line 354)
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
Source

pub fn bzpopmax( &mut self, keys: &[&str], timeout: Duration, ) -> Result<Option<(String, SortedSetEntry)>, Error>

Sends BZPOPMAX. Like Client::bzpopmin, highest score first.

Examples found in repository?
examples/tour.rs (line 358)
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
Source

pub fn zremrangebyrank( &mut self, key: &str, start: i64, stop: i64, ) -> Result<i64, Error>

Sends ZREMRANGEBYRANK. stop is inclusive; negative ranks count from the end.

Examples found in repository?
examples/tour.rs (line 361)
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
Source

pub fn zremrangebyscore( &mut self, key: &str, min: &str, max: &str, ) -> Result<i64, Error>

Sends ZREMRANGEBYSCORE. Bounds accept -inf, +inf, and ( for exclusive.

Examples found in repository?
examples/tour.rs (line 364)
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
Source

pub fn zremrangebylex( &mut self, key: &str, min: &str, max: &str, ) -> Result<i64, Error>

Sends ZREMRANGEBYLEX. Bounds are -, +, [member, or (member.

Examples found in repository?
examples/tour.rs (line 366)
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
Source

pub fn zcard(&mut self, key: &str) -> Result<i64, Error>

Sends ZCARD.

Examples found in repository?
examples/tour.rs (line 342)
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
Source

pub fn zscore(&mut self, key: &str, member: &str) -> Result<Option<f64>, Error>

Sends ZSCORE.

Examples found in repository?
examples/tour.rs (line 338)
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
Source

pub fn zrank(&mut self, key: &str, member: &str) -> Result<Option<i64>, Error>

Sends ZRANK: the 0-based rank from the lowest score.

Examples found in repository?
examples/tour.rs (line 339)
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
Source

pub fn zrevrank( &mut self, key: &str, member: &str, ) -> Result<Option<i64>, Error>

Sends ZREVRANK: the 0-based rank from the highest score.

Examples found in repository?
examples/tour.rs (line 340)
300fn sorted_sets(db: &mut Client) -> Result<(), ruvio_client::Error> {
301    let key = "{tour}:z";
302
303    println!("zadd {}", db.zadd(key, &[("ada", 100.0), ("bob", 50.0)])?);
304    println!(
305        "geoadd {}",
306        db.geo_add(key, &[(13.361389, 38.115556, "Palermo")])?
307    );
308    println!(
309        "geosearch {:?}",
310        db.geo_search(key, 13.36, 38.11, 20.0, "km")?
311    );
312    let greater = SortedSetAddOptions {
313        greater_than: true,
314        changed: true,
315        ..SortedSetAddOptions::default()
316    };
317
318    println!(
319        "zadd_with {}",
320        db.zadd_with(key, greater, &[("bob", 10.0)])?
321    );
322    println!("zincr_by {}", db.zincr_by(key, "bob", 5.5)?);
323    println!(
324        "zadd_incr {:?}",
325        db.zadd_incr(key, "cy", 1.0, SortedSetAddOptions::default())?
326    );
327    println!("zrange {:?}", db.zrange(key, 0, -1)?);
328    println!("zrevrange {:?}", db.zrevrange(key, 0, 0)?);
329    println!("zrange_with_scores {:?}", db.zrange_with_scores(key, 0, 0)?);
330    println!(
331        "zrevrange_with_scores {:?}",
332        db.zrevrange_with_scores(key, 0, 0)?
333    );
334    println!(
335        "zrange_by_score {:?}",
336        db.zrange_by_score_with_scores(key, "(1", "+inf")?
337    );
338    println!("zscore {:?}", db.zscore(key, "ada")?);
339    println!("zrank {:?}", db.zrank(key, "ada")?);
340    println!("zrevrank {:?}", db.zrevrank(key, "ada")?);
341    println!("zrem {}", db.zrem(key, &["cy"])?);
342    println!("zcard {}", db.zcard(key)?);
343
344    let queue = "{tour}:zq";
345
346    db.zadd(
347        queue,
348        &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("d", 4.0), ("e", 5.0)],
349    )?;
350    println!("zpopmin {:?}", db.zpopmin(queue, 1)?);
351    println!("zpopmax {:?}", db.zpopmax(queue, 1)?);
352    println!(
353        "bzpopmin {:?}",
354        db.bzpopmin(&[queue], Duration::from_secs(1))?
355    );
356    println!(
357        "bzpopmax {:?}",
358        db.bzpopmax(&[queue], Duration::from_secs(1))?
359    );
360    db.zadd(queue, &[("a", 1.0), ("b", 2.0), ("c", 3.0), ("x", 0.0)])?;
361    println!("zremrangebyrank {}", db.zremrangebyrank(queue, 0, 0)?);
362    println!(
363        "zremrangebyscore {}",
364        db.zremrangebyscore(queue, "(1", "2")?
365    );
366    println!("zremrangebylex {}", db.zremrangebylex(queue, "-", "+")?);
367
368    Ok(())
369}
Source

pub fn bf_reserve( &mut self, key: &str, error_rate: f64, capacity: u64, ) -> Result<(), Error>

Sends BF.RESERVE.

Examples found in repository?
examples/tour.rs (line 372)
371fn bloom(db: &mut Client) -> Result<(), ruvio_client::Error> {
372    db.bf_reserve("{tour}:bf", 0.01, 1000)?;
373    println!("bf_add {}", db.bf_add("{tour}:bf", "x")?);
374    println!(
375        "bf_exists {} {}",
376        db.bf_exists("{tour}:bf", "x")?,
377        db.bf_exists("{tour}:bf", "y")?
378    );
379
380    Ok(())
381}
Source

pub fn bf_add(&mut self, key: &str, item: &str) -> Result<bool, Error>

Sends BF.ADD. False when the item may already have been added.

Examples found in repository?
examples/tour.rs (line 373)
371fn bloom(db: &mut Client) -> Result<(), ruvio_client::Error> {
372    db.bf_reserve("{tour}:bf", 0.01, 1000)?;
373    println!("bf_add {}", db.bf_add("{tour}:bf", "x")?);
374    println!(
375        "bf_exists {} {}",
376        db.bf_exists("{tour}:bf", "x")?,
377        db.bf_exists("{tour}:bf", "y")?
378    );
379
380    Ok(())
381}
Source

pub fn bf_exists(&mut self, key: &str, item: &str) -> Result<bool, Error>

Sends BF.EXISTS. True means “maybe added”; false means “never added”.

Examples found in repository?
examples/tour.rs (line 376)
371fn bloom(db: &mut Client) -> Result<(), ruvio_client::Error> {
372    db.bf_reserve("{tour}:bf", 0.01, 1000)?;
373    println!("bf_add {}", db.bf_add("{tour}:bf", "x")?);
374    println!(
375        "bf_exists {} {}",
376        db.bf_exists("{tour}:bf", "x")?,
377        db.bf_exists("{tour}:bf", "y")?
378    );
379
380    Ok(())
381}
Source

pub fn xadd_nomkstream( &mut self, key: &str, id: &str, fields: &[(&str, &str)], ) -> Result<Option<String>, Error>

Sends XADD NOMKSTREAM. A missing key stays absent and the reply is nil.

Source

pub fn xadd_delay( &mut self, key: &str, delay_ms: u64, id: &str, fields: &[(&str, &str)], ) -> Result<String, Error>

Sends XADD key DELAY ms. The entry stays hidden from XREADGROUP until the delay passes.

Examples found in repository?
examples/tour.rs (line 394)
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}
Source

pub fn xadd( &mut self, key: &str, id: &str, fields: &[(&str, &str)], ) -> Result<String, Error>

Sends XADD and returns the entry id. Use * for id to let the server pick one. ms-* fixes the millisecond.

Examples found in repository?
examples/tour.rs (line 385)
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}
Source

pub fn xadd_maxlen( &mut self, key: &str, max_len: u64, id: &str, fields: &[(&str, &str)], ) -> Result<String, Error>

Sends XADD key MAXLEN n: the stream keeps exactly the newest max_len entries.

Examples found in repository?
examples/tour.rs (line 390)
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}
Source

pub fn xlen(&mut self, key: &str) -> Result<i64, Error>

Sends XLEN.

Examples found in repository?
examples/tour.rs (line 396)
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}
Source

pub fn xinfo_stream(&mut self, key: &str) -> Result<RespValue, Error>

Sends XINFO STREAM.

Source

pub fn xinfo_groups(&mut self, key: &str) -> Result<RespValue, Error>

Sends XINFO GROUPS.

Source

pub fn xinfo_consumers( &mut self, key: &str, group: &str, ) -> Result<RespValue, Error>

Sends XINFO CONSUMERS.

Source

pub fn xsetid(&mut self, key: &str, id: &str) -> Result<(), Error>

Sends XSETID. The id must be ms-seq and at least the stream’s current top id.

Source

pub fn xautoclaim( &mut self, key: &str, group: &str, consumer: &str, min_idle_ms: u64, start: &str, ) -> Result<RespValue, Error>

Sends XAUTOCLAIM. start is exclusive (0-0 scans from the beginning).

Source

pub fn xrange( &mut self, key: &str, start: &str, end: &str, count: Option<u64>, ) -> Result<Vec<StreamEntry>, Error>

Sends XRANGE from start to end (- and + for the ends), with an optional COUNT.

Examples found in repository?
examples/tour.rs (line 397)
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}
Source

pub fn xrevrange( &mut self, key: &str, end: &str, start: &str, count: Option<u64>, ) -> Result<Vec<StreamEntry>, Error>

Sends XREVRANGE from end down to start, with an optional COUNT.

Examples found in repository?
examples/tour.rs (line 400)
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}
Source

pub fn xdel(&mut self, key: &str, ids: &[&str]) -> Result<i64, Error>

Sends XDEL and returns how many entries were removed.

Examples found in repository?
examples/tour.rs (line 451)
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}
Source

pub fn xtrim_minid(&mut self, key: &str, id: &str) -> Result<i64, Error>

Sends XTRIM MINID. Entries below id are removed. ~ is trimmed exactly.

Source

pub fn xtrim_maxlen(&mut self, key: &str, max_len: u64) -> Result<i64, Error>

Sends XTRIM MAXLEN and returns how many entries were removed.

Examples found in repository?
examples/tour.rs (line 452)
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}
Source

pub fn xread( &mut self, options: &StreamReadOptions, streams: &[(&str, &str)], ) -> Result<Vec<StreamReadResult>, Error>

Sends XREAD for (key, id) pairs. A block that times out returns an empty vector.

Examples found in repository?
examples/tour.rs (lines 402-408)
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}
Source

pub fn xgroup_create_consumer( &mut self, key: &str, group: &str, consumer: &str, ) -> Result<i64, Error>

Sends XGROUP CREATECONSUMER. Returns 1 when the consumer name is new.

Source

pub fn xgroup_create( &mut self, key: &str, group: &str, id: &str, make_stream: bool, ) -> Result<(), Error>

Sends XGROUP CREATE. With make_stream it adds MKSTREAM.

Examples found in repository?
examples/tour.rs (line 411)
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}
Source

pub fn xreadgroup( &mut self, group: &str, consumer: &str, options: &StreamReadOptions, streams: &[(&str, &str)], ) -> Result<Vec<StreamReadResult>, Error>

Sends XREADGROUP GROUP with COUNT, BLOCK, and NOACK from options. Use > as the id for entries never delivered to the group.

Examples found in repository?
examples/tour.rs (line 413)
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}
Source

pub fn xgroup_destroy(&mut self, key: &str, group: &str) -> Result<bool, Error>

Sends XGROUP DESTROY. False when the group did not exist.

Examples found in repository?
examples/tour.rs (line 450)
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}
Source

pub fn xgroup_setid( &mut self, key: &str, group: &str, id: &str, ) -> Result<(), Error>

Sends XGROUP SETID.

Examples found in repository?
examples/tour.rs (line 449)
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}
Source

pub fn xgroup_delconsumer( &mut self, key: &str, group: &str, consumer: &str, ) -> Result<i64, Error>

Sends XGROUP DELCONSUMER and returns how many pending entries the consumer had.

Examples found in repository?
examples/tour.rs (line 447)
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}
Source

pub fn xack( &mut self, key: &str, group: &str, ids: &[&str], ) -> Result<i64, Error>

Sends XACK and returns how many entries were acknowledged.

Examples found in repository?
examples/tour.rs (line 444)
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}
Source

pub fn xpending_summary( &mut self, key: &str, group: &str, ) -> Result<RespValue, Error>

Sends the summary form of XPENDING: count, smallest id, largest id, and per-consumer counts.

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}
Source

pub fn xpending( &mut self, key: &str, group: &str, start: &str, end: &str, count: u64, filter: &StreamPendingFilter, ) -> Result<Vec<StreamPendingEntry>, Error>

Sends the extended XPENDING form: ids from start to end (inclusive), at most count, narrowed by filter.

Examples found in repository?
examples/tour.rs (line 416)
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}
Source

pub fn xclaim( &mut self, key: &str, group: &str, consumer: &str, min_idle: Duration, ids: &[&str], options: &StreamClaimOptions, ) -> Result<Vec<StreamEntry>, Error>

Sends XCLAIM with IDLE, TIME, RETRYCOUNT, FORCE, or LASTID from options.

Examples found in repository?
examples/tour.rs (lines 423-430)
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}
Source

pub fn xclaim_ids( &mut self, key: &str, group: &str, consumer: &str, min_idle: Duration, ids: &[&str], options: &StreamClaimOptions, ) -> Result<Vec<String>, Error>

Sends XCLAIM ... JUSTID and returns only the claimed ids.

Examples found in repository?
examples/tour.rs (lines 435-442)
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}
Source

pub fn info(&mut self, section: Option<&str>) -> Result<String, Error>

Sends INFO, or INFO section. The prometheus section returns Prometheus text.

Examples found in repository?
examples/tour.rs (line 511)
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 config_get( &mut self, parameter: &str, ) -> Result<Vec<(String, String)>, Error>

Sends CONFIG GET and returns (parameter, value) pairs.

Examples found in repository?
examples/tour.rs (line 513)
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 save(&mut self) -> Result<(), Error>

Sends SAVE.

Examples found in repository?
examples/tour.rs (line 544)
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 bgsave(&mut self) -> Result<(), Error>

Sends BGSAVE.

Examples found in repository?
examples/tour.rs (line 545)
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 flushdb(&mut self) -> Result<(), Error>

Sends FLUSHDB. Only the selected database is emptied.

Examples found in repository?
examples/tour.rs (line 59)
17fn main() -> Result<(), ruvio_client::Error> {
18    let host = std::env::args()
19        .nth(1)
20        .unwrap_or_else(|| "127.0.0.1".to_owned());
21    let port = std::env::args()
22        .nth(2)
23        .and_then(|text| text.parse().ok())
24        .unwrap_or(6379);
25    let mut db = Client::connect(&host, port)?;
26
27    db.on_connection_lost(|notice| {
28        println!(
29            "connection lost {}:{} subscriber={}",
30            notice.host, notice.port, notice.subscriber
31        );
32    });
33
34    db.on_connection_restored(|notice| {
35        println!(
36            "connection restored {}:{} subscriber={}",
37            notice.host, notice.port, notice.subscriber
38        );
39    });
40
41    db.set_reconnect_delay(|attempt| {
42        if attempt >= 8 {
43            None
44        } else {
45            Some(Duration::from_millis(100 * 2u64.pow(attempt - 1)))
46        }
47    });
48
49    println!(
50        "connected cluster={} shards={} slot={}",
51        db.is_cluster(),
52        db.shard_count(),
53        ruvio_client::hash_slot("{tour}")
54    );
55    println!("reconnect armed; the command that sees a drop fails, the next one opens the socket");
56
57    if !db.is_cluster() {
58        db.select(15)?;
59        db.flushdb()?;
60        println!("selected database {}", db.database());
61    }
62
63    strings(&mut db)?;
64    owned(&mut db)?;
65    lists(&mut db)?;
66    sets(&mut db)?;
67    hashes(&mut db)?;
68    sorted_sets(&mut db)?;
69    bloom(&mut db)?;
70    streams(&mut db)?;
71    transactions(&mut db)?;
72    server(&mut db)?;
73    pubsub(&host, port)?;
74
75    println!("tour finished");
76
77    Ok(())
78}
Source

pub fn flushall(&mut self) -> Result<(), Error>

Sends FLUSHALL. Every database is emptied.

Source

pub fn swapdb(&mut self, first: u32, second: u32) -> Result<(), Error>

Sends SWAPDB.

Examples found in repository?
examples/tour.rs (line 500)
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 move_key(&mut self, key: &str, database: u32) -> Result<bool, Error>

Sends MOVE. False when the key is missing or already exists in database.

Examples found in repository?
examples/tour.rs (line 499)
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 multi(&mut self) -> Result<(), Error>

Sends MULTI. Until Self::exec, the server answers QUEUED, so queue commands with Client::execute rather than the typed methods.

Examples found in repository?
examples/tour.rs (line 460)
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 exec(&mut self) -> Result<Option<Vec<RespValue>>, Error>

Sends EXEC. None when a watched key changed and the transaction was aborted.

Examples found in repository?
examples/tour.rs (line 465)
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 discard(&mut self) -> Result<(), Error>

Sends DISCARD.

Examples found in repository?
examples/tour.rs (line 469)
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 watch_key(&mut self, key: &str) -> Result<(), Error>

Sends WATCH for one key.

Examples found in repository?
examples/tour.rs (line 458)
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 watch(&mut self, keys: &[&str]) -> Result<(), Error>

Sends WATCH.

Examples found in repository?
examples/tour.rs (line 459)
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 unwatch(&mut self) -> Result<(), Error>

Sends UNWATCH.

Examples found in repository?
examples/tour.rs (line 467)
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 eval( &mut self, script: &str, keys: &[&str], arguments: &[&str], ) -> Result<RespValue, Error>

Sends EVAL. The key count is keys.len().

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 evalsha( &mut self, sha: &str, keys: &[&str], arguments: &[&str], ) -> Result<RespValue, Error>

Sends EVALSHA. The key count is keys.len().

Examples found in repository?
examples/tour.rs (line 479)
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 script_load(&mut self, script: &str) -> Result<String, Error>

Sends SCRIPT LOAD and returns the SHA1 for Self::evalsha.

Examples found in repository?
examples/tour.rs (line 474)
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 script_exists(&mut self, hashes: &[&str]) -> Result<Vec<bool>, Error>

Sends SCRIPT EXISTS, one flag per hash.

Examples found in repository?
examples/tour.rs (line 476)
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 script_flush(&mut self) -> Result<(), Error>

Sends SCRIPT FLUSH.

Examples found in repository?
examples/tour.rs (line 491)
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 script_kill(&mut self) -> Result<(), Error>

Sends SCRIPT KILL.

Examples found in repository?
examples/tour.rs (line 492)
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 fcall( &mut self, name: &str, keys: &[&str], arguments: &[&str], ) -> Result<RespValue, Error>

Sends FCALL. The key count is keys.len().

Examples found in repository?
examples/tour.rs (line 484)
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 function_load(&mut self, name: &str, body: &str) -> Result<(), Error>

Sends FUNCTION LOAD name body. The body is plain Lua, not a Redis library shebang, and is lost when the server restarts.

Examples found in repository?
examples/tour.rs (line 481)
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 function_list(&mut self) -> Result<RespValue, Error>

Sends FUNCTION LIST.

Examples found in repository?
examples/tour.rs (line 488)
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 function_delete(&mut self, name: &str) -> Result<bool, Error>

Sends FUNCTION DELETE. False when no function had that name.

Examples found in repository?
examples/tour.rs (line 490)
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 acl_whoami(&mut self) -> Result<String, Error>

Sends ACL WHOAMI.

Examples found in repository?
examples/tour.rs (line 514)
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 acl_users(&mut self) -> Result<Vec<String>, Error>

Sends ACL USERS.

Examples found in repository?
examples/tour.rs (line 515)
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 acl_list(&mut self) -> Result<Vec<String>, Error>

Sends ACL LIST.

Examples found in repository?
examples/tour.rs (line 516)
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 acl_getuser(&mut self, user: &str) -> Result<RespValue, Error>

Sends ACL GETUSER.

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}
Source

pub fn acl_cat(&mut self) -> Result<Vec<String>, Error>

Sends ACL CAT.

Examples found in repository?
examples/tour.rs (line 517)
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 acl_setuser(&mut self, user: &str, rules: &[&str]) -> Result<(), Error>

Sends ACL SETUSER user rule....

Examples found in repository?
examples/tour.rs (line 519)
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 acl_load(&mut self) -> Result<(), Error>

Sends ACL LOAD.

Source

pub fn acl_save(&mut self) -> Result<(), Error>

Sends ACL SAVE.

Source

pub fn cluster_slots(&mut self) -> Result<RespValue, Error>

Sends CLUSTER SLOTS.

Examples found in repository?
examples/tour.rs (line 532)
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 cluster_nodes(&mut self) -> Result<String, Error>

Sends CLUSTER NODES.

Examples found in repository?
examples/tour.rs (line 528)
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 cluster_shards(&mut self) -> Result<RespValue, Error>

Sends CLUSTER SHARDS.

Examples found in repository?
examples/tour.rs (line 536)
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 cluster_info(&mut self) -> Result<String, Error>

Sends CLUSTER INFO.

Examples found in repository?
examples/tour.rs (line 538)
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 cluster_myid(&mut self) -> Result<String, Error>

Sends CLUSTER MYID.

Examples found in repository?
examples/tour.rs (line 539)
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 cluster_keyslot(&mut self, key: &str) -> Result<i64, Error>

Sends CLUSTER KEYSLOT.

Examples found in repository?
examples/tour.rs (line 523)
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 readonly(&mut self) -> Result<(), Error>

Sends READONLY. Ruvio has no replicas; the reply is still OK in cluster mode.

Examples found in repository?
examples/tour.rs (line 540)
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 readwrite(&mut self) -> Result<(), Error>

Sends READWRITE.

Examples found in repository?
examples/tour.rs (line 541)
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 client_getname(&mut self) -> Result<Option<String>, Error>

Sends CLIENT GETNAME.

Examples found in repository?
examples/tour.rs (line 521)
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 client_setname(&mut self, name: &str) -> Result<(), Error>

Sends CLIENT SETNAME.

Examples found in repository?
examples/tour.rs (line 520)
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 client_tracking(&mut self, enabled: bool) -> Result<(), Error>

Sends CLIENT TRACKING ON or OFF.

Examples found in repository?
examples/tour.rs (line 522)
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 hello(&mut self, protocol: u8) -> Result<RespValue, Error>

Sends HELLO protocol. Connecting itself does not send this, and this client only decodes RESP2 replies.

Examples found in repository?
examples/tour.rs (line 546)
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 publish(&mut self, channel: &str, message: &str) -> Result<i64, Error>

Sends PUBLISH and returns how many subscribers received the message.

Examples found in repository?
examples/tour.rs (line 559)
552fn pubsub(host: &str, port: u16) -> Result<(), ruvio_client::Error> {
553    let mut commands = Client::connect(host, port)?;
554    let mut listener = commands.subscriber()?;
555
556    listener.subscribe(&["{tour}:news"])?;
557    listener.psubscribe(&["{tour}:n*"])?;
558    listener.set_read_timeout(Some(Duration::from_secs(2)))?;
559    println!("publish {}", commands.publish("{tour}:news", "hello-tour")?);
560
561    let exact = listener.next_message()?;
562    let pattern = listener.next_message()?;
563
564    println!(
565        "message {} {:?}",
566        exact.channel,
567        String::from_utf8_lossy(&exact.payload)
568    );
569    println!("pmessage {:?}", pattern.pattern);
570    listener.unsubscribe(&["{tour}:news"])?;
571    listener.punsubscribe(&["{tour}:n*"])?;
572    listener.ssubscribe(&["{tour}:shard"])?;
573    println!("spublish {}", commands.spublish("{tour}:shard", "sharded")?);
574    println!("smessage {}", listener.next_message()?.kind);
575    listener.sunsubscribe(&["{tour}:shard"])?;
576    println!("ping after subscribe {}", commands.ping()?);
577
578    Ok(())
579}
Source

pub fn spublish(&mut self, channel: &str, message: &str) -> Result<i64, Error>

Sends SPUBLISH and returns how many subscribers received the message.

Examples found in repository?
examples/tour.rs (line 573)
552fn pubsub(host: &str, port: u16) -> Result<(), ruvio_client::Error> {
553    let mut commands = Client::connect(host, port)?;
554    let mut listener = commands.subscriber()?;
555
556    listener.subscribe(&["{tour}:news"])?;
557    listener.psubscribe(&["{tour}:n*"])?;
558    listener.set_read_timeout(Some(Duration::from_secs(2)))?;
559    println!("publish {}", commands.publish("{tour}:news", "hello-tour")?);
560
561    let exact = listener.next_message()?;
562    let pattern = listener.next_message()?;
563
564    println!(
565        "message {} {:?}",
566        exact.channel,
567        String::from_utf8_lossy(&exact.payload)
568    );
569    println!("pmessage {:?}", pattern.pattern);
570    listener.unsubscribe(&["{tour}:news"])?;
571    listener.punsubscribe(&["{tour}:n*"])?;
572    listener.ssubscribe(&["{tour}:shard"])?;
573    println!("spublish {}", commands.spublish("{tour}:shard", "sharded")?);
574    println!("smessage {}", listener.next_message()?.kind);
575    listener.sunsubscribe(&["{tour}:shard"])?;
576    println!("ping after subscribe {}", commands.ping()?);
577
578    Ok(())
579}
Source

pub fn subscribe(&mut self, channels: &[&str]) -> Result<Vec<RespValue>, Error>

Sends SUBSCRIBE and reads one confirmation per channel. Opens a dedicated Pub/Sub socket so PING and PUBLISH stay on the command connection. Then read deliveries with Self::next_message.

Examples found in repository?
examples/tour.rs (line 556)
552fn pubsub(host: &str, port: u16) -> Result<(), ruvio_client::Error> {
553    let mut commands = Client::connect(host, port)?;
554    let mut listener = commands.subscriber()?;
555
556    listener.subscribe(&["{tour}:news"])?;
557    listener.psubscribe(&["{tour}:n*"])?;
558    listener.set_read_timeout(Some(Duration::from_secs(2)))?;
559    println!("publish {}", commands.publish("{tour}:news", "hello-tour")?);
560
561    let exact = listener.next_message()?;
562    let pattern = listener.next_message()?;
563
564    println!(
565        "message {} {:?}",
566        exact.channel,
567        String::from_utf8_lossy(&exact.payload)
568    );
569    println!("pmessage {:?}", pattern.pattern);
570    listener.unsubscribe(&["{tour}:news"])?;
571    listener.punsubscribe(&["{tour}:n*"])?;
572    listener.ssubscribe(&["{tour}:shard"])?;
573    println!("spublish {}", commands.spublish("{tour}:shard", "sharded")?);
574    println!("smessage {}", listener.next_message()?.kind);
575    listener.sunsubscribe(&["{tour}:shard"])?;
576    println!("ping after subscribe {}", commands.ping()?);
577
578    Ok(())
579}
Source

pub fn unsubscribe( &mut self, channels: &[&str], ) -> Result<Vec<RespValue>, Error>

Sends UNSUBSCRIBE. No channels drops every exact subscription on this connection.

Examples found in repository?
examples/tour.rs (line 570)
552fn pubsub(host: &str, port: u16) -> Result<(), ruvio_client::Error> {
553    let mut commands = Client::connect(host, port)?;
554    let mut listener = commands.subscriber()?;
555
556    listener.subscribe(&["{tour}:news"])?;
557    listener.psubscribe(&["{tour}:n*"])?;
558    listener.set_read_timeout(Some(Duration::from_secs(2)))?;
559    println!("publish {}", commands.publish("{tour}:news", "hello-tour")?);
560
561    let exact = listener.next_message()?;
562    let pattern = listener.next_message()?;
563
564    println!(
565        "message {} {:?}",
566        exact.channel,
567        String::from_utf8_lossy(&exact.payload)
568    );
569    println!("pmessage {:?}", pattern.pattern);
570    listener.unsubscribe(&["{tour}:news"])?;
571    listener.punsubscribe(&["{tour}:n*"])?;
572    listener.ssubscribe(&["{tour}:shard"])?;
573    println!("spublish {}", commands.spublish("{tour}:shard", "sharded")?);
574    println!("smessage {}", listener.next_message()?.kind);
575    listener.sunsubscribe(&["{tour}:shard"])?;
576    println!("ping after subscribe {}", commands.ping()?);
577
578    Ok(())
579}
Source

pub fn psubscribe(&mut self, patterns: &[&str]) -> Result<Vec<RespValue>, Error>

Sends PSUBSCRIBE and reads one confirmation per pattern.

Examples found in repository?
examples/tour.rs (line 557)
552fn pubsub(host: &str, port: u16) -> Result<(), ruvio_client::Error> {
553    let mut commands = Client::connect(host, port)?;
554    let mut listener = commands.subscriber()?;
555
556    listener.subscribe(&["{tour}:news"])?;
557    listener.psubscribe(&["{tour}:n*"])?;
558    listener.set_read_timeout(Some(Duration::from_secs(2)))?;
559    println!("publish {}", commands.publish("{tour}:news", "hello-tour")?);
560
561    let exact = listener.next_message()?;
562    let pattern = listener.next_message()?;
563
564    println!(
565        "message {} {:?}",
566        exact.channel,
567        String::from_utf8_lossy(&exact.payload)
568    );
569    println!("pmessage {:?}", pattern.pattern);
570    listener.unsubscribe(&["{tour}:news"])?;
571    listener.punsubscribe(&["{tour}:n*"])?;
572    listener.ssubscribe(&["{tour}:shard"])?;
573    println!("spublish {}", commands.spublish("{tour}:shard", "sharded")?);
574    println!("smessage {}", listener.next_message()?.kind);
575    listener.sunsubscribe(&["{tour}:shard"])?;
576    println!("ping after subscribe {}", commands.ping()?);
577
578    Ok(())
579}
Source

pub fn punsubscribe( &mut self, patterns: &[&str], ) -> Result<Vec<RespValue>, Error>

Sends PUNSUBSCRIBE. No patterns drops every pattern subscription on this connection.

Examples found in repository?
examples/tour.rs (line 571)
552fn pubsub(host: &str, port: u16) -> Result<(), ruvio_client::Error> {
553    let mut commands = Client::connect(host, port)?;
554    let mut listener = commands.subscriber()?;
555
556    listener.subscribe(&["{tour}:news"])?;
557    listener.psubscribe(&["{tour}:n*"])?;
558    listener.set_read_timeout(Some(Duration::from_secs(2)))?;
559    println!("publish {}", commands.publish("{tour}:news", "hello-tour")?);
560
561    let exact = listener.next_message()?;
562    let pattern = listener.next_message()?;
563
564    println!(
565        "message {} {:?}",
566        exact.channel,
567        String::from_utf8_lossy(&exact.payload)
568    );
569    println!("pmessage {:?}", pattern.pattern);
570    listener.unsubscribe(&["{tour}:news"])?;
571    listener.punsubscribe(&["{tour}:n*"])?;
572    listener.ssubscribe(&["{tour}:shard"])?;
573    println!("spublish {}", commands.spublish("{tour}:shard", "sharded")?);
574    println!("smessage {}", listener.next_message()?.kind);
575    listener.sunsubscribe(&["{tour}:shard"])?;
576    println!("ping after subscribe {}", commands.ping()?);
577
578    Ok(())
579}
Source

pub fn ssubscribe(&mut self, channels: &[&str]) -> Result<Vec<RespValue>, Error>

Sends SSUBSCRIBE and reads one confirmation per channel.

Examples found in repository?
examples/tour.rs (line 572)
552fn pubsub(host: &str, port: u16) -> Result<(), ruvio_client::Error> {
553    let mut commands = Client::connect(host, port)?;
554    let mut listener = commands.subscriber()?;
555
556    listener.subscribe(&["{tour}:news"])?;
557    listener.psubscribe(&["{tour}:n*"])?;
558    listener.set_read_timeout(Some(Duration::from_secs(2)))?;
559    println!("publish {}", commands.publish("{tour}:news", "hello-tour")?);
560
561    let exact = listener.next_message()?;
562    let pattern = listener.next_message()?;
563
564    println!(
565        "message {} {:?}",
566        exact.channel,
567        String::from_utf8_lossy(&exact.payload)
568    );
569    println!("pmessage {:?}", pattern.pattern);
570    listener.unsubscribe(&["{tour}:news"])?;
571    listener.punsubscribe(&["{tour}:n*"])?;
572    listener.ssubscribe(&["{tour}:shard"])?;
573    println!("spublish {}", commands.spublish("{tour}:shard", "sharded")?);
574    println!("smessage {}", listener.next_message()?.kind);
575    listener.sunsubscribe(&["{tour}:shard"])?;
576    println!("ping after subscribe {}", commands.ping()?);
577
578    Ok(())
579}
Source

pub fn sunsubscribe( &mut self, channels: &[&str], ) -> Result<Vec<RespValue>, Error>

Sends SUNSUBSCRIBE. No channels drops every sharded subscription on this connection.

Examples found in repository?
examples/tour.rs (line 575)
552fn pubsub(host: &str, port: u16) -> Result<(), ruvio_client::Error> {
553    let mut commands = Client::connect(host, port)?;
554    let mut listener = commands.subscriber()?;
555
556    listener.subscribe(&["{tour}:news"])?;
557    listener.psubscribe(&["{tour}:n*"])?;
558    listener.set_read_timeout(Some(Duration::from_secs(2)))?;
559    println!("publish {}", commands.publish("{tour}:news", "hello-tour")?);
560
561    let exact = listener.next_message()?;
562    let pattern = listener.next_message()?;
563
564    println!(
565        "message {} {:?}",
566        exact.channel,
567        String::from_utf8_lossy(&exact.payload)
568    );
569    println!("pmessage {:?}", pattern.pattern);
570    listener.unsubscribe(&["{tour}:news"])?;
571    listener.punsubscribe(&["{tour}:n*"])?;
572    listener.ssubscribe(&["{tour}:shard"])?;
573    println!("spublish {}", commands.spublish("{tour}:shard", "sharded")?);
574    println!("smessage {}", listener.next_message()?.kind);
575    listener.sunsubscribe(&["{tour}:shard"])?;
576    println!("ping after subscribe {}", commands.ping()?);
577
578    Ok(())
579}
Source

pub fn next_message(&mut self) -> Result<PubSubMessage, Error>

Reads replies until a message, pmessage, or smessage arrives, skipping subscribe confirmations. Blocks until Self::set_read_timeout passes.

Examples found in repository?
examples/tour.rs (line 561)
552fn pubsub(host: &str, port: u16) -> Result<(), ruvio_client::Error> {
553    let mut commands = Client::connect(host, port)?;
554    let mut listener = commands.subscriber()?;
555
556    listener.subscribe(&["{tour}:news"])?;
557    listener.psubscribe(&["{tour}:n*"])?;
558    listener.set_read_timeout(Some(Duration::from_secs(2)))?;
559    println!("publish {}", commands.publish("{tour}:news", "hello-tour")?);
560
561    let exact = listener.next_message()?;
562    let pattern = listener.next_message()?;
563
564    println!(
565        "message {} {:?}",
566        exact.channel,
567        String::from_utf8_lossy(&exact.payload)
568    );
569    println!("pmessage {:?}", pattern.pattern);
570    listener.unsubscribe(&["{tour}:news"])?;
571    listener.punsubscribe(&["{tour}:n*"])?;
572    listener.ssubscribe(&["{tour}:shard"])?;
573    println!("spublish {}", commands.spublish("{tour}:shard", "sharded")?);
574    println!("smessage {}", listener.next_message()?.kind);
575    listener.sunsubscribe(&["{tour}:shard"])?;
576    println!("ping after subscribe {}", commands.ping()?);
577
578    Ok(())
579}
Source

pub fn listen<F>(&mut self, on_message: F) -> Result<(), Error>
where F: FnMut(PubSubMessage),

Calls on_message for each delivery. Safe on the command client after subscribe; deliveries are read from the dedicated Pub/Sub socket.

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> 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 = !

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.