aboutsummaryrefslogtreecommitdiff
path: root/pkg/commands/expire.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/commands/expire.go')
-rw-r--r--pkg/commands/expire.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/pkg/commands/expire.go b/pkg/commands/expire.go
new file mode 100644
index 0000000..4337e83
--- /dev/null
+++ b/pkg/commands/expire.go
@@ -0,0 +1,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
+}