blob: 4337e83ccee5e75273412a64d0bfb5a06527c939 (
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
|
package commands
import (
"errors"
"redisClone/pkg/core"
"strconv"
"time"
)
func Expire(args []string, getShard func(k string) *core.Shard) interface{} {
key := args[1]
seconds, err := strconv.Atoi(args[2])
if err != nil {
return errors.New("value is not an integer")
}
s := getShard(key)
item, exists := s.Data[key]
if !exists {
return 0
}
expiry := time.Now().Add(time.Duration(seconds) * time.Second)
item.ExpiresAt = &expiry
s.Data[key] = item
return 1
}
|