-
Notifications
You must be signed in to change notification settings - Fork 0
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
add redis seed #19
add redis seed #19
Conversation
cmd/envite/redis.go
Outdated
|
||
// buildRedisSeed is a builder function that constructs a new Redis seed component. | ||
// It takes a byte slice of JSON data as input. | ||
// The function attempts to parse the JSON data into a mongo.SeedConfig struct, which defines the configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mongo.SeedConfig -> redis.SeedConfig
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
cmd/envite/redis.go
Outdated
// It takes a byte slice of JSON data as input. | ||
// The function attempts to parse the JSON data into a mongo.SeedConfig struct, which defines the configuration | ||
// for a Redis seed component. If the JSON data is successfully parsed, it then uses this configuration | ||
// to instantiate and return a new MongoDB seed component via the redis.NewSeedComponent function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MongoDB -> Redis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
seed/redis/config.go
Outdated
// SeedData represents data for a redis hash. | ||
type SeedData struct { | ||
// Key - the name of the redis key | ||
Key string `json:"key,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my only comment on the config is that this structure will only let us support HSet, or at least block the name Key
for this specific use.
What do you think about something like this:
// SeedConfig represents the configuration for the redis seed component.
type SeedConfig struct {
// Address - a valid redis server address to connect to
Address string `json:"address,omitempty"`
// ClientProvider - can be used as an alternative to Address, provides a redis client to use.
// available only via code, not available in config files.
// if both ClientProvider and Address are provided, ClientProvider is used.
ClientProvider func() (*redis.Client, error) `json:"-"`
SetKeys []*Set `json:"set_keys"`
HSetKeys []*HSet `json:"hset_keys"`
}
type Set struct {
Key string `json:"key"`
Value string `json:"value"`
TTL time.Duration `json:"ttl"`
}
type HSet struct {
Key string `json:"key"`
Values map[string]string `json:"values"`
TTL time.Duration `json:"ttl"`
}
this will allow us to add future support for other data types as well without breaking anything
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@avivpxi , please review
cmd/envite/redis.go
Outdated
|
||
// buildRedisSeed is a builder function that constructs a new Redis seed component. | ||
// It takes a byte slice of JSON data as input. | ||
// The function attempts to parse the JSON data into a mongo.SeedConfig struct, which defines the configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
cmd/envite/redis.go
Outdated
// It takes a byte slice of JSON data as input. | ||
// The function attempts to parse the JSON data into a mongo.SeedConfig struct, which defines the configuration | ||
// for a Redis seed component. If the JSON data is successfully parsed, it then uses this configuration | ||
// to instantiate and return a new MongoDB seed component via the redis.NewSeedComponent function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
seed/redis/config.go
Outdated
// SeedData represents data for a redis hash. | ||
type SeedData struct { | ||
// Key - the name of the redis key | ||
Key string `json:"key,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
seed/redis/component.go
Outdated
return nil | ||
} | ||
|
||
func (r *SeedComponent) HashSetEntries(ctx context.Context, err error, client *redis.Client) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be private
seed/redis/component.go
Outdated
|
||
func (r *SeedComponent) setEntries(ctx context.Context, err error, client *redis.Client) error { | ||
for _, entry := range r.config.Entries { | ||
err = client.Set(ctx, entry.Key, entry.Value, entry.TTL*time.Second).Err() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
entry.TTL*time.Second
is a mistake, it's already a duration - multipying by time.Second will just multiply the duration by 1000^3 (source code)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
seed/redis/component.go
Outdated
return err | ||
} | ||
if hEntry.TTL > 0 { | ||
err = client.Expire(ctx, hEntry.Key, hEntry.TTL*time.Second).Err() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same duration comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
- change method to private
No description provided.