ruvio-client
Blocking RESP2 client for Ruvio. Connecting does not send CLIENT SETINFO or HELLO. Give the client one address; it sends CLUSTER SLOTS and, on a sharded server, opens one socket per shard and routes by hash slot. MOVED refreshes the map. MGET / MSET / DEL split across shards. Methods take &mut self and are named after the command they send. They cover every command Ruvio supports. execute and execute_many send any argument list, as redis-cli would.
use Duration;
use Client;
let mut db = connect?;
db.set?;
let value = db.get_string?;
db.incr?;
db.expire?;
db.hset?;
db.zadd?;
let top = db.zrevrange_with_scores?;
Connecting
hash_slot(key) is the same 0–16383 slot Ruvio uses, including {hash tags}. Set ClientOptions::discover_cluster to false to stay on the seed socket.
A standalone client is bound to one logical database. Database 0 sends nothing after discovery. Any other index sends SELECT before the connect call returns. Cluster mode has only database 0.
use ;
use ;
let mut cache = connect_database?;
let mut sessions = connect_ip?;
let mut main = connect_addr?;
let mut secured = connect_with?;
select switches the same connection, and into_database does the same and returns the client. flushdb, flushall, swapdb, and move_key send FLUSHDB, FLUSHALL, SWAPDB, and MOVE.
A password is sent as AUTH only when ClientOptions::password is set. A server error reply leaves the connection usable. A broken read or write does not.
Commands
| Family | Methods |
|---|---|
| Strings | get, get_string, set, set_with, set_expires_at, set_keep_ttl, set_and_get, mget, mset, getset, append, strlen, incr, incr_by, decr, decr_by |
| Keys | del, del_key, unlink, unlink_key, exists, exists_key, key_type, rename, scan, dbsize, expire, pexpire, expire_at, ttl, pttl, persist |
| Lists | lpush, rpush, lpop, lpop_count, rpop, rpop_count, llen, lindex, lrange, ltrim, blpop, blpop_key, brpop, brpop_key |
| Sets | sadd, srem, sismember, scard, smembers, sinter, sunion, sdiff, sinterstore, sunionstore, sdiffstore, smove, spop, spop_count, srandmember, srandmember_count |
| Hashes | hset, hget, hdel, hlen, hgetall, hmget, hexists, hkeys, hvals, hincr_by, hsetnx, hstrlen, hscan |
| Sorted sets | zadd, zadd_with, zadd_incr, zincr_by, zrange, zrevrange, zrange_with_scores, zrevrange_with_scores, zrange_by_score_with_scores, zrem, zcard, zscore, zrank, zrevrank |
| Bloom filters | bf_reserve, bf_add, bf_exists |
| Streams | xadd, xadd_maxlen, xlen, xrange, xrevrange, xdel, xtrim_maxlen, xread, xgroup_create, xreadgroup, xgroup_destroy, xgroup_setid, xgroup_delconsumer, xack, xpending_summary, xpending, xclaim, xclaim_ids |
| Transactions | multi, exec, discard, watch, watch_key, unwatch |
| Scripts and functions | eval, evalsha, script_load, script_exists, script_flush, script_kill, fcall, function_load, function_list, function_delete |
| Pub/Sub | publish, spublish, subscribe, unsubscribe, psubscribe, punsubscribe, ssubscribe, sunsubscribe, next_message, read_message |
| Server | ping, ping_message, info, config_get, save, bgsave, select, flushdb, flushall, swapdb, move_key, hello, client_getname, client_setname, client_tracking, cluster_slots, cluster_nodes |
| ACL | acl_whoami, acl_users, acl_list, acl_getuser, acl_cat, acl_setuser |
SortedSetAddOptions, StreamReadOptions, StreamPendingFilter, and StreamClaimOptions carry the optional ZADD, XREAD/XREADGROUP, XPENDING, and XCLAIM arguments. eval, evalsha, and fcall take keys and arguments separately and send keys.len() as the key count.
Inside MULTI the server answers QUEUED instead of the typed reply, so queue commands with execute and read the results from exec:
db.watch?;
db.multi?;
db.execute?;
db.execute?;
let replies = db.exec?; // None when a watched key changed
After subscribe, psubscribe, or ssubscribe, next_message blocks until the next message, pmessage, or smessage. set_read_timeout bounds that wait.
Tests
cargo test runs the unit tests. RUVIO_TEST_ADDR=127.0.0.1:16390 cargo test also runs tests/live.rs against a server on that address. Those tests use databases 0 to 7 and flush them.
0.2.2
del_key,unlink_key,exists_key,watch_key,blpop_key, andbrpop_keytake one key. The slice methods remain for many keys.
0.2.1
- A sharded server is discovered from one seed address. Commands are routed by hash slot,
MOVEDis followed, andMGET/MSET/DELsplit across shards. cluster_shards,cluster_info,cluster_myid,cluster_keyslot,readonly,readwrite.hash_slot,is_cluster,shard_count, andClientOptions::discover_cluster.
0.2.0
- Typed methods for every command Ruvio supports.
ClientOptions::database,connect_database,connect_ip,connect_addr,select,into_database, anddatabase.set_expires_at(PXAT),set_keep_ttl(KEEPTTL),set_and_get(GET), andping_message.expiresendsPEXPIREwhen the duration is not whole seconds. It used to round up to the next second.RespValue::as_integer,as_array, andis_null.- The minimum Rust version is 1.87.