mirror of
https://github.com/gofiber/storage.git
synced 2025-10-04 16:22:52 +08:00
🎑 update tests
This commit is contained in:
@@ -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
|
||||||
|
@@ -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()
|
||||||
|
@@ -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
|
||||||
|
@@ -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()
|
||||||
|
@@ -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
|
||||||
}
|
}
|
||||||
|
@@ -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.
@@ -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()
|
||||||
|
Reference in New Issue
Block a user