-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2303 from OffchainLabs/redis-stream-creation
Create streams in redis client, poll on it in redis-server
- Loading branch information
Showing
7 changed files
with
125 additions
and
25 deletions.
There are no files selected for viewing
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,29 @@ | ||
package pubsub | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/go-redis/redis/v8" | ||
) | ||
|
||
// CreateStream tries to create stream with given name, if it already exists | ||
// does not return an error. | ||
func CreateStream(ctx context.Context, streamName string, client redis.UniversalClient) error { | ||
_, err := client.XGroupCreateMkStream(ctx, streamName, streamName, "$").Result() | ||
if err != nil && !StreamExists(ctx, streamName, client) { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// StreamExists returns whether there are any consumer group for specified | ||
// redis stream. | ||
func StreamExists(ctx context.Context, streamName string, client redis.UniversalClient) bool { | ||
got, err := client.Do(ctx, "XINFO", "STREAM", streamName).Result() | ||
if err != nil { | ||
log.Error("Reading redis streams", "error", err) | ||
return false | ||
} | ||
return got != 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
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
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
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