blob: 9dc2bcdf6558b6d55a540552d72ac3353f653973 (
plain)
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
|
package commands
import (
"errors"
"redisClone/pkg/core"
"time"
)
func Get(args []string, getShard func(k string) *core.Shard) interface{} {
key := args[1]
s := getShard(key)
item, exists := s.Data[key]
if !exists {
return nil
}
if item.ExpiresAt != nil && time.Now().After(*item.ExpiresAt) {
delete(s.Data, key)
return nil
}
strValue, ok := item.Value.(string)
if !ok {
err := errors.New("WRONGTYPE Operation against a key holding the wrong kind of value")
return err
}
return strValue
}
|