moonredis

    A Redis client for MoonBit: RESP2 and RESP3, pipelines, transactions, pub/sub, cluster and sentinel.

    redis
    resp
    client
    moonbit
    Download zip
    Version
    0.1.1
    License
    Apache-2.0
    Last updated
    6 hours ago
    Downloads
    17

    #moonredis

    A Redis client for MoonBit. It speaks RESP2 and RESP3, covers the command families, and carries the pieces a real deployment needs: a connection pool, retries, TLS, ACL auth, pipelines, transactions, pub/sub (including sharded), client-side caching, cluster routing and sentinel discovery. The protocol and command surface build on every backend; the socket transport runs on native and wasm.

    #Install

    moon add moonbitstack/moonredis

    moon.mod gains moonbitstack/moonredis. The protocol codec is the moonredis/resp package; the client, its command surface and the routing pieces are the root moonredis package; the socket transport is moonredis/socket.

    #Quick start

    async 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)")
    }
    }

    Connection::connect dials, negotiates the protocol with HELLO, authenticates with AUTH when credentials are set, SELECTs the database, and turns on CLIENT TRACKING when asked. A Client wraps any RedisConn; FakeConn is an in-memory one for tests.

    #Interface

    #Client and connection

    ItemPurpose
    ClientThe 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.
    FakeConnA scripted in-memory connection for tests (new, handler).
    RedisErrorReply(msg) for a redis error, Connection(msg), Closed, Protocol(msg), and Aborted for a transaction a watched key changed under.

    #Configuration

    ItemPurpose
    ClientOptionsEndpoint, credentials, protocol, timeouts, and the pool/retry/tracking policies.
    ClientOptions::at(host, port)Options at an address over the standard defaults.
    ClientOptions::with_auth(user?, password?), with_db(db)Copies with auth or database set.
    client_default, pool_default, retry_default, tracking_defaultThe market-standard presets.
    ProtocolResp2 or Resp3 (the default).
    PoolOptionsmax_idle, max_active, min_idle, idle_timeout, health_check.
    RetryOptionsattempts, base_delay, max_delay, level, jitter.
    TrackingOptionsenabled, bcast, optin, optout, noloop, redirect.
    backoff_delay(attempt, retry)The wait before a retry.

    #Batching and routing

    ItemPurpose
    PipelineQueue commands (add) and send them in one round trip (execute); multi wraps them in MULTI/EXEC.
    Client::watch, Client::unwatch, Client::discardTransaction control.
    ClusterTopologyA slot-to-node map; node_for_slot(slot).
    ClusterSlot, ClusterSlot::newA slot range owned by a node.
    ClusterClientRoutes 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.
    SentinelClientResolve 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.

    #Pub/sub and values

    ItemPurpose
    MessageA pub/sub frame: kind, channel, payload, pattern, count.
    Message::parse(value)Parse a RESP2 array or RESP3 push frame into a Message.
    StreamEntryOne stream entry: id and fields.
    PendingSummaryThe XPENDING summary: count, min_id, max_id, consumers.

    #Socket transport (moonredis/socket, native and wasm)

    ItemPurpose
    ConnectionA 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.
    PoolReuse idle connections (get, put, idle_count), bounded by max_idle.
    Subscriptionsubscribe/unsubscribe and next for Message frames; pattern and shard select PSUBSCRIBE and SSUBSCRIBE.

    #Codec (moonredis/resp)

    ItemPurpose
    RespValueEvery 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).
    RespReaderStream 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.

    The command methods also expose the small builders and decoders they use — arg_string, arg_int, arg_int64, arg_double, arg_bytes, push_some; expect_int64, expect_bool, expect_bytes, expect_string, expect_string_value, expect_array, expect_double, expect_map; status_ok — so a caller can compose a command or decode a reply by hand.

    #Commands

    One async method per command, named as in redis-py. Two helpers where MoonBit needs a name that redis uses as a keyword: type_ for TYPE and move_ for MOVE.

    FamilyMethods
    Stringset, set_get, setnx, setex, psetex, get, mget, mset, append, strlen, incr, incrby, decr, decrby, getrange, setrange, getdel, getex
    Keydel, 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
    Hashhset, hsetnx, hmset, hget, hmget, hgetall, hdel, hexists, hlen, hstrlen, hincrby, hincrbyfloat, hkeys, hvals, hscan, hrandfield
    Listlpush, rpush, lpushx, rpushx, lpop, lpopn, rpop, rpopn, llen, lindex, lrange, lset, lrem, linsert, ltrim, rpoplpush, lmove, blpop, brpop, brpoplpush, blmove
    Setsadd, srem, smembers, sismember, scard, spop, spopn, srandmember, srandmembern, sinter, sunion, sdiff, sinterstore, sunionstore, sdiffstore, smove, sscan
    Sorted setzadd, 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
    Streamxadd, xlen, xdel, xtrim, xrange, xrevrange, xread, xack, xgroup_create, xgroup_destroy, xgroup_createconsumer, xgroup_delconsumer, xreadgroup, xpending
    HyperLogLogpfadd, pfcount, pfmerge
    Geogeoadd, geodist, geohash, geopos, geosearch
    Bitmapsetbit, getbit, bitcount, bitpos, bitop
    Script / functionScript 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/subpublish, spublish, subscribe, unsubscribe, psubscribe, punsubscribe, ssubscribe, sunsubscribe
    Server / connectionping, 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

    #Pipelines and transactions

    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]

    Call pipeline.multi() before execute to wrap the queued commands in MULTI/EXEC, so redis runs them atomically. Client::watch/unwatch/discard are available for optimistic locking around a transaction: when a watched key changes first, execute raises Aborted and nothing ran. An error reply inside a plain pipeline is one reply among the others.

    #Pub/sub

    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 => ()
    }

    ssubscribe/spublish are the sharded forms, routed to one cluster shard.

    #Cluster and sentinel

    ClusterClient routes each command to the node owning the key's slot (from hash_slot/crc16, honouring {hash tags}) and follows a MOVED/ASK redirect once. ClusterTopology comes from decode_cluster_slots, and same_slot checks that a multi-key command's keys colocate. SentinelClient resolves a master address by asking sentinels in turn.

    #Service discovery

    moonredis/sd implements the moonsd contract on Redis. An endpoint is a key that expires, so an instance that stops renewing leaves by itself. Redis reports expiry only on a best-effort channel, so a watcher reads the service again every poll milliseconds.

    let registry = @sd.Registry::new(client)
    group.spawn_bg(() => @moonsd.hold(registry, "greeter", @moonsd.Endpoint::new("10.0.0.1", 12000)))
    let endpoints = registry.resolve("greeter")

    Registry::new takes prefix, default moonsd, and poll, default 1000. Any number of tasks may share one registry. Give it a client of its own: its lock orders its own commands, not those of anything else on that connection. A service's keys share a hash tag, so they stay in one cluster slot.

    #Pool and retries

    @socket.Pool reuses idle connections up to PoolOptions.max_idle. RetryConn retries a transport failure up to RetryOptions.attempts, while a redis error reply surfaces immediately; backoff_delay/should_retry expose the policy.

    #Examples

    ExampleRun
    01-respmoon run src/examples/01-resp — the codec, no server.
    02-commandsmoon run src/examples/02-commands — typed commands against a fake.
    03-connectmoon run src/examples/03-connect --target native — a real connection.
    04-pipelinemoon run src/examples/04-pipeline --target native — one round trip, and a transaction that loses a race.
    05-pubsubmoon run src/examples/05-pubsub --target native — a pattern subscription.
    06-clustermoon run src/examples/06-cluster --target native — keys routed by slot.

    #Testing

    The codec and command surface are tested against FakeConn with no network, so they run on every backend. src/integration runs every command family against a real server under both protocols, and covers transactions losing a race, redirects, a slot migrating, a failover and a connection killed underneath. scripts/start_redis.sh starts what those tests connect to: a standalone redis, a six-node cluster, and a master and replica under a sentinel. Without servers the tests return early; with MOONREDIS_LIVE set, as in CI, a missing server fails them.

    #Licence

    Apache-2.0.

    RedisConn

    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 = _
    }

    A live redis connection: it sends an encoded command (an array of argument byte strings) and returns the decoded reply. Implementations own the transport — a real socket speaking RESP, or an in-memory fake. It is open and async so a socket can be one: real redis I/O suspends, and a sealed synchronous trait left every implementation a test double.

    RedisError

    pub(all) suberror RedisError {
    Reply(String)
    Connection(String)
    Protocol(String)
    Closed
    Aborted
    } derive(Eq,
    Debug
    )

    Why a redis call failed: a redis error reply, a transport failure, a closed connection, a reply the client could not interpret as the command promised, or a transaction a watched key changed under.

    RedisError::equal

    fn RedisError::equal(RedisError, RedisError) -> Bool

    RedisError::not_equal

    fn RedisError::not_equal(x : RedisError, y : RedisError) -> Bool

    Client

    pub struct Client {
    conn : &RedisConn
    }

    A redis client over a RedisConn: the typed command families are methods on it, and command is the general entry when a caller wants to send raw argument bytes.

    Client::append

    async fn Client::append(self : Client, key : String, value : String) -> Int64 raise RedisError

    APPEND key value: append value to key, returning the new length in bytes.

    Client::auth

    async fn Client::auth(self : Client, password : String) -> Unit raise RedisError

    AUTH password: authenticate with the default user.

    Client::auth_user

    async fn Client::auth_user(self : Client, username : String, password : String) -> Unit raise RedisError

    AUTH user password: authenticate with a named ACL account.

    Client::bgrewriteaof

    async fn Client::bgrewriteaof(self : Client) -> String raise RedisError

    BGREWRITEAOF: start a background rewrite of the append-only file.

    Client::bgsave

    async fn Client::bgsave(self : Client) -> String raise RedisError

    BGSAVE: start a background save, returning the status line.

    Client::bitcount

    async fn Client::bitcount(self : Client, key : String, start? : Int, end? : Int) -> Int64 raise RedisError

    BITCOUNT key [start end]: the number of set bits, optionally within a byte range.

    Client::bitop

    async fn Client::bitop(self : Client, op : String, destination : String, keys : Array[String]) -> Int64 raise RedisError

    BITOP op dest key...: store the bitwise AND/OR/XOR of the keys, or the NOT of a single key, in dest, returning the result length in bytes.

    Client::bitpos

    async fn Client::bitpos(self : Client, key : String, bit : Int, start? : Int, end? : Int) -> Int64 raise RedisError

    BITPOS key bit [start end]: the first bit equal to bit (0 or 1), optionally within a byte range. -1 if none is found.

    Client::blmove

    async fn Client::blmove(self : Client, source : String, destination : String, wherefrom : String, whereto : String, timeout : Int) -> Bytes? raise RedisError

    BLMOVE source destination wherefrom whereto timeout: blocking LMOVE.

    Client::blpop

    async fn Client::blpop(self : Client, keys : Array[String], timeout : Int) -> (String, Bytes)? raise RedisError

    BLPOP key... timeout: blocking pop of the first available head element across the given keys, waiting up to timeout seconds (0 = forever). Returns the key and value, or None on timeout.

    Client::brpop

    async fn Client::brpop(self : Client, keys : Array[String], timeout : Int) -> (String, Bytes)? raise RedisError

    BRPOP key... timeout: blocking pop of the first available tail element across the given keys. Returns the key and value, or None on timeout.

    Client::brpoplpush

    async fn Client::brpoplpush(self : Client, source : String, destination : String, timeout : Int) -> Bytes? raise RedisError

    BRPOPLPUSH source destination timeout: blocking RPOPLPUSH.

    Client::bzpopmax

    async fn Client::bzpopmax(self : Client, keys : Array[String], timeout : Int) -> (String, String, Double)? raise RedisError

    BZPOPMAX key... timeout: blocking pop of the highest-scoring member across keys.

    Client::bzpopmin

    async fn Client::bzpopmin(self : Client, keys : Array[String], timeout : Int) -> (String, String, Double)? raise RedisError

    BZPOPMIN key... timeout: blocking pop of the lowest-scoring member across keys. Returns (key, member, score), or None on timeout.

    Client::client_getname

    async fn Client::client_getname(self : Client) -> String? raise RedisError

    CLIENT GETNAME: this connection's name, or None if unset.

    Client::client_id

    async fn Client::client_id(self : Client) -> Int64 raise RedisError

    CLIENT ID: this connection's numeric id.

    Client::client_kill

    async fn Client::client_kill(self : Client, filters : Array[String]) -> Int64 raise RedisError

    CLIENT KILL [ID id] [ADDR host:port] [TYPE ...] [SKIPME yes/no]: close matching client connections.

    Client::client_setname

    async fn Client::client_setname(self : Client, name : String) -> Unit raise RedisError

    CLIENT SETNAME name: label this connection in CLIENT LIST.

    Client::cluster_slots

    CLUSTER SLOTS: the cluster's slot map, as the raw reply (each caller decodes it).

    Client::command

    async fn Client::command(self : Client, args : Array[Bytes]) ->
    RespValue
    raise RedisError

    Send args as a command and return the reply, turning a redis error reply (-ERR or a bulk error) into RedisError::Reply. A transport failure raises from execute as a Connection or Closed error, unchanged.

    Client::command_count

    async fn Client::command_count(self : Client) -> Int64 raise RedisError

    COMMAND COUNT: the number of commands the server implements.

    Client::config_get

    async fn Client::config_get(self : Client, parameter : String) -> Array[(String, String)] raise RedisError

    CONFIG GET parameter: the current value(s) of a config parameter (which may match several via a glob), as alternating name/value pairs.

    Client::config_resetstat

    async fn Client::config_resetstat(self : Client) -> Unit raise RedisError

    CONFIG RESETSTAT: reset the server's statistics counters.

    Client::config_rewrite

    async fn Client::config_rewrite(self : Client) -> Unit raise RedisError

    CONFIG REWRITE: persist the running config to the config file.

    Client::config_set

    async fn Client::config_set(self : Client, parameter : String, value : String) -> Unit raise RedisError

    CONFIG SET parameter value: change a config parameter at runtime.

    Client::copy

    async fn Client::copy(self : Client, source : String, destination : String, db? : Int, replace? : Bool) -> Bool raise RedisError

    COPY source destination [DB n] [REPLACE]: copy source to destination. true if copied.

    Client::dbsize

    async fn Client::dbsize(self : Client) -> Int64 raise RedisError

    DBSIZE: the number of keys in the selected database.

    Client::decr

    async fn Client::decr(self : Client, key : String) -> Int64 raise RedisError

    DECR key: decrement key's integer value by 1, returning the result.

    Client::decrby

    async fn Client::decrby(self : Client, key : String, n : Int64) -> Int64 raise RedisError

    DECRBY key n: subtract n from key's integer value, returning the result.

    Client::del

    async fn Client::del(self : Client, keys : Array[String]) -> Int64 raise RedisError

    DEL key...: delete the given keys, returning how many existed.

    Client::discard

    async fn Client::discard(self : Client) -> Unit raise RedisError

    DISCARD: abort a transaction started with MULTI.

    Client::dump

    async fn Client::dump(self : Client, key : String) -> Bytes? raise RedisError

    DUMP key: serialise key's value to a binary dump, or None if the key is absent.

    Client::echo

    async fn Client::echo(self : Client, message : String) -> Bytes raise RedisError

    ECHO message: return message unchanged (a larger round-trip probe than PING).

    Client::eval

    async fn Client::eval(self : Client, script : String, keys : Array[String], args : Array[String]) ->
    RespValue
    raise RedisError

    EVAL script numkeys key... arg...: run script, declaring how many of the leading arguments are keys. Returns the script's (arbitrary) reply.

    Client::evalsha

    async fn Client::evalsha(self : Client, sha : String, keys : Array[String], args : Array[String]) ->
    RespValue
    raise RedisError

    EVALSHA sha numkeys key... arg...: run a script by its SCRIPT LOAD digest.

    Client::exists

    async fn Client::exists(self : Client, keys : Array[String]) -> Int64 raise RedisError

    EXISTS key...: the number of the given keys that exist.

    Client::expire

    async fn Client::expire(self : Client, key : String, seconds : Int64) -> Bool raise RedisError

    EXPIRE key secs: set a secs-second expiry on key. false if the key is absent.

    Client::expireat

    async fn Client::expireat(self : Client, key : String, timestamp : Int64) -> Bool raise RedisError

    EXPIREAT key ts: expire key at the given Unix second. false if the key is absent.

    Client::flushall

    async fn Client::flushall(self : Client, sync? : Bool) -> Unit raise RedisError

    FLUSHALL [ASYNC|SYNC]: delete every key in every database.

    Client::flushdb

    async fn Client::flushdb(self : Client, sync? : Bool) -> Unit raise RedisError

    FLUSHDB [ASYNC|SYNC]: delete every key in the selected database.

    Client::function_call

    async fn Client::function_call(self : Client, function : String, keys : Array[String], args : Array[String]) ->
    RespValue
    raise RedisError

    FCALL function numkeys key... arg...: call a registered function.

    Client::function_delete

    async fn Client::function_delete(self : Client, name : String) -> Unit raise RedisError

    FUNCTION DELETE name: delete a function library by name.

    Client::function_flush

    async fn Client::function_flush(self : Client) -> Unit raise RedisError

    FUNCTION FLUSH: discard every registered function library.

    Client::function_load

    async fn Client::function_load(self : Client, code : String, replace? : Bool) -> String raise RedisError

    FUNCTION LOAD [REPLACE] code: register a functions library, returning its name.

    Client::geoadd

    async fn Client::geoadd(self : Client, key : String, points : Array[(String, Double, Double)]) -> Int64 raise RedisError

    GEOADD key longitude latitude member...: index the members, returning how many were new.

    Client::geodist

    async fn Client::geodist(self : Client, key : String, a : String, b : String, unit? : String) -> Double? raise RedisError

    GEODIST key a b [unit]: the distance between members a and b, or None if a member is absent. unit is one of m, km, mi, ft (metres by default).

    Client::geohash

    async fn Client::geohash(self : Client, key : String, members : Array[String]) -> Array[String?] raise RedisError

    GEOHASH key member...: the geohash string of each member, None where absent.

    Client::geopos

    async fn Client::geopos(self : Client, key : String, members : Array[String]) -> Array[(Double, Double)?] raise RedisError

    GEOPOS key member...: the [longitude, latitude] of each member, None where absent.

    Client::geosearch

    async 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 RedisError

    GEOSEARCH key [FROMMEMBER m] [FROMLONLAT lon lat] [BYRADIUS r unit] [BYBOX w h unit][COUNT n] [ASC|DESC]: the members matching a circular or rectangular area, optionally ordered and capped. Returns the member names.

    Client::get

    async fn Client::get(self : Client, key : String) -> Bytes? raise RedisError

    GET key: the value at key, or None if absent or expired.

    Client::getbit

    async fn Client::getbit(self : Client, key : String, offset : Int64) -> Int64 raise RedisError

    GETBIT key offset: the bit at offset (0 or 1).

    Client::getdel

    async fn Client::getdel(self : Client, key : String) -> Bytes? raise RedisError

    GETDEL key: return key's value and delete the key, or None if absent.

    Client::getex

    async fn Client::getex(self : Client, key : String, ex? : Int64, px? : Int64, exat? : Int64, pxat? : Int64, persist? : Bool) -> Bytes? raise RedisError

    GETEX key [EX secs] [PX ms] [EXAT secs] [PXAT ms] [PERSIST]: return key's value and apply or clear its expiry, or None if absent.

    Client::getrange

    async fn Client::getrange(self : Client, key : String, start : Int, end : Int) -> Bytes raise RedisError

    GETRANGE key start end: the substring of key from start to end (inclusive, negative from the end).

    Client::hdel

    async fn Client::hdel(self : Client, key : String, fields : Array[String]) -> Int64 raise RedisError

    HDEL key field...: delete the given fields, returning how many existed.

    Client::hexists

    async fn Client::hexists(self : Client, key : String, field : String) -> Bool raise RedisError

    HEXISTS key field: whether field exists in the hash.

    Client::hget

    async fn Client::hget(self : Client, key : String, field : String) -> Bytes? raise RedisError

    HGET key field: the value at field, or None if the key or field is absent.

    Client::hgetall

    async fn Client::hgetall(self : Client, key : String) -> Array[(String, String)] raise RedisError

    HGETALL key: every field/value pair as an array of alternating field, value.

    Client::hincrby

    async fn Client::hincrby(self : Client, key : String, field : String, n : Int64) -> Int64 raise RedisError

    HINCRBY key field n: add n to field's integer value, returning the result.

    Client::hincrbyfloat

    async fn Client::hincrbyfloat(self : Client, key : String, field : String, f : Double) -> Double raise RedisError

    HINCRBYFLOAT key field f: add f to field's value, returning the new value.

    Client::hkeys

    async fn Client::hkeys(self : Client, key : String) -> Array[String] raise RedisError

    HKEYS key: the field names of the hash.

    Client::hlen

    async fn Client::hlen(self : Client, key : String) -> Int64 raise RedisError

    HLEN key: the number of fields in the hash.

    Client::hmget

    async fn Client::hmget(self : Client, key : String, fields : Array[String]) -> Array[Bytes?] raise RedisError

    HMGET key field...: the value at each field, None where absent, in order.

    Client::hmset

    async fn Client::hmset(self : Client, key : String, fields : Array[(String, String)]) -> Unit raise RedisError

    HMSET key field value...: set several fields atomically. Deprecated in favour of HSET but kept for parity with redis-py.

    Client::hrandfield

    async fn Client::hrandfield(self : Client, key : String, count? : Int) -> Array[String] raise RedisError

    HRANDFIELD key [count] [WITHVALUES]: one or more random fields, optionally with their values.

    Client::hrandfield_values

    async fn Client::hrandfield_values(self : Client, key : String, count : Int) -> Array[(String, String)] raise RedisError

    HRANDFIELD key count WITHVALUES: random fields with their values. A negative count may repeat a field.

    Client::hscan

    async fn Client::hscan(self : Client, key : String, cursor : String, pattern? : String, count? : Int) -> (String, Array[(String, String)]) raise RedisError

    HSCAN key cursor [MATCH pattern] [COUNT n]: an incremental hash field scan. Returns the next cursor and the field/value pairs found this call.

    Client::hset

    async fn Client::hset(self : Client, key : String, fields : Array[(String, String)]) -> Int64 raise RedisError

    HSET key field value...: set one or more fields, returning the count of fields that were new.

    Client::hsetnx

    async fn Client::hsetnx(self : Client, key : String, field : String, value : String) -> Bool raise RedisError

    HSETNX key field value: set field only if absent. true if set.

    Client::hstrlen

    async fn Client::hstrlen(self : Client, key : String, field : String) -> Int64 raise RedisError

    HSTRLEN key field: the byte length of field's value (0 if absent).

    Client::hvals

    async fn Client::hvals(self : Client, key : String) -> Array[String] raise RedisError

    HVALS key: the values of the hash.

    Client::incr

    async fn Client::incr(self : Client, key : String) -> Int64 raise RedisError

    INCR key: increment key's integer value by 1, returning the result.

    Client::incrby

    async fn Client::incrby(self : Client, key : String, n : Int64) -> Int64 raise RedisError

    INCRBY key n: add n to key's integer value, returning the result.

    Client::info

    async fn Client::info(self : Client, section? : String) -> String raise RedisError

    INFO [section]: the server's key/value metrics, as the raw text block redis returns.

    Client::keys

    async fn Client::keys(self : Client, pattern : String) -> Array[String] raise RedisError

    KEYS pattern: every key matching pattern. Use scan in production.

    Client::lastsave

    async fn Client::lastsave(self : Client) -> Int64 raise RedisError

    LASTSAVE: the Unix timestamp of the last successful save to disk.

    Client::lindex

    async fn Client::lindex(self : Client, key : String, index : Int) -> Bytes? raise RedisError

    LINDEX key index: the element at index, or None if out of range.

    Client::linsert

    async fn Client::linsert(self : Client, key : String, where_ : String, pivot : String, value : String) -> Int64 raise RedisError

    LINSERT key where pivot value: insert value before (BEFORE) or after (AFTER) pivot. Returns the new length, or -1 when pivot is absent.

    Client::llen

    async fn Client::llen(self : Client, key : String) -> Int64 raise RedisError

    LLEN key: the length of the list.

    Client::lmove

    async fn Client::lmove(self : Client, source : String, destination : String, wherefrom : String, whereto : String) -> Bytes? raise RedisError

    LMOVE source destination LEFT|RIGHT LEFT|RIGHT: pop from one end of source and push to one end of destination, returning the element, or None when empty.

    Client::lpop

    async fn Client::lpop(self : Client, key : String) -> Bytes? raise RedisError

    LPOP key: remove and return the head element, or None when the list is empty.

    Client::lpopn

    async fn Client::lpopn(self : Client, key : String, count : Int) -> Array[Bytes] raise RedisError

    LPOP key count: remove and return up to count head elements.

    Client::lpush

    async fn Client::lpush(self : Client, key : String, values : Array[String]) -> Int64 raise RedisError

    LPUSH key value...: prepend each value, returning the new length.

    Client::lpushx

    async fn Client::lpushx(self : Client, key : String, values : Array[String]) -> Int64 raise RedisError

    LPUSHX key value...: prepend only if key already exists, returning the length.

    Client::lrange

    async fn Client::lrange(self : Client, key : String, start : Int, stop : Int) -> Array[Bytes] raise RedisError

    LRANGE key start stop: the elements from start to stop (inclusive, negative from the tail).

    Client::lrem

    async fn Client::lrem(self : Client, key : String, count : Int, value : String) -> Int64 raise RedisError

    LREM key count value: remove the first count elements equal to value. When count is negative, remove from the tail; when 0, remove all. Returns the removed.

    Client::lset

    async fn Client::lset(self : Client, key : String, index : Int, value : String) -> Unit raise RedisError

    LSET key index value: set the element at index. Raises Reply on a bad index.

    Client::ltrim

    async fn Client::ltrim(self : Client, key : String, start : Int, stop : Int) -> Unit raise RedisError

    LTRIM key start stop: keep only the elements from start to stop.

    Client::mget

    async fn Client::mget(self : Client, keys : Array[String]) -> Array[Bytes?] raise RedisError

    MGET key...: the value at each key, None where a key is absent, in the same order.

    Client::move_

    async fn Client::move_(self : Client, key : String, db : Int) -> Bool raise RedisError

    MOVE key db: move key to another logical database. true if moved.

    Client::mset

    async fn Client::mset(self : Client, pairs : Array[(String, String)]) -> Unit raise RedisError

    MSET key value...: store every pair atomically.

    Client::new

    fn Client::new(conn : &RedisConn) -> Client

    A client over conn.

    Client::object_encoding

    async fn Client::object_encoding(self : Client, key : String) -> String raise RedisError

    OBJECT ENCODING key / OBJECT REFCOUNT key / OBJECT IDLETIME key: inspect a key's internal encoding, reference count, or idle time.

    Client::object_idletime

    async fn Client::object_idletime(self : Client, key : String) -> Int64 raise RedisError

    Client::object_refcount

    async fn Client::object_refcount(self : Client, key : String) -> Int64 raise RedisError

    Client::persist

    async fn Client::persist(self : Client, key : String) -> Bool raise RedisError

    PERSIST key: remove key's expiry. true if a TTL was removed.

    Client::pexpire

    async fn Client::pexpire(self : Client, key : String, milliseconds : Int64) -> Bool raise RedisError

    PEXPIRE key ms: set a ms-millisecond expiry on key. false if the key is absent.

    Client::pexpireat

    async fn Client::pexpireat(self : Client, key : String, milliseconds_timestamp : Int64) -> Bool raise RedisError

    PEXPIREAT key ts: expire key at the given Unix millisecond. false if absent.

    Client::pfadd

    async fn Client::pfadd(self : Client, key : String, values : Array[String]) -> Int64 raise RedisError

    PFADD key value...: register the values, returning 1 if the sketch changed.

    Client::pfcount

    async fn Client::pfcount(self : Client, keys : Array[String]) -> Int64 raise RedisError

    PFCOUNT key...: the approximate cardinality of one key, or the union of several.

    Client::pfmerge

    async fn Client::pfmerge(self : Client, destination : String, sources : Array[String]) -> Unit raise RedisError

    PFMERGE dest src...: merge the source sketches into dest.

    Client::ping

    async fn Client::ping(self : Client) -> String raise RedisError

    PING: a round-trip health check, returning the server's PONG text.

    Client::ping_message

    async fn Client::ping_message(self : Client, message : String) -> String raise RedisError

    PING message: echo message back, confirming the connection.

    Client::psetex

    async fn Client::psetex(self : Client, key : String, milliseconds : Int64, value : String) -> Unit raise RedisError

    PSETEX key ms value: store value at key with a ms-millisecond expiry.

    Client::psubscribe

    async fn Client::psubscribe(self : Client, patterns : Array[String]) -> Unit raise RedisError

    PSUBSCRIBE pattern...: subscribe to channels by glob pattern.

    Client::pttl

    async fn Client::pttl(self : Client, key : String) -> Int64 raise RedisError

    PTTL key: key's remaining time to live in milliseconds.

    Client::publish

    async fn Client::publish(self : Client, channel : String, message : String) -> Int64 raise RedisError

    PUBLISH channel message: post message to channel, returning how many subscribers received it. (Publishing is an ordinary command, not a subscription.)

    Client::punsubscribe

    async fn Client::punsubscribe(self : Client, patterns? : Array[String]) -> Unit raise RedisError

    PUNSUBSCRIBE [pattern...]: unsubscribe from the given patterns, or all when omitted.

    Client::randomkey

    async fn Client::randomkey(self : Client) -> String? raise RedisError

    RANDOMKEY: a random key from the database, or None when the database is empty.

    Client::rename

    async fn Client::rename(self : Client, key : String, newkey : String) -> Unit raise RedisError

    RENAME key newkey: rename key to newkey, replacing newkey if present.

    Client::renamenx

    async fn Client::renamenx(self : Client, key : String, newkey : String) -> Bool raise RedisError

    RENAMENX key newkey: rename key to newkey only if newkey is absent. true if renamed.

    Client::replicaof

    async fn Client::replicaof(self : Client, host : String, port : Int) -> Unit raise RedisError

    REPLICAOF host port: make this server a replica of host:port. Use REPLICAOF NO ONE (via replicaof_noone) to promote it back to a master.

    Client::replicaof_noone

    async fn Client::replicaof_noone(self : Client) -> Unit raise RedisError

    REPLICAOF NO ONE: stop replicating and become a master.

    Client::restore

    async fn Client::restore(self : Client, key : String, ttl : Int64, serialized : Bytes, replace? : Bool, absttl? : Bool) -> Unit raise RedisError

    RESTORE key ttl serialized [REPLACE] [ABSTTL]: restore a DUMP value at key with a ttl-millisecond expiry (0 = no expiry).

    Client::rpop

    async fn Client::rpop(self : Client, key : String) -> Bytes? raise RedisError

    RPOP key: remove and return the tail element, or None when the list is empty.

    Client::rpoplpush

    async fn Client::rpoplpush(self : Client, source : String, destination : String) -> Bytes? raise RedisError

    RPOPLPUSH source destination: pop the tail of source and push it to the head of destination, returning the element, or None when source is empty.

    Client::rpopn

    async fn Client::rpopn(self : Client, key : String, count : Int) -> Array[Bytes] raise RedisError

    RPOP key count: remove and return up to count tail elements.

    Client::rpush

    async fn Client::rpush(self : Client, key : String, values : Array[String]) -> Int64 raise RedisError

    RPUSH key value...: append each value, returning the new length.

    Client::rpushx

    async fn Client::rpushx(self : Client, key : String, values : Array[String]) -> Int64 raise RedisError

    RPUSHX key value...: append only if key already exists, returning the length.

    Client::sadd

    async fn Client::sadd(self : Client, key : String, members : Array[String]) -> Int64 raise RedisError

    SADD key member...: add the members, returning how many were new.

    Client::save

    async fn Client::save(self : Client) -> Unit raise RedisError

    SAVE: synchronously save the dataset to disk (blocks the server).

    Client::scan

    async fn Client::scan(self : Client, cursor : String, pattern? : String, count? : Int, kind? : String) -> (String, Array[String]) raise RedisError

    SCAN cursor [MATCH pattern] [COUNT n] [TYPE kind]: an incremental key scan. Returns the next cursor (the empty string when the scan is done) and the keys found this call.

    Client::scard

    async fn Client::scard(self : Client, key : String) -> Int64 raise RedisError

    SCARD key: the number of members in the set.

    Client::script_exists

    async fn Client::script_exists(self : Client, shas : Array[String]) -> Array[Bool] raise RedisError

    SCRIPT EXISTS sha...: whether each digest is loaded, in order.

    Client::script_flush

    async fn Client::script_flush(self : Client) -> Unit raise RedisError

    SCRIPT FLUSH: discard every loaded script.

    Client::script_load

    async fn Client::script_load(self : Client, script : String) -> String raise RedisError

    SCRIPT LOAD script: register script and return its SHA-1 digest for later EVALSHA.

    Client::sdiff

    async fn Client::sdiff(self : Client, keys : Array[String]) -> Array[String] raise RedisError

    SDIFF key...: the members in the first set absent from the rest.

    Client::sdiffstore

    async fn Client::sdiffstore(self : Client, destination : String, keys : Array[String]) -> Int64 raise RedisError

    SDIFFSTORE destination key...: store the difference of the sets in destination.

    Client::select

    async fn Client::select(self : Client, index : Int) -> Unit raise RedisError

    SELECT index: switch the connection to logical database index.

    Client::sentinel

    async fn Client::sentinel(self : Client, args : Array[String]) ->
    RespValue
    raise RedisError

    SENTINEL ...: send a raw sentinel sub-command (the sub-command name is the first args element), returning the reply.

    Client::sentinel_get_master_addr_by_name

    async fn Client::sentinel_get_master_addr_by_name(self : Client, name : String) -> (String, Int)? raise RedisError

    SENTINEL GET-MASTER-ADDR-BY-NAME name: the current master's (host, port) for the monitored master name, or None if the sentinel does not know it.

    Client::set

    async fn Client::set(self : Client, key : String, value : String, ex? : Int64, px? : Int64, nx? : Bool, xx? : Bool, keepttl? : Bool) -> Bool raise RedisError

    SET key value [EX secs] [PX ms] [NX|XX] [KEEPTTL]: store value at key. Returns false when nx/xx leaves the key unchanged, true otherwise.

    Client::set_get

    async fn Client::set_get(self : Client, key : String, value : String) -> Bytes? raise RedisError

    SET key value GET: store value and return the value key held before, or None if it had none.

    Client::setbit

    async fn Client::setbit(self : Client, key : String, offset : Int64, value : Int) -> Int64 raise RedisError

    SETBIT key offset value: set the bit at offset (0 or 1), returning its previous value (0 or 1).

    Client::setex

    async fn Client::setex(self : Client, key : String, seconds : Int64, value : String) -> Unit raise RedisError

    SETEX key secs value: store value at key with a secs-second expiry.

    Client::setnx

    async fn Client::setnx(self : Client, key : String, value : String) -> Bool raise RedisError

    SETNX key value: store value only if key is absent. true if stored.

    Client::setrange

    async fn Client::setrange(self : Client, key : String, offset : Int, value : String) -> Int64 raise RedisError

    SETRANGE key offset value: overwrite key at offset, returning the new length.

    Client::shutdown

    async fn Client::shutdown(self : Client, save? : Bool) -> Unit raise RedisError

    SHUTDOWN [NOSAVE|SAVE]: stop the server. The call normally raises Closed when the connection drops, rather than returning.

    Client::sinter

    async fn Client::sinter(self : Client, keys : Array[String]) -> Array[String] raise RedisError

    SINTER key...: the members present in every given set.

    Client::sinterstore

    async fn Client::sinterstore(self : Client, destination : String, keys : Array[String]) -> Int64 raise RedisError

    SINTERSTORE destination key...: store the intersection of the sets in destination.

    Client::sismember

    async fn Client::sismember(self : Client, key : String, m : String) -> Bool raise RedisError

    SISMEMBER key member: whether member is in the set.

    Client::slowlog_get

    async fn Client::slowlog_get(self : Client, count? : Int) -> Array[
    RespValue
    ] raise RedisError

    SLOWLOG GET [count]: the most recent slow commands the server logged.

    Client::slowlog_len

    async fn Client::slowlog_len(self : Client) -> Int64 raise RedisError

    SLOWLOG LEN: the number of entries in the slow log.

    Client::slowlog_reset

    async fn Client::slowlog_reset(self : Client) -> Unit raise RedisError

    SLOWLOG RESET: clear the slow log.

    Client::smembers

    async fn Client::smembers(self : Client, key : String) -> Array[String] raise RedisError

    SMEMBERS key: every member of the set.

    Client::smove

    async fn Client::smove(self : Client, source : String, destination : String, m : String) -> Bool raise RedisError

    SMOVE source destination member: move member from source to destination. true if moved.

    Client::spop

    async fn Client::spop(self : Client, key : String) -> String? raise RedisError

    SPOP key: remove and return a random member, or None when the set is empty.

    Client::spopn

    async fn Client::spopn(self : Client, key : String, count : Int) -> Array[String] raise RedisError

    SPOP key count: remove and return up to count random members.

    Client::spublish

    async fn Client::spublish(self : Client, channel : String, message : String) -> Int64 raise RedisError

    SPUBLISH shardchannel message: post message to a shard channel, returning how many subscribers received it.

    Client::srandmember

    async fn Client::srandmember(self : Client, key : String) -> String? raise RedisError

    SRANDMEMBER key: a random member, or None when the set is empty.

    Client::srandmembern

    async fn Client::srandmembern(self : Client, key : String, count : Int) -> Array[String] raise RedisError

    SRANDMEMBER key count: count random members, with repeats when count exceeds the set size.

    Client::srem

    async fn Client::srem(self : Client, key : String, members : Array[String]) -> Int64 raise RedisError

    SREM key member...: remove the members, returning how many existed.

    Client::sscan

    async fn Client::sscan(self : Client, key : String, cursor : String, pattern? : String, count? : Int) -> (String, Array[String]) raise RedisError

    SSCAN key cursor [MATCH pattern] [COUNT n]: an incremental set member scan. Returns the next cursor and the members found this call.

    Client::ssubscribe

    async fn Client::ssubscribe(self : Client, channels : Array[String]) -> Unit raise RedisError

    SSUBSCRIBE shardchannel...: subscribe to shard channels (cluster pub/sub), which route to a single shard rather than every node.

    Client::strlen

    async fn Client::strlen(self : Client, key : String) -> Int64 raise RedisError

    STRLEN key: the length of key's value in bytes.

    Client::subscribe

    async fn Client::subscribe(self : Client, channels : Array[String]) -> Unit raise RedisError

    SUBSCRIBE channel...: subscribe the connection to the given channels. After this the connection receives message frames until unsubscribed.

    Client::sunion

    async fn Client::sunion(self : Client, keys : Array[String]) -> Array[String] raise RedisError

    SUNION key...: the members present in any given set.

    Client::sunionstore

    async fn Client::sunionstore(self : Client, destination : String, keys : Array[String]) -> Int64 raise RedisError

    SUNIONSTORE destination key...: store the union of the sets in destination.

    Client::sunsubscribe

    async fn Client::sunsubscribe(self : Client, channels? : Array[String]) -> Unit raise RedisError

    SUNSUBSCRIBE [shardchannel...]: unsubscribe from the given shard channels, or all when omitted.

    Client::swapdb

    async fn Client::swapdb(self : Client, a : Int, b : Int) -> Unit raise RedisError

    SWAPDB a b: atomically swap the data of databases a and b.

    Client::time_

    async fn Client::time_(self : Client) -> (Int64, Int64) raise RedisError

    TIME: the server's current time as (seconds, microseconds).

    Client::touch

    async fn Client::touch(self : Client, keys : Array[String]) -> Int64 raise RedisError

    TOUCH key...: the number of the given keys that exist (like EXISTS but does not alter the LRU/LFU, and accepts multiple keys).

    Client::ttl

    async fn Client::ttl(self : Client, key : String) -> Int64 raise RedisError

    TTL key: key's remaining time to live in seconds: -2 if absent, -1 if no expiry, otherwise the seconds left.

    Client::type_

    async fn Client::type_(self : Client, key : String) -> String raise RedisError

    TYPE key: the type stored at key (string, list, set, ...), or none.
    async fn Client::unlink(self : Client, keys : Array[String]) -> Int64 raise RedisError

    UNLINK key...: delete the given keys asynchronously, returning how many existed.

    Client::unsubscribe

    async fn Client::unsubscribe(self : Client, channels? : Array[String]) -> Unit raise RedisError

    UNSUBSCRIBE [channel...]: unsubscribe from the given channels, or all when omitted.

    Client::unwatch

    async fn Client::unwatch(self : Client) -> Unit raise RedisError

    UNWATCH: clear all watched keys.

    Client::watch

    async fn Client::watch(self : Client, keys : Array[String]) -> Unit raise RedisError

    WATCH key...: mark keys so a later transaction aborts if they change before EXEC.

    Client::xack

    async fn Client::xack(self : Client, key : String, group : String, ids : Array[String]) -> Int64 raise RedisError

    XACK key group id...: acknowledge the given entries for a consumer group, returning how many were newly acknowledged.

    Client::xadd

    async fn Client::xadd(self : Client, key : String, id : String, fields : Array[(String, String)], maxlen? : Int64, approx? : Bool) -> String raise RedisError

    XADD key [MAXLEN [~] n] id field value...: append an entry, returning its id. Use id of * for an auto-generated id.

    Client::xdel

    async fn Client::xdel(self : Client, key : String, ids : Array[String]) -> Int64 raise RedisError

    XDEL key id...: delete the given entries, returning how many were removed.

    Client::xgroup_create

    async fn Client::xgroup_create(self : Client, key : String, group : String, id : String, mkstream? : Bool) -> Unit raise RedisError

    XGROUP CREATE key group id [MKSTREAM]: create a consumer group. id is the last delivered id ($ for new entries only, 0 for all); mkstream creates the stream if absent.

    Client::xgroup_createconsumer

    async fn Client::xgroup_createconsumer(self : Client, key : String, group : String, consumer : String) -> Bool raise RedisError

    XGROUP CREATECONSUMER key group consumer: create a consumer in a group. true if newly created.

    Client::xgroup_delconsumer

    async fn Client::xgroup_delconsumer(self : Client, key : String, group : String, consumer : String) -> Int64 raise RedisError

    XGROUP DELCONSUMER key group consumer: delete a consumer, returning its pending entries that are now orphaned.

    Client::xgroup_destroy

    async fn Client::xgroup_destroy(self : Client, key : String, group : String) -> Bool raise RedisError

    XGROUP DESTROY key group: delete a consumer group. true if it existed.

    Client::xlen

    async fn Client::xlen(self : Client, key : String) -> Int64 raise RedisError

    XLEN key: the number of entries in the stream.

    Client::xpending

    async fn Client::xpending(self : Client, key : String, group : String) -> PendingSummary raise RedisError

    XPENDING key group: the pending-entry summary for a group. For the detailed entry list use xpending_extended.

    Client::xrange

    async fn Client::xrange(self : Client, key : String, start : String, end : String, count? : Int) -> Array[StreamEntry] raise RedisError

    XRANGE key start end [COUNT n]: the entries from start to end (use -/+ for the ends), oldest first.

    Client::xread

    async fn Client::xread(self : Client, streams : Array[(String, String)], count? : Int, block? : Int64) -> Array[(String, Array[StreamEntry])]? raise RedisError

    XREAD [COUNT n] [BLOCK ms] STREAMS key id...: read new entries from one or more streams. block of 0 reads without blocking; a positive block waits up to that many milliseconds for the first entry. Returns, per stream, its name and the entries read, or None when a blocking read times out.

    Client::xreadgroup

    async fn Client::xreadgroup(self : Client, group : String, consumer : String, streams : Array[(String, String)], count? : Int, block? : Int64, noack? : Bool) -> Array[(String, Array[StreamEntry])]? raise RedisError

    XREADGROUP GROUP group consumer [COUNT n] [BLOCK ms] [NOACK] STREAMS key id...: read entries for a consumer, marking them pending. id of > reads new entries; a specific id reads pending ones. Returns per stream its name and entries, or None on a blocking timeout.

    Client::xrevrange

    async fn Client::xrevrange(self : Client, key : String, end : String, start : String, count? : Int) -> Array[StreamEntry] raise RedisError

    XREVRANGE key end start [COUNT n]: the entries from end to start, newest first.

    Client::xtrim

    async fn Client::xtrim(self : Client, key : String, maxlen : Int64, approx? : Bool) -> Int64 raise RedisError

    XTRIM key MAXLEN [~] n: cap the stream at n entries, returning how many were trimmed.

    Client::zadd

    async fn Client::zadd(self : Client, key : String, members : Array[(String, Double)], nx? : Bool, xx? : Bool, ch? : Bool) -> Int64 raise RedisError

    ZADD key [NX] [XX] [CH] score member...: add or update members with their scores, returning how many members changed (or, with ch, were added or updated).

    Client::zcard

    async fn Client::zcard(self : Client, key : String) -> Int64 raise RedisError

    ZCARD key: the number of members in the sorted set.

    Client::zcount

    async fn Client::zcount(self : Client, key : String, min : String, max : String) -> Int64 raise RedisError

    ZCOUNT key min max: the number of members with scores in [min, max].

    Client::zincrby

    async fn Client::zincrby(self : Client, key : String, increment : Double, m : String) -> Double raise RedisError

    ZINCRBY key increment member: add increment to member's score, returning the new score.

    Client::zinterstore

    async fn Client::zinterstore(self : Client, destination : String, keys : Array[String], weights? : Array[Double], aggregate? : String) -> Int64 raise RedisError

    ZINTERSTORE destination numkeys key... [WEIGHTS w...] [AGGREGATE SUM|MIN|MAX]: store the intersection of the sorted sets, returning how many members the result has.

    Client::zmscore

    async fn Client::zmscore(self : Client, key : String, members : Array[String]) -> Array[Double?] raise RedisError

    ZMSCORE key member...: the score of each member, None where absent, in order.

    Client::zpopmax

    async fn Client::zpopmax(self : Client, key : String, count? : Int) -> Array[(String, Double)] raise RedisError

    ZPOPMAX key [count]: remove and return the highest-scoring count members.

    Client::zpopmin

    async fn Client::zpopmin(self : Client, key : String, count? : Int) -> Array[(String, Double)] raise RedisError

    ZPOPMIN key [count]: remove and return the lowest-scoring count members and their scores.

    Client::zrandmember

    async fn Client::zrandmember(self : Client, key : String, count? : Int) -> Array[String] raise RedisError

    ZRANDMEMBER key [count] [WITHSCORES]: one or more random members, optionally with scores.

    Client::zrandmember_scores

    async fn Client::zrandmember_scores(self : Client, key : String, count : Int) -> Array[(String, Double)] raise RedisError

    ZRANDMEMBER key count WITHSCORES: random members with their scores. A negative count may repeat a member.

    Client::zrange

    async fn Client::zrange(self : Client, key : String, start : Int, stop : Int) -> Array[String] raise RedisError

    ZRANGE key start stop: the members from start to stop (inclusive, negative from the tail), lowest score first.

    Client::zrange_scores

    async fn Client::zrange_scores(self : Client, key : String, start : Int, stop : Int) -> Array[(String, Double)] raise RedisError

    ZRANGE key start stop WITHSCORES: the members and scores in rank order.

    Client::zrangebyscore

    async fn Client::zrangebyscore(self : Client, key : String, min : String, max : String, offset? : Int, count? : Int) -> Array[String] raise RedisError

    ZRANGEBYSCORE key min max [LIMIT offset count]: members with scores in [min, max] (use (score to exclude a bound), lowest score first.

    Client::zrangebyscore_scores

    async fn Client::zrangebyscore_scores(self : Client, key : String, min : String, max : String, offset? : Int, count? : Int) -> Array[(String, Double)] raise RedisError

    ZRANGEBYSCORE ... WITHSCORES: the members and scores in score order.

    Client::zrank

    async fn Client::zrank(self : Client, key : String, m : String) -> Int64? raise RedisError

    ZRANK key member: the rank (0-based, lowest score first) of member, or None if absent.

    Client::zrem

    async fn Client::zrem(self : Client, key : String, members : Array[String]) -> Int64 raise RedisError

    ZREM key member...: remove the members, returning how many existed.

    Client::zremrangebyrank

    async fn Client::zremrangebyrank(self : Client, key : String, start : Int, stop : Int) -> Int64 raise RedisError

    ZREMRANGEBYRANK key start stop: remove members by rank range, returning the removed.

    Client::zremrangebyscore

    async fn Client::zremrangebyscore(self : Client, key : String, min : String, max : String) -> Int64 raise RedisError

    ZREMRANGEBYSCORE key min max: remove members by score range, returning the removed.

    Client::zrevrange

    async fn Client::zrevrange(self : Client, key : String, start : Int, stop : Int) -> Array[String] raise RedisError

    ZREVRANGE key start stop: the members in rank order, highest score first.

    Client::zrevrange_scores

    async fn Client::zrevrange_scores(self : Client, key : String, start : Int, stop : Int) -> Array[(String, Double)] raise RedisError

    ZREVRANGE key start stop WITHSCORES: the members and scores, highest score first.

    Client::zrevrangebyscore

    async fn Client::zrevrangebyscore(self : Client, key : String, max : String, min : String, offset? : Int, count? : Int) -> Array[String] raise RedisError

    ZREVRANGEBYSCORE key max min [LIMIT offset count]: members with scores in [min, max], highest score first.

    Client::zrevrangebyscore_scores

    async fn Client::zrevrangebyscore_scores(self : Client, key : String, max : String, min : String, offset? : Int, count? : Int) -> Array[(String, Double)] raise RedisError

    ZREVRANGEBYSCORE ... WITHSCORES: the members and scores, highest score first.

    Client::zrevrank

    async fn Client::zrevrank(self : Client, key : String, m : String) -> Int64? raise RedisError

    ZREVRANK key member: the rank (0-based, highest score first) of member.

    Client::zscan

    async fn Client::zscan(self : Client, key : String, cursor : String, pattern? : String, count? : Int) -> (String, Array[String]) raise RedisError

    ZSCAN key cursor [MATCH pattern] [COUNT n]: an incremental sorted-set member scan. Returns the next cursor and the members found this call.

    Client::zscore

    async fn Client::zscore(self : Client, key : String, m : String) -> Double? raise RedisError

    ZSCORE key member: the score of member, or None if absent.

    Client::zunionstore

    async fn Client::zunionstore(self : Client, destination : String, keys : Array[String], weights? : Array[Double], aggregate? : String) -> Int64 raise RedisError

    ZUNIONSTORE destination numkeys key... [WEIGHTS w...] [AGGREGATE SUM|MIN|MAX]: store the union of the sorted sets, returning how many members the result has.

    ClientOptions

    pub(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
    }

    Everything needed to reach and speak to a redis: the endpoint and credentials, the protocol, the timeouts, and the pool, retry and tracking policies.

    ClientOptions::at

    fn ClientOptions::at(host : String, port : Int) -> ClientOptions

    ClientOptions at host:port, over the standard defaults (RESP3, database 0, no TLS).

    ClientOptions::with_auth

    fn ClientOptions::with_auth(self : ClientOptions, username : String?, password : String?) -> ClientOptions

    A copy of self that authenticates with username and password.

    ClientOptions::with_db

    fn ClientOptions::with_db(self : ClientOptions, db : Int) -> ClientOptions

    A copy of self that SELECTs db on connect.

    ClusterClient

    pub struct ClusterClient {
    nodes : Map[String, &RedisConn]
    topology : ClusterTopology
    limit : Int
    dial : async (String) -> &RedisConn raise RedisError?
    }

    A cluster-aware client: it routes a command to the node owning its key and follows MOVED and ASK redirects. Built from a connection per node address and the topology.

    A redirect can name a node it was not built with, after a reshard or a failover. dial opens a connection to such a node; without it that redirect is a Connection error.

    ClusterClient::command

    Send args to the node owning its key, following redirects up to the limit. The key is the first argument after the command name. MOVED updates the topology, since the slot has gone for good; ASK does not, since only this key has gone ahead so far, and the node it names serves the key only straight after ASKING.

    ClusterClient::new

    fn ClusterClient::new(nodes : Array[(String, &RedisConn)], topology : ClusterTopology, limit? : Int, dial? : async (String) -> &RedisConn raise RedisError) -> ClusterClient

    A cluster client over nodes (address, connection pairs) and topology.

    ClusterClient::set_topology

    fn ClusterClient::set_topology(self : ClusterClient, topology : ClusterTopology) -> Unit

    Replace the routing topology (after a redirect, or on a refresh).

    ClusterSlot

    pub struct ClusterSlot {
    start : Int
    end : Int
    node : String
    }

    A contiguous range of slots owned by one node, named by host:port.

    ClusterSlot::new

    fn ClusterSlot::new(start : Int, end : Int, node : String) -> ClusterSlot

    A slot range [start, end] owned by node (host:port).

    ClusterTopology

    pub struct ClusterTopology {
    slots : Array[ClusterSlot]
    }

    The slot-to-node map the client routes with.

    ClusterTopology::assign

    fn ClusterTopology::assign(self : ClusterTopology, slot : Int, node : String) -> Unit

    Record that slot lives on node. Singles sit ahead of the ranges, so the first match in node_for_slot is the latest word on a slot.

    ClusterTopology::new

    ClusterTopology from an explicit slot list (used after parsing CLUSTER SLOTS, or in tests).

    ClusterTopology::node_for_slot

    fn ClusterTopology::node_for_slot(self : ClusterTopology, slot : Int) -> String?

    The node address (host:port) that owns slot, or None if no range covers it.

    FakeConn

    A redis connection backed by a scripted reply queue and, once the queue is spent, a handler keyed on the command sent. The tests drive the whole command surface through it without a socket, and the cluster and sentinel routing tests feed it handlers that mimic a node.

    FakeConn::execute

    async fn FakeConn::execute(self : FakeConn, args : Array[Bytes]) ->
    RespValue
    raise RedisError

    FakeConn::execute_all

    async fn FakeConn::execute_all(self : FakeConn, commands : Array[Array[Bytes]]) -> Array[
    RespValue
    ] raise RedisError

    FakeConn::handler

    A fake that answers every call with handler, ignoring any queue.

    FakeConn::new

    A fake that returns replies in order, then Null for every further call.

    Message

    pub struct Message {
    kind : String
    channel : String
    payload : Bytes
    pattern : String?
    count : Int64
    }

    One frame of the pub/sub stream. kind is the redis frame name (message, subscribe, ...); payload is the message body for a message/smessage frame, and count is the remaining subscription count for a subscribe/unsubscribe frame.

    Message::parse

    Parse a pub/sub frame — a RESP2 array or RESP3 push — into a Message, or None if the value is not a pub/sub frame.

    PendingSummary

    pub struct PendingSummary {
    count : Int64
    min_id : String?
    max_id : String?
    consumers : Array[(String, Int64)]
    }

    The summary XPENDING returns for a group: how many pending, the first and last pending ids, and per-consumer pending counts.

    Pipeline

    pub struct Pipeline {
    conn : &RedisConn
    queue : Array[Array[Bytes]]
    transaction : Bool
    }

    A queued batch of commands against one connection. Add commands with add; run them with execute. Set multi first to send them inside MULTI/EXEC.

    Pipeline::add

    fn Pipeline::add(self : Pipeline, args : Array[Bytes]) -> Unit

    Queue args as the next command.

    Pipeline::execute

    Run the queued commands in one round trip. Without multi the replies come back in order, an error reply being one among them. With multi they run atomically and the EXEC result comes back: Aborted when a watched key changed, Reply when redis refused the batch, as it does for a command it could not queue.

    Pipeline::multi

    fn Pipeline::multi(self : Pipeline) -> Unit

    Switch the pipeline to transaction mode: execute will wrap the queued commands in MULTI/EXEC.

    Pipeline::new

    fn Pipeline::new(conn : &RedisConn) -> Pipeline

    A pipeline over conn.

    PoolOptions

    pub(all) struct PoolOptions {
    max_idle : Int
    max_active : Int
    min_idle : Int
    idle_timeout : Int64
    health_check : Bool
    }

    The pool a client draws connections from: its size bounds, how long an idle connection lives, and whether a borrowed connection is checked before use.

    Protocol

    pub(all) enum Protocol {
    Resp2
    Resp3
    }

    Which RESP version to negotiate with HELLO. RESP2 is the long-standing wire; RESP3 adds the typed null, boolean, double, map, set and push values and is required for client-side caching.

    Redirect

    pub(all) enum Redirect {
    Moved(slot~ : Int, node~ : String)
    Ask(slot~ : Int, node~ : String)
    } derive(Eq,
    Debug
    )

    Where a cluster node sent a command.

    Redirect::equal

    fn Redirect::equal(Redirect, Redirect) -> Bool

    Redirect::not_equal

    fn Redirect::not_equal(x : Redirect, y : Redirect) -> Bool

    Redirect::to_repr

    RetryConn

    pub struct RetryConn {
    inner : &RedisConn
    retry : RetryOptions
    dial : async () -> &RedisConn raise RedisError?
    wait : async (Int64) -> Unit noraise?
    }

    A connection that retries transport failures up to retry.attempts times, leaving a redis error reply to surface at once. A dropped connection stays dropped, so a retry that is to reach the server needs dial to open another; wait sleeps for the backoff. @socket.connect_retrying wires both.

    RetryConn::execute

    async fn RetryConn::execute(self : RetryConn, args : Array[Bytes]) ->
    RespValue
    raise RedisError

    RetryConn::execute_all

    async fn RetryConn::execute_all(self : RetryConn, commands : Array[Array[Bytes]]) -> Array[
    RespValue
    ] raise RedisError

    RetryConn::new

    fn RetryConn::new(inner : &RedisConn, retry : RetryOptions, dial? : async () -> &RedisConn raise RedisError, wait? : async (Int64) -> Unit noraise) -> RetryConn

    A retrying view of inner under retry.

    RetryOptions

    pub(all) struct RetryOptions {
    attempts : Int
    base_delay : Int64
    max_delay : Int64
    level : Int
    jitter : Bool
    }

    How a call retries after a transport failure: how many attempts in total, the backoff between them and how hard it backs off.

    Script

    pub struct Script {
    source : String
    // private fields
    }

    A Lua script run by its digest, as go-redis's Script runs one: loaded on first use, and loaded again if the server has forgotten it.

    Script::new

    fn Script::new(source : String) -> Script

    A script of source. Nothing is sent until run.

    Script::run

    async fn Script::run(self : Script, client : Client, keys : Array[String], args : Array[String]) ->
    RespValue
    raise RedisError

    Run the script over keys and args.

    SentinelClient

    pub struct SentinelClient {
    sentinels : Array[&RedisConn]
    }

    A client that resolves a master address through a list of sentinel connections, trying each in turn until one answers.

    SentinelClient::new

    fn SentinelClient::new(sentinels : Array[&RedisConn]) -> SentinelClient

    A sentinel client over sentinels (connection to each sentinel node).

    SentinelClient::resolve

    async fn SentinelClient::resolve(self : SentinelClient, name : String) -> String raise RedisError

    Resolve the master address for name, querying sentinels in order; the first answer wins. Returns the host:port string to dial.

    StreamEntry

    pub struct StreamEntry {
    id : String
    fields : Array[(String, String)]
    }

    One stream entry: its id and its field/value pairs.

    TrackingOptions

    pub(all) struct TrackingOptions {
    enabled : Bool
    bcast : Bool
    optin : Bool
    optout : Bool
    noloop : Bool
    redirect : Int64?
    }

    Client-side caching (CLIENT TRACKING): whether keys this client reads are tracked so redis pushes invalidations, and in which mode.

    arg_bytes

    fn arg_bytes(b : Bytes) -> Bytes

    A binary-safe argument, passed through unchanged.

    arg_double

    fn arg_double(d : Double) -> Bytes

    A Double argument as its decimal text.

    arg_int

    fn arg_int(n : Int) -> Bytes

    An Int argument as its decimal text.

    arg_int64

    fn arg_int64(n : Int64) -> Bytes

    An Int64 argument as its decimal text.

    arg_string

    fn arg_string(s : String) -> Bytes

    A string argument, UTF-8 encoded.

    backoff_delay

    fn backoff_delay(attempt : Int, retry : RetryOptions) -> Int64

    The delay before retry number attempt (0-based), growing as base * level^attempt and capped at max_delay. The transport adds jitter when the policy asks for it.

    client_default

    let client_default : ClientOptions

    crc16

    fn crc16(data : Bytes) -> Int

    The CRC16-CCITT (XMODEM) of data: polynomial 0x1021, initial 0, no reflection — the checksum redis uses to place a key in a slot.

    decode_cluster_slots

    Parse a CLUSTER SLOTS reply into a ClusterTopology. Each entry is [start, end,[host, port, id], ...replicas...]; the master's host:port is the owning node.

    expect_array

    A reply as an Array[RespValue]: an array, or the nil an empty result decodes to.

    expect_bool

    fn expect_bool(reply :
    RespValue
    ) -> Bool raise RedisError

    A reply as a Bool: the 1/0 redis uses for existence, success and comparison.

    expect_bytes

    fn expect_bytes(reply :
    RespValue
    ) -> Bytes? raise RedisError

    A reply as binary bytes, or None for the nil a missing key decodes to.

    expect_double

    fn expect_double(reply :
    RespValue
    ) -> Double raise RedisError

    A reply as a Double: a double, the integer a score may come back as, or a parsed decimal string.

    expect_int64

    fn expect_int64(reply :
    RespValue
    ) -> Int64 raise RedisError

    A reply as an Int64: an integer value, or the +1/-1 a command aliases to.

    expect_number

    fn expect_number(reply :
    RespValue
    ) -> Int64 raise RedisError

    A number redis writes as text: TIME, and the ports and counts of sentinel and stream replies, come back as strings under both protocols.

    expect_score

    fn expect_score(reply :
    RespValue
    ) -> Double? raise RedisError

    A score that may be missing: RESP3 sends a double, RESP2 a string, and both nil.

    expect_some

    The members of a reply that is one bulk value without a count and an array with one, and nothing when the key is missing.

    expect_string

    fn expect_string(reply :
    RespValue
    ) -> String? raise RedisError

    A reply as a String, or None for nil.

    expect_string_value

    fn expect_string_value(reply :
    RespValue
    ) -> String raise RedisError

    A reply as a String, raising on nil (for commands that always return a value).

    hash_slot

    fn hash_slot(key : String) -> Int

    The slot a key hashes to. A key of the form prefix{tag}suffix hashes by tag (the hash tag), so those keys colocate; otherwise the whole key is hashed. The result is taken modulo 16384.

    is_cluster_down

    fn is_cluster_down(msg : String) -> Bool

    Whether a redis error reply is a CLUSTERDOWN, the cluster unable to serve.

    is_noscript

    fn is_noscript(msg : String) -> Bool

    Whether a redis error reply is the NOSCRIPT a forgotten script digest draws, so a Script reloads and retries.

    pool_default

    let pool_default : PoolOptions

    protocol_version

    fn protocol_version(protocol : Protocol) -> Int

    The HELLO version argument each protocol negotiates.

    push_some

    fn push_some(builder : Array[Bytes], token : Bytes, value : Bytes?) -> Unit

    Append an optional argument only when it is present, in a when Some arm.

    redirect

    fn redirect(msg : String) -> Redirect?

    What a MOVED or ASK error reply points at; None when the message is neither.

    redirect_limit

    let redirect_limit : Int

    How many redirects one command may follow before giving up; go-redis's MaxRedirects.

    reply_error

    The client's reply when a command returns a redis error value, or Protocol when the reply is not an error value at all but also not the shape the command expected.

    retry_default

    let retry_default : RetryOptions

    same_slot

    fn same_slot(keys : Array[String]) -> Bool

    Whether every key hashes to the same slot — required for multi-key commands in a cluster.

    should_retry

    fn should_retry(error : RedisError, attempt : Int, retry : RetryOptions) -> Bool

    Whether an error on attempt (0-based, the attempt that just failed) is worth retrying under retry: only a transport failure, and only while attempts remain.

    status_ok

    Assert a status reply (the +OK most write commands return). Any other shape is a protocol error.

    tracking_default

    let tracking_default : TrackingOptions

    Powered by MoonBit

    Site sourceReport issueModulesSkillsBuild queueStatistics

    © 2026 mooncakes.io