A Redis client for MoonBit: RESP2 and RESP3, pipelines, transactions, pub/sub, cluster and sentinel.
moon add moonbitstack/moonredisasync fn main {
let options = @moonredis.ClientOptions::at("127.0.0.1", 6379)
let conn = @socket.Connection::connect(options) catch {
_ => return
}
let client = @moonredis.Client::new(conn)
let _ = client.set("greeting", "hello")
match client.get("greeting") {
Some(bytes) => println(@utf8.decode_lossy(bytes[:]))
None => println("(nil)")
}
}| Item | Purpose |
|---|---|
| Client | The command surface: one async method per redis command, named as in redis-py. |
| Client::new(&RedisConn) | A client over a connection. |
| Client::command(Array[Bytes]) | Send a raw command (binary-safe), returning the reply value. |
| RedisConn (open trait) | The transport contract: execute(Array[Bytes]) -> RespValue, and execute_all for several commands in one round trip, which defaults to sending them one at a time. |
| FakeConn | A scripted in-memory connection for tests (new, handler). |
| RedisError | Reply(msg) for a redis error, Connection(msg), Closed, Protocol(msg), and Aborted for a transaction a watched key changed under. |
| Item | Purpose |
|---|---|
| ClientOptions | Endpoint, credentials, protocol, timeouts, and the pool/retry/tracking policies. |
| ClientOptions::at(host, port) | Options at an address over the standard defaults. |
| ClientOptions::with_auth(username, password), with_db(db) | Copies with auth or database set. |
| client_default, pool_default, retry_default, tracking_default | The market-standard presets. |
| Protocol | Resp2 or Resp3 (the default). |
| PoolOptions | max_idle, max_active, min_idle, idle_timeout, health_check. |
| RetryOptions | attempts, base_delay, max_delay, level, jitter. |
| TrackingOptions | enabled, bcast, optin, optout, noloop, redirect. |
| backoff_delay(attempt, retry) | The wait before a retry. |
| Item | Purpose |
|---|---|
| Pipeline | Queue commands (add) and send them in one round trip (execute); multi wraps them in MULTI/EXEC. |
| Client::watch, Client::unwatch, Client::discard | Transaction control. |
| ClusterTopology | A slot-to-node map; node_for_slot(slot). |
| ClusterSlot, ClusterSlot::new | A slot range owned by a node. |
| ClusterClient | Routes a command to the node owning its key and follows MOVED and ASK, up to limit (redirect_limit, 3). dial opens nodes it was not built with. |
| Redirect, redirect(msg) | Moved or Ask with the slot and node, read from an error reply. |
| ClusterTopology::assign(slot, node) | Record where a slot lives. |
| crc16(bytes), hash_slot(key), same_slot(keys) | Slot hashing, honouring {hash tags}. |
| decode_cluster_slots(reply) | Parse a CLUSTER SLOTS reply into a ClusterTopology. |
| SentinelClient | Resolve a master address through a list of sentinels. |
| RetryConn, should_retry(error, attempt, retry) | A retrying view of any connection; dial opens a new one after a failure and wait sleeps for the backoff. |
| Item | Purpose |
|---|---|
| Message | A pub/sub frame: kind, channel, payload, pattern, count. |
| Message::parse(value) | Parse a RESP2 array or RESP3 push frame into a Message. |
| StreamEntry | One stream entry: id and fields. |
| PendingSummary | The XPENDING summary: count, min_id, max_id, consumers. |
| Item | Purpose |
|---|---|
| Connection | A real connection over TCP or TLS; implements RedisConn. |
| Connection::connect(options) | Dial and negotiate from ClientOptions. |
| Connection::take_pushes() | Push frames read since the last command, such as the invalidations CLIENT TRACKING sends. |
| connect_retrying(options) | A RetryConn that reconnects under options.retry. Only for commands that are safe to send twice. |
| Pool | Reuse idle connections (get, put, idle_count), bounded by max_idle. |
| Subscription | subscribe/unsubscribe and next for Message frames; pattern and shard select PSUBSCRIBE and SSUBSCRIBE. |
| Item | Purpose |
|---|---|
| RespValue | Every RESP2/RESP3 value: simple string, error, integer, bulk string, null, array, boolean, double, big number, bulk error, verbatim string, map, set, push. |
| RespValue::decode(bytes), encode() | Decode one value (or encode it back). |
| RespReader | Stream a sequence of values (read, at_end, rest). |
| resp_encode_command(args), resp_command(args) | Frame a command as an array of bulk strings. |
| resp_kind(value) | A value's type name, for diagnostics. |
| Family | Methods |
|---|---|
| String | set, set_get, setnx, setex, psetex, get, mget, mset, append, strlen, incr, incrby, decr, decrby, getrange, setrange, getdel, getex |
| Key | del, unlink, exists, expire, pexpire, expireat, pexpireat, persist, ttl, pttl, type_, rename, renamenx, randomkey, touch, move_, copy, keys, scan, object_encoding, object_refcount, object_idletime, dump, restore |
| Hash | hset, hsetnx, hmset, hget, hmget, hgetall, hdel, hexists, hlen, hstrlen, hincrby, hincrbyfloat, hkeys, hvals, hscan, hrandfield |
| List | lpush, rpush, lpushx, rpushx, lpop, lpopn, rpop, rpopn, llen, lindex, lrange, lset, lrem, linsert, ltrim, rpoplpush, lmove, blpop, brpop, brpoplpush, blmove |
| Set | sadd, srem, smembers, sismember, scard, spop, spopn, srandmember, srandmembern, sinter, sunion, sdiff, sinterstore, sunionstore, sdiffstore, smove, sscan |
| Sorted set | zadd, zrem, zscore, zmscore, zincrby, zcard, zrank, zrevrank, zrange, zrange_scores, zrevrange, zrevrange_scores, zrangebyscore, zrangebyscore_scores, zrevrangebyscore, zrevrangebyscore_scores, zcount, zremrangebyrank, zremrangebyscore, zpopmin, zpopmax, zunionstore, zinterstore, zscan, zrandmember, bzpopmin, bzpopmax |
| Stream | xadd, xlen, xdel, xtrim, xrange, xrevrange, xread, xack, xgroup_create, xgroup_destroy, xgroup_createconsumer, xgroup_delconsumer, xreadgroup, xpending |
| HyperLogLog | pfadd, pfcount, pfmerge |
| Geo | geoadd, geodist, geohash, geopos, geosearch |
| Bitmap | setbit, getbit, bitcount, bitpos, bitop |
| Script / function | Script runs a script by digest and reloads it when the server forgets; eval, evalsha, script_load, script_exists, script_flush, function_load, function_call, function_flush, function_delete |
| Pub/sub | publish, spublish, subscribe, unsubscribe, psubscribe, punsubscribe, ssubscribe, sunsubscribe |
| Server / connection | ping, ping_message, echo, select, auth, auth_user, info, dbsize, flushdb, flushall, swapdb, time_, lastsave, save, bgsave, bgrewriteaof, shutdown, config_get, config_set, config_rewrite, config_resetstat, client_setname, client_getname, client_id, client_kill, command_count, slowlog_get, slowlog_len, slowlog_reset, replicaof, replicaof_noone |
| JSON | json_set, json_mset, json_merge, json_get, json_get_text, json_mget, json_del, json_forget, json_type, json_numincrby, json_nummultby, json_strappend, json_strlen, json_arrlen, json_arrindex, json_arrappend, json_arrinsert, json_arrpop, json_arrtrim, json_objkeys, json_objlen, json_toggle, json_clear, json_resp, json_debug_memory |
| Search | ft_create, ft_alter, ft_dropindex, ft_list, ft_aliasadd, ft_aliasupdate, ft_aliasdel, ft_search, ft_aggregate, ft_cursor_read, ft_cursor_del, ft_info, ft_explain, ft_explaincli, ft_profile, ft_tagvals, ft_spellcheck, ft_dictadd, ft_dictdel, ft_dictdump, ft_synupdate, ft_syndump, ft_sugadd, ft_sugget, ft_sugget_scored, ft_suglen, ft_sugdel, ft_config_get, ft_config_set, ft_hybrid |
| Time series | ts_create, ts_alter, ts_add, ts_madd, ts_incrby, ts_decrby, ts_del, ts_createrule, ts_deleterule, ts_range, ts_revrange, ts_mrange, ts_mrevrange, ts_get, ts_mget, ts_read, ts_nrange, ts_nrevrange, ts_info, ts_queryindex, ts_querylabels, ts_querylabel_values |
| Bloom and cuckoo filters | bf_reserve, bf_add, bf_madd, bf_insert, bf_exists, bf_mexists, bf_scandump, bf_loadchunk, bf_info, bf_card, cf_reserve, cf_add, cf_addnx, cf_insert, cf_insertnx, cf_exists, cf_mexists, cf_del, cf_count, cf_scandump, cf_loadchunk, cf_info |
| Counting sketches | cms_initbydim, cms_initbyprob, cms_incrby, cms_query, cms_merge, cms_info, topk_reserve, topk_add, topk_incrby, topk_query, topk_count, topk_list, topk_list_with_count, topk_info, tdigest_create, tdigest_reset, tdigest_add, tdigest_merge, tdigest_min, tdigest_max, tdigest_quantile, tdigest_cdf, tdigest_rank, tdigest_revrank, tdigest_byrank, tdigest_byrevrank, tdigest_trimmed_mean, tdigest_info |
async fn store_and_read(client : @moonredis.Client) -> Unit raise @moonredis.RedisError {
let text = "{\"title\":\"moon\",\"readings\":[1,2,3]}"
let document = @json.parse(text) catch {
_ => raise @moonredis.Protocol("the document is not JSON")
}
let _ = client.json_set("doc", "$", document)
let grown = client.json_arrappend("doc", "$.readings", [@json.Json::number(4.0)])
println(grown[0].unwrap().to_string()) // 4
let title = client.json_get_text("doc", path="$.title")
println(title.unwrap_or("")) // ["moon"]
}async fn index_books(client : @moonredis.Client) -> Unit raise @moonredis.RedisError {
client.ft_create("books", {
..@moonredis.Schema::new([
@moonredis.SchemaField::text("title", sortable=true),
@moonredis.SchemaField::numeric("pages", sortable=true),
@moonredis.SchemaField::vector("vec", @moonredis.VectorSpec::hnsw(4)),
]),
prefixes: ["book:"],
})
let found = client.ft_search("books", "moon", options={
..@moonredis.search_default,
sort_by: Some({ field: "pages", ascending: true }),
return_fields: ["title"],
limit: 10,
})
for hit in found.hits {
println(hit.id + " " + hit.field("title").unwrap_or(""))
}
}async fn counter(conn : &@moonredis.RedisConn) -> Unit raise @moonredis.RedisError {
let pipeline = @moonredis.Pipeline::new(conn)
pipeline.add([b"SET", b"a", b"1"])
pipeline.add([b"INCR", b"a"])
let replies = pipeline.execute() // [OK, 2]
println(replies.length())
}async fn listen(
conn : @socket.Connection,
publisher : @moonredis.Client,
) -> Unit raise @moonredis.RedisError {
let sub = @socket.Subscription::subscribe(conn, ["news"])
let _ = publisher.publish("news", "hello")
match sub.next() {
Some(message) => println(message.channel + ": " + @utf8.decode_lossy(message.payload[:]))
None => ()
}
}async fn serve_and_find(client : @moonredis.Client) -> Unit raise {
let registry = @sd.Registry::new(client)
@async.with_task_group(group => {
group.spawn_bg(() => @moonsd.hold(registry, "greeter", @moonsd.Endpoint::new("10.0.0.1", 12000)))
let endpoints = registry.resolve("greeter")
println(endpoints.length())
})
}| Example | Run |
|---|---|
| 01-resp | moon run src/examples/01-resp — the codec, no server. |
| 02-commands | moon run src/examples/02-commands — typed commands against a fake. |
| 03-connect | moon run src/examples/03-connect --target native — a real connection. |
| 04-pipeline | moon run src/examples/04-pipeline --target native — one round trip, and a transaction that loses a race. |
| 05-pubsub | moon run src/examples/05-pubsub --target native — a pattern subscription. |
| 06-cluster | moon run src/examples/06-cluster --target native — keys routed by slot. |
| 07-modules | moon run src/examples/07-modules --target native — one command from each Redis 8 module. |
pub(open) trait RedisConn {
async fn execute(Self, Array[Bytes]) -> RespValue raise RedisError
async fn execute_all(Self, Array[Array[Bytes]]) -> Array[RespValue] raise RedisError = _
}pub(all) struct AggregateOptions {
verbatim : Bool
load : Array[String]
group_by : Array[String]
reducers : Array[Reducer]
apply : Array[(String, String)]
sort_by : Array[SortKey]
offset : Int64
limit : Int64
filter : String?
params : Array[(String, Bytes)]
dialect : Int?
timeout : Int64?
cursor_count : Int64?
max_idle : Int64?
}pub(all) struct AggregateResult {
total : Int64
rows : Array[Array[(String, FieldValue)]]
cursor : Int64?
}async fn Client::auth_user(self : Client, username : String, password : String) -> Unit raise RedisErrorasync fn Client::bf_insert(self : Client, key : String, items : Array[String], capacity? : Int64, error_rate? : Double, expansion? : Int64, nocreate? : Bool, nonscaling? : Bool) -> Array[Bool] raise RedisErrorasync fn Client::bf_loadchunk(self : Client, key : String, iterator : Int64, data : Bytes) -> Unit raise RedisErrorasync fn Client::bf_madd(self : Client, key : String, items : Array[String]) -> Array[Bool] raise RedisErrorasync fn Client::bf_mexists(self : Client, key : String, items : Array[String]) -> Array[Bool] raise RedisErrorasync fn Client::bf_reserve(self : Client, key : String, error_rate : Double, capacity : Int64, expansion? : Int64, nonscaling? : Bool) -> Unit raise RedisErrorasync fn Client::bf_scandump(self : Client, key : String, iterator : Int64) -> (Int64, Bytes?) raise RedisErrorasync fn Client::bitcount(self : Client, key : String, start? : Int, end? : Int) -> Int64 raise RedisErrorasync fn Client::bitop(self : Client, op : String, destination : String, keys : Array[String]) -> Int64 raise RedisErrorasync fn Client::bitpos(self : Client, key : String, bit : Int, start? : Int, end? : Int) -> Int64 raise RedisErrorasync fn Client::blmove(self : Client, source : String, destination : String, wherefrom : String, whereto : String, timeout : Int) -> Bytes? raise RedisErrorasync fn Client::blpop(self : Client, keys : Array[String], timeout : Int) -> (String, Bytes)? raise RedisErrorasync fn Client::brpop(self : Client, keys : Array[String], timeout : Int) -> (String, Bytes)? raise RedisErrorasync fn Client::brpoplpush(self : Client, source : String, destination : String, timeout : Int) -> Bytes? raise RedisErrorasync fn Client::bzpopmax(self : Client, keys : Array[String], timeout : Int) -> (String, String, Double)? raise RedisErrorasync fn Client::bzpopmin(self : Client, keys : Array[String], timeout : Int) -> (String, String, Double)? raise RedisErrorasync fn Client::cf_insert(self : Client, key : String, items : Array[String], capacity? : Int64, nocreate? : Bool) -> Array[Bool] raise RedisErrorasync fn Client::cf_insertnx(self : Client, key : String, items : Array[String], capacity? : Int64, nocreate? : Bool) -> Array[Bool] raise RedisErrorasync fn Client::cf_loadchunk(self : Client, key : String, iterator : Int64, data : Bytes) -> Unit raise RedisErrorasync fn Client::cf_mexists(self : Client, key : String, items : Array[String]) -> Array[Bool] raise RedisErrorasync fn Client::cf_reserve(self : Client, key : String, capacity : Int64, bucket_size? : Int64, max_iterations? : Int64, expansion? : Int64) -> Unit raise RedisErrorasync fn Client::cf_scandump(self : Client, key : String, iterator : Int64) -> (Int64, Bytes?) raise RedisErrorasync fn Client::cms_incrby(self : Client, key : String, items : Array[(String, Int64)]) -> Array[Int64] raise RedisErrorasync fn Client::cms_initbydim(self : Client, key : String, width : Int64, depth : Int64) -> Unit raise RedisErrorasync fn Client::cms_initbyprob(self : Client, key : String, error_rate : Double, probability : Double) -> Unit raise RedisErrorasync fn Client::cms_merge(self : Client, destination : String, sources : Array[String], weights? : Array[Int64]) -> Unit raise RedisErrorasync fn Client::cms_query(self : Client, key : String, items : Array[String]) -> Array[Int64] raise RedisErrorasync fn Client::config_get(self : Client, parameter : String) -> Array[(String, String)] raise RedisErrorasync fn Client::config_set(self : Client, parameter : String, value : String) -> Unit raise RedisErrorasync fn Client::copy(self : Client, source : String, destination : String, db? : Int, replace? : Bool) -> Bool raise RedisErrorasync fn Client::ft_aggregate(self : Client, index : String, query : String, options? : AggregateOptions) -> AggregateResult raise RedisErrorasync fn Client::ft_aliasadd(self : Client, alias_name : String, index : String) -> Unit raise RedisErrorasync fn Client::ft_aliasupdate(self : Client, alias_name : String, index : String) -> Unit raise RedisErrorasync fn Client::ft_alter(self : Client, index : String, fields : Array[SchemaField], skip_initial_scan? : Bool) -> Unit raise RedisErrorasync fn Client::ft_config_get(self : Client, pattern : String) -> Array[(String, String)] raise RedisErrorasync fn Client::ft_config_set(self : Client, name : String, value : String) -> Unit raise RedisErrorasync fn Client::ft_cursor_del(self : Client, index : String, cursor : Int64) -> Unit raise RedisErrorasync fn Client::ft_cursor_read(self : Client, index : String, cursor : Int64, count? : Int64) -> AggregateResult raise RedisErrorasync fn Client::ft_dictadd(self : Client, dictionary : String, terms : Array[String]) -> Int64 raise RedisErrorasync fn Client::ft_dictdel(self : Client, dictionary : String, terms : Array[String]) -> Int64 raise RedisErrorasync fn Client::ft_dropindex(self : Client, index : String, delete_documents? : Bool) -> Unit raise RedisErrorasync fn Client::ft_explain(self : Client, index : String, query : String, dialect? : Int) -> String raise RedisErrorasync fn Client::ft_explaincli(self : Client, index : String, query : String, dialect? : Int) -> Array[String] raise RedisErrorasync fn Client::ft_hybrid(self : Client, index : String, query : String, vector_field : String, vector : Bytes, options? : HybridOptions) -> SearchResult raise RedisErrorasync fn Client::ft_profile(self : Client, index : String, aggregate : Bool, query : String, limited? : Bool) -> RespValue raise RedisErrorasync fn Client::ft_search(self : Client, index : String, query : String, options? : SearchOptions) -> SearchResult raise RedisErrorasync fn Client::ft_spellcheck(self : Client, index : String, query : String, distance? : Int, dialect? : Int) -> Array[SpellCheckTerm] raise RedisErrorasync fn Client::ft_sugadd(self : Client, key : String, suggestion : String, score : Double, increment? : Bool, payload? : String) -> Int64 raise RedisErrorasync fn Client::ft_sugdel(self : Client, key : String, suggestion : String) -> Bool raise RedisErrorasync fn Client::ft_sugget(self : Client, key : String, prefix : String, fuzzy? : Bool, max? : Int64) -> Array[String] raise RedisErrorasync fn Client::ft_sugget_scored(self : Client, key : String, prefix : String, fuzzy? : Bool, max? : Int64) -> Array[(String, Double)] raise RedisErrorasync fn Client::ft_syndump(self : Client, index : String) -> Array[(String, Array[String])] raise RedisErrorasync fn Client::ft_synupdate(self : Client, index : String, group : String, terms : Array[String], skip_initial_scan? : Bool) -> Unit raise RedisErrorasync fn Client::ft_tagvals(self : Client, index : String, field : String) -> Array[String] raise RedisErrorasync fn Client::function_load(self : Client, code : String, replace? : Bool) -> String raise RedisErrorasync fn Client::geoadd(self : Client, key : String, points : Array[(String, Double, Double)]) -> Int64 raise RedisErrorasync fn Client::geodist(self : Client, key : String, a : String, b : String, unit? : String) -> Double? raise RedisErrorasync fn Client::geohash(self : Client, key : String, members : Array[String]) -> Array[String?] raise RedisErrorasync fn Client::geopos(self : Client, key : String, members : Array[String]) -> Array[(Double, Double)?] raise RedisErrorasync fn Client::geosearch(self : Client, key : String, from_member? : String, longitude? : Double, latitude? : Double, radius? : Double, width? : Double, height? : Double, unit : String, count? : Int, asc? : Bool, desc? : Bool) -> Array[String] raise RedisErrorasync fn Client::getex(self : Client, key : String, ex? : Int64, px? : Int64, exat? : Int64, pxat? : Int64, persist? : Bool) -> Bytes? raise RedisErrorasync fn Client::getrange(self : Client, key : String, start : Int, end : Int) -> Bytes raise RedisErrorasync fn Client::hdel(self : Client, key : String, fields : Array[String]) -> Int64 raise RedisErrorasync fn Client::hincrby(self : Client, key : String, field : String, n : Int64) -> Int64 raise RedisErrorasync fn Client::hincrbyfloat(self : Client, key : String, field : String, f : Double) -> Double raise RedisErrorasync fn Client::hmget(self : Client, key : String, fields : Array[String]) -> Array[Bytes?] raise RedisErrorasync fn Client::hmset(self : Client, key : String, fields : Array[(String, String)]) -> Unit raise RedisErrorasync fn Client::hrandfield(self : Client, key : String, count? : Int) -> Array[String] raise RedisErrorasync fn Client::hrandfield_values(self : Client, key : String, count : Int) -> Array[(String, String)] raise RedisErrorasync fn Client::hscan(self : Client, key : String, cursor : String, pattern? : String, count? : Int) -> (String, Array[(String, String)]) raise RedisErrorasync fn Client::hset(self : Client, key : String, fields : Array[(String, String)]) -> Int64 raise RedisErrorasync fn Client::hsetnx(self : Client, key : String, field : String, value : String) -> Bool raise RedisErrorasync fn Client::json_arrindex(self : Client, key : String, path : String, value : Json, start? : Int64, stop? : Int64) -> Array[Int64?] raise RedisErrorasync fn Client::json_arrlen(self : Client, key : String, path? : String) -> Array[Int64?] raise RedisErrorasync fn Client::json_arrpop(self : Client, key : String, path : String, index? : Int64) -> Array[Json?] raise RedisErrorasync fn Client::json_arrtrim(self : Client, key : String, path : String, start : Int64, stop : Int64) -> Array[Int64?] raise RedisErrorasync fn Client::json_debug_memory(self : Client, key : String, path? : String) -> Int64 raise RedisErrorasync fn Client::json_get_text(self : Client, key : String, path? : String, indent? : String, newline? : String, space? : String) -> String? raise RedisErrorasync fn Client::json_merge(self : Client, key : String, path : String, value : Json) -> Unit raise RedisErrorasync fn Client::json_mset(self : Client, triplets : Array[(String, String, Json)]) -> Unit raise RedisErrorasync fn Client::json_numincrby(self : Client, key : String, path : String, value : Double) -> Array[Double?] raise RedisErrorasync fn Client::json_nummultby(self : Client, key : String, path : String, value : Double) -> Array[Double?] raise RedisErrorasync fn Client::json_objkeys(self : Client, key : String, path? : String) -> Array[Array[String]?] raise RedisErrorasync fn Client::json_objlen(self : Client, key : String, path? : String) -> Array[Int64?] raise RedisErrorasync fn Client::json_resp(self : Client, key : String, path? : String) -> RespValue raise RedisErrorasync fn Client::json_set(self : Client, key : String, path : String, value : Json, nx? : Bool, xx? : Bool, fpha? : Fpha) -> Bool raise RedisErrorasync fn Client::json_strappend(self : Client, key : String, path : String, value : String) -> Array[Int64?] raise RedisErrorasync fn Client::json_strlen(self : Client, key : String, path? : String) -> Array[Int64?] raise RedisErrorasync fn Client::json_toggle(self : Client, key : String, path : String) -> Array[Bool?] raise RedisErrorasync fn Client::json_type(self : Client, key : String, path? : String) -> Array[String?] raise RedisErrorasync fn Client::linsert(self : Client, key : String, where_ : String, pivot : String, value : String) -> Int64 raise RedisErrorasync fn Client::lmove(self : Client, source : String, destination : String, wherefrom : String, whereto : String) -> Bytes? raise RedisErrorasync fn Client::lpush(self : Client, key : String, values : Array[String]) -> Int64 raise RedisErrorasync fn Client::lpushx(self : Client, key : String, values : Array[String]) -> Int64 raise RedisErrorasync fn Client::lrange(self : Client, key : String, start : Int, stop : Int) -> Array[Bytes] raise RedisErrorasync fn Client::lrem(self : Client, key : String, count : Int, value : String) -> Int64 raise RedisErrorasync fn Client::lset(self : Client, key : String, index : Int, value : String) -> Unit raise RedisErrorasync fn Client::ltrim(self : Client, key : String, start : Int, stop : Int) -> Unit raise RedisErrorasync fn Client::pexpire(self : Client, key : String, milliseconds : Int64) -> Bool raise RedisErrorasync fn Client::pexpireat(self : Client, key : String, milliseconds_timestamp : Int64) -> Bool raise RedisErrorasync fn Client::pfadd(self : Client, key : String, values : Array[String]) -> Int64 raise RedisErrorasync fn Client::pfmerge(self : Client, destination : String, sources : Array[String]) -> Unit raise RedisErrorasync fn Client::psetex(self : Client, key : String, milliseconds : Int64, value : String) -> Unit raise RedisErrorasync fn Client::publish(self : Client, channel : String, message : String) -> Int64 raise RedisErrorasync fn Client::restore(self : Client, key : String, ttl : Int64, serialized : Bytes, replace? : Bool, absttl? : Bool) -> Unit raise RedisErrorasync fn Client::rpoplpush(self : Client, source : String, destination : String) -> Bytes? raise RedisErrorasync fn Client::rpush(self : Client, key : String, values : Array[String]) -> Int64 raise RedisErrorasync fn Client::rpushx(self : Client, key : String, values : Array[String]) -> Int64 raise RedisErrorasync fn Client::sadd(self : Client, key : String, members : Array[String]) -> Int64 raise RedisErrorasync fn Client::scan(self : Client, cursor : String, pattern? : String, count? : Int, kind? : String) -> (String, Array[String]) raise RedisErrorasync fn Client::sdiffstore(self : Client, destination : String, keys : Array[String]) -> Int64 raise RedisErrorasync fn Client::sentinel_get_master_addr_by_name(self : Client, name : String) -> (String, Int)? raise RedisErrorasync fn Client::set(self : Client, key : String, value : String, ex? : Int64, px? : Int64, nx? : Bool, xx? : Bool, keepttl? : Bool) -> Bool raise RedisErrorasync fn Client::setbit(self : Client, key : String, offset : Int64, value : Int) -> Int64 raise RedisErrorasync fn Client::setex(self : Client, key : String, seconds : Int64, value : String) -> Unit raise RedisErrorasync fn Client::setrange(self : Client, key : String, offset : Int, value : String) -> Int64 raise RedisErrorasync fn Client::sinterstore(self : Client, destination : String, keys : Array[String]) -> Int64 raise RedisErrorasync fn Client::smove(self : Client, source : String, destination : String, m : String) -> Bool raise RedisErrorasync fn Client::spublish(self : Client, channel : String, message : String) -> Int64 raise RedisErrorasync fn Client::srandmembern(self : Client, key : String, count : Int) -> Array[String] raise RedisErrorasync fn Client::srem(self : Client, key : String, members : Array[String]) -> Int64 raise RedisErrorasync fn Client::sscan(self : Client, key : String, cursor : String, pattern? : String, count? : Int) -> (String, Array[String]) raise RedisErrorasync fn Client::sunionstore(self : Client, destination : String, keys : Array[String]) -> Int64 raise RedisErrorasync fn Client::tdigest_add(self : Client, key : String, values : Array[Double]) -> Unit raise RedisErrorasync fn Client::tdigest_byrank(self : Client, key : String, ranks : Array[Int64]) -> Array[Double] raise RedisErrorasync fn Client::tdigest_byrevrank(self : Client, key : String, ranks : Array[Int64]) -> Array[Double] raise RedisErrorasync fn Client::tdigest_cdf(self : Client, key : String, values : Array[Double]) -> Array[Double] raise RedisErrorasync fn Client::tdigest_create(self : Client, key : String, compression? : Int64) -> Unit raise RedisErrorasync fn Client::tdigest_merge(self : Client, destination : String, sources : Array[String], compression? : Int64, overwrite? : Bool) -> Unit raise RedisErrorasync fn Client::tdigest_quantile(self : Client, key : String, quantiles : Array[Double]) -> Array[Double] raise RedisErrorasync fn Client::tdigest_rank(self : Client, key : String, values : Array[Double]) -> Array[Int64] raise RedisErrorasync fn Client::tdigest_revrank(self : Client, key : String, values : Array[Double]) -> Array[Int64] raise RedisErrorasync fn Client::tdigest_trimmed_mean(self : Client, key : String, low_cut : Double, high_cut : Double) -> Double raise RedisErrorasync fn Client::topk_add(self : Client, key : String, items : Array[String]) -> Array[String?] raise RedisErrorasync fn Client::topk_count(self : Client, key : String, items : Array[String]) -> Array[Int64] raise RedisErrorasync fn Client::topk_incrby(self : Client, key : String, items : Array[(String, Int64)]) -> Array[String?] raise RedisErrorasync fn Client::topk_list_with_count(self : Client, key : String) -> Array[(String, Int64)] raise RedisErrorasync fn Client::topk_query(self : Client, key : String, items : Array[String]) -> Array[Bool] raise RedisErrorasync fn Client::topk_reserve(self : Client, key : String, topk : Int64, width? : Int64, depth? : Int64, decay? : Double) -> Unit raise RedisErrorasync fn Client::ts_add(self : Client, key : String, timestamp : Int64, value : Double, retention? : Int64, uncompressed? : Bool, chunk_size? : Int64, on_duplicate? : String, labels? : Array[(String, String)]) -> Int64 raise RedisErrorasync fn Client::ts_alter(self : Client, key : String, retention? : Int64, chunk_size? : Int64, duplicate_policy? : String, ignore_max_time_diff? : Int64, ignore_max_val_diff? : Double, labels? : Array[(String, String)]) -> Unit raise RedisErrorasync fn Client::ts_create(self : Client, key : String, retention? : Int64, uncompressed? : Bool, chunk_size? : Int64, duplicate_policy? : String, ignore_max_time_diff? : Int64, ignore_max_val_diff? : Double, labels? : Array[(String, String)]) -> Unit raise RedisErrorasync fn Client::ts_createrule(self : Client, source : String, destination : String, aggregator : String, bucket : Int64, align_timestamp? : Int64) -> Unit raise RedisErrorasync fn Client::ts_decrby(self : Client, key : String, value : Double, timestamp? : Int64, retention? : Int64, uncompressed? : Bool, chunk_size? : Int64, duplicate_policy? : String, labels? : Array[(String, String)]) -> Int64 raise RedisErrorasync fn Client::ts_del(self : Client, key : String, from_ : String, to : String) -> Int64 raise RedisErrorasync fn Client::ts_deleterule(self : Client, source : String, destination : String) -> Unit raise RedisErrorasync fn Client::ts_incrby(self : Client, key : String, value : Double, timestamp? : Int64, retention? : Int64, uncompressed? : Bool, chunk_size? : Int64, duplicate_policy? : String, labels? : Array[(String, String)]) -> Int64 raise RedisErrorasync fn Client::ts_madd(self : Client, samples : Array[(String, Int64, Double)]) -> Array[Int64?] raise RedisErrorasync fn Client::ts_mget(self : Client, filters : Array[String], options? : MultiGetOptions) -> Array[Series] raise RedisErrorasync fn Client::ts_mrange(self : Client, from_ : TimeBound, to : TimeBound, filters : Array[String], options? : MultiRangeOptions) -> Array[Series] raise RedisErrorasync fn Client::ts_mrevrange(self : Client, from_ : TimeBound, to : TimeBound, filters : Array[String], options? : MultiRangeOptions) -> Array[Series] raise RedisErrorasync fn Client::ts_nrange(self : Client, keys : Array[String], from_ : TimeBound, to : TimeBound, options? : RangeOptions) -> Array[PivotRow] raise RedisErrorasync fn Client::ts_nrevrange(self : Client, keys : Array[String], from_ : TimeBound, to : TimeBound, options? : RangeOptions) -> Array[PivotRow] raise RedisErrorasync fn Client::ts_queryindex(self : Client, filters : Array[String]) -> Array[String] raise RedisErrorasync fn Client::ts_querylabel_values(self : Client, label : String, filters? : Array[String]) -> Array[String] raise RedisErrorasync fn Client::ts_querylabels(self : Client, filters? : Array[String]) -> Array[String] raise RedisErrorasync fn Client::ts_range(self : Client, key : String, from_ : TimeBound, to : TimeBound, options? : RangeOptions) -> Array[Sample] raise RedisErrorasync fn Client::ts_read(self : Client, key : String, timestamp : Int64, block? : (Int64, Int64), max_count? : Int64) -> Array[Sample] raise RedisErrorasync fn Client::ts_revrange(self : Client, key : String, from_ : TimeBound, to : TimeBound, options? : RangeOptions) -> Array[Sample] raise RedisErrorasync fn Client::xack(self : Client, key : String, group : String, ids : Array[String]) -> Int64 raise RedisErrorasync fn Client::xadd(self : Client, key : String, id : String, fields : Array[(String, String)], maxlen? : Int64, approx? : Bool) -> String raise RedisErrorasync fn Client::xgroup_create(self : Client, key : String, group : String, id : String, mkstream? : Bool) -> Unit raise RedisErrorasync fn Client::xgroup_createconsumer(self : Client, key : String, group : String, consumer : String) -> Bool raise RedisErrorasync fn Client::xgroup_delconsumer(self : Client, key : String, group : String, consumer : String) -> Int64 raise RedisErrorasync fn Client::xgroup_destroy(self : Client, key : String, group : String) -> Bool raise RedisErrorasync fn Client::xpending(self : Client, key : String, group : String) -> PendingSummary raise RedisErrorasync fn Client::xrange(self : Client, key : String, start : String, end : String, count? : Int) -> Array[StreamEntry] raise RedisErrorasync fn Client::xread(self : Client, streams : Array[(String, String)], count? : Int, block? : Int64) -> Array[(String, Array[StreamEntry])]? raise RedisErrorasync fn Client::xreadgroup(self : Client, group : String, consumer : String, streams : Array[(String, String)], count? : Int, block? : Int64, noack? : Bool) -> Array[(String, Array[StreamEntry])]? raise RedisErrorasync fn Client::xrevrange(self : Client, key : String, end : String, start : String, count? : Int) -> Array[StreamEntry] raise RedisErrorasync fn Client::xtrim(self : Client, key : String, maxlen : Int64, approx? : Bool) -> Int64 raise RedisErrorasync fn Client::zadd(self : Client, key : String, members : Array[(String, Double)], nx? : Bool, xx? : Bool, ch? : Bool) -> Int64 raise RedisErrorasync fn Client::zcount(self : Client, key : String, min : String, max : String) -> Int64 raise RedisErrorasync fn Client::zincrby(self : Client, key : String, increment : Double, m : String) -> Double raise RedisErrorasync fn Client::zinterstore(self : Client, destination : String, keys : Array[String], weights? : Array[Double], aggregate? : String) -> Int64 raise RedisErrorasync fn Client::zmscore(self : Client, key : String, members : Array[String]) -> Array[Double?] raise RedisErrorasync fn Client::zpopmax(self : Client, key : String, count? : Int) -> Array[(String, Double)] raise RedisErrorasync fn Client::zpopmin(self : Client, key : String, count? : Int) -> Array[(String, Double)] raise RedisErrorasync fn Client::zrandmember(self : Client, key : String, count? : Int) -> Array[String] raise RedisErrorasync fn Client::zrandmember_scores(self : Client, key : String, count : Int) -> Array[(String, Double)] raise RedisErrorasync fn Client::zrange(self : Client, key : String, start : Int, stop : Int) -> Array[String] raise RedisErrorasync fn Client::zrange_scores(self : Client, key : String, start : Int, stop : Int) -> Array[(String, Double)] raise RedisErrorasync fn Client::zrangebyscore(self : Client, key : String, min : String, max : String, offset? : Int, count? : Int) -> Array[String] raise RedisErrorasync fn Client::zrangebyscore_scores(self : Client, key : String, min : String, max : String, offset? : Int, count? : Int) -> Array[(String, Double)] raise RedisErrorasync fn Client::zrem(self : Client, key : String, members : Array[String]) -> Int64 raise RedisErrorasync fn Client::zremrangebyrank(self : Client, key : String, start : Int, stop : Int) -> Int64 raise RedisErrorasync fn Client::zremrangebyscore(self : Client, key : String, min : String, max : String) -> Int64 raise RedisErrorasync fn Client::zrevrange(self : Client, key : String, start : Int, stop : Int) -> Array[String] raise RedisErrorasync fn Client::zrevrange_scores(self : Client, key : String, start : Int, stop : Int) -> Array[(String, Double)] raise RedisErrorasync fn Client::zrevrangebyscore(self : Client, key : String, max : String, min : String, offset? : Int, count? : Int) -> Array[String] raise RedisErrorasync fn Client::zrevrangebyscore_scores(self : Client, key : String, max : String, min : String, offset? : Int, count? : Int) -> Array[(String, Double)] raise RedisErrorasync fn Client::zscan(self : Client, key : String, cursor : String, pattern? : String, count? : Int) -> (String, Array[String]) raise RedisErrorasync fn Client::zunionstore(self : Client, destination : String, keys : Array[String], weights? : Array[Double], aggregate? : String) -> Int64 raise RedisErrorpub(all) struct ClientOptions {
host : String
port : Int
username : String?
password : String?
db : Int
protocol : Protocol
tls : Client?
connect_timeout : Int64
read_timeout : Int64
write_timeout : Int64
pool : PoolOptions
retry : RetryOptions
tracking : TrackingOptions
}fn ClientOptions::with_auth(self : ClientOptions, username : String?, password : String?) -> ClientOptionspub struct ClusterClient {
nodes : Map[String, &RedisConn]
topology : ClusterTopology
limit : Int
dial : async (String) -> &RedisConn raise RedisError?
}async fn ClusterClient::command(self : ClusterClient, args : Array[Bytes]) -> RespValue raise RedisErrorfn ClusterClient::new(nodes : Array[(String, &RedisConn)], topology : ClusterTopology, limit? : Int, dial? : async (String) -> &RedisConn raise RedisError) -> ClusterClientpub struct ClusterSlot {
start : Int
end : Int
node : String
}pub(all) struct CompactionRule {
destination : String
bucket : Int64
aggregator : String
}pub(all) struct GeoFilter {
field : String
longitude : Double
latitude : Double
radius : Double
unit : String
}pub(all) struct IndexField {
identifier : String
attribute : String
type_ : String
sortable : Bool
unf : Bool
noindex : Bool
weight : Double
}pub(all) struct IndexInfo {
name : String
key_type : String
prefixes : Array[String]
filter : String?
default_score : Double
num_docs : Int64
max_doc_id : Int64
num_terms : Int64
num_records : Int64
indexing : Bool
percent_indexed : Double
indexing_failures : Int64
attributes : Array[IndexField]
}pub struct Message {
kind : String
channel : String
payload : Bytes
pattern : String?
count : Int64
}pub(all) struct MultiRangeOptions {
range : RangeOptions
with_labels : Bool
select_labels : Array[String]
group_by : String?
reduce : String?
exclude_empty : Bool
}pub(all) struct NumericFilter {
field : String
min : String
max : String
}pub struct PendingSummary {
count : Int64
min_id : String?
max_id : String?
consumers : Array[(String, Int64)]
}pub(all) struct PoolOptions {
max_idle : Int
max_active : Int
min_idle : Int
idle_timeout : Int64
health_check : Bool
}pub(all) enum Protocol {
Resp2
Resp3
}pub(all) struct RangeOptions {
latest : Bool
filter_by_ts : Array[Int64]
filter_by_value : (Double, Double)?
count : Int64
aggregation : String?
bucket : Int64
align : String?
bucket_timestamp : String?
empty : Bool
}pub struct RetryConn {
inner : &RedisConn
retry : RetryOptions
dial : async () -> &RedisConn raise RedisError?
wait : async (Int64) -> Unit noraise?
}fn RetryConn::new(inner : &RedisConn, retry : RetryOptions, dial? : async () -> &RedisConn raise RedisError, wait? : async (Int64) -> Unit noraise) -> RetryConnpub(all) struct RetryOptions {
attempts : Int
base_delay : Int64
max_delay : Int64
level : Int
jitter : Bool
}pub(all) struct Schema {
on : IndexKind
prefixes : Array[String]
filter : String?
language : String?
language_field : String?
score : Double?
score_field : String?
temporary : Int64?
stopwords : Array[String]?
fields : Array[SchemaField]
}pub(all) struct SchemaField {
name : String
kind : SchemaKind
as_ : String?
sortable : Bool
unf : Bool
noindex : Bool
weight : Double?
separator : String?
case_sensitive : Bool
phonetic : String?
no_stem : Bool
with_suffix_trie : Bool
index_empty : Bool
index_missing : Bool
vector : VectorSpec?
}fn SchemaField::geo(name : String, as_? : String, sortable? : Bool, unf? : Bool, noindex? : Bool, index_empty? : Bool, index_missing? : Bool) -> SchemaFieldfn SchemaField::numeric(name : String, as_? : String, sortable? : Bool, unf? : Bool, noindex? : Bool, index_empty? : Bool, index_missing? : Bool) -> SchemaFieldfn SchemaField::tag(name : String, as_? : String, separator? : String, case_sensitive? : Bool, sortable? : Bool, unf? : Bool, noindex? : Bool, with_suffix_trie? : Bool, index_empty? : Bool, index_missing? : Bool) -> SchemaFieldfn SchemaField::text(name : String, as_? : String, sortable? : Bool, unf? : Bool, noindex? : Bool, weight? : Double, phonetic? : String, no_stem? : Bool, with_suffix_trie? : Bool, index_empty? : Bool, index_missing? : Bool) -> SchemaFieldfn SchemaField::vector(name : String, spec : VectorSpec, as_? : String, sortable? : Bool, noindex? : Bool) -> SchemaFieldpub struct Script {
source : String
// private fields
}pub(all) struct SearchOptions {
nocontent : Bool
verbatim : Bool
with_scores : Bool
with_payloads : Bool
with_sort_keys : Bool
return_fields : Array[String]
highlight : Array[String]
summarize : Summarize?
sort_by : SortKey?
offset : Int64
limit : Int64
dialect : Int?
params : Array[(String, Bytes)]
timeout : Int64?
in_keys : Array[String]
in_fields : Array[String]
filter : NumericFilter?
geo_filter : GeoFilter?
scorer : String?
slop : Int64?
language : String?
explain_score : Bool
}pub(all) struct SortKey {
field : String
ascending : Bool
}pub(all) struct Summarize {
fields : Array[String]
fragments : Int64?
length : Int64?
separator : String?
}pub(all) struct TrackingOptions {
enabled : Bool
bcast : Bool
optin : Bool
optout : Bool
noloop : Bool
redirect : Int64?
}pub(all) struct TsInfo {
total_samples : Int64
memory_usage : Int64
first_timestamp : Int64
last_timestamp : Int64
retention_millis : Int64
chunk_count : Int64
chunk_size : Int64
chunk_type : String
duplicate_policy : String
labels : Array[(String, String)]
source_key : String?
rules : Array[CompactionRule]
ignore_max_time_diff : Int64
ignore_max_val_diff : Double
}pub(all) struct VectorSpec {
algorithm : VectorAlgorithm
dim : Int
element : String
distance : String
initial_cap : Int64?
block_size : Int64?
m : Int64?
ef_construction : Int64?
ef_runtime : Int64?
epsilon : Double?
}fn VectorSpec::flat(dim : Int, element? : String, distance? : String, initial_cap? : Int64, block_size? : Int64) -> VectorSpecfn VectorSpec::hnsw(dim : Int, element? : String, distance? : String, initial_cap? : Int64, m? : Int64, ef_construction? : Int64, ef_runtime? : Int64, epsilon? : Double) -> VectorSpecfn crc16(data : Bytes) -> Intfn hash_slot(key : String) -> Intfn is_cluster_down(msg : String) -> Boolfn is_noscript(msg : String) -> Boollet redirect_limit : IntInstall
Download zipA Redis client for MoonBit: RESP2 and RESP3, pipelines, transactions, pub/sub, cluster and sentinel.