Skip to content

Commit

Permalink
Add option to publish message on object update
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcook committed Oct 4, 2022
1 parent 6c13213 commit 72b2133
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions update.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
// UpdateOptions provides options that may be passed to UpdateWithOptions if
// the default behavior of Update needs to be changed.
type UpdateOptions struct {
// Notify should be set to true if you would like a message to be published
// to the <struct name>:<id> channel once this update completes.
Notify bool

// SetZeroValues should be set to true if you would like to update all zero
// values in Redis (e.g. empty strings, 0 ints). By default, when creating
// a struct to pass to Update, you may not set each value, which is why
Expand Down Expand Up @@ -211,6 +215,11 @@ func updateInternal(id string, ptr interface{}, opts *UpdateOptions) error {
}
}

if opts.Notify {
// Publish message if notify is enabled
pip.Publish(ctx, prefix+":"+id, "")
}

// Don't exec if a pipeline was provided to us
if opts.Pipeline == nil {
if _, err := pip.Exec(ctx); err != nil {
Expand Down

0 comments on commit 72b2133

Please sign in to comment.