From 814bc60167874bd425a8db609d6e05d331ebf8d5 Mon Sep 17 00:00:00 2001 From: xh3b4sd Date: Thu, 23 Nov 2023 15:27:17 +0100 Subject: [PATCH] separate locker from redigo interface --- .../client_sentinel_connection_test.go | 2 +- conformance/client_single_locker_test.go | 95 ++++++++++++------- conformance/client_single_simple_test.go | 2 +- factory.go | 16 ---- {pkg/index => index}/index.go | 0 interface.go | 5 +- {pkg/locker => locker}/error.go | 0 locker/fake_acquire.go | 9 ++ locker/fake_locker.go | 7 ++ locker/fake_refresh.go | 9 ++ locker/fake_release.go | 9 ++ {pkg/locker => locker}/interface.go | 0 .../acquire.go => locker/redis_acquire.go | 10 +- locker/redis_locker.go | 84 ++++++++++++++++ .../refresh.go => locker/redis_refresh.go | 14 +-- .../release.go => locker/redis_release.go | 14 +-- pkg/fake/client.go | 7 +- pkg/fake/locker.go | 31 ------ pkg/fake/simple.go | 10 +- pkg/locker/locker.go | 66 ------------- pkg/sorted/create/create_test.go | 2 +- pkg/sorted/create/redis.go | 4 +- pkg/sorted/delete.go | 5 +- pkg/sorted/exists.go | 5 +- pkg/sorted/floats.go | 3 +- pkg/sorted/metric.go | 3 +- pkg/sorted/search.go | 5 +- pkg/sorted/update.go | 5 +- {pkg/pool => pool}/pool.go | 0 {pkg/prefix => prefix}/prefix.go | 0 redigo.go | 31 +----- {pkg/simple => simple}/create/error.go | 0 {pkg/simple => simple}/create/fake.go | 0 {pkg/simple => simple}/create/redis.go | 2 +- {pkg/simple => simple}/delete/fake.go | 0 {pkg/simple => simple}/delete/redis.go | 2 +- {pkg/simple => simple}/error.go | 2 +- {pkg/simple => simple}/exists/fake.go | 0 {pkg/simple => simple}/exists/redis.go | 2 +- {pkg/simple => simple}/interface.go | 0 {pkg/simple => simple}/search/error.go | 0 {pkg/simple => simple}/search/fake.go | 0 {pkg/simple => simple}/search/redis.go | 2 +- {pkg/simple => simple}/simple.go | 8 +- 44 files changed, 239 insertions(+), 232 deletions(-) rename {pkg/index => index}/index.go (100%) rename {pkg/locker => locker}/error.go (100%) create mode 100644 locker/fake_acquire.go create mode 100644 locker/fake_locker.go create mode 100644 locker/fake_refresh.go create mode 100644 locker/fake_release.go rename {pkg/locker => locker}/interface.go (100%) rename pkg/locker/acquire.go => locker/redis_acquire.go (62%) create mode 100644 locker/redis_locker.go rename pkg/locker/refresh.go => locker/redis_refresh.go (60%) rename pkg/locker/release.go => locker/redis_release.go (60%) delete mode 100644 pkg/fake/locker.go delete mode 100644 pkg/locker/locker.go rename {pkg/pool => pool}/pool.go (100%) rename {pkg/prefix => prefix}/prefix.go (100%) rename {pkg/simple => simple}/create/error.go (100%) rename {pkg/simple => simple}/create/fake.go (100%) rename {pkg/simple => simple}/create/redis.go (94%) rename {pkg/simple => simple}/delete/fake.go (100%) rename {pkg/simple => simple}/delete/redis.go (94%) rename {pkg/simple => simple}/error.go (66%) rename {pkg/simple => simple}/exists/fake.go (100%) rename {pkg/simple => simple}/exists/redis.go (94%) rename {pkg/simple => simple}/interface.go (100%) rename {pkg/simple => simple}/search/error.go (100%) rename {pkg/simple => simple}/search/fake.go (100%) rename {pkg/simple => simple}/search/redis.go (94%) rename {pkg/simple => simple}/simple.go (84%) diff --git a/conformance/client_sentinel_connection_test.go b/conformance/client_sentinel_connection_test.go index b2fb59d..72735d4 100644 --- a/conformance/client_sentinel_connection_test.go +++ b/conformance/client_sentinel_connection_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/xh3b4sd/redigo" - "github.com/xh3b4sd/redigo/pkg/simple" + "github.com/xh3b4sd/redigo/simple" ) func Test_Client_Sentinel_Connection(t *testing.T) { diff --git a/conformance/client_single_locker_test.go b/conformance/client_single_locker_test.go index c822f30..43ec163 100644 --- a/conformance/client_single_locker_test.go +++ b/conformance/client_single_locker_test.go @@ -11,7 +11,8 @@ import ( "github.com/xh3b4sd/breakr" "github.com/xh3b4sd/redigo" - "github.com/xh3b4sd/redigo/pkg/locker" + "github.com/xh3b4sd/redigo/locker" + "github.com/xh3b4sd/redigo/pool" "github.com/xh3b4sd/tracer" ) @@ -28,13 +29,22 @@ func Test_Client_Single_Locker_Lifecycle(t *testing.T) { if err != nil { t.Fatal(err) } + } + { err = cli.Purge() if err != nil { t.Fatal(err) } } + var loc locker.Interface + { + loc = locker.New(locker.Config{ + Poo: pool.NewSinglePoolWithAddress(cli.Listen()), + }) + } + erc := make(chan error, 1) don := make(chan struct{}, 1) @@ -57,7 +67,7 @@ func Test_Client_Single_Locker_Lifecycle(t *testing.T) { go func() { defer w.Done() - err = cli.Locker().Acquire() + err = loc.Acquire() if err != nil { erc <- tracer.Mask(err) return @@ -81,7 +91,7 @@ func Test_Client_Single_Locker_Lifecycle(t *testing.T) { } } - err = cli.Locker().Release() + err = loc.Release() if err != nil { erc <- tracer.Mask(err) return @@ -94,7 +104,7 @@ func Test_Client_Single_Locker_Lifecycle(t *testing.T) { defer w.Done() for { - err = cli.Locker().Acquire() + err = loc.Acquire() if locker.IsAcquire(err) { time.Sleep(50 * time.Millisecond) continue @@ -122,7 +132,7 @@ func Test_Client_Single_Locker_Lifecycle(t *testing.T) { } } - err = cli.Locker().Release() + err = loc.Release() if err != nil { erc <- tracer.Mask(err) return @@ -173,41 +183,48 @@ func Test_Client_Single_Locker_Lifecycle(t *testing.T) { func Test_Client_Single_Locker_Acquire_Budget(t *testing.T) { var err error - var bre breakr.Interface - { - bre = breakr.New(breakr.Config{ - Failure: breakr.Failure{ - Budget: 3, - Cooler: 1 * time.Second, - }, - }) - } - var cli redigo.Interface { c := redigo.Config{ Kind: redigo.KindSingle, - Locker: redigo.ConfigLocker{ - Breakr: bre, - Expiry: 1 * time.Second, - }, } cli, err = redigo.New(c) if err != nil { t.Fatal(err) } + } + { err = cli.Purge() if err != nil { t.Fatal(err) } } + var brk breakr.Interface + { + brk = breakr.New(breakr.Config{ + Failure: breakr.Failure{ + Budget: 3, + Cooler: 1 * time.Second, + }, + }) + } + + var loc locker.Interface + { + loc = locker.New(locker.Config{ + Brk: brk, + Exp: 1 * time.Second, + Poo: pool.NewSinglePoolWithAddress(cli.Listen()), + }) + } + don := make(chan struct{}, 1) go func() { - err = cli.Locker().Acquire() + err = loc.Acquire() if err != nil { panic(err) } @@ -222,7 +239,7 @@ func Test_Client_Single_Locker_Acquire_Budget(t *testing.T) { // The first Acquire call should still hold the lock on the first try, but // the locker is configured with a breakr implementation that retries until // the lock expires and then can be acquired a second time here. - err = cli.Locker().Acquire() + err = loc.Acquire() if err != nil { t.Fatal(err) } @@ -235,26 +252,33 @@ func Test_Client_Single_Locker_Acquire_Error(t *testing.T) { { c := redigo.Config{ Kind: redigo.KindSingle, - Locker: redigo.ConfigLocker{ - Breakr: breakr.Fake(), - Expiry: 1 * time.Second, - }, } cli, err = redigo.New(c) if err != nil { t.Fatal(err) } + } + { err = cli.Purge() if err != nil { t.Fatal(err) } } + var loc locker.Interface + { + loc = locker.New(locker.Config{ + Brk: breakr.Fake(), + Exp: 1 * time.Second, + Poo: pool.NewSinglePoolWithAddress(cli.Listen()), + }) + } + // Aquiring the lock the first time. { - err = cli.Locker().Acquire() + err = loc.Acquire() if err != nil { t.Fatal(err) } @@ -262,7 +286,7 @@ func Test_Client_Single_Locker_Acquire_Error(t *testing.T) { // The first Acquire call should still hold the lock. { - err = cli.Locker().Acquire() + err = loc.Acquire() if !locker.IsAcquire(err) { t.Fatal("expected acquireError") } @@ -276,26 +300,33 @@ func Test_Client_Single_Locker_Acquire_Expiry(t *testing.T) { { c := redigo.Config{ Kind: redigo.KindSingle, - Locker: redigo.ConfigLocker{ - Expiry: 1 * time.Second, - }, } cli, err = redigo.New(c) if err != nil { t.Fatal(err) } + } + { err = cli.Purge() if err != nil { t.Fatal(err) } } + var loc locker.Interface + { + loc = locker.New(locker.Config{ + Exp: 1 * time.Second, + Poo: pool.NewSinglePoolWithAddress(cli.Listen()), + }) + } + don := make(chan struct{}, 1) go func() { - err = cli.Locker().Acquire() + err = loc.Acquire() if err != nil { panic(err) } @@ -308,7 +339,7 @@ func Test_Client_Single_Locker_Acquire_Expiry(t *testing.T) { <-don // The first Acquire call should not hold the lock anymore due to expiry. - err = cli.Locker().Acquire() + err = loc.Acquire() if err != nil { t.Fatal(err) } diff --git a/conformance/client_single_simple_test.go b/conformance/client_single_simple_test.go index 38b06e6..a86ece8 100644 --- a/conformance/client_single_simple_test.go +++ b/conformance/client_single_simple_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/xh3b4sd/redigo" - "github.com/xh3b4sd/redigo/pkg/simple" + "github.com/xh3b4sd/redigo/simple" ) func Test_Client_Single_Simple_Lifecycle(t *testing.T) { diff --git a/factory.go b/factory.go index 4f4bfce..db8de60 100644 --- a/factory.go +++ b/factory.go @@ -1,32 +1,16 @@ package redigo import ( - "time" - - "github.com/xh3b4sd/breakr" "github.com/xh3b4sd/redigo/pkg/fake" ) func Default() Interface { var err error - var bre breakr.Interface - { - bre = breakr.New(breakr.Config{ - Failure: breakr.Failure{ - Budget: 30, - Cooler: 1 * time.Second, - }, - }) - } - var red Interface { c := Config{ Kind: KindSingle, - Locker: ConfigLocker{ - Breakr: bre, - }, } red, err = New(c) diff --git a/pkg/index/index.go b/index/index.go similarity index 100% rename from pkg/index/index.go rename to index/index.go diff --git a/interface.go b/interface.go index 8e2a69a..7eeb903 100644 --- a/interface.go +++ b/interface.go @@ -3,11 +3,10 @@ package redigo import ( "github.com/gomodule/redigo/redis" "github.com/xh3b4sd/redigo/pkg/backup" - "github.com/xh3b4sd/redigo/pkg/locker" "github.com/xh3b4sd/redigo/pkg/pubsub" - "github.com/xh3b4sd/redigo/pkg/simple" "github.com/xh3b4sd/redigo/pkg/sorted" "github.com/xh3b4sd/redigo/pkg/walker" + "github.com/xh3b4sd/redigo/simple" ) type Interface interface { @@ -17,10 +16,10 @@ type Interface interface { Purge() error Redis(fun func(con redis.Conn) error) error + // Listen returns the host:port configuration for this redigo instance. Listen() string Backup() backup.Interface - Locker() locker.Interface PubSub() pubsub.Interface Sorted() sorted.Interface Simple() simple.Interface diff --git a/pkg/locker/error.go b/locker/error.go similarity index 100% rename from pkg/locker/error.go rename to locker/error.go diff --git a/locker/fake_acquire.go b/locker/fake_acquire.go new file mode 100644 index 0000000..505920d --- /dev/null +++ b/locker/fake_acquire.go @@ -0,0 +1,9 @@ +package locker + +func (f *Fake) Acquire() error { + if f.FakeAcquire != nil { + return f.FakeAcquire() + } + + return nil +} diff --git a/locker/fake_locker.go b/locker/fake_locker.go new file mode 100644 index 0000000..3418c4f --- /dev/null +++ b/locker/fake_locker.go @@ -0,0 +1,7 @@ +package locker + +type Fake struct { + FakeAcquire func() error + FakeRefresh func() error + FakeRelease func() error +} diff --git a/locker/fake_refresh.go b/locker/fake_refresh.go new file mode 100644 index 0000000..5d4a53b --- /dev/null +++ b/locker/fake_refresh.go @@ -0,0 +1,9 @@ +package locker + +func (f *Fake) Refresh() error { + if f.FakeRefresh != nil { + return f.FakeRefresh() + } + + return nil +} diff --git a/locker/fake_release.go b/locker/fake_release.go new file mode 100644 index 0000000..56c0b13 --- /dev/null +++ b/locker/fake_release.go @@ -0,0 +1,9 @@ +package locker + +func (f *Fake) Release() error { + if f.FakeRelease != nil { + return f.FakeRelease() + } + + return nil +} diff --git a/pkg/locker/interface.go b/locker/interface.go similarity index 100% rename from pkg/locker/interface.go rename to locker/interface.go diff --git a/pkg/locker/acquire.go b/locker/redis_acquire.go similarity index 62% rename from pkg/locker/acquire.go rename to locker/redis_acquire.go index 2bba93e..cc8623f 100644 --- a/pkg/locker/acquire.go +++ b/locker/redis_acquire.go @@ -4,7 +4,7 @@ import ( "github.com/xh3b4sd/tracer" ) -func (l *Locker) Acquire() error { +func (l *Redis) Acquire() error { act := func() error { err := l.mut.Lock() if err != nil { @@ -14,9 +14,11 @@ func (l *Locker) Acquire() error { return nil } - err := l.brk.Execute(act) - if err != nil { - return tracer.Mask(err) + { + err := l.brk.Execute(act) + if err != nil { + return tracer.Mask(err) + } } return nil diff --git a/locker/redis_locker.go b/locker/redis_locker.go new file mode 100644 index 0000000..7569119 --- /dev/null +++ b/locker/redis_locker.go @@ -0,0 +1,84 @@ +package locker + +import ( + "fmt" + "time" + + "github.com/go-redsync/redsync/v4" + "github.com/go-redsync/redsync/v4/redis/redigo" + "github.com/gomodule/redigo/redis" + "github.com/xh3b4sd/breakr" + "github.com/xh3b4sd/redigo/prefix" +) + +type Config struct { + // Brk is the budget implementation used to retry redis connections on + // failure. + Brk breakr.Interface + // Exp is the lock's expiry, so that locks can expire after a certain amount + // of time of inactivity. Defaults to 30 seconds. Disabled with -1. + Exp time.Duration + // Nam is some uniquely scoped identifier for a lock purpose. + Nam string + // Poo is the redis connection pool to select client connections from. + Poo *redis.Pool + // Pre is the prefix of the underlying redis key used to coordinate the + // distributed lock. + Pre string +} + +type Redis struct { + brk breakr.Interface + mut *redsync.Mutex +} + +func New(c Config) *Redis { + if c.Brk == nil { + c.Brk = breakr.Default() + } + if c.Exp == 0 { + c.Exp = 30 * time.Second + } + if c.Nam == "" { + c.Nam = "def" + } + + var r *redsync.Redsync + { + p := redigo.NewPool( + &redis.Pool{ + MaxIdle: c.Poo.MaxIdle, + IdleTimeout: c.Poo.IdleTimeout, + Dial: c.Poo.Dial, + TestOnBorrow: c.Poo.TestOnBorrow, + }, + ) + + r = redsync.New(p) + } + + var o []redsync.Option + { + o = []redsync.Option{ + redsync.WithRetryDelayFunc(func(tries int) time.Duration { return 100 * time.Millisecond }), + redsync.WithTries(1), + } + } + + if c.Exp > 0 { + o = append(o, redsync.WithExpiry(c.Exp)) + } + + var l *Redis + { + l = &Redis{ + brk: c.Brk, + mut: r.NewMutex( + prefix.WithKeys(c.Pre, fmt.Sprintf("red:%s", c.Nam)), + o..., + ), + } + } + + return l +} diff --git a/pkg/locker/refresh.go b/locker/redis_refresh.go similarity index 60% rename from pkg/locker/refresh.go rename to locker/redis_refresh.go index 68b4a24..9153cca 100644 --- a/pkg/locker/refresh.go +++ b/locker/redis_refresh.go @@ -5,7 +5,7 @@ import ( "github.com/xh3b4sd/tracer" ) -func (l *Locker) Refresh() error { +func (l *Redis) Refresh() error { act := func() error { sta, err := l.mut.Extend() if err != nil { @@ -19,11 +19,13 @@ func (l *Locker) Refresh() error { return nil } - err := l.brk.Execute(act) - if breakr.IsCancel(err) { - return tracer.Mask(statusError) - } else if err != nil { - return tracer.Mask(err) + { + err := l.brk.Execute(act) + if breakr.IsCancel(err) { + return tracer.Mask(statusError) + } else if err != nil { + return tracer.Mask(err) + } } return nil diff --git a/pkg/locker/release.go b/locker/redis_release.go similarity index 60% rename from pkg/locker/release.go rename to locker/redis_release.go index 7818ca0..4813ba0 100644 --- a/pkg/locker/release.go +++ b/locker/redis_release.go @@ -5,7 +5,7 @@ import ( "github.com/xh3b4sd/tracer" ) -func (l *Locker) Release() error { +func (l *Redis) Release() error { act := func() error { sta, err := l.mut.Unlock() if err != nil { @@ -19,11 +19,13 @@ func (l *Locker) Release() error { return nil } - err := l.brk.Execute(act) - if breakr.IsCancel(err) { - return tracer.Mask(statusError) - } else if err != nil { - return tracer.Mask(err) + { + err := l.brk.Execute(act) + if breakr.IsCancel(err) { + return tracer.Mask(statusError) + } else if err != nil { + return tracer.Mask(err) + } } return nil diff --git a/pkg/fake/client.go b/pkg/fake/client.go index 24b0fee..9198806 100644 --- a/pkg/fake/client.go +++ b/pkg/fake/client.go @@ -2,13 +2,12 @@ package fake import ( "github.com/gomodule/redigo/redis" - + "github.com/xh3b4sd/redigo/locker" "github.com/xh3b4sd/redigo/pkg/backup" - "github.com/xh3b4sd/redigo/pkg/locker" "github.com/xh3b4sd/redigo/pkg/pubsub" - "github.com/xh3b4sd/redigo/pkg/simple" "github.com/xh3b4sd/redigo/pkg/sorted" "github.com/xh3b4sd/redigo/pkg/walker" + "github.com/xh3b4sd/redigo/simple" ) type Client struct { @@ -61,7 +60,7 @@ func (c *Client) Locker() locker.Interface { return c.FakeLocker() } - return &Locker{} + return &locker.Fake{} } func (c *Client) PubSub() pubsub.Interface { diff --git a/pkg/fake/locker.go b/pkg/fake/locker.go deleted file mode 100644 index ff52d0f..0000000 --- a/pkg/fake/locker.go +++ /dev/null @@ -1,31 +0,0 @@ -package fake - -type Locker struct { - FakeAcquire func() error - FakeRefresh func() error - FakeRelease func() error -} - -func (f *Locker) Acquire() error { - if f.FakeAcquire != nil { - return f.FakeAcquire() - } - - return nil -} - -func (f *Locker) Refresh() error { - if f.FakeRefresh != nil { - return f.FakeRefresh() - } - - return nil -} - -func (f *Locker) Release() error { - if f.FakeRelease != nil { - return f.FakeRelease() - } - - return nil -} diff --git a/pkg/fake/simple.go b/pkg/fake/simple.go index 282e213..144f187 100644 --- a/pkg/fake/simple.go +++ b/pkg/fake/simple.go @@ -1,11 +1,11 @@ package fake import ( - "github.com/xh3b4sd/redigo/pkg/simple" - "github.com/xh3b4sd/redigo/pkg/simple/create" - "github.com/xh3b4sd/redigo/pkg/simple/delete" - "github.com/xh3b4sd/redigo/pkg/simple/exists" - "github.com/xh3b4sd/redigo/pkg/simple/search" + "github.com/xh3b4sd/redigo/simple" + "github.com/xh3b4sd/redigo/simple/create" + "github.com/xh3b4sd/redigo/simple/delete" + "github.com/xh3b4sd/redigo/simple/exists" + "github.com/xh3b4sd/redigo/simple/search" ) type Simple struct { diff --git a/pkg/locker/locker.go b/pkg/locker/locker.go deleted file mode 100644 index aa98c45..0000000 --- a/pkg/locker/locker.go +++ /dev/null @@ -1,66 +0,0 @@ -package locker - -import ( - "fmt" - "time" - - "github.com/go-redsync/redsync/v4" - "github.com/go-redsync/redsync/v4/redis/redigo" - "github.com/gomodule/redigo/redis" - "github.com/xh3b4sd/breakr" - "github.com/xh3b4sd/redigo/pkg/prefix" -) - -type Config struct { - Breakr breakr.Interface - Expiry time.Duration - Name string - Pool *redis.Pool - Prefix string -} - -type Locker struct { - brk breakr.Interface - mut *redsync.Mutex -} - -func New(c Config) *Locker { - if c.Breakr == nil { - c.Breakr = breakr.Default() - } - if c.Expiry == 0 { - c.Expiry = 30 * time.Second - } - if c.Name == "" { - c.Name = "def" - } - - var r *redsync.Redsync - { - p := redigo.NewPool( - &redis.Pool{ - MaxIdle: c.Pool.MaxIdle, - IdleTimeout: c.Pool.IdleTimeout, - Dial: c.Pool.Dial, - TestOnBorrow: c.Pool.TestOnBorrow, - }, - ) - - r = redsync.New(p) - } - - var l *Locker - { - l = &Locker{ - brk: c.Breakr, - mut: r.NewMutex( - prefix.WithKeys(c.Prefix, fmt.Sprintf("red:%s", c.Name)), - redsync.WithExpiry(c.Expiry), - redsync.WithRetryDelayFunc(func(tries int) time.Duration { return 100 * time.Millisecond }), - redsync.WithTries(1), - ), - } - } - - return l -} diff --git a/pkg/sorted/create/create_test.go b/pkg/sorted/create/create_test.go index fbea428..0bcf60e 100644 --- a/pkg/sorted/create/create_test.go +++ b/pkg/sorted/create/create_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/rafaeljusto/redigomock" - "github.com/xh3b4sd/redigo/pkg/pool" + "github.com/xh3b4sd/redigo/pool" ) func Test_Sorted_Create_Index_Input_Error(t *testing.T) { diff --git a/pkg/sorted/create/redis.go b/pkg/sorted/create/redis.go index dd77873..b1fbf47 100644 --- a/pkg/sorted/create/redis.go +++ b/pkg/sorted/create/redis.go @@ -4,8 +4,8 @@ import ( "strings" "github.com/gomodule/redigo/redis" - "github.com/xh3b4sd/redigo/pkg/index" - "github.com/xh3b4sd/redigo/pkg/prefix" + "github.com/xh3b4sd/redigo/index" + "github.com/xh3b4sd/redigo/prefix" "github.com/xh3b4sd/tracer" ) diff --git a/pkg/sorted/delete.go b/pkg/sorted/delete.go index 447b4fc..6c99320 100644 --- a/pkg/sorted/delete.go +++ b/pkg/sorted/delete.go @@ -2,10 +2,9 @@ package sorted import ( "github.com/gomodule/redigo/redis" + "github.com/xh3b4sd/redigo/index" + "github.com/xh3b4sd/redigo/prefix" "github.com/xh3b4sd/tracer" - - "github.com/xh3b4sd/redigo/pkg/index" - "github.com/xh3b4sd/redigo/pkg/prefix" ) const deleteCleanScript = ` diff --git a/pkg/sorted/exists.go b/pkg/sorted/exists.go index 138a67d..6ecccca 100644 --- a/pkg/sorted/exists.go +++ b/pkg/sorted/exists.go @@ -2,10 +2,9 @@ package sorted import ( "github.com/gomodule/redigo/redis" + "github.com/xh3b4sd/redigo/index" + "github.com/xh3b4sd/redigo/prefix" "github.com/xh3b4sd/tracer" - - "github.com/xh3b4sd/redigo/pkg/index" - "github.com/xh3b4sd/redigo/pkg/prefix" ) type exists struct { diff --git a/pkg/sorted/floats.go b/pkg/sorted/floats.go index c993f72..3a54b55 100644 --- a/pkg/sorted/floats.go +++ b/pkg/sorted/floats.go @@ -2,9 +2,8 @@ package sorted import ( "github.com/gomodule/redigo/redis" + "github.com/xh3b4sd/redigo/prefix" "github.com/xh3b4sd/tracer" - - "github.com/xh3b4sd/redigo/pkg/prefix" ) type floats struct { diff --git a/pkg/sorted/metric.go b/pkg/sorted/metric.go index a5d686b..0a2f7c7 100644 --- a/pkg/sorted/metric.go +++ b/pkg/sorted/metric.go @@ -2,9 +2,8 @@ package sorted import ( "github.com/gomodule/redigo/redis" + "github.com/xh3b4sd/redigo/prefix" "github.com/xh3b4sd/tracer" - - "github.com/xh3b4sd/redigo/pkg/prefix" ) type metric struct { diff --git a/pkg/sorted/search.go b/pkg/sorted/search.go index 2a6ebd9..65ff5f4 100644 --- a/pkg/sorted/search.go +++ b/pkg/sorted/search.go @@ -4,10 +4,9 @@ import ( "strings" "github.com/gomodule/redigo/redis" + "github.com/xh3b4sd/redigo/index" + "github.com/xh3b4sd/redigo/prefix" "github.com/xh3b4sd/tracer" - - "github.com/xh3b4sd/redigo/pkg/index" - "github.com/xh3b4sd/redigo/pkg/prefix" ) const searchIndexScript = ` diff --git a/pkg/sorted/update.go b/pkg/sorted/update.go index 51cb37a..c504edf 100644 --- a/pkg/sorted/update.go +++ b/pkg/sorted/update.go @@ -2,10 +2,9 @@ package sorted import ( "github.com/gomodule/redigo/redis" + "github.com/xh3b4sd/redigo/index" + "github.com/xh3b4sd/redigo/prefix" "github.com/xh3b4sd/tracer" - - "github.com/xh3b4sd/redigo/pkg/index" - "github.com/xh3b4sd/redigo/pkg/prefix" ) const updateIndexScript = ` diff --git a/pkg/pool/pool.go b/pool/pool.go similarity index 100% rename from pkg/pool/pool.go rename to pool/pool.go diff --git a/pkg/prefix/prefix.go b/prefix/prefix.go similarity index 100% rename from pkg/prefix/prefix.go rename to prefix/prefix.go diff --git a/redigo.go b/redigo.go index 0a9237c..3502710 100644 --- a/redigo.go +++ b/redigo.go @@ -3,17 +3,14 @@ package redigo import ( "net" "os" - "time" "github.com/gomodule/redigo/redis" - "github.com/xh3b4sd/breakr" "github.com/xh3b4sd/redigo/pkg/backup" - "github.com/xh3b4sd/redigo/pkg/locker" - "github.com/xh3b4sd/redigo/pkg/pool" "github.com/xh3b4sd/redigo/pkg/pubsub" - "github.com/xh3b4sd/redigo/pkg/simple" "github.com/xh3b4sd/redigo/pkg/sorted" "github.com/xh3b4sd/redigo/pkg/walker" + "github.com/xh3b4sd/redigo/pool" + "github.com/xh3b4sd/redigo/simple" "github.com/xh3b4sd/tracer" ) @@ -26,21 +23,13 @@ type Config struct { Address string Count int Kind string - Locker ConfigLocker Pool *redis.Pool Prefix string } -type ConfigLocker struct { - Breakr breakr.Interface - Expiry time.Duration - Name string -} - type Redigo struct { add string bac backup.Interface - loc locker.Interface poo *redis.Pool pub pubsub.Interface sim simple.Interface @@ -81,17 +70,6 @@ func New(con Config) (*Redigo, error) { } } - var loc locker.Interface - { - loc = locker.New(locker.Config{ - Breakr: con.Locker.Breakr, - Expiry: con.Locker.Expiry, - Name: con.Locker.Name, - Pool: con.Pool, - Prefix: con.Prefix, - }) - } - var pub pubsub.Interface { c := pubsub.Config{ @@ -152,7 +130,6 @@ func New(con Config) (*Redigo, error) { r := &Redigo{ add: con.Address, bac: bac, - loc: loc, poo: con.Pool, pub: pub, sim: sim, @@ -232,10 +209,6 @@ func (r *Redigo) Backup() backup.Interface { return r.bac } -func (r *Redigo) Locker() locker.Interface { - return r.loc -} - func (r *Redigo) PubSub() pubsub.Interface { return r.pub } diff --git a/pkg/simple/create/error.go b/simple/create/error.go similarity index 100% rename from pkg/simple/create/error.go rename to simple/create/error.go diff --git a/pkg/simple/create/fake.go b/simple/create/fake.go similarity index 100% rename from pkg/simple/create/fake.go rename to simple/create/fake.go diff --git a/pkg/simple/create/redis.go b/simple/create/redis.go similarity index 94% rename from pkg/simple/create/redis.go rename to simple/create/redis.go index a78aea0..aa12036 100644 --- a/pkg/simple/create/redis.go +++ b/simple/create/redis.go @@ -2,7 +2,7 @@ package create import ( "github.com/gomodule/redigo/redis" - "github.com/xh3b4sd/redigo/pkg/prefix" + "github.com/xh3b4sd/redigo/prefix" "github.com/xh3b4sd/tracer" ) diff --git a/pkg/simple/delete/fake.go b/simple/delete/fake.go similarity index 100% rename from pkg/simple/delete/fake.go rename to simple/delete/fake.go diff --git a/pkg/simple/delete/redis.go b/simple/delete/redis.go similarity index 94% rename from pkg/simple/delete/redis.go rename to simple/delete/redis.go index 1562f03..3747485 100644 --- a/pkg/simple/delete/redis.go +++ b/simple/delete/redis.go @@ -2,7 +2,7 @@ package delete import ( "github.com/gomodule/redigo/redis" - "github.com/xh3b4sd/redigo/pkg/prefix" + "github.com/xh3b4sd/redigo/prefix" "github.com/xh3b4sd/tracer" ) diff --git a/pkg/simple/error.go b/simple/error.go similarity index 66% rename from pkg/simple/error.go rename to simple/error.go index b9b461d..dd4d1a0 100644 --- a/pkg/simple/error.go +++ b/simple/error.go @@ -1,7 +1,7 @@ package simple import ( - "github.com/xh3b4sd/redigo/pkg/simple/search" + "github.com/xh3b4sd/redigo/simple/search" ) func IsNotFound(err error) bool { diff --git a/pkg/simple/exists/fake.go b/simple/exists/fake.go similarity index 100% rename from pkg/simple/exists/fake.go rename to simple/exists/fake.go diff --git a/pkg/simple/exists/redis.go b/simple/exists/redis.go similarity index 94% rename from pkg/simple/exists/redis.go rename to simple/exists/redis.go index 28d802d..ba45b5a 100644 --- a/pkg/simple/exists/redis.go +++ b/simple/exists/redis.go @@ -2,7 +2,7 @@ package exists import ( "github.com/gomodule/redigo/redis" - "github.com/xh3b4sd/redigo/pkg/prefix" + "github.com/xh3b4sd/redigo/prefix" "github.com/xh3b4sd/tracer" ) diff --git a/pkg/simple/interface.go b/simple/interface.go similarity index 100% rename from pkg/simple/interface.go rename to simple/interface.go diff --git a/pkg/simple/search/error.go b/simple/search/error.go similarity index 100% rename from pkg/simple/search/error.go rename to simple/search/error.go diff --git a/pkg/simple/search/fake.go b/simple/search/fake.go similarity index 100% rename from pkg/simple/search/fake.go rename to simple/search/fake.go diff --git a/pkg/simple/search/redis.go b/simple/search/redis.go similarity index 94% rename from pkg/simple/search/redis.go rename to simple/search/redis.go index 99315a5..bd66f95 100644 --- a/pkg/simple/search/redis.go +++ b/simple/search/redis.go @@ -2,7 +2,7 @@ package search import ( "github.com/gomodule/redigo/redis" - "github.com/xh3b4sd/redigo/pkg/prefix" + "github.com/xh3b4sd/redigo/prefix" "github.com/xh3b4sd/tracer" ) diff --git a/pkg/simple/simple.go b/simple/simple.go similarity index 84% rename from pkg/simple/simple.go rename to simple/simple.go index cfdf231..495507f 100644 --- a/pkg/simple/simple.go +++ b/simple/simple.go @@ -2,10 +2,10 @@ package simple import ( "github.com/gomodule/redigo/redis" - "github.com/xh3b4sd/redigo/pkg/simple/create" - "github.com/xh3b4sd/redigo/pkg/simple/delete" - "github.com/xh3b4sd/redigo/pkg/simple/exists" - "github.com/xh3b4sd/redigo/pkg/simple/search" + "github.com/xh3b4sd/redigo/simple/create" + "github.com/xh3b4sd/redigo/simple/delete" + "github.com/xh3b4sd/redigo/simple/exists" + "github.com/xh3b4sd/redigo/simple/search" ) type Config struct {