-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example proto for incremented float values
- Fix parsing `OK` value returned from the storage
- Loading branch information
Showing
12 changed files
with
491 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
func main() { | ||
// see test file to usage examples | ||
// you may try your custom usage of kvstore here | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/redis/go-redis/v9" | ||
"github.com/stretchr/testify/suite" | ||
|
||
"github.com/ehsundar/kvstore" | ||
"github.com/ehsundar/kvstore/examples/balance" | ||
) | ||
|
||
type BalanceTestSuite struct { | ||
suite.Suite | ||
|
||
r *redis.Client | ||
} | ||
|
||
func TestBalanceTestSuite(t *testing.T) { | ||
suite.Run(t, new(BalanceTestSuite)) | ||
} | ||
|
||
func (s *BalanceTestSuite) SetupSuite() { | ||
r := redis.NewClient(&redis.Options{ | ||
Network: "tcp", | ||
Addr: "localhost:6379", | ||
ClientName: "tests", | ||
}) | ||
|
||
_, err := r.FlushAll(context.Background()).Result() | ||
s.Nil(err) | ||
|
||
s.r = r | ||
} | ||
|
||
func (s *BalanceTestSuite) TearDownTest() { | ||
_, err := s.r.FlushAll(context.Background()).Result() | ||
s.Nil(err) | ||
} | ||
|
||
func (s *BalanceTestSuite) TestShouldReadWriteToStorageRespectingTTL() { | ||
ctx := context.Background() | ||
storage := balance.NewBalanceStore(s.r) | ||
|
||
bal, err := storage.Set(ctx, &balance.BalanceKey{Username: "username"}, 11.11, kvstore.WithRetrieveDisabled()) | ||
s.Nil(err) | ||
s.InDelta(0, bal, 0.001) | ||
|
||
bal, err = storage.Incr(ctx, &balance.BalanceKey{Username: "username"}, -3.01) | ||
s.Nil(err) | ||
s.InDelta(8.1, bal, 0.001) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
syntax = "proto3"; | ||
|
||
package balance; | ||
|
||
option go_package = "github.com/ehsundar/kvstore/examples/balance"; | ||
|
||
import "kvstore/options.proto"; | ||
|
||
message BalanceKey { | ||
option (kvstore.key_options) = {}; | ||
|
||
string username = 1; | ||
} | ||
|
||
message BalanceValue { | ||
option (kvstore.value_options) = { | ||
numeral: {} | ||
}; | ||
|
||
double balance = 1; | ||
} |
Oops, something went wrong.