-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnosql-keyvalue.go
45 lines (37 loc) · 951 Bytes
/
nosql-keyvalue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package storage
import (
"time"
"github.com/labstack/echo/v4"
"github.com/golang-common-packages/hash"
)
// INoSQLKeyValue factory pattern interface
type INoSQLKeyValue interface {
Middleware(hash hash.IHash) echo.MiddlewareFunc
Get(key string) (interface{}, error)
Set(key string, value interface{}, expire time.Duration) error
Update(key string, value interface{}, expire time.Duration) error
Delete(key string) error
GetNumberOfRecords() int
GetCapacity() (interface{}, error)
Close() error
}
const (
// CUSTOM caching on local memory
CUSTOM = iota
// BIGCACHE database
BIGCACHE
// REDIS database
REDIS
)
// newNoSQLKeyValue factory pattern
func newNoSQLKeyValue(databaseCompany int, config *Config) interface{} {
switch databaseCompany {
case CUSTOM:
return newKeyValueCustom(&config.CustomKeyValue)
case REDIS:
return newRedis(&config.Redis)
case BIGCACHE:
return newBigCache(&config.BigCache)
}
return nil
}