mirror of
https://github.com/eosswedenorg/thalos
synced 2026-06-16 04:24:56 +02:00
api/redis/subscriber.go: Adding context as first parameter to NewSubscriber()
This commit is contained in:
parent
c1efffd4ba
commit
f9124c2864
4 changed files with 11 additions and 9 deletions
|
|
@ -27,10 +27,10 @@ func WithTimeout(value time.Duration) SubscriberOption {
|
|||
}
|
||||
}
|
||||
|
||||
func NewSubscriber(client *redis.Client, ns Namespace, options ...SubscriberOption) *Subscriber {
|
||||
func NewSubscriber(ctx context.Context, client *redis.Client, ns Namespace, options ...SubscriberOption) *Subscriber {
|
||||
sub := &Subscriber{
|
||||
ctx: client.Context(),
|
||||
sub: client.PSubscribe(client.Context()),
|
||||
ctx: ctx,
|
||||
sub: client.PSubscribe(ctx),
|
||||
channels: make(map[string]chan []byte),
|
||||
timeout: time.Millisecond * 200,
|
||||
ns: ns,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package redis
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -16,14 +17,14 @@ func TestSubscriber_Construct(t *testing.T) {
|
|||
client, _ := redismock.NewClientMock()
|
||||
ns := Namespace{Prefix: "prefix", ChainID: "8f2f6ec19400d372c9b3340b1438e9c805cf9e69be962fa81d055bc037ceed8d"}
|
||||
|
||||
s := NewSubscriber(client, ns)
|
||||
s := NewSubscriber(context.Background(), client, ns)
|
||||
|
||||
assert.Equal(t, s.ctx, client.Context())
|
||||
assert.Equal(t, s.ctx, context.Background())
|
||||
assert.NotNil(t, s.sub)
|
||||
assert.Equal(t, s.ns, ns)
|
||||
assert.Equal(t, s.timeout, 200*time.Millisecond)
|
||||
|
||||
s = NewSubscriber(client, ns, WithTimeout(4*time.Second))
|
||||
s = NewSubscriber(context.Background(), client, ns, WithTimeout(4*time.Second))
|
||||
assert.Equal(t, s.timeout, 4*time.Second)
|
||||
}
|
||||
|
||||
|
|
@ -36,7 +37,7 @@ func TestSubscriber_Read(t *testing.T) {
|
|||
Addr: server.Addr(),
|
||||
})
|
||||
|
||||
s := NewSubscriber(client, Namespace{Prefix: "prefix", ChainID: "d41dbd2921d5a377325661427090c6c508904d60920d6b7ea771c58da5299754"})
|
||||
s := NewSubscriber(context.Background(), client, Namespace{Prefix: "prefix", ChainID: "d41dbd2921d5a377325661427090c6c508904d60920d6b7ea771c58da5299754"})
|
||||
|
||||
go func() {
|
||||
time.Sleep(time.Millisecond * 10)
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ func main() {
|
|||
"interval": interval,
|
||||
}).Info("Starting benchmark")
|
||||
|
||||
sub := api_redis.NewSubscriber(rdb, api_redis.Namespace{
|
||||
sub := api_redis.NewSubscriber(context.Background(), rdb, api_redis.Namespace{
|
||||
Prefix: redis_prefix,
|
||||
ChainID: chain_id,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
|
@ -17,7 +18,7 @@ func main() {
|
|||
// Create redis client
|
||||
rdb := redis.NewClient(&redis.Options{})
|
||||
|
||||
sub := api_redis.NewSubscriber(rdb, api_redis.Namespace{
|
||||
sub := api_redis.NewSubscriber(context.Background(), rdb, api_redis.Namespace{
|
||||
Prefix: "ship",
|
||||
ChainID: "1064487b3cd1a897ce03ae5b6a865651747e2e152090f99c1d19d44e01aea5a4", // Wax mainnet.
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue