open
pub fn open(addr string) ClientPurpose
Open resource or establish connection. Throws on failure; handle the error or propagate it to the caller.
Parameters
addrstring- address (string)
Returns
Client — a value of this type
#github.com/xulang-org/packages/redisRedis 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
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@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
}openpub fn open(addr string) ClientOpen resource or establish connection. Throws on failure; handle the error or propagate it to the caller.
addr stringClient — a value of this type
open_authpub fn open_auth(addr string, password string) ClientOpen auth. Throws on failure; handle the error or propagate it to the caller.
addr stringpassword stringClient — a value of this type
open_urlpub fn open_url(raw string) ClientOpen url. Throws on failure; handle the error or propagate it to the caller.
raw stringClient — a value of this type
dial_urlpub fn dial_url(raw string) ClientDial url. Throws on failure; handle the error or propagate it to the caller.
raw stringClient — a value of this type
struct Clientpub struct Client {
pub fd int
pub buf string
pub addr string
}Redis Client session maintaining connection and operations.
fd intbuf stringaddr stringdialpub fn dial(addr string) ClientDial a connection. Throws on failure; handle the error or propagate it to the caller.
addr stringClient — a value of this type
($&Client) read_linepub fn (c $&Client) read_line() stringOperation on $&Client: read line. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).string — result string
($&Client) read_bytespub fn (c $&Client) read_bytes(n int) stringOperation on $&Client: read through delim (inclusive). Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).n intstring — result string
($&Client) read_valuepub fn (c $&Client) read_value() ValueOperation on $&Client: read value. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).Value — a value of this type
($&Client) write_rawpub fn (c $&Client) write_raw(data string) intOperation on $&Client: write raw. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).data stringint — a value of this type
($&Client) dopub fn (c $&Client) do(args []string) ValueExecute do on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).args []stringValue — a value of this type
($&Client) authpub fn (c $&Client) auth(password string) stringExecute auth on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).password stringstring — result string
($&Client) select_dbpub fn (c $&Client) select_db(index int) stringOperation on $&Client: select db. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).index intstring — result string
($&Client) closepub fn (c $&Client) close() intOperation on $&Client: close the resource.
c $&ClientClient instance used by this call (exclusive borrow).int — a value of this type
($&Client) pingpub fn (c $&Client) ping() stringSend a ping heartbeat request to verify connection liveness. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).string — result string
($&Client) echopub fn (c $&Client) echo(msg string) stringExecute echo on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).msg stringstring — result string
($&Client) getpub fn (c $&Client) get(key string) stringExecute get on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringstring — result string
($&Client) setpub fn (c $&Client) set(key string, val string) stringExecute set on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringval stringstring — result string
($&Client) set_expub fn (c $&Client) set_ex(key string, seconds int, val string) stringOperation on $&Client: set ex. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringseconds intval stringstring — result string
($&Client) delpub fn (c $&Client) del(key string) intDelete the entry matching the given key or identifier. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringint — a value of this type
($&Client) del_manypub fn (c $&Client) del_many(keys []string) intOperation on $&Client: del many. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).keys []stringint — a value of this type
($&Client) existspub fn (c $&Client) exists(key string) boolExecute exists on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringbool — true or false
($&Client) incrpub fn (c $&Client) incr(key string) intExecute incr on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringint — a value of this type
($&Client) decrpub fn (c $&Client) decr(key string) intExecute decr on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringint — a value of this type
($&Client) incr_bypub fn (c $&Client) incr_by(key string, delta int) intOperation on $&Client: incr by. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringdelta intint — a value of this type
($&Client) decr_bypub fn (c $&Client) decr_by(key string, delta int) intOperation on $&Client: decr by. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringdelta intint — a value of this type
($&Client) expirepub fn (c $&Client) expire(key string, seconds int) boolExecute expire on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringseconds intbool — true or false
($&Client) ttlpub fn (c $&Client) ttl(key string) intExecute ttl on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringint — a value of this type
($&Client) keyspub fn (c $&Client) keys(pattern string) []stringExecute keys on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).pattern string[]string — slice result
($&Client) hgetpub fn (c $&Client) hget(key string, field string) stringExecute hget on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringfield stringstring — result string
($&Client) hsetpub fn (c $&Client) hset(key string, field string, val string) intExecute hset on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringfield stringval stringint — a value of this type
($&Client) hdelpub fn (c $&Client) hdel(key string, field string) intExecute hdel on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringfield stringint — a value of this type
($&Client) hexistspub fn (c $&Client) hexists(key string, field string) boolExecute hexists on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringfield stringbool — true or false
($&Client) hgetallpub fn (c $&Client) hgetall(key string) []stringExecute hgetall on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key string[]string — slice result
($&Client) hkeyspub fn (c $&Client) hkeys(key string) []stringExecute hkeys on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key string[]string — slice result
($&Client) hlenpub fn (c $&Client) hlen(key string) intExecute hlen on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringint — a value of this type
($&Client) lpushpub fn (c $&Client) lpush(key string, val string) intExecute lpush on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringval stringint — a value of this type
($&Client) rpushpub fn (c $&Client) rpush(key string, val string) intExecute rpush on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringval stringint — a value of this type
($&Client) lpoppub fn (c $&Client) lpop(key string) stringExecute lpop on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringstring — result string
($&Client) rpoppub fn (c $&Client) rpop(key string) stringExecute rpop on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringstring — result string
($&Client) llenpub fn (c $&Client) llen(key string) intExecute llen on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringint — a value of this type
($&Client) lrangepub fn (c $&Client) lrange(key string, start int, stop int) []stringExecute lrange on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringstart intstop int[]string — slice result
($&Client) saddpub fn (c $&Client) sadd(key string, member string) intExecute sadd on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringmember stringint — a value of this type
($&Client) srempub fn (c $&Client) srem(key string, member string) intExecute srem on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringmember stringint — a value of this type
($&Client) sismemberpub fn (c $&Client) sismember(key string, member string) boolExecute sismember on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringmember stringbool — true or false
($&Client) smemberspub fn (c $&Client) smembers(key string) []stringExecute smembers on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key string[]string — slice result
($&Client) scardpub fn (c $&Client) scard(key string) intExecute scard on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringint — a value of this type
($&Client) mgetpub fn (c $&Client) mget(keys []string) []stringExecute mget on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).keys []string[]string — slice result
($&Client) msetpub fn (c $&Client) mset(pairs []string) stringExecute mset on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).pairs []stringstring — result string
($&Client) zaddpub fn (c $&Client) zadd(key string, score f64, member string) intExecute zadd on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringscore f64member stringint — a value of this type
($&Client) zrangepub fn (c $&Client) zrange(key string, start int, stop int) []stringExecute zrange on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringstart intstop int[]string — slice result
($&Client) zrevrangepub fn (c $&Client) zrevrange(key string, start int, stop int) []stringExecute zrevrange on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringstart intstop int[]string — slice result
($&Client) zscorepub fn (c $&Client) zscore(key string, member string) stringExecute zscore on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringmember stringstring — result string
($&Client) zrempub fn (c $&Client) zrem(key string, member string) intExecute zrem on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringmember stringint — a value of this type
($&Client) zcardpub fn (c $&Client) zcard(key string) intExecute zcard on $&Client. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).key stringint — a value of this type
struct Pipelinepub struct Pipeline {
pub raw string
pub count int
}Structure encapsulating raw, count.
raw stringcount intnew_pipelinepub fn new_pipeline() PipelineConstruct pipeline.
No arguments are required.
Pipeline — a value of this type
(&Client) pipelinepub fn (c &Client) pipeline() PipelineExecute pipeline on &Client.
c &ClientClient instance used by this call (borrow).Pipeline — a value of this type
($&Pipeline) lenpub fn (p $&Pipeline) len() intOperation on $&Pipeline: return the length.
p $&PipelinePipeline instance used by this call (exclusive borrow).int — a value of this type
($&Pipeline) commandpub fn (p $&Pipeline) command(args []string)Execute command on $&Pipeline.
p $&PipelinePipeline instance used by this call (exclusive borrow).args []stringThis call does not return a value.
($&Pipeline) pingpub fn (p $&Pipeline) ping()Send a ping heartbeat request to verify connection liveness.
p $&PipelinePipeline instance used by this call (exclusive borrow).This call does not return a value.
($&Pipeline) getpub fn (p $&Pipeline) get(key string)Execute get on $&Pipeline.
p $&PipelinePipeline instance used by this call (exclusive borrow).key stringThis call does not return a value.
($&Pipeline) setpub fn (p $&Pipeline) set(key string, val string)Execute set on $&Pipeline.
p $&PipelinePipeline instance used by this call (exclusive borrow).key stringval stringThis call does not return a value.
($&Pipeline) set_expub fn (p $&Pipeline) set_ex(key string, seconds int, val string)Operation on $&Pipeline: set ex.
p $&PipelinePipeline instance used by this call (exclusive borrow).key stringseconds intval stringThis call does not return a value.
($&Pipeline) delpub fn (p $&Pipeline) del(key string)Delete the entry matching the given key or identifier.
p $&PipelinePipeline instance used by this call (exclusive borrow).key stringThis call does not return a value.
($&Pipeline) incrpub fn (p $&Pipeline) incr(key string)Execute incr on $&Pipeline.
p $&PipelinePipeline instance used by this call (exclusive borrow).key stringThis call does not return a value.
($&Pipeline) decrpub fn (p $&Pipeline) decr(key string)Execute decr on $&Pipeline.
p $&PipelinePipeline instance used by this call (exclusive borrow).key stringThis call does not return a value.
($&Pipeline) incr_bypub fn (p $&Pipeline) incr_by(key string, delta int)Operation on $&Pipeline: incr by.
p $&PipelinePipeline instance used by this call (exclusive borrow).key stringdelta intThis call does not return a value.
($&Pipeline) decr_bypub fn (p $&Pipeline) decr_by(key string, delta int)Operation on $&Pipeline: decr by.
p $&PipelinePipeline instance used by this call (exclusive borrow).key stringdelta intThis call does not return a value.
($&Pipeline) expirepub fn (p $&Pipeline) expire(key string, seconds int)Execute expire on $&Pipeline.
p $&PipelinePipeline instance used by this call (exclusive borrow).key stringseconds intThis call does not return a value.
($&Pipeline) ttlpub fn (p $&Pipeline) ttl(key string)Execute ttl on $&Pipeline.
p $&PipelinePipeline instance used by this call (exclusive borrow).key stringThis call does not return a value.
($&Pipeline) hgetpub fn (p $&Pipeline) hget(key string, field string)Execute hget on $&Pipeline.
p $&PipelinePipeline instance used by this call (exclusive borrow).key stringfield stringThis call does not return a value.
($&Pipeline) hsetpub fn (p $&Pipeline) hset(key string, field string, val string)Execute hset on $&Pipeline.
p $&PipelinePipeline instance used by this call (exclusive borrow).key stringfield stringval stringThis call does not return a value.
($&Pipeline) hdelpub fn (p $&Pipeline) hdel(key string, field string)Execute hdel on $&Pipeline.
p $&PipelinePipeline instance used by this call (exclusive borrow).key stringfield stringThis call does not return a value.
($&Pipeline) lpushpub fn (p $&Pipeline) lpush(key string, val string)Execute lpush on $&Pipeline.
p $&PipelinePipeline instance used by this call (exclusive borrow).key stringval stringThis call does not return a value.
($&Pipeline) rpushpub fn (p $&Pipeline) rpush(key string, val string)Execute rpush on $&Pipeline.
p $&PipelinePipeline instance used by this call (exclusive borrow).key stringval stringThis call does not return a value.
($&Pipeline) lpoppub fn (p $&Pipeline) lpop(key string)Execute lpop on $&Pipeline.
p $&PipelinePipeline instance used by this call (exclusive borrow).key stringThis call does not return a value.
($&Pipeline) rpoppub fn (p $&Pipeline) rpop(key string)Execute rpop on $&Pipeline.
p $&PipelinePipeline instance used by this call (exclusive borrow).key stringThis call does not return a value.
($&Pipeline) saddpub fn (p $&Pipeline) sadd(key string, member string)Execute sadd on $&Pipeline.
p $&PipelinePipeline instance used by this call (exclusive borrow).key stringmember stringThis call does not return a value.
($&Pipeline) srempub fn (p $&Pipeline) srem(key string, member string)Execute srem on $&Pipeline.
p $&PipelinePipeline instance used by this call (exclusive borrow).key stringmember stringThis call does not return a value.
($&Pipeline) zaddpub fn (p $&Pipeline) zadd(key string, score f64, member string)Execute zadd on $&Pipeline.
p $&PipelinePipeline instance used by this call (exclusive borrow).key stringscore f64member stringThis call does not return a value.
($&Pipeline) zrempub fn (p $&Pipeline) zrem(key string, member string)Execute zrem on $&Pipeline.
p $&PipelinePipeline instance used by this call (exclusive borrow).key stringmember stringThis call does not return a value.
($&Pipeline) zscorepub fn (p $&Pipeline) zscore(key string, member string)Execute zscore on $&Pipeline.
p $&PipelinePipeline instance used by this call (exclusive borrow).key stringmember stringThis call does not return a value.
($&Pipeline) zrangepub fn (p $&Pipeline) zrange(key string, start int, stop int)Execute zrange on $&Pipeline.
p $&PipelinePipeline instance used by this call (exclusive borrow).key stringstart intstop intThis call does not return a value.
($&Pipeline) mgetpub fn (p $&Pipeline) mget(keys []string)Execute mget on $&Pipeline.
p $&PipelinePipeline instance used by this call (exclusive borrow).keys []stringThis call does not return a value.
($&Pipeline) msetpub fn (p $&Pipeline) mset(pairs []string)Execute mset on $&Pipeline.
p $&PipelinePipeline instance used by this call (exclusive borrow).pairs []stringThis call does not return a value.
($&Client) exec_pipelinepub fn (c $&Client) exec_pipeline(p $&Pipeline) []ValueOperation on $&Client: exec pipeline. Throws on failure; handle the error or propagate it to the caller.
c $&ClientClient instance used by this call (exclusive borrow).p $&Pipeline[]Value — slice result
($&Pipeline) execpub fn (p $&Pipeline) exec(c $&Client) []ValueExecute SQL statement or service command and return result. Throws on failure; handle the error or propagate it to the caller.
p $&PipelinePipeline instance used by this call (exclusive borrow).c $&Client[]Value — slice result
struct Poolpub struct Pool {
pub addr string
pub auth string
pub db int
pub idle chan int
pub max_idle int
}Redis Connection pool manager scheduling reusable socket connections.
addr stringauth stringdb intidle chan intmax_idle intnew_poolpub fn new_pool(addr string, max_idle int) PoolConstruct pool.
addr stringmax_idle intPool — a value of this type
new_pool_authpub fn new_pool_auth(addr string, auth string, max_idle int) PoolConstruct pool auth.
addr stringauth stringmax_idle intPool — a value of this type
new_pool_urlpub fn new_pool_url(raw string, max_idle int) PoolConstruct pool url.
raw stringmax_idle intPool — a value of this type
(&Pool) getpub fn (p &Pool) get() ClientExecute get on &Pool. Throws on failure; handle the error or propagate it to the caller.
p &PoolPool instance used by this call (borrow).Client — a value of this type
(&Pool) putpub fn (p &Pool) put(c Client)Store or update the value associated with the specified key.
p &PoolPool instance used by this call (borrow).c ClientThis call does not return a value.
(&Pool) closepub fn (p &Pool) close()Operation on &Pool: close the resource.
p &PoolPool instance used by this call (borrow).This call does not return a value.
encode_cmdpub fn encode_cmd(args []string) stringEncode cmd data.
args []stringstring — result string
find_crlfpub fn find_crlf(s &string) intFind crlf.
s &stringint — a value of this type
struct TlsClientpub struct TlsClient {
pub conn transport.Conn
pub host string
pub port int
}Redis Client session maintaining connection and operations.
conn transport.Connhost stringport inttls_connectpub fn tls_connect(endpoint string, default_port int) TlsClientTls connect. Throws on failure; handle the error or propagate it to the caller.
endpoint stringdefault_port intTlsClient — a value of this type
tls_connect_configpub fn tls_connect_config(endpoint string, default_port int, cfg tls.Config) TlsClientTls connect config. Throws on failure; handle the error or propagate it to the caller.
endpoint stringdefault_port intcfg tls.ConfigTlsClient — a value of this type
($&TlsClient) write_allpub fn (c $&TlsClient) write_all(data string) intOperation on $&TlsClient: write all. Throws on failure; handle the error or propagate it to the caller.
c $&TlsClientTlsClient instance used by this call (exclusive borrow).data stringint — a value of this type
($&TlsClient) readpub fn (c $&TlsClient) read(max int) stringOperation on $&TlsClient: read up to max bytes. Throws on failure; handle the error or propagate it to the caller.
c $&TlsClientTlsClient instance used by this call (exclusive borrow).max intstring — result string
($&TlsClient) read_exactpub fn (c $&TlsClient) read_exact(need int) stringOperation on $&TlsClient: read exact. Throws on failure; handle the error or propagate it to the caller.
c $&TlsClientTlsClient instance used by this call (exclusive borrow).need intstring — result string
($&TlsClient) closepub fn (c $&TlsClient) close() intOperation on $&TlsClient: close the resource. Throws on failure; handle the error or propagate it to the caller.
c $&TlsClientTlsClient instance used by this call (exclusive borrow).int — a value of this type
($&TlsClient) set_deadlinepub fn (c $&TlsClient) set_deadline(t_ns int) intOperation on $&TlsClient: set deadline. Throws on failure; handle the error or propagate it to the caller.
c $&TlsClientTlsClient instance used by this call (exclusive borrow).t_ns intint — a value of this type
($&TlsClient) set_read_deadlinepub fn (c $&TlsClient) set_read_deadline(t_ns int) intOperation on $&TlsClient: set read deadline. Throws on failure; handle the error or propagate it to the caller.
c $&TlsClientTlsClient instance used by this call (exclusive borrow).t_ns intint — a value of this type
($&TlsClient) set_write_deadlinepub fn (c $&TlsClient) set_write_deadline(t_ns int) intOperation on $&TlsClient: set write deadline. Throws on failure; handle the error or propagate it to the caller.
c $&TlsClientTlsClient instance used by this call (exclusive borrow).t_ns intint — a value of this type
struct RedisURLpub struct RedisURL {
pub host string
pub port int
pub addr string
pub password string
pub db int
}Structure encapsulating host, port, addr, password, db.
host stringport intaddr stringpassword stringdb intparse_urlpub fn parse_url(raw string) RedisURLParse as url.
raw stringRedisURL — a value of this type
const TYPE_STRpub const TYPE_STR = 1Constant TYPE_STR, defining protocol or algorithm parameters.
const TYPE_INTpub const TYPE_INT = 2Constant TYPE_INT, defining protocol or algorithm parameters.
const TYPE_ARRpub const TYPE_ARR = 3Constant TYPE_ARR, defining protocol or algorithm parameters.
const TYPE_NILpub const TYPE_NIL = 4Constant TYPE_NIL, defining protocol or algorithm parameters.
const TYPE_ERRpub const TYPE_ERR = 5Constant TYPE_ERR, defining protocol or algorithm parameters.
const TYPE_BOOLpub const TYPE_BOOL = 6Constant TYPE_BOOL, defining protocol or algorithm parameters.
const TYPE_MAPpub const TYPE_MAP = 7Constant TYPE_MAP, defining protocol or algorithm parameters.
const TYPE_SETpub const TYPE_SET = 8Constant TYPE_SET, defining protocol or algorithm parameters.
const TYPE_PUSHpub const TYPE_PUSH = 9Constant TYPE_PUSH, defining protocol or algorithm parameters.
const TYPE_DOUBLEpub const TYPE_DOUBLE = 10Constant TYPE_DOUBLE, defining protocol or algorithm parameters.
const TYPE_BIG_NUMBERpub const TYPE_BIG_NUMBER = 11Constant TYPE_BIG_NUMBER, defining protocol or algorithm parameters.
const TYPE_VERBATIMpub const TYPE_VERBATIM = 12Constant TYPE_VERBATIM, defining protocol or algorithm parameters.
struct Valuepub struct Value {
pub typ int
pub str_val string
pub int_val int
pub arr_val []string
pub is_null bool
pub raw string
}Structure encapsulating typ, str_val, int_val, arr_val, is_null.
typ intstr_val stringint_val intarr_val []stringis_null boolraw stringnil_valuepub fn nil_value() ValueNil value.
No arguments are required.
Value — a value of this type
str_valuepub fn str_value(s string) ValueStr value.
s stringValue — a value of this type
int_valuepub fn int_value(n int) ValueInt value.
n intValue — a value of this type
arr_valuepub fn arr_value(arr []string) ValueArr value.
arr []stringValue — a value of this type
err_valuepub fn err_value(msg string) ValueErr value.
msg stringValue — a value of this type
bool_valuepub fn bool_value(b bool) ValueBool value.
b boolValue — a value of this type
(&Value) is_nilpub fn (v &Value) is_nil() boolOperation on &Value: whether it is nil.
v &ValueValue instance used by this call (borrow).bool — true or false
(&Value) is_errpub fn (v &Value) is_err() boolOperation on &Value: whether it is err.
v &ValueValue instance used by this call (borrow).bool — true or false
(&Value) as_stringpub fn (v &Value) as_string() stringOperation on &Value: as string. Throws on failure; handle the error or propagate it to the caller.
v &ValueValue instance used by this call (borrow).string — result string
(&Value) as_string_orpub fn (v &Value) as_string_or(def string) stringOperation on &Value: as string or. Throws on failure; handle the error or propagate it to the caller.
v &ValueValue instance used by this call (borrow).def stringstring — result string
(&Value) as_intpub fn (v &Value) as_int() intOperation on &Value: as int. Throws on failure; handle the error or propagate it to the caller.
v &ValueValue instance used by this call (borrow).int — a value of this type
(&Value) as_boolpub fn (v &Value) as_bool() boolOperation on &Value: as bool. Throws on failure; handle the error or propagate it to the caller.
v &ValueValue instance used by this call (borrow).bool — true or false
(&Value) elementspub fn (v &Value) elements() []ValueMap 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.
v &ValueValue instance used by this call (borrow).[]Value — slice result
(&Value) as_stringspub fn (v &Value) as_strings() []stringOperation on &Value: as string slice. Throws on failure; handle the error or propagate it to the caller.
v &ValueValue instance used by this call (borrow).[]string — slice result