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

chore: make sure all example methods accept momento.Value args #214

Merged
merged 1 commit into from
Mar 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions examples/list-example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ var (
client momento.CacheClient
)

func pushFrontToList(value string) {
func pushFrontToList(value momento.Value) {
fmt.Printf("\npushing '%s' to front of list\n", value)
resp, err := client.ListPushFront(ctx, &momento.ListPushFrontRequest{
CacheName: cacheName,
ListName: listName,
Value: momento.String(value),
Value: value,
TruncateBackToSize: 0,
CollectionTtl: utils.CollectionTtl{
Ttl: utils.CollectionTtl{
Ttl: 5 * time.Second,
RefreshTtl: true,
},
Expand All @@ -45,14 +45,14 @@ func pushFrontToList(value string) {
}
}

func pushBackToList(value string) {
func pushBackToList(value momento.Value) {
fmt.Printf("\npushing '%s' to back of list\n", value)
resp, err := client.ListPushBack(ctx, &momento.ListPushBackRequest{
CacheName: cacheName,
ListName: listName,
Value: momento.String(value),
Value: value,
TruncateFrontToSize: 0,
CollectionTtl: utils.CollectionTtl{
Ttl: utils.CollectionTtl{
Ttl: 5 * time.Second,
RefreshTtl: true,
},
Expand Down Expand Up @@ -149,11 +149,11 @@ func main() {
}

// Initializes Momento
client, err = momento.NewSimpleCacheClient(&momento.SimpleCacheClientProps{
Configuration: config.LatestLaptopConfig(),
CredentialProvider: credentialProvider,
DefaultTTL: itemDefaultTTLSeconds * time.Second,
})
client, err = momento.NewCacheClient(
config.LatestLaptopConfig(),
credentialProvider,
itemDefaultTTLSeconds*time.Second,
)
if err != nil {
panic(err)
}
Expand All @@ -169,7 +169,8 @@ func main() {
printListLength()

for i := 0; i < 5; i++ {
pushFrontToList(fmt.Sprintf("hello #%d", i+1))
stringValue := fmt.Sprintf("hello #%d", i+1)
pushFrontToList(momento.String(stringValue))
}

printListLength()
Expand All @@ -178,7 +179,8 @@ func main() {
time.Sleep(time.Second * 5)

for i := 0; i < 5; i++ {
pushBackToList(fmt.Sprintf("hello #%d", i+1))
stringValue := fmt.Sprintf("hello #%d", i+1)
pushBackToList(momento.String(stringValue))
}

printListLength()
Expand All @@ -190,7 +192,8 @@ func main() {
printList()

for i := 0; i < 5; i++ {
pushFrontToList(fmt.Sprintf("hello #%d", i+1))
stringValue := fmt.Sprintf("hello #%d", i+1)
pushFrontToList(momento.String(stringValue))
}
for i := 0; i < 5; i++ {
resp, err := client.ListPopFront(ctx, &momento.ListPopFrontRequest{
Expand All @@ -209,7 +212,7 @@ func main() {
}
printListLength()

pushFrontToList("list seed")
pushFrontToList(momento.String("list seed"))

var values []momento.Value
for i := 0; i < 5; i++ {
Expand All @@ -235,9 +238,9 @@ func main() {

for i := 1; i < 11; i++ {
if i%2 != 0 {
pushBackToList("odd")
pushBackToList(momento.String("odd"))
} else {
pushBackToList("even")
pushBackToList(momento.String("even"))
}
}
printList()
Expand Down