diff options
author | Christopher Speller <crspeller@gmail.com> | 2017-11-13 09:09:58 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-13 09:09:58 -0800 |
commit | 1329aa51b605cb54ba9aae3a82a0a87b881fb7b3 (patch) | |
tree | 93cbf354ab894a560fc2cef8ef685d681b4ff889 /vendor/gopkg.in/throttled/throttled.v2/store | |
parent | 7304a61ef597970be3031b14e652fb3a4df44304 (diff) | |
download | chat-1329aa51b605cb54ba9aae3a82a0a87b881fb7b3.tar.gz chat-1329aa51b605cb54ba9aae3a82a0a87b881fb7b3.tar.bz2 chat-1329aa51b605cb54ba9aae3a82a0a87b881fb7b3.zip |
Updating server dependancies. (#7816)
Diffstat (limited to 'vendor/gopkg.in/throttled/throttled.v2/store')
-rw-r--r-- | vendor/gopkg.in/throttled/throttled.v2/store/deprecated.go | 6 | ||||
-rw-r--r-- | vendor/gopkg.in/throttled/throttled.v2/store/memstore/memstore.go | 2 | ||||
-rw-r--r-- | vendor/gopkg.in/throttled/throttled.v2/store/memstore/memstore_test.go | 4 | ||||
-rw-r--r-- | vendor/gopkg.in/throttled/throttled.v2/store/redigostore/redigostore.go | 34 | ||||
-rw-r--r-- | vendor/gopkg.in/throttled/throttled.v2/store/redigostore/redigostore_test.go (renamed from vendor/gopkg.in/throttled/throttled.v2/store/redigostore/redisstore_test.go) | 4 | ||||
-rw-r--r-- | vendor/gopkg.in/throttled/throttled.v2/store/storetest/doc.go | 2 | ||||
-rw-r--r-- | vendor/gopkg.in/throttled/throttled.v2/store/storetest/storetest.go | 4 |
7 files changed, 34 insertions, 22 deletions
diff --git a/vendor/gopkg.in/throttled/throttled.v2/store/deprecated.go b/vendor/gopkg.in/throttled/throttled.v2/store/deprecated.go index 5476e87ac..0492ba89e 100644 --- a/vendor/gopkg.in/throttled/throttled.v2/store/deprecated.go +++ b/vendor/gopkg.in/throttled/throttled.v2/store/deprecated.go @@ -1,11 +1,11 @@ // Package store contains deprecated aliases for subpackages -package store // import "gopkg.in/throttled/throttled.v2/store" +package store // import "github.com/throttled/throttled/store" import ( "github.com/garyburd/redigo/redis" - "gopkg.in/throttled/throttled.v2/store/memstore" - "gopkg.in/throttled/throttled.v2/store/redigostore" + "github.com/throttled/throttled/store/memstore" + "github.com/throttled/throttled/store/redigostore" ) // DEPRECATED. NewMemStore is a compatible alias for mem.New diff --git a/vendor/gopkg.in/throttled/throttled.v2/store/memstore/memstore.go b/vendor/gopkg.in/throttled/throttled.v2/store/memstore/memstore.go index 5d8fee8b5..352232958 100644 --- a/vendor/gopkg.in/throttled/throttled.v2/store/memstore/memstore.go +++ b/vendor/gopkg.in/throttled/throttled.v2/store/memstore/memstore.go @@ -1,5 +1,5 @@ // Package memstore offers an in-memory store implementation for throttled. -package memstore // import "gopkg.in/throttled/throttled.v2/store/memstore" +package memstore // import "github.com/throttled/throttled/store/memstore" import ( "sync" diff --git a/vendor/gopkg.in/throttled/throttled.v2/store/memstore/memstore_test.go b/vendor/gopkg.in/throttled/throttled.v2/store/memstore/memstore_test.go index ef003d3de..27b1c9b95 100644 --- a/vendor/gopkg.in/throttled/throttled.v2/store/memstore/memstore_test.go +++ b/vendor/gopkg.in/throttled/throttled.v2/store/memstore/memstore_test.go @@ -3,8 +3,8 @@ package memstore_test import ( "testing" - "gopkg.in/throttled/throttled.v2/store/memstore" - "gopkg.in/throttled/throttled.v2/store/storetest" + "github.com/throttled/throttled/store/memstore" + "github.com/throttled/throttled/store/storetest" ) func TestMemStoreLRU(t *testing.T) { diff --git a/vendor/gopkg.in/throttled/throttled.v2/store/redigostore/redigostore.go b/vendor/gopkg.in/throttled/throttled.v2/store/redigostore/redigostore.go index 54208fa6d..03acbcab0 100644 --- a/vendor/gopkg.in/throttled/throttled.v2/store/redigostore/redigostore.go +++ b/vendor/gopkg.in/throttled/throttled.v2/store/redigostore/redigostore.go @@ -1,5 +1,5 @@ // Package redigostore offers Redis-based store implementation for throttled using redigo. -package redigostore // import "gopkg.in/throttled/throttled.v2/store/redigostore" +package redigostore // import "github.com/throttled/throttled/store/redigostore" import ( "strings" @@ -18,11 +18,7 @@ end if v ~= ARGV[1] then return 0 end -if ARGV[3] ~= "0" then - redis.call('setex', KEYS[1], ARGV[3], ARGV[2]) -else - redis.call('set', KEYS[1], ARGV[2]) -end +redis.call('setex', KEYS[1], ARGV[3], ARGV[2]) return 1 ` ) @@ -106,10 +102,17 @@ func (r *RedigoStore) SetIfNotExistsWithTTL(key string, value int64, ttl time.Du updated := v == 1 - if ttl >= time.Second { - if _, err := conn.Do("EXPIRE", key, int(ttl.Seconds())); err != nil { - return updated, err - } + ttlSeconds := int(ttl.Seconds()) + + // An `EXPIRE 0` will delete the key immediately, so make sure that we set + // expiry for a minimum of one second out so that our results stay in the + // store. + if ttlSeconds < 1 { + ttlSeconds = 1 + } + + if _, err := conn.Do("EXPIRE", key, ttlSeconds); err != nil { + return updated, err } return updated, nil @@ -128,7 +131,16 @@ func (r *RedigoStore) CompareAndSwapWithTTL(key string, old, new int64, ttl time } defer conn.Close() - swapped, err := redis.Bool(conn.Do("EVAL", redisCASScript, 1, key, old, new, int(ttl.Seconds()))) + ttlSeconds := int(ttl.Seconds()) + + // An `EXPIRE 0` will delete the key immediately, so make sure that we set + // expiry for a minimum of one second out so that our results stay in the + // store. + if ttlSeconds < 1 { + ttlSeconds = 1 + } + + swapped, err := redis.Bool(conn.Do("EVAL", redisCASScript, 1, key, old, new, ttlSeconds)) if err != nil { if strings.Contains(err.Error(), redisCASMissingKey) { return false, nil diff --git a/vendor/gopkg.in/throttled/throttled.v2/store/redigostore/redisstore_test.go b/vendor/gopkg.in/throttled/throttled.v2/store/redigostore/redigostore_test.go index d47b635d2..ee9e2904d 100644 --- a/vendor/gopkg.in/throttled/throttled.v2/store/redigostore/redisstore_test.go +++ b/vendor/gopkg.in/throttled/throttled.v2/store/redigostore/redigostore_test.go @@ -6,8 +6,8 @@ import ( "github.com/garyburd/redigo/redis" - "gopkg.in/throttled/throttled.v2/store/redigostore" - "gopkg.in/throttled/throttled.v2/store/storetest" + "github.com/throttled/throttled/store/redigostore" + "github.com/throttled/throttled/store/storetest" ) const ( diff --git a/vendor/gopkg.in/throttled/throttled.v2/store/storetest/doc.go b/vendor/gopkg.in/throttled/throttled.v2/store/storetest/doc.go index ecfee2638..405c59a12 100644 --- a/vendor/gopkg.in/throttled/throttled.v2/store/storetest/doc.go +++ b/vendor/gopkg.in/throttled/throttled.v2/store/storetest/doc.go @@ -1,2 +1,2 @@ // Package storetest provides a helper for testing throttled stores. -package storetest // import "gopkg.in/throttled/throttled.v2/store/storetest" +package storetest // import "github.com/throttled/throttled/store/storetest" diff --git a/vendor/gopkg.in/throttled/throttled.v2/store/storetest/storetest.go b/vendor/gopkg.in/throttled/throttled.v2/store/storetest/storetest.go index 191b40a4f..2233ebdfb 100644 --- a/vendor/gopkg.in/throttled/throttled.v2/store/storetest/storetest.go +++ b/vendor/gopkg.in/throttled/throttled.v2/store/storetest/storetest.go @@ -1,5 +1,5 @@ // Package storetest provides a helper for testing throttled stores. -package storetest // import "gopkg.in/throttled/throttled.v2/store/storetest" +package storetest // import "github.com/throttled/throttled/store/storetest" import ( "math/rand" @@ -8,7 +8,7 @@ import ( "testing" "time" - "gopkg.in/throttled/throttled.v2" + "github.com/throttled/throttled" ) // TestGCRAStore tests the behavior of a GCRAStore implementation for |