Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is there any possibility of returning WriteBulk without pre specifying how many to return? #44

Open
hiqsociety opened this issue Jun 5, 2021 · 1 comment

Comments

@hiqsociety
Copy link

hiqsociety commented Jun 5, 2021

if i'm getting data from db,
is this possible without pre specifying with WriteArray() first?

for it.Seek(); it.Valid(); it.Next() {
conn.WriteBulk([]byte, it.Key.Data())
}

@tidwall
Copy link
Owner

tidwall commented Mar 22, 2022

No. You will need to call WriteArray, which writes the number of items in the array first.
If you don't know how many items there will be then you can buffer them like:

// buffer and count the items
var count int
var buf bufio.Buffer
w := redcon.NewWriter(&buf)
for it.Seek(); it.Valid(); it.Next() {
    w.WriteBulk(it.Key.Data())
    count++
}

// write the array header and the buffered items.
conn.WriteArray(count)
conn.WriteRaw(buf.Bytes())

Then wr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants