forked from cnu/godis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
29 lines (24 loc) · 684 Bytes
/
utils.go
File metadata and controls
29 lines (24 loc) · 684 Bytes
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
package godis
import (
"math/rand"
"time"
)
func (g *Godis) getSDS(key string) (*SDS, bool) {
s, exists := g.db[key]
return s, exists
}
// generateRandnum returns a random number within given range.
func (g *Godis) generateRandnum(n int) int {
rand.Seed(time.Now().UnixNano())
return rand.Intn(n)
}
// Destroy a key after given time in seconds
func (g *Godis) destroyInSecs(key string, exp uint64) (int, error) {
time.Sleep(time.Duration(exp) * time.Second)
return g.DEL(key)
}
// Destroy a key after given time in milliseconds
func (g *Godis) destroyInMillis(key string, exp uint64) (int, error) {
time.Sleep(time.Duration(exp) * time.Millisecond)
return g.DEL(key)
}