-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage.go
61 lines (53 loc) · 1.86 KB
/
storage.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package storage
import (
"encoding/hex"
"errors"
"github.com/spaolacci/murmur3"
"github.com/TykTechnologies/tyk/config"
logger "github.com/TykTechnologies/tyk/log"
)
var log = logger.Get()
// ErrKeyNotFound is a standard error for when a key is not found in the storage engine
var ErrKeyNotFound = errors.New("key not found")
// Handler is a standard interface to a storage backend, used by
// AuthorisationManager to read and write key values to the backend
type Handler interface {
GetKey(string) (string, error) // Returned string is expected to be a JSON object (user.SessionState)
GetRawKey(string) (string, error)
SetKey(string, string, int64) error // Second input string is expected to be a JSON object (user.SessionState)
SetRawKey(string, string, int64) error
SetExp(string, int64) error // Set key expiration
GetExp(string) (int64, error) // Returns expiry of a key
GetKeys(string) []string
DeleteKey(string) bool
DeleteRawKey(string) bool
Connect() bool
GetKeysAndValues() map[string]string
GetKeysAndValuesWithFilter(string) map[string]string
DeleteKeys([]string) bool
Decrement(string)
IncrememntWithExpire(string, int64) int64
SetRollingWindow(key string, per int64, val string, pipeline bool) (int, []interface{})
GetSet(string) (map[string]string, error)
AddToSet(string, string)
AppendToSet(string, string)
GetAndDeleteSet(string) []interface{}
RemoveFromSet(string, string)
DeleteScanMatch(string) bool
GetKeyPrefix() string
AddToSortedSet(string, string, float64)
GetSortedSetRange(string, string, string) ([]string, []float64, error)
RemoveSortedSetRange(string, string, string) error
}
func HashStr(in string) string {
h := murmur3.New32()
h.Write([]byte(in))
return hex.EncodeToString(h.Sum(nil))
}
func HashKey(in string) string {
if !config.Global.HashKeys {
// Not hashing? Return the raw key
return in
}
return HashStr(in)
}