XU XUv0.16.0

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

导入方式: redis #github.com/xulang-org/packages/redis

公开 API: 20 函数, 98 方法, 6 类型, 12 常量, 0 方法集

扩展包 `redis #github.com/xulang-org/packages/redis`,由模块 github.com/xulang-org/packages 提供。

github.com/xulang-org/packages · 1.17.2 · 安装与使用

示例代码 · API 声明

示例代码

以下源码来自官方 examples 仓库,可复制或下载。请在完整工程中使用本地 Xu SDK 运行;网络、数据库和桌面示例需要对应的服务或资源。

21_standalone_redis/main.xu

所需 SDK:Xu 0.8.3 · 完整工程 · 下载源码

Xu本地 SDK 示例
@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 声明

open

XuAPI
pub fn open(addr string) Client

用途

打开资源或建立网络连接。失败时抛出错误,调用方需处理或继续传播。

参数

addr string
地址(string)

返回值

Client — 该类型的值

open_auth

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

用途

执行 open auth 操作。失败时抛出错误,调用方需处理或继续传播。

参数

addr string
地址(string)
password string
password(string)

返回值

Client — 该类型的值

open_url

XuAPI
pub fn open_url(raw string) Client

用途

执行 open url 操作。失败时抛出错误,调用方需处理或继续传播。

参数

raw string
raw(string)

返回值

Client — 该类型的值

查看用法示例

dial_url

XuAPI
pub fn dial_url(raw string) Client

用途

执行 dial url 操作。失败时抛出错误,调用方需处理或继续传播。

参数

raw string
raw(string)

返回值

Client — 该类型的值

struct Client

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

用途

Redis 客户端会话实例,维护与服务端的连接并提供操作接口。

公开字段

fd int
文件描述符
buf string
缓冲
addr string
地址

dial

XuAPI
pub fn dial(addr string) Client

用途

发起连接。失败时抛出错误,调用方需处理或继续传播。

参数

addr string
地址(string)

返回值

Client — 该类型的值

($&Client) read_line

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

用途

$&Client 上的操作:执行 read line 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

string — 结果字符串

($&Client) read_bytes

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

用途

$&Client 上的操作:读到 delim(含 delim)。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
n int
数量、长度或上限(int)

返回值

string — 结果字符串

($&Client) read_value

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

用途

$&Client 上的操作:读取值。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

Value — 该类型的值

($&Client) write_raw

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

用途

$&Client 上的操作:执行 write raw 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
data string
数据(string)

返回值

int — 该类型的值

($&Client) do

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

用途

$&Client 上的操作:执行一次。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
args []string
可变实参([]string)

返回值

Value — 该类型的值

($&Client) auth

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

用途

在 $&Client 上执行 auth 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
password string
password(string)

返回值

string — 结果字符串

($&Client) select_db

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

用途

$&Client 上的操作:执行 select db 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
index int
index(int)

返回值

string — 结果字符串

($&Client) close

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

用途

$&Client 上的操作:关闭资源。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

($&Client) ping

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

用途

发送心跳保活探测请求,检测连接活性与服务可用性。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

string — 结果字符串

($&Client) echo

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

用途

在 $&Client 上执行 echo 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
msg string
消息(string)

返回值

string — 结果字符串

($&Client) get

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

用途

在 $&Client 上执行 get 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)

返回值

string — 结果字符串

($&Client) set

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

用途

在 $&Client 上执行 set 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
val string
值(string)

返回值

string — 结果字符串

($&Client) set_ex

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

用途

$&Client 上的操作:设置 ex。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
seconds int
seconds(int)
val string
值(string)

返回值

string — 结果字符串

($&Client) del

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

用途

删除指定键或标识对应的数据项。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)

返回值

int — 该类型的值

($&Client) del_many

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

用途

$&Client 上的操作:执行 del many 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
keys []string
keys([]string)

返回值

int — 该类型的值

($&Client) exists

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

用途

在 $&Client 上执行 exists 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)

返回值

bool — 是否成立

($&Client) incr

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

用途

在 $&Client 上执行 incr 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)

返回值

int — 该类型的值

($&Client) decr

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

用途

在 $&Client 上执行 decr 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)

返回值

int — 该类型的值

($&Client) incr_by

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

用途

$&Client 上的操作:执行 incr by 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
delta int
增量(int)

返回值

int — 该类型的值

($&Client) decr_by

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

用途

$&Client 上的操作:执行 decr by 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
delta int
增量(int)

返回值

int — 该类型的值

($&Client) expire

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

用途

在 $&Client 上执行 expire 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
seconds int
seconds(int)

返回值

bool — 是否成立

($&Client) ttl

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

用途

在 $&Client 上执行 ttl 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)

返回值

int — 该类型的值

($&Client) keys

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

用途

在 $&Client 上执行 keys 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
pattern string
匹配模式(string)

返回值

[]string — 切片结果

($&Client) hget

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

用途

在 $&Client 上执行 hget 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
field string
field(string)

返回值

string — 结果字符串

($&Client) hset

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

用途

在 $&Client 上执行 hset 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
field string
field(string)
val string
值(string)

返回值

int — 该类型的值

($&Client) hdel

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

用途

在 $&Client 上执行 hdel 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
field string
field(string)

返回值

int — 该类型的值

($&Client) hexists

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

用途

在 $&Client 上执行 hexists 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
field string
field(string)

返回值

bool — 是否成立

($&Client) hgetall

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

用途

在 $&Client 上执行 hgetall 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)

返回值

[]string — 切片结果

($&Client) hkeys

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

用途

在 $&Client 上执行 hkeys 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)

返回值

[]string — 切片结果

($&Client) hlen

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

用途

在 $&Client 上执行 hlen 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)

返回值

int — 该类型的值

($&Client) lpush

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

用途

在 $&Client 上执行 lpush 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
val string
值(string)

返回值

int — 该类型的值

($&Client) rpush

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

用途

在 $&Client 上执行 rpush 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
val string
值(string)

返回值

int — 该类型的值

($&Client) lpop

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

用途

在 $&Client 上执行 lpop 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)

返回值

string — 结果字符串

($&Client) rpop

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

用途

在 $&Client 上执行 rpop 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)

返回值

string — 结果字符串

($&Client) llen

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

用途

在 $&Client 上执行 llen 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)

返回值

int — 该类型的值

($&Client) lrange

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

用途

在 $&Client 上执行 lrange 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
start int
start(int)
stop int
stop(int)

返回值

[]string — 切片结果

($&Client) sadd

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

用途

在 $&Client 上执行 sadd 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
member string
member(string)

返回值

int — 该类型的值

($&Client) srem

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

用途

在 $&Client 上执行 srem 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
member string
member(string)

返回值

int — 该类型的值

($&Client) sismember

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

用途

在 $&Client 上执行 sismember 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
member string
member(string)

返回值

bool — 是否成立

($&Client) smembers

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

用途

在 $&Client 上执行 smembers 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)

返回值

[]string — 切片结果

($&Client) scard

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

用途

在 $&Client 上执行 scard 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)

返回值

int — 该类型的值

($&Client) mget

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

用途

在 $&Client 上执行 mget 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
keys []string
keys([]string)

返回值

[]string — 切片结果

($&Client) mset

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

用途

在 $&Client 上执行 mset 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
pairs []string
pairs([]string)

返回值

string — 结果字符串

($&Client) zadd

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

用途

在 $&Client 上执行 zadd 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
score f64
score(f64)
member string
member(string)

返回值

int — 该类型的值

($&Client) zrange

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

用途

在 $&Client 上执行 zrange 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
start int
start(int)
stop int
stop(int)

返回值

[]string — 切片结果

($&Client) zrevrange

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

用途

在 $&Client 上执行 zrevrange 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
start int
start(int)
stop int
stop(int)

返回值

[]string — 切片结果

($&Client) zscore

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

用途

在 $&Client 上执行 zscore 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
member string
member(string)

返回值

string — 结果字符串

($&Client) zrem

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

用途

在 $&Client 上执行 zrem 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
member string
member(string)

返回值

int — 该类型的值

($&Client) zcard

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

用途

在 $&Client 上执行 zcard 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)

返回值

int — 该类型的值

struct Pipeline

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

用途

承载 raw、count 等属性的结构体。

公开字段

raw string
字段(string)
count int
字段(int)

new_pipeline

XuAPI
pub fn new_pipeline() Pipeline

用途

构造 pipeline。

参数

无需传入参数。

返回值

Pipeline — 该类型的值

(&Client) pipeline

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

用途

在 &Client 上执行 pipeline 操作。

参数

c &Client
本次调用使用的 Client 实例;以只读借用传入,调用方仍持有实例。

返回值

Pipeline — 该类型的值

($&Pipeline) len

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

用途

$&Pipeline 上的操作:返回长度。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

($&Pipeline) command

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

用途

$&Pipeline 上的操作:命令。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
args []string
可变实参([]string)

返回值

不返回值。

($&Pipeline) ping

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

用途

发送心跳保活探测请求,检测连接活性与服务可用性。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

不返回值。

($&Pipeline) get

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

用途

在 $&Pipeline 上执行 get 操作。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)

返回值

不返回值。

($&Pipeline) set

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

用途

在 $&Pipeline 上执行 set 操作。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
val string
值(string)

返回值

不返回值。

($&Pipeline) set_ex

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

用途

$&Pipeline 上的操作:设置 ex。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
seconds int
seconds(int)
val string
值(string)

返回值

不返回值。

($&Pipeline) del

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

用途

删除指定键或标识对应的数据项。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)

返回值

不返回值。

($&Pipeline) incr

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

用途

在 $&Pipeline 上执行 incr 操作。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)

返回值

不返回值。

($&Pipeline) decr

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

用途

在 $&Pipeline 上执行 decr 操作。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)

返回值

不返回值。

($&Pipeline) incr_by

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

用途

$&Pipeline 上的操作:执行 incr by 操作。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
delta int
增量(int)

返回值

不返回值。

($&Pipeline) decr_by

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

用途

$&Pipeline 上的操作:执行 decr by 操作。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
delta int
增量(int)

返回值

不返回值。

($&Pipeline) expire

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

用途

在 $&Pipeline 上执行 expire 操作。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
seconds int
seconds(int)

返回值

不返回值。

($&Pipeline) ttl

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

用途

在 $&Pipeline 上执行 ttl 操作。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)

返回值

不返回值。

($&Pipeline) hget

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

用途

在 $&Pipeline 上执行 hget 操作。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
field string
field(string)

返回值

不返回值。

($&Pipeline) hset

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

用途

在 $&Pipeline 上执行 hset 操作。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
field string
field(string)
val string
值(string)

返回值

不返回值。

($&Pipeline) hdel

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

用途

在 $&Pipeline 上执行 hdel 操作。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
field string
field(string)

返回值

不返回值。

($&Pipeline) lpush

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

用途

在 $&Pipeline 上执行 lpush 操作。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
val string
值(string)

返回值

不返回值。

($&Pipeline) rpush

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

用途

在 $&Pipeline 上执行 rpush 操作。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
val string
值(string)

返回值

不返回值。

($&Pipeline) lpop

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

用途

在 $&Pipeline 上执行 lpop 操作。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)

返回值

不返回值。

($&Pipeline) rpop

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

用途

在 $&Pipeline 上执行 rpop 操作。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)

返回值

不返回值。

($&Pipeline) sadd

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

用途

在 $&Pipeline 上执行 sadd 操作。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
member string
member(string)

返回值

不返回值。

($&Pipeline) srem

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

用途

在 $&Pipeline 上执行 srem 操作。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
member string
member(string)

返回值

不返回值。

($&Pipeline) zadd

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

用途

在 $&Pipeline 上执行 zadd 操作。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
score f64
score(f64)
member string
member(string)

返回值

不返回值。

($&Pipeline) zrem

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

用途

在 $&Pipeline 上执行 zrem 操作。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
member string
member(string)

返回值

不返回值。

($&Pipeline) zscore

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

用途

在 $&Pipeline 上执行 zscore 操作。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
member string
member(string)

返回值

不返回值。

($&Pipeline) zrange

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

用途

在 $&Pipeline 上执行 zrange 操作。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
key string
键(string)
start int
start(int)
stop int
stop(int)

返回值

不返回值。

($&Pipeline) mget

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

用途

在 $&Pipeline 上执行 mget 操作。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
keys []string
keys([]string)

返回值

不返回值。

($&Pipeline) mset

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

用途

在 $&Pipeline 上执行 mset 操作。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
pairs []string
pairs([]string)

返回值

不返回值。

($&Client) exec_pipeline

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

用途

$&Client 上的操作:执行 exec pipeline 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&Client
本次调用使用的 Client 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
p $&Pipeline
p(独占借用,可修改原值;类型 $&Pipeline)

返回值

[]Value — 切片结果

($&Pipeline) exec

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

用途

执行 SQL 语句或服务命令,返回受影响行数或执行结果。失败时抛出错误,调用方需处理或继续传播。

参数

p $&Pipeline
本次调用使用的 Pipeline 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
c $&Client
字节或字符码(独占借用,可修改原值;类型 $&Client)

返回值

[]Value — 切片结果

struct Pool

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

用途

Redis 连接池管理器,并发安全地维护和调度复用套接字连接。

公开字段

addr string
地址
auth string
字段(string)
db int
字段(int)
idle chan int
字段(通道;类型 chan int)
max_idle int
字段(int)

查看用法示例

new_pool

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

用途

构造 pool。

参数

addr string
地址(string)
max_idle int
max_idle(int)

返回值

Pool — 该类型的值

new_pool_auth

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

用途

构造 pool auth。

参数

addr string
地址(string)
auth string
auth(string)
max_idle int
max_idle(int)

返回值

Pool — 该类型的值

new_pool_url

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

用途

构造 pool url。

参数

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

返回值

Pool — 该类型的值

查看用法示例

(&Pool) get

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

用途

在 &Pool 上执行 get 操作。失败时抛出错误,调用方需处理或继续传播。

参数

p &Pool
本次调用使用的 Pool 实例;以只读借用传入,调用方仍持有实例。

返回值

Client — 该类型的值

(&Pool) put

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

用途

写入或更新指定键对应的值数据。

参数

p &Pool
本次调用使用的 Pool 实例;以只读借用传入,调用方仍持有实例。
c Client
字节或字符码(Client)

返回值

不返回值。

(&Pool) close

XuAPI
pub fn (p &Pool) close()

用途

&Pool 上的操作:关闭资源。

参数

p &Pool
本次调用使用的 Pool 实例;以只读借用传入,调用方仍持有实例。

返回值

不返回值。

encode_cmd

XuAPI
pub fn encode_cmd(args []string) string

用途

编码 cmd 数据。

参数

args []string
可变实参([]string)

返回值

string — 结果字符串

查看用法示例

find_crlf

XuAPI
pub fn find_crlf(s &string) int

用途

执行 find crlf 操作。

参数

s &string
源字符串(只读借用,调用方仍持有原值;类型 &string)

返回值

int — 该类型的值

struct TlsClient

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

用途

Redis 客户端会话实例,维护与服务端的连接并提供操作接口。

公开字段

conn transport.Conn
字段(transport.Conn)
host string
主机
port int
端口

tls_connect

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

用途

执行 tls connect 操作。失败时抛出错误,调用方需处理或继续传播。

参数

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

返回值

TlsClient — 该类型的值

tls_connect_config

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

用途

执行 tls connect config 操作。失败时抛出错误,调用方需处理或继续传播。

参数

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

返回值

TlsClient — 该类型的值

($&TlsClient) write_all

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

用途

$&TlsClient 上的操作:执行 write all 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&TlsClient
本次调用使用的 TlsClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
data string
数据(string)

返回值

int — 该类型的值

($&TlsClient) read

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

用途

$&TlsClient 上的操作:读出最多 max 字节。失败时抛出错误,调用方需处理或继续传播。

参数

c $&TlsClient
本次调用使用的 TlsClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
max int
上限(int)

返回值

string — 结果字符串

($&TlsClient) read_exact

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

用途

$&TlsClient 上的操作:执行 read exact 操作。失败时抛出错误,调用方需处理或继续传播。

参数

c $&TlsClient
本次调用使用的 TlsClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
need int
need(int)

返回值

string — 结果字符串

($&TlsClient) close

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

用途

$&TlsClient 上的操作:关闭资源。失败时抛出错误,调用方需处理或继续传播。

参数

c $&TlsClient
本次调用使用的 TlsClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

int — 该类型的值

($&TlsClient) set_deadline

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

用途

$&TlsClient 上的操作:设置 deadline。失败时抛出错误,调用方需处理或继续传播。

参数

c $&TlsClient
本次调用使用的 TlsClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
t_ns int
t_ns(int)

返回值

int — 该类型的值

($&TlsClient) set_read_deadline

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

用途

$&TlsClient 上的操作:设置 read deadline。失败时抛出错误,调用方需处理或继续传播。

参数

c $&TlsClient
本次调用使用的 TlsClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
t_ns int
t_ns(int)

返回值

int — 该类型的值

($&TlsClient) set_write_deadline

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

用途

$&TlsClient 上的操作:设置 write deadline。失败时抛出错误,调用方需处理或继续传播。

参数

c $&TlsClient
本次调用使用的 TlsClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
t_ns int
t_ns(int)

返回值

int — 该类型的值

struct RedisURL

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

用途

承载 host、port、addr、password、db 等属性的结构体。

公开字段

host string
主机
port int
端口
addr string
地址
password string
字段(string)
db int
字段(int)

parse_url

XuAPI
pub fn parse_url(raw string) RedisURL

用途

解析为 url。

参数

raw string
raw(string)

返回值

RedisURL — 该类型的值

查看用法示例

const TYPE_STR

XuAPI
pub const TYPE_STR = 1

用途

常量 TYPE_STR,定义了相关的协议或算法配置参数。

const TYPE_INT

XuAPI
pub const TYPE_INT = 2

用途

常量 TYPE_INT,定义了相关的协议或算法配置参数。

const TYPE_ARR

XuAPI
pub const TYPE_ARR = 3

用途

常量 TYPE_ARR,定义了相关的协议或算法配置参数。

const TYPE_NIL

XuAPI
pub const TYPE_NIL = 4

用途

常量 TYPE_NIL,定义了相关的协议或算法配置参数。

const TYPE_ERR

XuAPI
pub const TYPE_ERR = 5

用途

常量 TYPE_ERR,定义了相关的协议或算法配置参数。

const TYPE_BOOL

XuAPI
pub const TYPE_BOOL = 6

用途

常量 TYPE_BOOL,定义了相关的协议或算法配置参数。

const TYPE_MAP

XuAPI
pub const TYPE_MAP = 7

用途

常量 TYPE_MAP,定义了相关的协议或算法配置参数。

const TYPE_SET

XuAPI
pub const TYPE_SET = 8

用途

常量 TYPE_SET,定义了相关的协议或算法配置参数。

const TYPE_PUSH

XuAPI
pub const TYPE_PUSH = 9

用途

常量 TYPE_PUSH,定义了相关的协议或算法配置参数。

const TYPE_DOUBLE

XuAPI
pub const TYPE_DOUBLE = 10

用途

常量 TYPE_DOUBLE,定义了相关的协议或算法配置参数。

const TYPE_BIG_NUMBER

XuAPI
pub const TYPE_BIG_NUMBER = 11

用途

常量 TYPE_BIG_NUMBER,定义了相关的协议或算法配置参数。

const TYPE_VERBATIM

XuAPI
pub const TYPE_VERBATIM = 12

用途

常量 TYPE_VERBATIM,定义了相关的协议或算法配置参数。

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
}

用途

承载 typ、str_val、int_val、arr_val、is_null 等属性的结构体。

公开字段

typ int
字段(int)
str_val string
字段(string)
int_val int
字段(int)
arr_val []string
字段([]string)
is_null bool
字段(bool)
raw string
字段(string)

nil_value

XuAPI
pub fn nil_value() Value

用途

执行 nil value 操作。

参数

无需传入参数。

返回值

Value — 该类型的值

查看用法示例

str_value

XuAPI
pub fn str_value(s string) Value

用途

执行 str value 操作。

参数

s string
源字符串(string)

返回值

Value — 该类型的值

查看用法示例

int_value

XuAPI
pub fn int_value(n int) Value

用途

执行 int value 操作。

参数

n int
数量、长度或上限(int)

返回值

Value — 该类型的值

查看用法示例

arr_value

XuAPI
pub fn arr_value(arr []string) Value

用途

执行 arr value 操作。

参数

arr []string
要处理的切片([]string)

返回值

Value — 该类型的值

err_value

XuAPI
pub fn err_value(msg string) Value

用途

执行 err value 操作。

参数

msg string
消息(string)

返回值

Value — 该类型的值

bool_value

XuAPI
pub fn bool_value(b bool) Value

用途

执行 bool value 操作。

参数

b bool
b(bool)

返回值

Value — 该类型的值

(&Value) is_nil

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

用途

&Value 上的操作:判断是否 nil。

参数

v &Value
本次调用使用的 Value 实例;以只读借用传入,调用方仍持有实例。

返回值

bool — 是否成立

(&Value) is_err

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

用途

&Value 上的操作:判断是否 err。

参数

v &Value
本次调用使用的 Value 实例;以只读借用传入,调用方仍持有实例。

返回值

bool — 是否成立

(&Value) as_string

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

用途

&Value 上的操作:执行 as string 操作。失败时抛出错误,调用方需处理或继续传播。

参数

v &Value
本次调用使用的 Value 实例;以只读借用传入,调用方仍持有实例。

返回值

string — 结果字符串

(&Value) as_string_or

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

用途

&Value 上的操作:执行 as string or 操作。失败时抛出错误,调用方需处理或继续传播。

参数

v &Value
本次调用使用的 Value 实例;以只读借用传入,调用方仍持有实例。
def string
默认值(string)

返回值

string — 结果字符串

(&Value) as_int

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

用途

&Value 上的操作:执行 as int 操作。失败时抛出错误,调用方需处理或继续传播。

参数

v &Value
本次调用使用的 Value 实例;以只读借用传入,调用方仍持有实例。

返回值

int — 该类型的值

(&Value) as_bool

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

用途

&Value 上的操作:执行 as bool 操作。失败时抛出错误,调用方需处理或继续传播。

参数

v &Value
本次调用使用的 Value 实例;以只读借用传入,调用方仍持有实例。

返回值

bool — 是否成立

(&Value) elements

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

用途

在 &Value 上执行 elements 操作。失败时抛出错误,调用方需处理或继续传播。

参数

v &Value
本次调用使用的 Value 实例;以只读借用传入,调用方仍持有实例。

返回值

[]Value — 切片结果

(&Value) as_strings

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

用途

&Value 上的操作:执行 as strings 操作。失败时抛出错误,调用方需处理或继续传播。

参数

v &Value
本次调用使用的 Value 实例;以只读借用传入,调用方仍持有实例。

返回值

[]string — 切片结果