Skip to content

Commit

Permalink
Merge pull request #17 from momentohq/dictionary-methods
Browse files Browse the repository at this point in the history
feat: more dictionary methods
  • Loading branch information
anitarua authored Aug 1, 2024
2 parents 8d8bf05 + b838e7d commit c9f5edf
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 62 deletions.
19 changes: 9 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/momentohq/momento-go-redis-client
go 1.20

require (
github.com/google/uuid v1.3.0
github.com/momentohq/client-sdk-go v1.7.0
github.com/google/uuid v1.6.0
github.com/momentohq/client-sdk-go v1.26.1
github.com/onsi/ginkgo/v2 v2.11.0
github.com/onsi/gomega v1.27.8
github.com/redis/go-redis/v9 v9.0.5
Expand All @@ -16,15 +16,14 @@ require (
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/golang-jwt/jwt/v4 v4.3.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.9.3 // indirect
google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6 // indirect
google.golang.org/grpc v1.52.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/grpc v1.63.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
44 changes: 19 additions & 25 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@ github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEe
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/golang-jwt/jwt/v4 v4.3.0 h1:kHL1vqdqWNfATmA0FNMdmZNMyZI1U6O31X4rlIPoBog=
github.com/golang-jwt/jwt/v4 v4.3.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/momentohq/client-sdk-go v1.7.0 h1:43X5DG80gP0wKxp0/gDhuzrvCMdVyhtmceKaQjeDuEI=
github.com/momentohq/client-sdk-go v1.7.0/go.mod h1:FyLAPNLKClfyMlJqYJ/QVBXeciapiYr6cMF5UycPvqE=
github.com/momentohq/client-sdk-go v1.26.1 h1:TkAwq96Zvh9jS9ARAreMW/KIARqBDjyp9VTow3WE+ys=
github.com/momentohq/client-sdk-go v1.26.1/go.mod h1:CJ4RZ2ioq773eqfd1LtYERcGBfXOyyXSHITo5J0fGlw=
github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU=
github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM=
github.com/onsi/gomega v1.27.8 h1:gegWiwZjBsf2DgiSbf5hpokZ98JVDMcWkUiigk6/KXc=
Expand All @@ -41,24 +38,21 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk=
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.9.3 h1:Gn1I8+64MsuTb/HpH+LmQtNas23LhUVr3rYZ0eKuaMM=
golang.org/x/tools v0.9.3/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6 h1:a2S6M0+660BgMNl++4JPlcAO/CjkqYItDEZwkoDQK7c=
google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6/go.mod h1:rZS5c/ZVYMaOGBfO68GWtjOw/eLaZM1X6iVtgjZ+EWg=
google.golang.org/grpc v1.52.0 h1:kd48UiU7EHsV4rnLyOJRuP/Il/UHE7gdDAQ+SZI7nZk=
google.golang.org/grpc v1.52.0/go.mod h1:pu6fVzoFb+NBYNAvQL08ic+lvB2IojljRYuun5vorUY=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de h1:cZGRis4/ot9uVm639a+rHCUaG0JJHEsdyzSQTMX+suY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY=
google.golang.org/grpc v1.63.0 h1:WjKe+dnvABXyPJMD7KDNLxtoGk5tgk+YFWN6cBWjZE8=
google.golang.org/grpc v1.63.0/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
150 changes: 129 additions & 21 deletions momento-redis/hash_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,158 @@ import (

"github.com/momentohq/client-sdk-go/momento"
"github.com/momentohq/client-sdk-go/responses"
. "github.com/redis/go-redis/v9"
"github.com/redis/go-redis/v9"
)

func (m *MomentoRedisClient) HDel(ctx context.Context, key string, fields ...string) *IntCmd {
func (m *MomentoRedisClient) HDel(ctx context.Context, key string, fields ...string) *redis.IntCmd {
resp := &redis.IntCmd{}

panic(UnsupportedOperationError("This operation has not been implemented yet"))
// Defaults to 0 in case of cache miss
lengthBefore := uint32(0)
lengthAfter := uint32(0)

lengthResponse, err := m.client.DictionaryLength(ctx, &momento.DictionaryLengthRequest{
CacheName: m.cacheName,
DictionaryName: key,
})
if err != nil {
resp.SetErr(RedisError(err.Error()))
return resp
}
switch r := lengthResponse.(type) {
case *responses.DictionaryLengthHit:
lengthBefore = r.Length()
}

stringFields := []momento.Value{}
for _, field := range fields {
stringFields = append(stringFields, momento.String(field))
}

dictionaryRemoveFieldsResponse, err := m.client.DictionaryRemoveFields(ctx, &momento.DictionaryRemoveFieldsRequest{
CacheName: m.cacheName,
DictionaryName: key,
Fields: stringFields,
})
if err != nil {
resp.SetErr(RedisError(err.Error()))
return resp
}

lengthResponse, err = m.client.DictionaryLength(ctx, &momento.DictionaryLengthRequest{
CacheName: m.cacheName,
DictionaryName: key,
})
if err != nil {
resp.SetErr(RedisError(err.Error()))
return resp
}
switch r := lengthResponse.(type) {
case *responses.DictionaryLengthHit:
lengthAfter = r.Length()
}

switch dictionaryRemoveFieldsResponse.(type) {
case *responses.DictionaryRemoveFieldsSuccess:
resp.SetVal(int64(lengthBefore - lengthAfter))
}

return resp
}

func (m *MomentoRedisClient) HExists(ctx context.Context, key, field string) *BoolCmd {
func (m *MomentoRedisClient) HExists(ctx context.Context, key, field string) *redis.BoolCmd {

panic(UnsupportedOperationError("This operation has not been implemented yet"))
}

func (m *MomentoRedisClient) HGet(ctx context.Context, key, field string) *StringCmd {
func (m *MomentoRedisClient) HGet(ctx context.Context, key, field string) *redis.StringCmd {
resp := &redis.StringCmd{}

panic(UnsupportedOperationError("This operation has not been implemented yet"))
dictionaryGetFieldResponse, err := m.client.DictionaryGetField(ctx, &momento.DictionaryGetFieldRequest{
CacheName: m.cacheName,
DictionaryName: key,
Field: momento.String(field),
})

if err != nil {
resp.SetErr(RedisError(err.Error()))
return resp
}

switch r := dictionaryGetFieldResponse.(type) {
case *responses.DictionaryGetFieldHit:
resp.SetVal(r.ValueString())
case *responses.DictionaryGetFieldMiss:
resp.SetErr(redis.Nil)
}

return resp
}

func (m *MomentoRedisClient) HGetAll(ctx context.Context, key string) *MapStringStringCmd {
func (m *MomentoRedisClient) HGetAll(ctx context.Context, key string) *redis.MapStringStringCmd {
resp := &redis.MapStringStringCmd{}

panic(UnsupportedOperationError("This operation has not been implemented yet"))
dictionaryFetchResponse, err := m.client.DictionaryFetch(ctx, &momento.DictionaryFetchRequest{
CacheName: m.cacheName,
DictionaryName: key,
})

if err != nil {
resp.SetErr(RedisError(err.Error()))
return resp
}

// Miss return values differ from HGET but it matches what Redis client expects
switch r := dictionaryFetchResponse.(type) {
case *responses.DictionaryFetchHit:
resp.SetVal(r.ValueMapStringString())
case *responses.DictionaryFetchMiss:
resp.SetErr(nil)
resp.SetVal(map[string]string{})
}

return resp
}

func (m *MomentoRedisClient) HIncrBy(ctx context.Context, key, field string, incr int64) *IntCmd {
func (m *MomentoRedisClient) HIncrBy(ctx context.Context, key, field string, incr int64) *redis.IntCmd {

panic(UnsupportedOperationError("This operation has not been implemented yet"))
}

func (m *MomentoRedisClient) HIncrByFloat(ctx context.Context, key, field string, incr float64) *FloatCmd {
func (m *MomentoRedisClient) HIncrByFloat(ctx context.Context, key, field string, incr float64) *redis.FloatCmd {

panic(UnsupportedOperationError("This operation has not been implemented yet"))
}

func (m *MomentoRedisClient) HKeys(ctx context.Context, key string) *StringSliceCmd {
func (m *MomentoRedisClient) HKeys(ctx context.Context, key string) *redis.StringSliceCmd {

panic(UnsupportedOperationError("This operation has not been implemented yet"))
}

func (m *MomentoRedisClient) HLen(ctx context.Context, key string) *IntCmd {
func (m *MomentoRedisClient) HLen(ctx context.Context, key string) *redis.IntCmd {
resp := &redis.IntCmd{}

panic(UnsupportedOperationError("This operation has not been implemented yet"))
lengthResponse, err := m.client.DictionaryLength(ctx, &momento.DictionaryLengthRequest{
CacheName: m.cacheName,
DictionaryName: key,
})

if err != nil {
resp.SetErr(RedisError(err.Error()))
return resp
}

switch r := lengthResponse.(type) {
case *responses.DictionaryLengthHit:
resp.SetVal(int64(r.Length()))
case *responses.DictionaryLengthMiss:
resp.SetVal(int64(0))
}

return resp
}

func (m *MomentoRedisClient) HMGet(ctx context.Context, key string, fields ...string) *SliceCmd {
func (m *MomentoRedisClient) HMGet(ctx context.Context, key string, fields ...string) *redis.SliceCmd {

panic(UnsupportedOperationError("This operation has not been implemented yet"))
}
Expand Down Expand Up @@ -108,8 +216,8 @@ func hSetElementsFromStringMaps(values []interface{}) ([]momento.DictionaryEleme
return elements, nil
}

func (m *MomentoRedisClient) HSet(ctx context.Context, key string, values ...interface{}) *IntCmd {
resp := &IntCmd{}
func (m *MomentoRedisClient) HSet(ctx context.Context, key string, values ...interface{}) *redis.IntCmd {
resp := &redis.IntCmd{}
var elements []momento.DictionaryElement
var err error

Expand Down Expand Up @@ -151,27 +259,27 @@ func (m *MomentoRedisClient) HSet(ctx context.Context, key string, values ...int
return resp
}

func (m *MomentoRedisClient) HMSet(ctx context.Context, key string, values ...interface{}) *BoolCmd {
func (m *MomentoRedisClient) HMSet(ctx context.Context, key string, values ...interface{}) *redis.BoolCmd {

panic(UnsupportedOperationError("This operation has not been implemented yet"))
}

func (m *MomentoRedisClient) HSetNX(ctx context.Context, key, field string, value interface{}) *BoolCmd {
func (m *MomentoRedisClient) HSetNX(ctx context.Context, key, field string, value interface{}) *redis.BoolCmd {

panic(UnsupportedOperationError("This operation has not been implemented yet"))
}

func (m *MomentoRedisClient) HVals(ctx context.Context, key string) *StringSliceCmd {
func (m *MomentoRedisClient) HVals(ctx context.Context, key string) *redis.StringSliceCmd {

panic(UnsupportedOperationError("This operation has not been implemented yet"))
}

func (m *MomentoRedisClient) HRandField(ctx context.Context, key string, count int) *StringSliceCmd {
func (m *MomentoRedisClient) HRandField(ctx context.Context, key string, count int) *redis.StringSliceCmd {

panic(UnsupportedOperationError("This operation has not been implemented yet"))
}

func (m *MomentoRedisClient) HRandFieldWithValues(ctx context.Context, key string, count int) *KeyValueSliceCmd {
func (m *MomentoRedisClient) HRandFieldWithValues(ctx context.Context, key string, count int) *redis.KeyValueSliceCmd {

panic(UnsupportedOperationError("This operation has not been implemented yet"))
}
Loading

0 comments on commit c9f5edf

Please sign in to comment.