🎑 update tests

This commit is contained in:
Fenny
2020-11-05 05:36:27 +01:00
parent 504e8c31f8
commit 8440b5e3c0
8 changed files with 29 additions and 0 deletions

View File

@@ -72,6 +72,10 @@ func (s *Storage) Get(key string) ([]byte, error) {
// Set key with value // Set key with value
func (s *Storage) Set(key string, val []byte, exp time.Duration) error { func (s *Storage) Set(key string, val []byte, exp time.Duration) error {
// Ain't Nobody Got Time For That
if len(val) <= 0 {
return nil
}
item := s.acquireItem() item := s.acquireItem()
item.Key = key item.Key = key
item.Value = val item.Value = val

View File

@@ -52,6 +52,10 @@ func (s *Storage) Get(key string) ([]byte, error) {
// Set key with value // Set key with value
func (s *Storage) Set(key string, val []byte, exp time.Duration) error { func (s *Storage) Set(key string, val []byte, exp time.Duration) error {
// Ain't Nobody Got Time For That
if len(val) <= 0 {
return nil
}
var expire int64 var expire int64
if exp != 0 { if exp != 0 {
expire = time.Now().Add(exp).Unix() expire = time.Now().Add(exp).Unix()

View File

@@ -127,6 +127,11 @@ func (s *Storage) Get(key string) ([]byte, error) {
// //
// document will be remove automatically if exp is set, based on MongoDB TTL Indexes // document will be remove automatically if exp is set, based on MongoDB TTL Indexes
func (s *Storage) Set(key string, val []byte, exp time.Duration) error { func (s *Storage) Set(key string, val []byte, exp time.Duration) error {
// Ain't Nobody Got Time For That
if len(val) <= 0 {
return nil
}
filter := bson.M{"key": key} filter := bson.M{"key": key}
item := s.acquireItem() item := s.acquireItem()
item.Key = key item.Key = key

View File

@@ -118,6 +118,10 @@ func (s *Storage) Get(key string) ([]byte, error) {
// Set key with value // Set key with value
func (s *Storage) Set(key string, val []byte, exp time.Duration) error { func (s *Storage) Set(key string, val []byte, exp time.Duration) error {
// Ain't Nobody Got Time For That
if len(val) <= 0 {
return nil
}
var expSeconds int64 var expSeconds int64
if exp != 0 { if exp != 0 {
expSeconds = time.Now().Add(exp).Unix() expSeconds = time.Now().Add(exp).Unix()

View File

@@ -138,6 +138,10 @@ func (s *Storage) Get(key string) ([]byte, error) {
// Set key with value // Set key with value
func (s *Storage) Set(key string, val []byte, exp time.Duration) error { func (s *Storage) Set(key string, val []byte, exp time.Duration) error {
// Ain't Nobody Got Time For That
if len(val) <= 0 {
return nil
}
_, err := s.db.Exec(s.sqlInsert, key, utils.UnsafeString(val), time.Now().Add(exp).Unix()) _, err := s.db.Exec(s.sqlInsert, key, utils.UnsafeString(val), time.Now().Add(exp).Unix())
return err return err
} }

View File

@@ -59,6 +59,10 @@ func (s *Storage) Get(key string) ([]byte, error) {
// Set key with value // Set key with value
func (s *Storage) Set(key string, val []byte, exp time.Duration) error { func (s *Storage) Set(key string, val []byte, exp time.Duration) error {
// Ain't Nobody Got Time For That
if len(val) <= 0 {
return nil
}
return s.db.Set(context.Background(), key, val, exp).Err() return s.db.Set(context.Background(), key, val, exp).Err()
} }

Binary file not shown.

View File

@@ -117,6 +117,10 @@ func (s *Storage) Get(key string) ([]byte, error) {
// Set key with value // Set key with value
func (s *Storage) Set(key string, val []byte, exp time.Duration) error { func (s *Storage) Set(key string, val []byte, exp time.Duration) error {
// Ain't Nobody Got Time For That
if len(val) <= 0 {
return nil
}
var expSeconds int64 var expSeconds int64
if exp != 0 { if exp != 0 {
expSeconds = time.Now().Add(exp).Unix() expSeconds = time.Now().Add(exp).Unix()