add count, pop ingester
This commit is contained in:
parent
dd927a4ab4
commit
df036ec680
2 changed files with 42 additions and 6 deletions
|
|
@ -19,6 +19,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
channel := sonic.IngesterChannel{Connection: connection}
|
channel := sonic.IngesterChannel{Connection: connection}
|
||||||
e = channel.Push("test", "default", "captain", "lol is truth")
|
c, e := channel.Count("test", "default", "captain")
|
||||||
fmt.Println(e)
|
|
||||||
|
fmt.Println(c, e)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
package sonic
|
package sonic
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
type Ingestable interface {
|
type Ingestable interface {
|
||||||
Push(collection, bucket, object, text string) (err error)
|
Push(collection, bucket, object, text string) (err error)
|
||||||
|
|
@ -42,11 +46,42 @@ func (i IngesterChannel) Push(collection, bucket, object, text string) (err erro
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i IngesterChannel) Pop(collection, bucket, object, text string) (err error) {
|
func (i IngesterChannel) Pop(collection, bucket, object, text string) (err error) {
|
||||||
panic("implement me")
|
err = i.write(fmt.Sprintf("%s %s %s %s \"%s\"", pop, collection, bucket, object, text))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i IngesterChannel) Count(collection, bucket, object string) (count int, err error) {
|
// sonic should sent OK
|
||||||
panic("implement me")
|
_, err = i.read()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i IngesterChannel) Count(collection, bucket, object string) (cnt int, err error) {
|
||||||
|
err = i.write(fmt.Sprintf("%s %s %s", count, collection, buildCountQuery(bucket, object)))
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// RESULT NUMBER
|
||||||
|
r, err := i.read()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return strconv.Atoi(r[7:])
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildCountQuery(bucket, object string) string {
|
||||||
|
builder := strings.Builder{}
|
||||||
|
if bucket != "" {
|
||||||
|
builder.WriteString(bucket)
|
||||||
|
if object != "" {
|
||||||
|
builder.WriteString(" " + object)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return builder.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i IngesterChannel) FlushCollection(collection string) (err error) {
|
func (i IngesterChannel) FlushCollection(collection string) (err error) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue