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: directly use hash key to check messages #139

Merged
merged 7 commits into from
Aug 16, 2024
Merged
Changes from 2 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
26 changes: 22 additions & 4 deletions pkg/sinker/examples/redis-sink/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,32 @@ func (rds *redisTestSink) Sink(ctx context.Context, datumStreamCh <-chan sinksdk
_ = d.Watermark()

// We use redis hashes to store messages.
// The name of a hash is pipelineName:sinkName.
// Each field of a hash is the content of a message and value of the field is the no. of occurrences of the message.
hkey := fmt.Sprintf("%s:%s", os.Getenv("NUMAFLOW_PIPELINE_NAME"), os.Getenv("NUMAFLOW_VERTEX_NAME"))
err := client.HIncrBy(ctx, hkey, string(d.Value()), 1).Err()
var hashKey string

monoVertexName := os.Getenv("NUMAFLOW_MONO_VERTEX_NAME")
pipelineName := os.Getenv("NUMAFLOW_PIPELINE_NAME")
vertexName := os.Getenv("NUMAFLOW_VERTEX_NAME")

if !(monoVertexName != "" || (pipelineName != "" && vertexName != "")) {
log.Println("Error: Either mono vertex name or pipeline name and vertex name must be set in the environment variables.")
return result.Append(sinksdk.ResponseFailure(d.ID(), fmt.Sprintf("either mono vertex name or pipeline name and vertex name must be set in the environment variables.")))
}

if monoVertexName != "" {
// if the mono vertex name environment variable is set, we are in a mono vertex
// in this case, we use the mono vertex name as the hash key
hashKey = monoVertexName
} else {
// if the mono vertex name environment variable is not set, we are in a pipeline
// in this case, the name of a hash is pipelineName:sinkName.
hashKey = fmt.Sprintf("%s:%s", pipelineName, vertexName)
}
err := client.HIncrBy(ctx, hashKey, string(d.Value()), 1).Err()
if err != nil {
log.Println("Set Error - ", err)
} else {
log.Printf("Incremented by 1 the no. of occurrences of %s under hash key %s\n", string(d.Value()), hkey)
log.Printf("Incremented by 1 the no. of occurrences of %s under hash key %s\n", string(d.Value()), hashKey)
}

id := d.ID()
Expand Down
Loading