A modern, high performance Redis client for MoonBit.
///|
async test "string_set_get" {
@async.with_task_group(async fn(_root) {
let client = connect("localhost", 6379)
defer client.close()
// SET
let set_result = client.set("test:string", "hello_world")
assert_true(set_result is Ok("OK"))
// GET
let get_result = client.get("test:string")
assert_true(get_result is Ok("hello_world"))
// Cleanup
let _ = client.del(["test:string"])
})
}///|
async test "ping" {
@async.with_task_group(async fn(_root) {
let client = @redis.Client("localhost", port=6379)
defer client.close()
let pong = client.ping()
assert_true(pong is Ok("PONG"))
})
}///|
async test "connect_with_auth" {
@async.with_task_group(async fn(_root) {
let client = @redis.Client(
"localhost",
port=6379,
username="default",
password="secret",
db=1,
)
defer client.close()
let pong = client.ping()
assert_true(pong is Ok("PONG"))
})
}pub(all) suberror ConnectError {
AuthFailed(String)
SelectFailed(String)
}pub(all) enum Bit {
Zero
One
}pub(all) enum BitFieldEncoding {
U8
U16
U32
U64
I8
I16
I32
I64
}pub(all) enum BitFieldOperation {
Get(encoding~ : BitFieldEncoding, offset~ : Int)
Set(encoding~ : BitFieldEncoding, offset~ : Int, value~ : Bit)
Incrby(encoding~ : BitFieldEncoding, offset~ : Int, value~ : Int)
Overflow(behavior~ : String)
}async fn Client::Client(host : StringView, port? : Int, protocol? : IpProtocolPreference, username? : String, password? : String, db? : Int) -> Clientasync fn Client::blmove(self : Client, source : String, destination : String, wherefrom~ : Int, whereto~ : Int, timeout~ : Int) -> RedisValueasync fn Client::blmpop(self : Client, timeout~ : Int, numkeys : String, keys : Array[String], where_~ : String) -> RedisValueasync fn Client::brpoplpush(self : Client, source : String, destination : String, timeout~ : Int) -> RedisValueasync fn Client::geoadd_multiple(self : Client, key : String, coordinates : Array[GeoCoordinates]) -> Result[Int, String]async fn Client::geosearch_box(self : Client, key : String, coordinates : GeoCoordinates, search_box : GeoSearchByBox) -> Result[Array[String], String]async fn Client::geosearchstore_box(self : Client, destination : String, source : String, from_member : String, search_box : GeoSearchByBox) -> Result[Int, String]async fn Client::lmove(self : Client, source : String, destination : String, wherefrom~ : Int, whereto~ : Int) -> RedisValueasync fn Client::lmpop(self : Client, numkeys : String, keys : Array[String], where_~ : String) -> RedisValueasync fn Client::set(self : Client, key : String, value : String, condition? : SetCondition, get? : Bool, expiration? : SetExpiration) -> Result[String, String]async fn Client::xrange(self : Client, key : String, start~ : String, end~ : String, count? : Int) -> Result[Array[RedisStreamMessage], String]async fn Client::xread(self : Client, count? : Int, block? : Int, streams : Array[(String, String)]) -> Result[RedisStream, String]async fn Client::xreadgroup(self : Client, group : String, consumer : String, count? : Int, block? : Int, noack? : Bool, streams : Array[(String, String)]) -> Result[RedisStream, String]async fn Client::xrevrange(self : Client, key : String, end~ : String, start~ : String, count? : Int) -> Result[Array[RedisStreamMessage], String]async fn Client::xtrim(self : Client, key : String, strategy~ : XTrimStrategy, threshold~ : Int64, approximate? : Bool, limit? : Int, keepref? : Bool, delref? : Bool, acked? : Bool) -> Result[Int, String]async fn Client::zadd(self : Client, key : String, zadd_members : Array[ZAddMember]) -> Result[Int, String]pub(all) struct GeoCoordinates {
longitude : Double
latitude : Double
}pub(all) enum GeoUnits {
Meters
Kilometers
Miles
Feet
}impl Show for RedisStreamMessagepub(all) enum RedisValue {
SimpleString(String)
Error(String)
Integer(Int)
BulkString(String?)
Array(Array[RedisValue])
} derive(Eq, Hash, Debug)impl Show for RedisValuefn RedisValue::to_stream_message_array(self : RedisValue) -> Result[Array[RedisStreamMessage], String]pub(all) enum SetExpiration {
EX(Int)
PX(Int)
EXAT(Int)
PXAT(Int)
KEEPTTL
}#deprecated("Use `@redis.Client` instead of `@redis.Client` to create a RedisClient.")
async fn connect(host : StringView, port? : Int, protocol? : IpProtocolPreference, username? : String, password? : String, db? : Int) -> Client