componentized/directory

componentized:valkey

interface

A WASM component client for Valkey (and Redis).

Interfaces

Worlds

WIT

package componentized:valkey;

interface resp {
  type error = string;

  /// Values nested within an aggregate type. Since WIT types are not allowed to depend on
  /// themselves, nested values are stored as encoded RESP.
  type nested-value = list<u8>;

  variant value {
    %string(string),
    error(string),
    integer(s64),
    bulk-string(string),
    array(list<nested-value>),
    null,
    boolean(bool),
    double(f64),
    big-number(string),
    bulk-error(string),
    verbatim-string(tuple<string, string>),
    %map(list<tuple<nested-value, nested-value>>),
    set(list<nested-value>),
    push(list<nested-value>),
  }

  decode: func(data: list<u8>) -> result<value, error>;

  encode: func(value: value) -> result<list<u8>, error>;
}

interface store {
  use resp.{error as resp-error, value};

  variant error {
    /// Client errors can represent semantic issues with input/output values, or connection errors communicating with the server
    client(string),
    /// RESP errors are encoding issues converting values to/from bytes
    resp(resp-error),
    /// Valkey errors are Error or BulkError values returned directly from the server
    valkey(string),
  }

  record hello-opts {
    proto-ver: option<string>,
    auth: option<tuple<string, string>>,
    client-name: option<string>,
  }

  record hrandfield-opts {
    count: option<s64>,
    with-values: option<bool>,
  }

  record hscan-opts {
    match: option<string>,
    count: option<s64>,
    no-values: option<bool>,
  }

  resource connection {
    send: func(command: list<value>) -> result<value, error>;
    acl-deluser: func(username: string) -> result<_, error>;
    acl-genpass: func() -> result<string, error>;
    acl-setuser: func(username: string, rules: list<string>) -> result<_, error>;
    auth: func(username: string, password: string) -> result<_, error>;
    del: func(key: string) -> result<_, error>;
    exists: func(key: string) -> result<bool, error>;
    get: func(key: string) -> result<option<string>, error>;
    hdel: func(key: string, field: string) -> result<_, error>;
    hello: func(opts: option<hello-opts>) -> result<list<tuple<string, value>>, error>;
    hexists: func(key: string, field: string) -> result<bool, error>;
    hget: func(key: string, field: string) -> result<option<string>, error>;
    hgetall: func(key: string) -> result<list<tuple<string, string>>, error>;
    hincrby: func(key: string, field: string, increment: s64) -> result<s64, error>;
    hincrbyfloat: func(key: string, field: string, increment: f64) -> result<string, error>;
    hkeys: func(key: string) -> result<list<string>, error>;
    hlen: func(key: string) -> result<u64, error>;
    hmget: func(key: string, fields: list<string>) -> result<list<option<string>>, error>;
    hmset: func(key: string, fields: list<tuple<string, string>>) -> result<_, error>;
    hrandfield: func(key: string, opts: option<hrandfield-opts>) -> result<option<list<tuple<string, option<string>>>>, error>;
    hscan: func(key: string, cursor: option<string>, opts: option<hscan-opts>) -> result<tuple<option<string>, list<tuple<string, option<string>>>>, error>;
    hset: func(key: string, field: string, value: string) -> result<_, error>;
    hsetnx: func(key: string, field: string, value: string) -> result<bool, error>;
    hstrlen: func(key: string, field: string) -> result<u64, error>;
    hvals: func(key: string) -> result<list<string>, error>;
    incr: func(key: string) -> result<s64, error>;
    incrby: func(key: string, increment: s64) -> result<s64, error>;
    keys: func(pattern: string) -> result<list<string>, error>;
    ping: func() -> result<_, error>;
    publish: func(channel: string, message: string) -> result<s64, error>;
    quit: func() -> result<_, error>;
    set: func(key: string, value: string) -> result<_, error>;
  }

  connect: func(host: string, port: u16, opts: option<hello-opts>) -> result<connection, error>;
}

world imports {
  import resp;
  import store;
}