-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0421d51
commit f7fa565
Showing
13 changed files
with
529 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,78 @@ | ||
package momento | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
pb "github.com/momentohq/client-sdk-go/internal/protos" | ||
"github.com/momentohq/client-sdk-go/responses" | ||
) | ||
|
||
type DecreaseTtlRequest struct { | ||
// Name of the cache to get the item from to be deleted | ||
CacheName string | ||
// string or byte key to be used to store item. | ||
Key Key | ||
// Time to live that you want to decrease to. | ||
Ttl time.Duration | ||
|
||
grpcRequest *pb.XUpdateTtlRequest | ||
grpcResponse *pb.XUpdateTtlResponse | ||
response responses.DecreaseTtlResponse | ||
} | ||
|
||
func (r *DecreaseTtlRequest) cacheName() string { return r.CacheName } | ||
|
||
func (r *DecreaseTtlRequest) key() Key { return r.Key } | ||
|
||
func (r *DecreaseTtlRequest) updateTtl() time.Duration { return r.Ttl } | ||
|
||
func (r *DecreaseTtlRequest) requestName() string { return "DecreaseTtl" } | ||
|
||
func (r *DecreaseTtlRequest) initGrpcRequest(client scsDataClient) error { | ||
var err error | ||
var ttl uint64 | ||
|
||
var key []byte | ||
if key, err = prepareKey(r); err != nil { | ||
return err | ||
} | ||
|
||
if ttl, err = prepareUpdateTtl(r); err != nil { | ||
return err | ||
} | ||
r.grpcRequest = &pb.XUpdateTtlRequest{CacheKey: key, UpdateTtl: &pb.XUpdateTtlRequest_DecreaseToMilliseconds{DecreaseToMilliseconds: ttl}} | ||
|
||
return nil | ||
} | ||
|
||
func (r *DecreaseTtlRequest) makeGrpcRequest(metadata context.Context, client scsDataClient) (grpcResponse, error) { | ||
resp, err := client.grpcClient.UpdateTtl(metadata, r.grpcRequest) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
r.grpcResponse = resp | ||
|
||
return resp, nil | ||
} | ||
|
||
func (r *DecreaseTtlRequest) interpretGrpcResponse() error { | ||
grpcResp := r.grpcResponse | ||
|
||
var resp responses.DecreaseTtlResponse | ||
switch grpcResp.Result.(type) { | ||
case *pb.XUpdateTtlResponse_NotSet: | ||
resp = &responses.DecreaseTtlNotSet{} | ||
case *pb.XUpdateTtlResponse_Missing: | ||
resp = &responses.DecreaseTtlMiss{} | ||
case *pb.XUpdateTtlResponse_Set: | ||
resp = &responses.DecreaseTtlSet{} | ||
default: | ||
return errUnexpectedGrpcResponse(r, r.grpcResponse) | ||
} | ||
|
||
r.response = resp | ||
|
||
return nil | ||
} |
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,78 @@ | ||
package momento | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
pb "github.com/momentohq/client-sdk-go/internal/protos" | ||
"github.com/momentohq/client-sdk-go/responses" | ||
) | ||
|
||
type IncreaseTtlRequest struct { | ||
// Name of the cache to get the item from to be deleted | ||
CacheName string | ||
// string or byte key to be used to store item. | ||
Key Key | ||
// Time to live that you want to increase to. | ||
Ttl time.Duration | ||
|
||
grpcRequest *pb.XUpdateTtlRequest | ||
grpcResponse *pb.XUpdateTtlResponse | ||
response responses.IncreaseTtlResponse | ||
} | ||
|
||
func (r *IncreaseTtlRequest) cacheName() string { return r.CacheName } | ||
|
||
func (r *IncreaseTtlRequest) key() Key { return r.Key } | ||
|
||
func (r *IncreaseTtlRequest) updateTtl() time.Duration { return r.Ttl } | ||
|
||
func (r *IncreaseTtlRequest) requestName() string { return "IncreaseTtl" } | ||
|
||
func (r *IncreaseTtlRequest) initGrpcRequest(client scsDataClient) error { | ||
var err error | ||
var ttl uint64 | ||
|
||
var key []byte | ||
if key, err = prepareKey(r); err != nil { | ||
return err | ||
} | ||
|
||
if ttl, err = prepareUpdateTtl(r); err != nil { | ||
return err | ||
} | ||
r.grpcRequest = &pb.XUpdateTtlRequest{CacheKey: key, UpdateTtl: &pb.XUpdateTtlRequest_IncreaseToMilliseconds{IncreaseToMilliseconds: ttl}} | ||
|
||
return nil | ||
} | ||
|
||
func (r *IncreaseTtlRequest) makeGrpcRequest(metadata context.Context, client scsDataClient) (grpcResponse, error) { | ||
resp, err := client.grpcClient.UpdateTtl(metadata, r.grpcRequest) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
r.grpcResponse = resp | ||
|
||
return resp, nil | ||
} | ||
|
||
func (r *IncreaseTtlRequest) interpretGrpcResponse() error { | ||
grpcResp := r.grpcResponse | ||
|
||
var resp responses.IncreaseTtlResponse | ||
switch grpcResp.Result.(type) { | ||
case *pb.XUpdateTtlResponse_NotSet: | ||
resp = &responses.IncreaseTtlNotSet{} | ||
case *pb.XUpdateTtlResponse_Missing: | ||
resp = &responses.IncreaseTtlMiss{} | ||
case *pb.XUpdateTtlResponse_Set: | ||
resp = &responses.IncreaseTtlSet{} | ||
default: | ||
return errUnexpectedGrpcResponse(r, r.grpcResponse) | ||
} | ||
|
||
r.response = resp | ||
|
||
return nil | ||
} |
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
Oops, something went wrong.