Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Commit

Permalink
fix counter 2 old version
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadim Kilibaba committed Dec 24, 2018
1 parent 3dac366 commit bcf4f49
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions slowpoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package slowpoke

import (
"bytes"
"encoding/binary"
"encoding/gob"
"reflect"

Expand Down Expand Up @@ -48,8 +49,18 @@ func Count(file string) (uint64, error) {

// Counter return unique uint64
func Counter(file string, key []byte) (counter uint64, err error) {
res, err := pudge.Counter(file, key, 1)
return uint64(res), err
val, err := Get(file, key)
if val == nil || len(val) != 8 {
err = nil
counter = 0
} else {
counter = binary.BigEndian.Uint64(val)
}
counter++
b := make([]byte, 8)
binary.BigEndian.PutUint64(b, counter)
err = Set(file, key, b)
return counter, err
}

// Open open/create Db (with dirs)
Expand Down

0 comments on commit bcf4f49

Please sign in to comment.