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
impl Client
Sourcepub fn connect(host: impl Into<String>, port: u16) -> Result<Self, Error>
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?
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}Sourcepub fn connect_database(
host: impl Into<String>,
port: u16,
database: u32,
) -> Result<Self, Error>
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.
Sourcepub fn connect_ip(ip: IpAddr, port: u16, database: u32) -> Result<Self, Error>
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.
Sourcepub fn connect_addr(address: SocketAddr, database: u32) -> Result<Self, Error>
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.
Sourcepub fn connect_with(options: ClientOptions) -> Result<Self, Error>
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.
Sourcepub fn is_cluster(&self) -> bool
pub fn is_cluster(&self) -> bool
True when the server reported a slot map and commands are routed by slot.
Examples found in repository?
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}Sourcepub fn shard_count(&self) -> usize
pub fn shard_count(&self) -> usize
How many shards the client routes to. 1 for a single server.
Examples found in repository?
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}Sourcepub fn ping(&mut self) -> Result<String, Error>
pub fn ping(&mut self) -> Result<String, Error>
Sends PING and returns the simple-string reply.
Examples found in repository?
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}Sourcepub fn ping_message(&mut self, message: &str) -> Result<String, Error>
pub fn ping_message(&mut self, message: &str) -> Result<String, Error>
Sends PING message and returns the echoed message.
Examples found in repository?
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}Sourcepub fn database(&self) -> u32
pub fn database(&self) -> u32
The logical database this connection last selected.
Examples found in repository?
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}Sourcepub fn subscriber(&self) -> Result<Self, Error>
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?
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}Sourcepub fn select(&mut self, database: u32) -> Result<(), Error>
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?
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}Sourcepub fn into_database(self, database: u32) -> Result<Self, Error>
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.
Sourcepub fn set_read_timeout(
&mut self,
timeout: Option<Duration>,
) -> Result<(), Error>
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?
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}Sourcepub fn get(&mut self, key: &str) -> Result<Option<Vec<u8>>, Error>
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.
Sourcepub fn get_string(&mut self, key: &str) -> Result<Option<String>, Error>
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?
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}Sourcepub fn set(&mut self, key: &str, value: &str) -> Result<bool, Error>
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?
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}Sourcepub fn set_with(
&mut self,
key: &str,
value: &str,
expiry: Option<Duration>,
mode: SetMode,
) -> Result<bool, Error>
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?
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}Sourcepub fn set_expires_at(
&mut self,
key: &str,
value: &str,
expires_at: SystemTime,
mode: SetMode,
) -> Result<bool, Error>
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?
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}Sourcepub fn set_keep_ttl(
&mut self,
key: &str,
value: &str,
mode: SetMode,
) -> Result<bool, Error>
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?
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}Sourcepub fn set_and_get(
&mut self,
key: &str,
value: &str,
expiry: Option<Duration>,
mode: SetMode,
) -> Result<Option<String>, Error>
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?
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}Sourcepub fn incr(&mut self, key: &str) -> Result<i64, Error>
pub fn incr(&mut self, key: &str) -> Result<i64, Error>
Sends INCR.
Examples found in repository?
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}Sourcepub fn expire(&mut self, key: &str, ttl: Duration) -> Result<bool, Error>
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?
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}Sourcepub fn del_key(&mut self, key: &str) -> Result<i64, Error>
pub fn del_key(&mut self, key: &str) -> Result<i64, Error>
Sends DEL for one key.
Examples found in repository?
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}Sourcepub fn del(&mut self, keys: &[&str]) -> Result<i64, Error>
pub fn del(&mut self, keys: &[&str]) -> Result<i64, Error>
Sends DEL and returns how many keys were removed.
Examples found in repository?
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}Sourcepub fn read_message(&mut self) -> Result<RespValue, Error>
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.
Sourcepub fn on_connection_lost<F>(&mut self, hook: F)
pub fn on_connection_lost<F>(&mut self, hook: F)
Called when a command or subscriber socket drops.
Examples found in repository?
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}Sourcepub fn on_connection_restored<F>(&mut self, hook: F)
pub fn on_connection_restored<F>(&mut self, hook: F)
Called after a dropped socket is open again.
Examples found in repository?
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}Sourcepub fn set_reconnect_delay<F>(&mut self, delay: F)
pub fn set_reconnect_delay<F>(&mut self, delay: F)
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?
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}Sourcepub fn reconnect(&mut self) -> Result<(), Error>
pub fn reconnect(&mut self) -> Result<(), Error>
Opens a dropped command socket again. With ClientOptions::reconnect on, the next
command does this itself.
Sourcepub fn execute(&mut self, arguments: &[&str]) -> Result<RespValue, Error>
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?
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}Sourcepub fn execute_many(
&mut self,
commands: &[&[&str]],
) -> Result<Vec<RespValue>, Error>
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?
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
impl Client
Sourcepub fn mget(&mut self, keys: &[&str]) -> Result<Vec<Option<String>>, Error>
pub fn mget(&mut self, keys: &[&str]) -> Result<Vec<Option<String>>, Error>
Sends MGET. A missing key is None.
Examples found in repository?
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}Sourcepub fn limit(
&mut self,
key: &str,
max: u64,
window_ms: u64,
) -> Result<Option<i64>, Error>
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?
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}Sourcepub fn once(&mut self, key: &str, ttl_ms: u64) -> Result<i64, Error>
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?
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}Sourcepub fn idempotency_begin(
&mut self,
key: &str,
fingerprint: &str,
owner: &str,
ttl_ms: u64,
) -> Result<RespValue, Error>
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].
Sourcepub fn idempotency_complete(
&mut self,
key: &str,
fingerprint: &str,
owner: &str,
result: &str,
) -> Result<i64, Error>
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.
Sourcepub fn take(&mut self, key: &str, count: i64) -> Result<Option<i64>, Error>
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?
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}Sourcepub fn getex(&mut self, key: &str, ttl_ms: u64) -> Result<Option<String>, Error>
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?
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}Sourcepub fn lease(&mut self, key: &str, ttl_ms: u64) -> Result<Option<i64>, Error>
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?
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}Sourcepub fn semaphore(
&mut self,
key: &str,
max: u64,
ttl_ms: u64,
) -> Result<Option<i64>, Error>
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?
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}Sourcepub fn incr_by_max(
&mut self,
key: &str,
delta: i64,
limit: i64,
) -> Result<Option<i64>, Error>
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?
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}Sourcepub fn release(&mut self, key: &str, token: u64) -> Result<i64, Error>
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?
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}Sourcepub fn setv(
&mut self,
key: &str,
value: &str,
version: Option<u64>,
) -> Result<i64, Error>
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?
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}Sourcepub fn changes_start(&mut self) -> Result<i64, Error>
pub fn changes_start(&mut self) -> Result<i64, Error>
Sends CHANGES START and returns the cursor to read after.
Examples found in repository?
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}Sourcepub fn changes(&mut self, cursor: u64) -> Result<Vec<(i64, String)>, Error>
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?
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}Sourcepub fn mset(&mut self, pairs: &[(&str, &str)]) -> Result<(), Error>
pub fn mset(&mut self, pairs: &[(&str, &str)]) -> Result<(), Error>
Sends MSET.
Examples found in repository?
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}Sourcepub fn getset(
&mut self,
key: &str,
value: &str,
) -> Result<Option<String>, Error>
pub fn getset( &mut self, key: &str, value: &str, ) -> Result<Option<String>, Error>
Sends GETSET and returns the previous value.
Examples found in repository?
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}Sourcepub fn append(&mut self, key: &str, value: &str) -> Result<i64, Error>
pub fn append(&mut self, key: &str, value: &str) -> Result<i64, Error>
Sends APPEND and returns the new length.
Examples found in repository?
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}Sourcepub fn strlen(&mut self, key: &str) -> Result<i64, Error>
pub fn strlen(&mut self, key: &str) -> Result<i64, Error>
Sends STRLEN.
Examples found in repository?
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}Sourcepub fn decr(&mut self, key: &str) -> Result<i64, Error>
pub fn decr(&mut self, key: &str) -> Result<i64, Error>
Sends DECR.
Examples found in repository?
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}Sourcepub fn incr_by(&mut self, key: &str, delta: i64) -> Result<i64, Error>
pub fn incr_by(&mut self, key: &str, delta: i64) -> Result<i64, Error>
Sends INCRBY.
Examples found in repository?
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}Sourcepub fn decr_by(&mut self, key: &str, delta: i64) -> Result<i64, Error>
pub fn decr_by(&mut self, key: &str, delta: i64) -> Result<i64, Error>
Sends DECRBY.
Examples found in repository?
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}Sourcepub fn unlink_key(&mut self, key: &str) -> Result<i64, Error>
pub fn unlink_key(&mut self, key: &str) -> Result<i64, Error>
Sends UNLINK for one key.
Examples found in repository?
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}Sourcepub fn unlink(&mut self, keys: &[&str]) -> Result<i64, Error>
pub fn unlink(&mut self, keys: &[&str]) -> Result<i64, Error>
Sends UNLINK and returns how many keys were removed.
Examples found in repository?
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}Sourcepub fn exists_key(&mut self, key: &str) -> Result<i64, Error>
pub fn exists_key(&mut self, key: &str) -> Result<i64, Error>
Sends EXISTS for one key.
Examples found in repository?
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}Sourcepub fn exists(&mut self, keys: &[&str]) -> Result<i64, Error>
pub fn exists(&mut self, keys: &[&str]) -> Result<i64, Error>
Sends EXISTS and returns how many of the keys exist.
Examples found in repository?
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}Sourcepub fn key_type(&mut self, key: &str) -> Result<String, Error>
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?
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}Sourcepub fn rename(&mut self, key: &str, new_key: &str) -> Result<(), Error>
pub fn rename(&mut self, key: &str, new_key: &str) -> Result<(), Error>
Sends RENAME.
Examples found in repository?
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}Sourcepub fn scan(
&mut self,
cursor: u64,
pattern: Option<&str>,
count: Option<u64>,
) -> Result<ScanPage, Error>
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?
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}Sourcepub fn dbsize(&mut self) -> Result<i64, Error>
pub fn dbsize(&mut self) -> Result<i64, Error>
Sends DBSIZE for the selected database.
Examples found in repository?
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}Sourcepub fn expire_at(&mut self, key: &str, when: SystemTime) -> Result<bool, Error>
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?
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}Sourcepub fn pexpire(&mut self, key: &str, ttl: Duration) -> Result<bool, Error>
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?
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}Sourcepub fn ttl(&mut self, key: &str) -> Result<i64, Error>
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?
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}Sourcepub fn pttl(&mut self, key: &str) -> Result<i64, Error>
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?
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}Sourcepub fn persist(&mut self, key: &str) -> Result<bool, Error>
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?
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}Sourcepub fn lpush(&mut self, key: &str, values: &[&str]) -> Result<i64, Error>
pub fn lpush(&mut self, key: &str, values: &[&str]) -> Result<i64, Error>
Sends LPUSH and returns the new length.
Examples found in repository?
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}Sourcepub fn rpush(&mut self, key: &str, values: &[&str]) -> Result<i64, Error>
pub fn rpush(&mut self, key: &str, values: &[&str]) -> Result<i64, Error>
Sends RPUSH and returns the new length.
Examples found in repository?
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}Sourcepub fn lpop(&mut self, key: &str) -> Result<Option<String>, Error>
pub fn lpop(&mut self, key: &str) -> Result<Option<String>, Error>
Sends LPOP for one element.
Examples found in repository?
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}Sourcepub fn lpop_count(
&mut self,
key: &str,
count: u64,
) -> Result<Vec<String>, Error>
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?
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}Sourcepub fn rpop_count(
&mut self,
key: &str,
count: u64,
) -> Result<Vec<String>, Error>
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?
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}Sourcepub fn llen(&mut self, key: &str) -> Result<i64, Error>
pub fn llen(&mut self, key: &str) -> Result<i64, Error>
Sends LLEN.
Examples found in repository?
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}Sourcepub fn lindex(&mut self, key: &str, index: i64) -> Result<Option<String>, Error>
pub fn lindex(&mut self, key: &str, index: i64) -> Result<Option<String>, Error>
Sends LINDEX.
Examples found in repository?
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}Sourcepub fn lrange(
&mut self,
key: &str,
start: i64,
stop: i64,
) -> Result<Vec<String>, Error>
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?
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}Sourcepub fn ltrim(&mut self, key: &str, start: i64, stop: i64) -> Result<(), Error>
pub fn ltrim(&mut self, key: &str, start: i64, stop: i64) -> Result<(), Error>
Sends LTRIM.
Examples found in repository?
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}Sourcepub fn blpop_key(
&mut self,
key: &str,
timeout: Duration,
) -> Result<Option<(String, String)>, Error>
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?
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}Sourcepub fn blpop(
&mut self,
keys: &[&str],
timeout: Duration,
) -> Result<Option<(String, String)>, Error>
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.
Sourcepub fn brpop_key(
&mut self,
key: &str,
timeout: Duration,
) -> Result<Option<(String, String)>, Error>
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?
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}Sourcepub fn brpop(
&mut self,
keys: &[&str],
timeout: Duration,
) -> Result<Option<(String, String)>, Error>
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?
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}Sourcepub fn sadd(&mut self, key: &str, members: &[&str]) -> Result<i64, Error>
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?
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}Sourcepub fn srem(&mut self, key: &str, members: &[&str]) -> Result<i64, Error>
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?
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}Sourcepub fn sismember(&mut self, key: &str, member: &str) -> Result<bool, Error>
pub fn sismember(&mut self, key: &str, member: &str) -> Result<bool, Error>
Sends SISMEMBER.
Examples found in repository?
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}Sourcepub fn scard(&mut self, key: &str) -> Result<i64, Error>
pub fn scard(&mut self, key: &str) -> Result<i64, Error>
Sends SCARD.
Examples found in repository?
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}Sourcepub fn smembers(&mut self, key: &str) -> Result<Vec<String>, Error>
pub fn smembers(&mut self, key: &str) -> Result<Vec<String>, Error>
Sends SMEMBERS.
Examples found in repository?
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}Sourcepub fn sinter(&mut self, keys: &[&str]) -> Result<Vec<String>, Error>
pub fn sinter(&mut self, keys: &[&str]) -> Result<Vec<String>, Error>
Sends SINTER.
Examples found in repository?
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}Sourcepub fn sunion(&mut self, keys: &[&str]) -> Result<Vec<String>, Error>
pub fn sunion(&mut self, keys: &[&str]) -> Result<Vec<String>, Error>
Sends SUNION.
Examples found in repository?
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}Sourcepub fn sdiff(&mut self, keys: &[&str]) -> Result<Vec<String>, Error>
pub fn sdiff(&mut self, keys: &[&str]) -> Result<Vec<String>, Error>
Sends SDIFF.
Examples found in repository?
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}Sourcepub fn sinterstore(
&mut self,
destination: &str,
keys: &[&str],
) -> Result<i64, Error>
pub fn sinterstore( &mut self, destination: &str, keys: &[&str], ) -> Result<i64, Error>
Sends SINTERSTORE and returns the size of destination.
Examples found in repository?
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}Sourcepub fn sunionstore(
&mut self,
destination: &str,
keys: &[&str],
) -> Result<i64, Error>
pub fn sunionstore( &mut self, destination: &str, keys: &[&str], ) -> Result<i64, Error>
Sends SUNIONSTORE and returns the size of destination.
Examples found in repository?
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}Sourcepub fn sdiffstore(
&mut self,
destination: &str,
keys: &[&str],
) -> Result<i64, Error>
pub fn sdiffstore( &mut self, destination: &str, keys: &[&str], ) -> Result<i64, Error>
Sends SDIFFSTORE and returns the size of destination.
Examples found in repository?
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}Sourcepub fn smove(
&mut self,
source: &str,
destination: &str,
member: &str,
) -> Result<bool, Error>
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?
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}Sourcepub fn spop(&mut self, key: &str) -> Result<Option<String>, Error>
pub fn spop(&mut self, key: &str) -> Result<Option<String>, Error>
Sends SPOP for one member.
Examples found in repository?
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}Sourcepub fn spop_count(
&mut self,
key: &str,
count: u64,
) -> Result<Vec<String>, Error>
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?
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}Sourcepub fn srandmember(&mut self, key: &str) -> Result<Option<String>, Error>
pub fn srandmember(&mut self, key: &str) -> Result<Option<String>, Error>
Sends SRANDMEMBER for one member.
Examples found in repository?
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}Sourcepub fn srandmember_count(
&mut self,
key: &str,
count: i64,
) -> Result<Vec<String>, Error>
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?
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}Sourcepub fn hset(&mut self, key: &str, fields: &[(&str, &str)]) -> Result<i64, Error>
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?
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}Sourcepub fn hget(&mut self, key: &str, field: &str) -> Result<Option<String>, Error>
pub fn hget(&mut self, key: &str, field: &str) -> Result<Option<String>, Error>
Sends HGET.
Examples found in repository?
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}Sourcepub fn hdel(&mut self, key: &str, fields: &[&str]) -> Result<i64, Error>
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?
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}Sourcepub fn hlen(&mut self, key: &str) -> Result<i64, Error>
pub fn hlen(&mut self, key: &str) -> Result<i64, Error>
Sends HLEN.
Examples found in repository?
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}Sourcepub fn hgetall(&mut self, key: &str) -> Result<HashMap<String, String>, Error>
pub fn hgetall(&mut self, key: &str) -> Result<HashMap<String, String>, Error>
Sends HGETALL.
Examples found in repository?
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}Sourcepub fn hmget(
&mut self,
key: &str,
fields: &[&str],
) -> Result<Vec<Option<String>>, Error>
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?
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}Sourcepub fn hexists(&mut self, key: &str, field: &str) -> Result<bool, Error>
pub fn hexists(&mut self, key: &str, field: &str) -> Result<bool, Error>
Sends HEXISTS.
Examples found in repository?
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}Sourcepub fn hkeys(&mut self, key: &str) -> Result<Vec<String>, Error>
pub fn hkeys(&mut self, key: &str) -> Result<Vec<String>, Error>
Sends HKEYS.
Examples found in repository?
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}Sourcepub fn hvals(&mut self, key: &str) -> Result<Vec<String>, Error>
pub fn hvals(&mut self, key: &str) -> Result<Vec<String>, Error>
Sends HVALS.
Examples found in repository?
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}Sourcepub fn hincr_by(
&mut self,
key: &str,
field: &str,
delta: i64,
) -> Result<i64, Error>
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?
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}Sourcepub fn hsetnx(
&mut self,
key: &str,
field: &str,
value: &str,
) -> Result<bool, Error>
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?
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}Sourcepub fn hstrlen(&mut self, key: &str, field: &str) -> Result<i64, Error>
pub fn hstrlen(&mut self, key: &str, field: &str) -> Result<i64, Error>
Sends HSTRLEN.
Examples found in repository?
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}Sourcepub fn hexpire(
&mut self,
key: &str,
ttl: Duration,
fields: &[&str],
) -> Result<Vec<i64>, Error>
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?
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}Sourcepub fn hexpire_with(
&mut self,
key: &str,
ttl: Duration,
condition: FieldExpireCondition,
fields: &[&str],
) -> Result<Vec<i64>, Error>
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?
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}Sourcepub fn hpexpire(
&mut self,
key: &str,
ttl: Duration,
fields: &[&str],
) -> Result<Vec<i64>, Error>
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?
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}Sourcepub fn hexpire_at(
&mut self,
key: &str,
when: SystemTime,
fields: &[&str],
) -> Result<Vec<i64>, Error>
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?
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}Sourcepub fn httl(&mut self, key: &str, fields: &[&str]) -> Result<Vec<i64>, Error>
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?
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}Sourcepub fn hpttl(&mut self, key: &str, fields: &[&str]) -> Result<Vec<i64>, Error>
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?
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}Sourcepub fn hexpiretime(
&mut self,
key: &str,
fields: &[&str],
) -> Result<Vec<i64>, Error>
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?
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}Sourcepub fn hpexpiretime(
&mut self,
key: &str,
fields: &[&str],
) -> Result<Vec<i64>, Error>
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?
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}Sourcepub fn hpersist(
&mut self,
key: &str,
fields: &[&str],
) -> Result<Vec<i64>, Error>
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?
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}Sourcepub fn hscan(
&mut self,
key: &str,
cursor: u64,
pattern: Option<&str>,
count: Option<u64>,
) -> Result<HashScanPage, Error>
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?
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}Sourcepub fn zadd(&mut self, key: &str, entries: &[(&str, f64)]) -> Result<i64, Error>
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?
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}Sourcepub fn zadd_with(
&mut self,
key: &str,
options: SortedSetAddOptions,
entries: &[(&str, f64)],
) -> Result<i64, Error>
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?
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}Sourcepub fn zadd_incr(
&mut self,
key: &str,
member: &str,
delta: f64,
options: SortedSetAddOptions,
) -> Result<Option<f64>, Error>
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?
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}Sourcepub fn zincr_by(
&mut self,
key: &str,
member: &str,
delta: f64,
) -> Result<f64, Error>
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?
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}Sourcepub fn geo_add(
&mut self,
key: &str,
places: &[(f64, f64, &str)],
) -> Result<i64, Error>
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?
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}Sourcepub fn geo_dist(
&mut self,
key: &str,
from: &str,
to: &str,
unit: Option<&str>,
) -> Result<Option<f64>, Error>
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.
Sourcepub fn geo_hash(
&mut self,
key: &str,
members: &[&str],
) -> Result<Vec<Option<String>>, Error>
pub fn geo_hash( &mut self, key: &str, members: &[&str], ) -> Result<Vec<Option<String>>, Error>
Sends GEOHASH. A missing member is None.
Sourcepub fn geo_pos(
&mut self,
key: &str,
members: &[&str],
) -> Result<Vec<Option<(f64, f64)>>, Error>
pub fn geo_pos( &mut self, key: &str, members: &[&str], ) -> Result<Vec<Option<(f64, f64)>>, Error>
Sends GEOPOS. A missing member is None.
Sourcepub fn geo_search(
&mut self,
key: &str,
longitude: f64,
latitude: f64,
radius: f64,
unit: &str,
) -> Result<Vec<String>, Error>
pub fn geo_search( &mut self, key: &str, longitude: f64, latitude: f64, radius: f64, unit: &str, ) -> Result<Vec<String>, Error>
Sends GEOSEARCH ... FROMLONLAT ... BYRADIUS ... ASC.
Examples found in repository?
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}Sourcepub fn geo_search_store(
&mut self,
destination: &str,
source: &str,
member: &str,
radius: f64,
unit: &str,
) -> Result<i64, Error>
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.
Sourcepub fn geo_radius_by_member(
&mut self,
key: &str,
member: &str,
radius: f64,
unit: &str,
) -> Result<Vec<String>, Error>
pub fn geo_radius_by_member( &mut self, key: &str, member: &str, radius: f64, unit: &str, ) -> Result<Vec<String>, Error>
Sends GEORADIUSBYMEMBER ... ASC.
Sourcepub fn geo_radius(
&mut self,
key: &str,
longitude: f64,
latitude: f64,
radius: f64,
unit: &str,
) -> Result<Vec<String>, Error>
pub fn geo_radius( &mut self, key: &str, longitude: f64, latitude: f64, radius: f64, unit: &str, ) -> Result<Vec<String>, Error>
Sends GEORADIUS ... ASC.
Sourcepub fn zrange(
&mut self,
key: &str,
start: i64,
stop: i64,
) -> Result<Vec<String>, Error>
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?
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}Sourcepub fn zrevrange(
&mut self,
key: &str,
start: i64,
stop: i64,
) -> Result<Vec<String>, Error>
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?
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}Sourcepub fn zrange_with_scores(
&mut self,
key: &str,
start: i64,
stop: i64,
) -> Result<Vec<SortedSetEntry>, Error>
pub fn zrange_with_scores( &mut self, key: &str, start: i64, stop: i64, ) -> Result<Vec<SortedSetEntry>, Error>
Sends ZRANGE ... WITHSCORES.
Examples found in repository?
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}Sourcepub fn zrevrange_with_scores(
&mut self,
key: &str,
start: i64,
stop: i64,
) -> Result<Vec<SortedSetEntry>, Error>
pub fn zrevrange_with_scores( &mut self, key: &str, start: i64, stop: i64, ) -> Result<Vec<SortedSetEntry>, Error>
Sends ZREVRANGE ... WITHSCORES.
Examples found in repository?
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}Sourcepub fn zrange_by_lex(
&mut self,
key: &str,
min: &str,
max: &str,
) -> Result<Vec<String>, Error>
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.
Sourcepub fn zrange_by_score_with_scores(
&mut self,
key: &str,
min: &str,
max: &str,
) -> Result<Vec<SortedSetEntry>, Error>
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?
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}Sourcepub fn zrem(&mut self, key: &str, members: &[&str]) -> Result<i64, Error>
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?
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}Sourcepub fn zpopmin(
&mut self,
key: &str,
count: u64,
) -> Result<Vec<SortedSetEntry>, Error>
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?
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}Sourcepub fn zpopmax(
&mut self,
key: &str,
count: u64,
) -> Result<Vec<SortedSetEntry>, Error>
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?
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}Sourcepub fn bzpopmin(
&mut self,
keys: &[&str],
timeout: Duration,
) -> Result<Option<(String, SortedSetEntry)>, Error>
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?
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}Sourcepub fn bzpopmax(
&mut self,
keys: &[&str],
timeout: Duration,
) -> Result<Option<(String, SortedSetEntry)>, Error>
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?
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}Sourcepub fn zremrangebyrank(
&mut self,
key: &str,
start: i64,
stop: i64,
) -> Result<i64, Error>
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?
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}Sourcepub fn zremrangebyscore(
&mut self,
key: &str,
min: &str,
max: &str,
) -> Result<i64, Error>
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?
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}Sourcepub fn zremrangebylex(
&mut self,
key: &str,
min: &str,
max: &str,
) -> Result<i64, Error>
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?
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}Sourcepub fn zcard(&mut self, key: &str) -> Result<i64, Error>
pub fn zcard(&mut self, key: &str) -> Result<i64, Error>
Sends ZCARD.
Examples found in repository?
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}Sourcepub fn zscore(&mut self, key: &str, member: &str) -> Result<Option<f64>, Error>
pub fn zscore(&mut self, key: &str, member: &str) -> Result<Option<f64>, Error>
Sends ZSCORE.
Examples found in repository?
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}Sourcepub fn zrank(&mut self, key: &str, member: &str) -> Result<Option<i64>, Error>
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?
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}Sourcepub fn zrevrank(
&mut self,
key: &str,
member: &str,
) -> Result<Option<i64>, Error>
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?
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}Sourcepub fn bf_reserve(
&mut self,
key: &str,
error_rate: f64,
capacity: u64,
) -> Result<(), Error>
pub fn bf_reserve( &mut self, key: &str, error_rate: f64, capacity: u64, ) -> Result<(), Error>
Sends BF.RESERVE.
Sourcepub fn bf_add(&mut self, key: &str, item: &str) -> Result<bool, Error>
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.
Sourcepub fn bf_exists(&mut self, key: &str, item: &str) -> Result<bool, Error>
pub fn bf_exists(&mut self, key: &str, item: &str) -> Result<bool, Error>
Sends BF.EXISTS. True means “maybe added”; false means “never added”.
Sourcepub fn xadd_nomkstream(
&mut self,
key: &str,
id: &str,
fields: &[(&str, &str)],
) -> Result<Option<String>, Error>
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.
Sourcepub fn xadd_delay(
&mut self,
key: &str,
delay_ms: u64,
id: &str,
fields: &[(&str, &str)],
) -> Result<String, Error>
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?
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}Sourcepub fn xadd(
&mut self,
key: &str,
id: &str,
fields: &[(&str, &str)],
) -> Result<String, Error>
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?
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}Sourcepub fn xadd_maxlen(
&mut self,
key: &str,
max_len: u64,
id: &str,
fields: &[(&str, &str)],
) -> Result<String, Error>
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?
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}Sourcepub fn xlen(&mut self, key: &str) -> Result<i64, Error>
pub fn xlen(&mut self, key: &str) -> Result<i64, Error>
Sends XLEN.
Examples found in repository?
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}Sourcepub fn xinfo_consumers(
&mut self,
key: &str,
group: &str,
) -> Result<RespValue, Error>
pub fn xinfo_consumers( &mut self, key: &str, group: &str, ) -> Result<RespValue, Error>
Sends XINFO CONSUMERS.
Sourcepub fn xsetid(&mut self, key: &str, id: &str) -> Result<(), Error>
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.
Sourcepub fn xautoclaim(
&mut self,
key: &str,
group: &str,
consumer: &str,
min_idle_ms: u64,
start: &str,
) -> Result<RespValue, Error>
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).
Sourcepub fn xrange(
&mut self,
key: &str,
start: &str,
end: &str,
count: Option<u64>,
) -> Result<Vec<StreamEntry>, Error>
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?
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}Sourcepub fn xrevrange(
&mut self,
key: &str,
end: &str,
start: &str,
count: Option<u64>,
) -> Result<Vec<StreamEntry>, Error>
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?
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}Sourcepub fn xdel(&mut self, key: &str, ids: &[&str]) -> Result<i64, Error>
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?
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}Sourcepub fn xtrim_minid(&mut self, key: &str, id: &str) -> Result<i64, Error>
pub fn xtrim_minid(&mut self, key: &str, id: &str) -> Result<i64, Error>
Sends XTRIM MINID. Entries below id are removed. ~ is trimmed exactly.
Sourcepub fn xtrim_maxlen(&mut self, key: &str, max_len: u64) -> Result<i64, Error>
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?
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}Sourcepub fn xread(
&mut self,
options: &StreamReadOptions,
streams: &[(&str, &str)],
) -> Result<Vec<StreamReadResult>, Error>
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?
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}Sourcepub fn xgroup_create_consumer(
&mut self,
key: &str,
group: &str,
consumer: &str,
) -> Result<i64, Error>
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.
Sourcepub fn xgroup_create(
&mut self,
key: &str,
group: &str,
id: &str,
make_stream: bool,
) -> Result<(), Error>
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?
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}Sourcepub fn xreadgroup(
&mut self,
group: &str,
consumer: &str,
options: &StreamReadOptions,
streams: &[(&str, &str)],
) -> Result<Vec<StreamReadResult>, Error>
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?
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}Sourcepub fn xgroup_destroy(&mut self, key: &str, group: &str) -> Result<bool, Error>
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?
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}Sourcepub fn xgroup_setid(
&mut self,
key: &str,
group: &str,
id: &str,
) -> Result<(), Error>
pub fn xgroup_setid( &mut self, key: &str, group: &str, id: &str, ) -> Result<(), Error>
Sends XGROUP SETID.
Examples found in repository?
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}Sourcepub fn xgroup_delconsumer(
&mut self,
key: &str,
group: &str,
consumer: &str,
) -> Result<i64, Error>
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?
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}Sourcepub fn xack(
&mut self,
key: &str,
group: &str,
ids: &[&str],
) -> Result<i64, Error>
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?
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}Sourcepub fn xpending_summary(
&mut self,
key: &str,
group: &str,
) -> Result<RespValue, Error>
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?
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}Sourcepub fn xpending(
&mut self,
key: &str,
group: &str,
start: &str,
end: &str,
count: u64,
filter: &StreamPendingFilter,
) -> Result<Vec<StreamPendingEntry>, Error>
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?
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}Sourcepub fn xclaim(
&mut self,
key: &str,
group: &str,
consumer: &str,
min_idle: Duration,
ids: &[&str],
options: &StreamClaimOptions,
) -> Result<Vec<StreamEntry>, Error>
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?
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}Sourcepub fn xclaim_ids(
&mut self,
key: &str,
group: &str,
consumer: &str,
min_idle: Duration,
ids: &[&str],
options: &StreamClaimOptions,
) -> Result<Vec<String>, Error>
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?
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}Sourcepub fn info(&mut self, section: Option<&str>) -> Result<String, Error>
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?
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}Sourcepub fn config_get(
&mut self,
parameter: &str,
) -> Result<Vec<(String, String)>, Error>
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?
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}Sourcepub fn save(&mut self) -> Result<(), Error>
pub fn save(&mut self) -> Result<(), Error>
Sends SAVE.
Examples found in repository?
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}Sourcepub fn bgsave(&mut self) -> Result<(), Error>
pub fn bgsave(&mut self) -> Result<(), Error>
Sends BGSAVE.
Examples found in repository?
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}Sourcepub fn flushdb(&mut self) -> Result<(), Error>
pub fn flushdb(&mut self) -> Result<(), Error>
Sends FLUSHDB. Only the selected database is emptied.
Examples found in repository?
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}Sourcepub fn swapdb(&mut self, first: u32, second: u32) -> Result<(), Error>
pub fn swapdb(&mut self, first: u32, second: u32) -> Result<(), Error>
Sends SWAPDB.
Examples found in repository?
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}Sourcepub fn move_key(&mut self, key: &str, database: u32) -> Result<bool, Error>
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?
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}Sourcepub fn multi(&mut self) -> Result<(), Error>
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?
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}Sourcepub fn exec(&mut self) -> Result<Option<Vec<RespValue>>, Error>
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?
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}Sourcepub fn discard(&mut self) -> Result<(), Error>
pub fn discard(&mut self) -> Result<(), Error>
Sends DISCARD.
Examples found in repository?
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}Sourcepub fn watch_key(&mut self, key: &str) -> Result<(), Error>
pub fn watch_key(&mut self, key: &str) -> Result<(), Error>
Sends WATCH for one key.
Examples found in repository?
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}Sourcepub fn watch(&mut self, keys: &[&str]) -> Result<(), Error>
pub fn watch(&mut self, keys: &[&str]) -> Result<(), Error>
Sends WATCH.
Examples found in repository?
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}Sourcepub fn unwatch(&mut self) -> Result<(), Error>
pub fn unwatch(&mut self) -> Result<(), Error>
Sends UNWATCH.
Examples found in repository?
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}Sourcepub fn eval(
&mut self,
script: &str,
keys: &[&str],
arguments: &[&str],
) -> Result<RespValue, Error>
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?
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}Sourcepub fn evalsha(
&mut self,
sha: &str,
keys: &[&str],
arguments: &[&str],
) -> Result<RespValue, Error>
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?
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}Sourcepub fn script_load(&mut self, script: &str) -> Result<String, Error>
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?
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}Sourcepub fn script_exists(&mut self, hashes: &[&str]) -> Result<Vec<bool>, Error>
pub fn script_exists(&mut self, hashes: &[&str]) -> Result<Vec<bool>, Error>
Sends SCRIPT EXISTS, one flag per hash.
Examples found in repository?
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}Sourcepub fn script_flush(&mut self) -> Result<(), Error>
pub fn script_flush(&mut self) -> Result<(), Error>
Sends SCRIPT FLUSH.
Examples found in repository?
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}Sourcepub fn script_kill(&mut self) -> Result<(), Error>
pub fn script_kill(&mut self) -> Result<(), Error>
Sends SCRIPT KILL.
Examples found in repository?
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}Sourcepub fn fcall(
&mut self,
name: &str,
keys: &[&str],
arguments: &[&str],
) -> Result<RespValue, Error>
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?
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}Sourcepub fn function_load(&mut self, name: &str, body: &str) -> Result<(), Error>
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?
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}Sourcepub fn function_list(&mut self) -> Result<RespValue, Error>
pub fn function_list(&mut self) -> Result<RespValue, Error>
Sends FUNCTION LIST.
Examples found in repository?
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}Sourcepub fn function_delete(&mut self, name: &str) -> Result<bool, Error>
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?
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}Sourcepub fn acl_whoami(&mut self) -> Result<String, Error>
pub fn acl_whoami(&mut self) -> Result<String, Error>
Sends ACL WHOAMI.
Examples found in repository?
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}Sourcepub fn acl_users(&mut self) -> Result<Vec<String>, Error>
pub fn acl_users(&mut self) -> Result<Vec<String>, Error>
Sends ACL USERS.
Examples found in repository?
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}Sourcepub fn acl_list(&mut self) -> Result<Vec<String>, Error>
pub fn acl_list(&mut self) -> Result<Vec<String>, Error>
Sends ACL LIST.
Examples found in repository?
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}Sourcepub fn acl_getuser(&mut self, user: &str) -> Result<RespValue, Error>
pub fn acl_getuser(&mut self, user: &str) -> Result<RespValue, Error>
Sends ACL GETUSER.
Examples found in repository?
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}Sourcepub fn acl_cat(&mut self) -> Result<Vec<String>, Error>
pub fn acl_cat(&mut self) -> Result<Vec<String>, Error>
Sends ACL CAT.
Examples found in repository?
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}Sourcepub fn acl_setuser(&mut self, user: &str, rules: &[&str]) -> Result<(), Error>
pub fn acl_setuser(&mut self, user: &str, rules: &[&str]) -> Result<(), Error>
Sends ACL SETUSER user rule....
Examples found in repository?
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}Sourcepub fn cluster_slots(&mut self) -> Result<RespValue, Error>
pub fn cluster_slots(&mut self) -> Result<RespValue, Error>
Sends CLUSTER SLOTS.
Examples found in repository?
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}Sourcepub fn cluster_nodes(&mut self) -> Result<String, Error>
pub fn cluster_nodes(&mut self) -> Result<String, Error>
Sends CLUSTER NODES.
Examples found in repository?
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}Sourcepub fn cluster_shards(&mut self) -> Result<RespValue, Error>
pub fn cluster_shards(&mut self) -> Result<RespValue, Error>
Sends CLUSTER SHARDS.
Examples found in repository?
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}Sourcepub fn cluster_info(&mut self) -> Result<String, Error>
pub fn cluster_info(&mut self) -> Result<String, Error>
Sends CLUSTER INFO.
Examples found in repository?
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}Sourcepub fn cluster_myid(&mut self) -> Result<String, Error>
pub fn cluster_myid(&mut self) -> Result<String, Error>
Sends CLUSTER MYID.
Examples found in repository?
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}Sourcepub fn cluster_keyslot(&mut self, key: &str) -> Result<i64, Error>
pub fn cluster_keyslot(&mut self, key: &str) -> Result<i64, Error>
Sends CLUSTER KEYSLOT.
Examples found in repository?
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}Sourcepub fn readonly(&mut self) -> Result<(), Error>
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?
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}Sourcepub fn readwrite(&mut self) -> Result<(), Error>
pub fn readwrite(&mut self) -> Result<(), Error>
Sends READWRITE.
Examples found in repository?
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}Sourcepub fn client_getname(&mut self) -> Result<Option<String>, Error>
pub fn client_getname(&mut self) -> Result<Option<String>, Error>
Sends CLIENT GETNAME.
Examples found in repository?
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}Sourcepub fn client_setname(&mut self, name: &str) -> Result<(), Error>
pub fn client_setname(&mut self, name: &str) -> Result<(), Error>
Sends CLIENT SETNAME.
Examples found in repository?
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}Sourcepub fn client_tracking(&mut self, enabled: bool) -> Result<(), Error>
pub fn client_tracking(&mut self, enabled: bool) -> Result<(), Error>
Sends CLIENT TRACKING ON or OFF.
Examples found in repository?
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}Sourcepub fn hello(&mut self, protocol: u8) -> Result<RespValue, Error>
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?
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}Sourcepub fn publish(&mut self, channel: &str, message: &str) -> Result<i64, Error>
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?
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}Sourcepub fn spublish(&mut self, channel: &str, message: &str) -> Result<i64, Error>
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?
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}Sourcepub fn subscribe(&mut self, channels: &[&str]) -> Result<Vec<RespValue>, Error>
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?
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}Sourcepub fn unsubscribe(
&mut self,
channels: &[&str],
) -> Result<Vec<RespValue>, Error>
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?
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}Sourcepub fn psubscribe(&mut self, patterns: &[&str]) -> Result<Vec<RespValue>, Error>
pub fn psubscribe(&mut self, patterns: &[&str]) -> Result<Vec<RespValue>, Error>
Sends PSUBSCRIBE and reads one confirmation per pattern.
Examples found in repository?
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}Sourcepub fn punsubscribe(
&mut self,
patterns: &[&str],
) -> Result<Vec<RespValue>, Error>
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?
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}Sourcepub fn ssubscribe(&mut self, channels: &[&str]) -> Result<Vec<RespValue>, Error>
pub fn ssubscribe(&mut self, channels: &[&str]) -> Result<Vec<RespValue>, Error>
Sends SSUBSCRIBE and reads one confirmation per channel.
Examples found in repository?
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}Sourcepub fn sunsubscribe(
&mut self,
channels: &[&str],
) -> Result<Vec<RespValue>, Error>
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?
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}Sourcepub fn next_message(&mut self) -> Result<PubSubMessage, Error>
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?
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}