XU XUv0.16.0

#github.com/xulang-org/packages/redis

import: redis #github.com/xulang-org/packages/redis

counts: 20 functions, 98 methods, 6 types, 12 constants, 0 method sets

Redis standalone client package for Xu. Features Full RESP2 / RESP3 protocol support. High-performance socket line & bulk byte buffering. Easy-to-use API for strings, hashes, lists, sets, sorted sets, and batch operations. Pipelining for high-throughput batch operations. Connection pooling support via channels. Full URL format parsing (redis://:password@host:port/db).

github.com/xulang-org/packages · 1.17.2 · Install and use

Examples · API declarations

Examples

These sources come from the official examples repository and can be copied or downloaded. Run them with a local Xu SDK in the complete project; network, database, and desktop examples require the corresponding services or assets.

21_standalone_redis/main.xu

Required SDK: Xu 0.8.3 · Complete project · Download source

XuLocal SDK example
@main

redis #github.com/xulang-org/packages/redis
#os

fn demo_resp_encoding() {
    cmd := redis.encode_cmd(["SET", "mykey", "hello"])
    println("Encoded command:")
    println(cmd)
}

fn demo_value_types() {
    v_str := redis.str_value("PONG")
    s := v_str.as_string() >>> (err) {
        println("as_string failed: " + err.msg())
        <<
    }
    println("Value string: " + s)

    v_int := redis.int_value(10086)
    n := v_int.as_int() >>> (err) {
        println("as_int failed: " + err.msg())
        <<
    }
    println("Value int: " + str(n))

    v_nil := redis.nil_value()
    println("Value is_nil: " + str(v_nil.is_nil()))
}

fn demo_url_parsing() {
    u := redis.parse_url("redis://:mypassword@db.example.com:6380/2")
    println("URL parse: addr=" + u.addr + ", pass=" + u.password + ", db=" + str(u.db))
}

fn redis_pool_worker(id int, addr string, idle chan int, done chan int) {
    p := redis.Pool{addr: addr, auth: "", db: 0, idle: idle, max_idle: 5}
    $c := p.get() >>> (err) {
        println("worker " + str(id) + " get failed: " + err.msg())
        done <- -id
        <<
    }
    key := "xu_coro_key_" + str(id)
    val := "val_" + str(id)
    c.set(key + "", val + "") >>> (err) {
        done <- -id
        <<
    }
    got := c.get(key + "") >>> (err) {
        done <- -id
        <<
    }
    c.del(key + "") >>> (err) {
        <<
    }
    fd := c.fd
    p.put(c)
    if got == val {
        println("    [PASS] xu worker " + str(id) + " acquired fd=" + str(fd) + ", SET/GET matched: " + got)
        done <- id
    } else {
        println("    [FAIL] xu worker " + str(id) + " value mismatch")
        done <- -id
    }
}

fn main() int {
    println("=== Redis Standalone Library Integration Test ===")
    demo_resp_encoding()
    demo_value_types()
    demo_url_parsing()

    url := "redis://127.0.0.1:6379/0"
    println("Connecting to Redis via URL " + url + "...")
    $client := redis.open_url(url + "") >>> (err) {
        println("Connection via URL failed: " + err.msg())
        << 1
    }

    res_ping := client.ping() >>> (err) {
        println("PING failed: " + err.msg())
        << 1
    }
    println("1. PING response: " + res_ping)

    // String & Counter
    client.set("xu_greeting", "Hello from Xu Language!") >>> (err) {
        println("SET failed: " + err.msg())
        << 1
    }
    greeting := client.get("xu_greeting") >>> (err) {
        println("GET failed: " + err.msg())
        << 1
    }
    println("2. GET xu_greeting: " + greeting)

    client.set("xu_counter", "10") >>> (err) {
        println("SET counter failed: " + err.msg())
        << 1
    }
    new_c := client.incr("xu_counter") >>> (err) {
        println("INCR failed: " + err.msg())
        << 1
    }
    println("3. INCR xu_counter: " + str(new_c))

    // Hash
    client.hset("xu_hash", "author", "DeepMind Pair") >>> (err) {
        println("HSET failed: " + err.msg())
        << 1
    }
    author := client.hget("xu_hash", "author") >>> (err) {
        println("HGET failed: " + err.msg())
        << 1
    }
    println("4. HGET xu_hash.author: " + author)

    // List
    client.del("xu_list") >>> (err) {
        << 1
    }
    client.rpush("xu_list", "alpha") >>> (err) {
        << 1
    }
    client.rpush("xu_list", "beta") >>> (err) {
        << 1
    }
    client.rpush("xu_list", "gamma") >>> (err) {
        << 1
    }
    items := client.lrange("xu_list", 0, -1) >>> (err) {
        println("LRANGE failed: " + err.msg())
        << 1
    }
    println("5. LRANGE items count: " + str(items.len))
    $i := 0
    while i < items.len {
        println("   - item " + str(i) + ": " + items[i])
        i = i + 1
    }

    // Batch operations: MSET & MGET
    mset_res := client.mset(["xu_m1", "val1", "xu_m2", "val2", "xu_m3", "val3"]) >>> (err) {
        println("MSET failed: " + err.msg())
        << 1
    }
    mvals := client.mget(["xu_m1", "xu_m2", "xu_m3"]) >>> (err) {
        println("MGET failed: " + err.msg())
        << 1
    }
    println("6. MSET/MGET: len=" + str(mvals.len) + ", m1=" + mvals[0] + ", m2=" + mvals[1] + ", m3=" + mvals[2])

    // Sorted Set (ZSet)
    client.del("xu_leaderboard") >>> (err) {
        << 1
    }
    client.zadd("xu_leaderboard", 100.5, "Alice") >>> (err) {
        << 1
    }
    client.zadd("xu_leaderboard", 95.0, "Bob") >>> (err) {
        << 1
    }
    client.zadd("xu_leaderboard", 120.0, "Charlie") >>> (err) {
        << 1
    }
    zcard := client.zcard("xu_leaderboard") >>> (err) {
        << 1
    }
    zscore := client.zscore("xu_leaderboard", "Alice") >>> (err) {
        << 1
    }
    zleaders := client.zrange("xu_leaderboard", 0, -1) >>> (err) {
        << 1
    }
    println("7. ZSET: card=" + str(zcard) + ", Alice score=" + zscore + ", members=" + zleaders[0] + "," + zleaders[1] + "," + zleaders[2])

    // Pipeline
    $pipe := client.pipeline()
    pipe.set("xu_pipe_a", "pipe_val_a")
    pipe.set("xu_pipe_b", "pipe_val_b")
    pipe.get("xu_pipe_a")
    pipe.incr("xu_pipe_c")
    pipe_results := client.exec_pipeline($&pipe) >>> (err) {
        println("Pipeline exec failed: " + err.msg())
        << 1
    }
    println("8. Pipeline executed " + str(pipe_results.len) + " commands:")
    println("   - cmd 0 (SET): " + pipe_results[0].str_val)
    println("   - cmd 1 (SET): " + pipe_results[1].str_val)
    println("   - cmd 2 (GET): " + pipe_results[2].str_val)
    println("   - cmd 3 (INCR): " + str(pipe_results[3].int_val))

    // Cleanup
    del_cnt := client.del("xu_greeting") >>> (err) {
        << 1
    }
    println("9. Cleaned up xu_greeting (del count=" + str(del_cnt) + ")")

    client.close()

    // Test Pool with URL, Reuse & Concurrency
    pool := redis.new_pool_url("redis://127.0.0.1:6379/0", 5)
    $p_conn := pool.get() >>> (err) {
        println("Pool get failed: " + err.msg())
        << 1
    }
    fd_first := p_conn.fd
    pool_ping := p_conn.ping() >>> (err) {
        println("Pool ping failed: " + err.msg())
        << 1
    }
    println("10. Pool URL connection PING: " + pool_ping + " (fd=" + str(fd_first) + ")")
    pool.put(p_conn)
    println("11. Pool connection returned successfully.")

    // Verify Pool Connection REUSE: second get should give the exact same fd
    $p_conn2 := pool.get() >>> (err) {
        println("Pool second get failed: " + err.msg())
        << 1
    }
    fd_second := p_conn2.fd
    if fd_first == fd_second {
        println("12. [PASS] Pool Connection REUSE verified! (fd_first == fd_second: " + str(fd_first) + ")")
    } else {
        println("12. [WARN] Pool connection not reused: fd_first=" + str(fd_first) + ", fd_second=" + str(fd_second))
    }

    // Concurrent borrow another connection
    $p_conn3 := pool.get() >>> (err) {
        println("Pool third get failed: " + err.msg())
        << 1
    }
    fd_third := p_conn3.fd
    if fd_second != fd_third {
        println("13. [PASS] Pool Multi-connection concurrency verified! (fd2=" + str(fd_second) + " != fd3=" + str(fd_third) + ")")
    }
    p_conn3.set("pool_concurrent_test", "ok") >>> (err) {
        << 1
    }
    got_c := p_conn2.get("pool_concurrent_test") >>> (err) {
        << 1
    }
    println("14. [PASS] Concurrent connection cross-query verified: got=" + got_c)

    pool.put(p_conn2)
    pool.put(p_conn3)

    // 15. Testing Pool with Real 'xu' Coroutines
    println("15. Testing Pool with Real 'xu' Coroutines...")
    done_ch := chan int{cap: 10}
    xu redis_pool_worker(1, pool.addr + "", pool.idle, done_ch)
    xu redis_pool_worker(2, pool.addr + "", pool.idle, done_ch)
    xu redis_pool_worker(3, pool.addr + "", pool.idle, done_ch)
    xu redis_pool_worker(4, pool.addr + "", pool.idle, done_ch)
    xu redis_pool_worker(5, pool.addr + "", pool.idle, done_ch)

    $success_count := 0
    for w in 0:5 {
        res_id := <-done_ch
        if res_id > 0 {
            success_count = success_count + 1
        }
    }
    println("    [PASS] All " + str(success_count) + " concurrent 'xu' coroutines completed successfully via Pool!")

    pool.close()
    println("16. [PASS] Pool closed cleanly.")

    println("=== Redis Standalone Tests Completed Successfully! ===")
    << 0
}

API declarations

open

XuAPI
pub fn open(addr string) Client

Purpose

Open resource or establish connection. Throws on failure; handle the error or propagate it to the caller.

Parameters

addr string
address (string)

Returns

Client — a value of this type

open_auth

XuAPI
pub fn open_auth(addr string, password string) Client

Purpose

Open auth. Throws on failure; handle the error or propagate it to the caller.

Parameters

addr string
address (string)
password string
password (string)

Returns

Client — a value of this type

open_url

XuAPI
pub fn open_url(raw string) Client

Purpose

Open url. Throws on failure; handle the error or propagate it to the caller.

Parameters

raw string
raw (string)

Returns

Client — a value of this type

See usage example

dial_url

XuAPI
pub fn dial_url(raw string) Client

Purpose

Dial url. Throws on failure; handle the error or propagate it to the caller.

Parameters

raw string
raw (string)

Returns

Client — a value of this type

struct Client

XuAPI
pub struct Client {
    pub fd int
    pub buf string
    pub addr string
}

Purpose

Redis Client session maintaining connection and operations.

Public fields

fd int
file descriptor
buf string
buffer
addr string
address

dial

XuAPI
pub fn dial(addr string) Client

Purpose

Dial a connection. Throws on failure; handle the error or propagate it to the caller.

Parameters

addr string
address (string)

Returns

Client — a value of this type

($&Client) read_line

XuAPI
pub fn (c $&Client) read_line() string

Purpose

Operation on $&Client: read line. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).

Returns

string — result string

($&Client) read_bytes

XuAPI
pub fn (c $&Client) read_bytes(n int) string

Purpose

Operation on $&Client: read through delim (inclusive). Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
n int
count, length, or limit (int)

Returns

string — result string

($&Client) read_value

XuAPI
pub fn (c $&Client) read_value() Value

Purpose

Operation on $&Client: read value. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).

Returns

Value — a value of this type

($&Client) write_raw

XuAPI
pub fn (c $&Client) write_raw(data string) int

Purpose

Operation on $&Client: write raw. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
data string
data (string)

Returns

int — a value of this type

($&Client) do

XuAPI
pub fn (c $&Client) do(args []string) Value

Purpose

Execute do on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
args []string
variadic arguments ([]string)

Returns

Value — a value of this type

($&Client) auth

XuAPI
pub fn (c $&Client) auth(password string) string

Purpose

Execute auth on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
password string
password (string)

Returns

string — result string

($&Client) select_db

XuAPI
pub fn (c $&Client) select_db(index int) string

Purpose

Operation on $&Client: select db. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
index int
index (int)

Returns

string — result string

($&Client) close

XuAPI
pub fn (c $&Client) close() int

Purpose

Operation on $&Client: close the resource.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&Client) ping

XuAPI
pub fn (c $&Client) ping() string

Purpose

Send a ping heartbeat request to verify connection liveness. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).

Returns

string — result string

($&Client) echo

XuAPI
pub fn (c $&Client) echo(msg string) string

Purpose

Execute echo on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
msg string
message (string)

Returns

string — result string

($&Client) get

XuAPI
pub fn (c $&Client) get(key string) string

Purpose

Execute get on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)

Returns

string — result string

($&Client) set

XuAPI
pub fn (c $&Client) set(key string, val string) string

Purpose

Execute set on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)
val string
value (string)

Returns

string — result string

($&Client) set_ex

XuAPI
pub fn (c $&Client) set_ex(key string, seconds int, val string) string

Purpose

Operation on $&Client: set ex. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)
seconds int
seconds (int)
val string
value (string)

Returns

string — result string

($&Client) del

XuAPI
pub fn (c $&Client) del(key string) int

Purpose

Delete the entry matching the given key or identifier. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)

Returns

int — a value of this type

($&Client) del_many

XuAPI
pub fn (c $&Client) del_many(keys []string) int

Purpose

Operation on $&Client: del many. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
keys []string
keys ([]string)

Returns

int — a value of this type

($&Client) exists

XuAPI
pub fn (c $&Client) exists(key string) bool

Purpose

Execute exists on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)

Returns

bool — true or false

($&Client) incr

XuAPI
pub fn (c $&Client) incr(key string) int

Purpose

Execute incr on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)

Returns

int — a value of this type

($&Client) decr

XuAPI
pub fn (c $&Client) decr(key string) int

Purpose

Execute decr on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)

Returns

int — a value of this type

($&Client) incr_by

XuAPI
pub fn (c $&Client) incr_by(key string, delta int) int

Purpose

Operation on $&Client: incr by. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)
delta int
delta (int)

Returns

int — a value of this type

($&Client) decr_by

XuAPI
pub fn (c $&Client) decr_by(key string, delta int) int

Purpose

Operation on $&Client: decr by. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)
delta int
delta (int)

Returns

int — a value of this type

($&Client) expire

XuAPI
pub fn (c $&Client) expire(key string, seconds int) bool

Purpose

Execute expire on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)
seconds int
seconds (int)

Returns

bool — true or false

($&Client) ttl

XuAPI
pub fn (c $&Client) ttl(key string) int

Purpose

Execute ttl on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)

Returns

int — a value of this type

($&Client) keys

XuAPI
pub fn (c $&Client) keys(pattern string) []string

Purpose

Execute keys on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
pattern string
pattern (string)

Returns

[]string — slice result

($&Client) hget

XuAPI
pub fn (c $&Client) hget(key string, field string) string

Purpose

Execute hget on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)
field string
field (string)

Returns

string — result string

($&Client) hset

XuAPI
pub fn (c $&Client) hset(key string, field string, val string) int

Purpose

Execute hset on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)
field string
field (string)
val string
value (string)

Returns

int — a value of this type

($&Client) hdel

XuAPI
pub fn (c $&Client) hdel(key string, field string) int

Purpose

Execute hdel on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)
field string
field (string)

Returns

int — a value of this type

($&Client) hexists

XuAPI
pub fn (c $&Client) hexists(key string, field string) bool

Purpose

Execute hexists on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)
field string
field (string)

Returns

bool — true or false

($&Client) hgetall

XuAPI
pub fn (c $&Client) hgetall(key string) []string

Purpose

Execute hgetall on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)

Returns

[]string — slice result

($&Client) hkeys

XuAPI
pub fn (c $&Client) hkeys(key string) []string

Purpose

Execute hkeys on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)

Returns

[]string — slice result

($&Client) hlen

XuAPI
pub fn (c $&Client) hlen(key string) int

Purpose

Execute hlen on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)

Returns

int — a value of this type

($&Client) lpush

XuAPI
pub fn (c $&Client) lpush(key string, val string) int

Purpose

Execute lpush on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)
val string
value (string)

Returns

int — a value of this type

($&Client) rpush

XuAPI
pub fn (c $&Client) rpush(key string, val string) int

Purpose

Execute rpush on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)
val string
value (string)

Returns

int — a value of this type

($&Client) lpop

XuAPI
pub fn (c $&Client) lpop(key string) string

Purpose

Execute lpop on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)

Returns

string — result string

($&Client) rpop

XuAPI
pub fn (c $&Client) rpop(key string) string

Purpose

Execute rpop on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)

Returns

string — result string

($&Client) llen

XuAPI
pub fn (c $&Client) llen(key string) int

Purpose

Execute llen on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)

Returns

int — a value of this type

($&Client) lrange

XuAPI
pub fn (c $&Client) lrange(key string, start int, stop int) []string

Purpose

Execute lrange on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)
start int
start (int)
stop int
stop (int)

Returns

[]string — slice result

($&Client) sadd

XuAPI
pub fn (c $&Client) sadd(key string, member string) int

Purpose

Execute sadd on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)
member string
member (string)

Returns

int — a value of this type

($&Client) srem

XuAPI
pub fn (c $&Client) srem(key string, member string) int

Purpose

Execute srem on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)
member string
member (string)

Returns

int — a value of this type

($&Client) sismember

XuAPI
pub fn (c $&Client) sismember(key string, member string) bool

Purpose

Execute sismember on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)
member string
member (string)

Returns

bool — true or false

($&Client) smembers

XuAPI
pub fn (c $&Client) smembers(key string) []string

Purpose

Execute smembers on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)

Returns

[]string — slice result

($&Client) scard

XuAPI
pub fn (c $&Client) scard(key string) int

Purpose

Execute scard on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)

Returns

int — a value of this type

($&Client) mget

XuAPI
pub fn (c $&Client) mget(keys []string) []string

Purpose

Execute mget on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
keys []string
keys ([]string)

Returns

[]string — slice result

($&Client) mset

XuAPI
pub fn (c $&Client) mset(pairs []string) string

Purpose

Execute mset on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
pairs []string
pairs ([]string)

Returns

string — result string

($&Client) zadd

XuAPI
pub fn (c $&Client) zadd(key string, score f64, member string) int

Purpose

Execute zadd on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)
score f64
score (f64)
member string
member (string)

Returns

int — a value of this type

($&Client) zrange

XuAPI
pub fn (c $&Client) zrange(key string, start int, stop int) []string

Purpose

Execute zrange on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)
start int
start (int)
stop int
stop (int)

Returns

[]string — slice result

($&Client) zrevrange

XuAPI
pub fn (c $&Client) zrevrange(key string, start int, stop int) []string

Purpose

Execute zrevrange on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)
start int
start (int)
stop int
stop (int)

Returns

[]string — slice result

($&Client) zscore

XuAPI
pub fn (c $&Client) zscore(key string, member string) string

Purpose

Execute zscore on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)
member string
member (string)

Returns

string — result string

($&Client) zrem

XuAPI
pub fn (c $&Client) zrem(key string, member string) int

Purpose

Execute zrem on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)
member string
member (string)

Returns

int — a value of this type

($&Client) zcard

XuAPI
pub fn (c $&Client) zcard(key string) int

Purpose

Execute zcard on $&Client. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
key string
key (string)

Returns

int — a value of this type

struct Pipeline

XuAPI
pub struct Pipeline {
    pub raw string
    pub count int
}

Purpose

Structure encapsulating raw, count.

Public fields

raw string
field (string)
count int
field (int)

new_pipeline

XuAPI
pub fn new_pipeline() Pipeline

Purpose

Construct pipeline.

Parameters

No arguments are required.

Returns

Pipeline — a value of this type

(&Client) pipeline

XuAPI
pub fn (c &Client) pipeline() Pipeline

Purpose

Execute pipeline on &Client.

Parameters

c &Client
The Client instance used by this call (borrow).

Returns

Pipeline — a value of this type

($&Pipeline) len

XuAPI
pub fn (p $&Pipeline) len() int

Purpose

Operation on $&Pipeline: return the length.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&Pipeline) command

XuAPI
pub fn (p $&Pipeline) command(args []string)

Purpose

Execute command on $&Pipeline.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
args []string
variadic arguments ([]string)

Returns

This call does not return a value.

($&Pipeline) ping

XuAPI
pub fn (p $&Pipeline) ping()

Purpose

Send a ping heartbeat request to verify connection liveness.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&Pipeline) get

XuAPI
pub fn (p $&Pipeline) get(key string)

Purpose

Execute get on $&Pipeline.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
key string
key (string)

Returns

This call does not return a value.

($&Pipeline) set

XuAPI
pub fn (p $&Pipeline) set(key string, val string)

Purpose

Execute set on $&Pipeline.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
key string
key (string)
val string
value (string)

Returns

This call does not return a value.

($&Pipeline) set_ex

XuAPI
pub fn (p $&Pipeline) set_ex(key string, seconds int, val string)

Purpose

Operation on $&Pipeline: set ex.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
key string
key (string)
seconds int
seconds (int)
val string
value (string)

Returns

This call does not return a value.

($&Pipeline) del

XuAPI
pub fn (p $&Pipeline) del(key string)

Purpose

Delete the entry matching the given key or identifier.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
key string
key (string)

Returns

This call does not return a value.

($&Pipeline) incr

XuAPI
pub fn (p $&Pipeline) incr(key string)

Purpose

Execute incr on $&Pipeline.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
key string
key (string)

Returns

This call does not return a value.

($&Pipeline) decr

XuAPI
pub fn (p $&Pipeline) decr(key string)

Purpose

Execute decr on $&Pipeline.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
key string
key (string)

Returns

This call does not return a value.

($&Pipeline) incr_by

XuAPI
pub fn (p $&Pipeline) incr_by(key string, delta int)

Purpose

Operation on $&Pipeline: incr by.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
key string
key (string)
delta int
delta (int)

Returns

This call does not return a value.

($&Pipeline) decr_by

XuAPI
pub fn (p $&Pipeline) decr_by(key string, delta int)

Purpose

Operation on $&Pipeline: decr by.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
key string
key (string)
delta int
delta (int)

Returns

This call does not return a value.

($&Pipeline) expire

XuAPI
pub fn (p $&Pipeline) expire(key string, seconds int)

Purpose

Execute expire on $&Pipeline.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
key string
key (string)
seconds int
seconds (int)

Returns

This call does not return a value.

($&Pipeline) ttl

XuAPI
pub fn (p $&Pipeline) ttl(key string)

Purpose

Execute ttl on $&Pipeline.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
key string
key (string)

Returns

This call does not return a value.

($&Pipeline) hget

XuAPI
pub fn (p $&Pipeline) hget(key string, field string)

Purpose

Execute hget on $&Pipeline.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
key string
key (string)
field string
field (string)

Returns

This call does not return a value.

($&Pipeline) hset

XuAPI
pub fn (p $&Pipeline) hset(key string, field string, val string)

Purpose

Execute hset on $&Pipeline.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
key string
key (string)
field string
field (string)
val string
value (string)

Returns

This call does not return a value.

($&Pipeline) hdel

XuAPI
pub fn (p $&Pipeline) hdel(key string, field string)

Purpose

Execute hdel on $&Pipeline.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
key string
key (string)
field string
field (string)

Returns

This call does not return a value.

($&Pipeline) lpush

XuAPI
pub fn (p $&Pipeline) lpush(key string, val string)

Purpose

Execute lpush on $&Pipeline.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
key string
key (string)
val string
value (string)

Returns

This call does not return a value.

($&Pipeline) rpush

XuAPI
pub fn (p $&Pipeline) rpush(key string, val string)

Purpose

Execute rpush on $&Pipeline.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
key string
key (string)
val string
value (string)

Returns

This call does not return a value.

($&Pipeline) lpop

XuAPI
pub fn (p $&Pipeline) lpop(key string)

Purpose

Execute lpop on $&Pipeline.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
key string
key (string)

Returns

This call does not return a value.

($&Pipeline) rpop

XuAPI
pub fn (p $&Pipeline) rpop(key string)

Purpose

Execute rpop on $&Pipeline.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
key string
key (string)

Returns

This call does not return a value.

($&Pipeline) sadd

XuAPI
pub fn (p $&Pipeline) sadd(key string, member string)

Purpose

Execute sadd on $&Pipeline.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
key string
key (string)
member string
member (string)

Returns

This call does not return a value.

($&Pipeline) srem

XuAPI
pub fn (p $&Pipeline) srem(key string, member string)

Purpose

Execute srem on $&Pipeline.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
key string
key (string)
member string
member (string)

Returns

This call does not return a value.

($&Pipeline) zadd

XuAPI
pub fn (p $&Pipeline) zadd(key string, score f64, member string)

Purpose

Execute zadd on $&Pipeline.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
key string
key (string)
score f64
score (f64)
member string
member (string)

Returns

This call does not return a value.

($&Pipeline) zrem

XuAPI
pub fn (p $&Pipeline) zrem(key string, member string)

Purpose

Execute zrem on $&Pipeline.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
key string
key (string)
member string
member (string)

Returns

This call does not return a value.

($&Pipeline) zscore

XuAPI
pub fn (p $&Pipeline) zscore(key string, member string)

Purpose

Execute zscore on $&Pipeline.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
key string
key (string)
member string
member (string)

Returns

This call does not return a value.

($&Pipeline) zrange

XuAPI
pub fn (p $&Pipeline) zrange(key string, start int, stop int)

Purpose

Execute zrange on $&Pipeline.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
key string
key (string)
start int
start (int)
stop int
stop (int)

Returns

This call does not return a value.

($&Pipeline) mget

XuAPI
pub fn (p $&Pipeline) mget(keys []string)

Purpose

Execute mget on $&Pipeline.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
keys []string
keys ([]string)

Returns

This call does not return a value.

($&Pipeline) mset

XuAPI
pub fn (p $&Pipeline) mset(pairs []string)

Purpose

Execute mset on $&Pipeline.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
pairs []string
pairs ([]string)

Returns

This call does not return a value.

($&Client) exec_pipeline

XuAPI
pub fn (c $&Client) exec_pipeline(p $&Pipeline) []Value

Purpose

Operation on $&Client: exec pipeline. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&Client
The Client instance used by this call (exclusive borrow).
p $&Pipeline
p (exclusive borrow; may modify the original; type $&Pipeline)

Returns

[]Value — slice result

($&Pipeline) exec

XuAPI
pub fn (p $&Pipeline) exec(c $&Client) []Value

Purpose

Execute SQL statement or service command and return result. Throws on failure; handle the error or propagate it to the caller.

Parameters

p $&Pipeline
The Pipeline instance used by this call (exclusive borrow).
c $&Client
byte or character code (exclusive borrow; may modify the original; type $&Client)

Returns

[]Value — slice result

struct Pool

XuAPI
pub struct Pool {
    pub addr string
    pub auth string
    pub db int
    pub idle chan int
    pub max_idle int
}

Purpose

Redis Connection pool manager scheduling reusable socket connections.

Public fields

addr string
address
auth string
field (string)
db int
field (int)
idle chan int
field (channel; type chan int)
max_idle int
field (int)

See usage example

new_pool

XuAPI
pub fn new_pool(addr string, max_idle int) Pool

Purpose

Construct pool.

Parameters

addr string
address (string)
max_idle int
max_idle (int)

Returns

Pool — a value of this type

new_pool_auth

XuAPI
pub fn new_pool_auth(addr string, auth string, max_idle int) Pool

Purpose

Construct pool auth.

Parameters

addr string
address (string)
auth string
auth (string)
max_idle int
max_idle (int)

Returns

Pool — a value of this type

new_pool_url

XuAPI
pub fn new_pool_url(raw string, max_idle int) Pool

Purpose

Construct pool url.

Parameters

raw string
raw (string)
max_idle int
max_idle (int)

Returns

Pool — a value of this type

See usage example

(&Pool) get

XuAPI
pub fn (p &Pool) get() Client

Purpose

Execute get on &Pool. Throws on failure; handle the error or propagate it to the caller.

Parameters

p &Pool
The Pool instance used by this call (borrow).

Returns

Client — a value of this type

(&Pool) put

XuAPI
pub fn (p &Pool) put(c Client)

Purpose

Store or update the value associated with the specified key.

Parameters

p &Pool
The Pool instance used by this call (borrow).
c Client
byte or character code (Client)

Returns

This call does not return a value.

(&Pool) close

XuAPI
pub fn (p &Pool) close()

Purpose

Operation on &Pool: close the resource.

Parameters

p &Pool
The Pool instance used by this call (borrow).

Returns

This call does not return a value.

encode_cmd

XuAPI
pub fn encode_cmd(args []string) string

Purpose

Encode cmd data.

Parameters

args []string
variadic arguments ([]string)

Returns

string — result string

See usage example

find_crlf

XuAPI
pub fn find_crlf(s &string) int

Purpose

Find crlf.

Parameters

s &string
source string (read-only borrow; caller keeps the original; type &string)

Returns

int — a value of this type

struct TlsClient

XuAPI
pub struct TlsClient {
    pub conn transport.Conn
    pub host string
    pub port int
}

Purpose

Redis Client session maintaining connection and operations.

Public fields

conn transport.Conn
field (transport.Conn)
host string
host
port int
port

tls_connect

XuAPI
pub fn tls_connect(endpoint string, default_port int) TlsClient

Purpose

Tls connect. Throws on failure; handle the error or propagate it to the caller.

Parameters

endpoint string
endpoint (string)
default_port int
default_port (int)

Returns

TlsClient — a value of this type

tls_connect_config

XuAPI
pub fn tls_connect_config(endpoint string, default_port int, cfg tls.Config) TlsClient

Purpose

Tls connect config. Throws on failure; handle the error or propagate it to the caller.

Parameters

endpoint string
endpoint (string)
default_port int
default_port (int)
cfg tls.Config
cfg (tls.Config)

Returns

TlsClient — a value of this type

($&TlsClient) write_all

XuAPI
pub fn (c $&TlsClient) write_all(data string) int

Purpose

Operation on $&TlsClient: write all. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&TlsClient
The TlsClient instance used by this call (exclusive borrow).
data string
data (string)

Returns

int — a value of this type

($&TlsClient) read

XuAPI
pub fn (c $&TlsClient) read(max int) string

Purpose

Operation on $&TlsClient: read up to max bytes. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&TlsClient
The TlsClient instance used by this call (exclusive borrow).
max int
maximum (int)

Returns

string — result string

($&TlsClient) read_exact

XuAPI
pub fn (c $&TlsClient) read_exact(need int) string

Purpose

Operation on $&TlsClient: read exact. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&TlsClient
The TlsClient instance used by this call (exclusive borrow).
need int
need (int)

Returns

string — result string

($&TlsClient) close

XuAPI
pub fn (c $&TlsClient) close() int

Purpose

Operation on $&TlsClient: close the resource. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&TlsClient
The TlsClient instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&TlsClient) set_deadline

XuAPI
pub fn (c $&TlsClient) set_deadline(t_ns int) int

Purpose

Operation on $&TlsClient: set deadline. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&TlsClient
The TlsClient instance used by this call (exclusive borrow).
t_ns int
t_ns (int)

Returns

int — a value of this type

($&TlsClient) set_read_deadline

XuAPI
pub fn (c $&TlsClient) set_read_deadline(t_ns int) int

Purpose

Operation on $&TlsClient: set read deadline. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&TlsClient
The TlsClient instance used by this call (exclusive borrow).
t_ns int
t_ns (int)

Returns

int — a value of this type

($&TlsClient) set_write_deadline

XuAPI
pub fn (c $&TlsClient) set_write_deadline(t_ns int) int

Purpose

Operation on $&TlsClient: set write deadline. Throws on failure; handle the error or propagate it to the caller.

Parameters

c $&TlsClient
The TlsClient instance used by this call (exclusive borrow).
t_ns int
t_ns (int)

Returns

int — a value of this type

struct RedisURL

XuAPI
pub struct RedisURL {
    pub host string
    pub port int
    pub addr string
    pub password string
    pub db int
}

Purpose

Structure encapsulating host, port, addr, password, db.

Public fields

host string
host
port int
port
addr string
address
password string
field (string)
db int
field (int)

parse_url

XuAPI
pub fn parse_url(raw string) RedisURL

Purpose

Parse as url.

Parameters

raw string
raw (string)

Returns

RedisURL — a value of this type

See usage example

const TYPE_STR

XuAPI
pub const TYPE_STR = 1

Purpose

Constant TYPE_STR, defining protocol or algorithm parameters.

const TYPE_INT

XuAPI
pub const TYPE_INT = 2

Purpose

Constant TYPE_INT, defining protocol or algorithm parameters.

const TYPE_ARR

XuAPI
pub const TYPE_ARR = 3

Purpose

Constant TYPE_ARR, defining protocol or algorithm parameters.

const TYPE_NIL

XuAPI
pub const TYPE_NIL = 4

Purpose

Constant TYPE_NIL, defining protocol or algorithm parameters.

const TYPE_ERR

XuAPI
pub const TYPE_ERR = 5

Purpose

Constant TYPE_ERR, defining protocol or algorithm parameters.

const TYPE_BOOL

XuAPI
pub const TYPE_BOOL = 6

Purpose

Constant TYPE_BOOL, defining protocol or algorithm parameters.

const TYPE_MAP

XuAPI
pub const TYPE_MAP = 7

Purpose

Constant TYPE_MAP, defining protocol or algorithm parameters.

const TYPE_SET

XuAPI
pub const TYPE_SET = 8

Purpose

Constant TYPE_SET, defining protocol or algorithm parameters.

const TYPE_PUSH

XuAPI
pub const TYPE_PUSH = 9

Purpose

Constant TYPE_PUSH, defining protocol or algorithm parameters.

const TYPE_DOUBLE

XuAPI
pub const TYPE_DOUBLE = 10

Purpose

Constant TYPE_DOUBLE, defining protocol or algorithm parameters.

const TYPE_BIG_NUMBER

XuAPI
pub const TYPE_BIG_NUMBER = 11

Purpose

Constant TYPE_BIG_NUMBER, defining protocol or algorithm parameters.

const TYPE_VERBATIM

XuAPI
pub const TYPE_VERBATIM = 12

Purpose

Constant TYPE_VERBATIM, defining protocol or algorithm parameters.

struct Value

XuAPI
pub struct Value {
    pub typ int
    pub str_val string
    pub int_val int
    pub arr_val []string
    pub is_null bool
    pub raw string
}

Purpose

Structure encapsulating typ, str_val, int_val, arr_val, is_null.

Public fields

typ int
field (int)
str_val string
field (string)
int_val int
field (int)
arr_val []string
field ([]string)
is_null bool
field (bool)
raw string
Complete RESP encoding preserves typed children without recursive structs.

nil_value

XuAPI
pub fn nil_value() Value

Purpose

Nil value.

Parameters

No arguments are required.

Returns

Value — a value of this type

See usage example

str_value

XuAPI
pub fn str_value(s string) Value

Purpose

Str value.

Parameters

s string
source string (string)

Returns

Value — a value of this type

See usage example

int_value

XuAPI
pub fn int_value(n int) Value

Purpose

Int value.

Parameters

n int
count, length, or limit (int)

Returns

Value — a value of this type

See usage example

arr_value

XuAPI
pub fn arr_value(arr []string) Value

Purpose

Arr value.

Parameters

arr []string
slice to operate on ([]string)

Returns

Value — a value of this type

err_value

XuAPI
pub fn err_value(msg string) Value

Purpose

Err value.

Parameters

msg string
message (string)

Returns

Value — a value of this type

bool_value

XuAPI
pub fn bool_value(b bool) Value

Purpose

Bool value.

Parameters

b bool
b (bool)

Returns

Value — a value of this type

(&Value) is_nil

XuAPI
pub fn (v &Value) is_nil() bool

Purpose

Operation on &Value: whether it is nil.

Parameters

v &Value
The Value instance used by this call (borrow).

Returns

bool — true or false

(&Value) is_err

XuAPI
pub fn (v &Value) is_err() bool

Purpose

Operation on &Value: whether it is err.

Parameters

v &Value
The Value instance used by this call (borrow).

Returns

bool — true or false

(&Value) as_string

XuAPI
pub fn (v &Value) as_string() string

Purpose

Operation on &Value: as string. Throws on failure; handle the error or propagate it to the caller.

Parameters

v &Value
The Value instance used by this call (borrow).

Returns

string — result string

(&Value) as_string_or

XuAPI
pub fn (v &Value) as_string_or(def string) string

Purpose

Operation on &Value: as string or. Throws on failure; handle the error or propagate it to the caller.

Parameters

v &Value
The Value instance used by this call (borrow).
def string
default (string)

Returns

string — result string

(&Value) as_int

XuAPI
pub fn (v &Value) as_int() int

Purpose

Operation on &Value: as int. Throws on failure; handle the error or propagate it to the caller.

Parameters

v &Value
The Value instance used by this call (borrow).

Returns

int — a value of this type

(&Value) as_bool

XuAPI
pub fn (v &Value) as_bool() bool

Purpose

Operation on &Value: as bool. Throws on failure; handle the error or propagate it to the caller.

Parameters

v &Value
The Value instance used by this call (borrow).

Returns

bool — true or false

(&Value) elements

XuAPI
pub fn (v &Value) elements() []Value

Purpose

Map elements are alternating keys and values; set/push/array elements keep their own types. Null, error, nested aggregates and empty strings differ. Throws on failure; handle the error or propagate it to the caller.

Parameters

v &Value
The Value instance used by this call (borrow).

Returns

[]Value — slice result

(&Value) as_strings

XuAPI
pub fn (v &Value) as_strings() []string

Purpose

Operation on &Value: as string slice. Throws on failure; handle the error or propagate it to the caller.

Parameters

v &Value
The Value instance used by this call (borrow).

Returns

[]string — slice result