Skip to content

data.resp #

redis serialization protocol

example

module main
import resp
import crypto.ed25519

fn do()?{
    mut b := resp.builder_new()
    b.add(resp.r_list_string(['a', 'b']))
    b.add(resp.r_int(10))
    b.add(resp.r_ok())
    //to get some binary
    pubkey,privkey := ed25519.generate_key()?

    b.add(resp.r_bytestring(privkey))

    //b.data now has the info as binary data
    // println(b.data)
    println(b.data.bytestr())

    lr := resp.decode(b.data)?
    println(lr)

}


fn main(){
    do() or { panic(err) }
}

Constants #

const crlf = '\r\n'

fn buffered_string_reader #

fn buffered_string_reader(s string) &io.BufferedReader

fn builder_new #

fn builder_new() Builder

fn decode #

fn decode(data []u8) ![]RValue

fn encode #

fn encode(items []RValue) []u8

encode list of RArray | RBString | RError | RInt | RNil | RString bytestring is result

fn get_array_value #

fn get_array_value(rv RValue, index int) string

fn get_redis_array #

fn get_redis_array(rv RValue) []RValue

fn get_redis_array_len #

fn get_redis_array_len(rv RValue) int

fn get_redis_value #

fn get_redis_value(rv RValue) string

fn get_redis_value_by_index #

fn get_redis_value_by_index(rv RValue, i int) string

fn new_line_reader #

fn new_line_reader(data []u8) StringLineReader

fn r_array #

fn r_array(value string) RValue

fn r_bytestring #

fn r_bytestring(value []u8) RValue

fn r_error #

fn r_error(value string) RValue

fn r_float #

fn r_float(value f64) RValue

might be that this does no exist for redis, lets check if it doesn't exist lets create it

fn r_int #

fn r_int(value int) RValue

fn r_list_bstring #

fn r_list_bstring(values []string) RValue

fn r_list_bytestring #

fn r_list_bytestring(values [][]u8) RValue

fn r_list_int #

fn r_list_int(values []int) RValue

fn r_list_string #

fn r_list_string(values []string) RValue

fn r_list_u32 #

fn r_list_u32(values []u32) RValue

fn r_nil #

fn r_nil() RValue

fn r_ok #

fn r_ok() RValue

fn r_string #

fn r_string(value string) RValue

fn r_u32 #

fn r_u32(value u32) RValue

fn (RValue) encode #

fn (val RValue) encode() []u8

fn (RValue) int #

fn (v RValue) int() int

fn (RValue) strget #

fn (v RValue) strget() string

fn (RValue) strlist #

fn (v RValue) strlist() []string

fn (RValue) u32 #

fn (v RValue) u32() u32

fn (RValue) u32list #

fn (v RValue) u32list() []u32

fn (StringLineReader) get_response #

fn (mut r StringLineReader) get_response() !RValue

mut r := io.new_buffered_reader(reader: io.make_reader(conn)) for { l := r.read_line() or { break } console.print_debug('$l') // Make it nice and obvious that we are doing this line by line time.sleep(100 * time.millisecond) } }

fn (StringLineReader) get_int #

fn (mut r StringLineReader) get_int() !int

fn (StringLineReader) get_list_int #

fn (mut r StringLineReader) get_list_int() ![]int

fn (StringLineReader) get_string #

fn (mut r StringLineReader) get_string() !string

fn (StringLineReader) get_bool #

fn (mut r StringLineReader) get_bool() !bool

fn (StringLineReader) get_bytes #

fn (mut r StringLineReader) get_bytes() ![]u8

struct Builder #

struct Builder {
pub mut:
	data []u8
}

fn (Builder) add #

fn (mut b Builder) add(val RValue)

fn (Builder) prepend #

fn (mut b Builder) prepend(val RValue)

add the data at the beginning

struct RArray #

struct RArray {
pub mut:
	// Redis Array
	values []RValue
}

struct RBString #

struct RBString {
pub mut:
	// Redis Bulk String
	value []u8
}

struct RError #

struct RError {
pub mut:
	// Redis Error
	value string
}

struct RInt #

struct RInt {
pub mut:
	// Redis Integer
	value int
}

struct RNil #

struct RNil {
	// Redis Nil
}

struct RString #

struct RString {
pub mut:
	// Redis string
	value string
}

struct StringReader #

struct StringReader {
	text string
mut:
	place int
}