diff options
| author | alex <[email protected]> | 2026-07-10 20:28:47 +0200 |
|---|---|---|
| committer | alex <[email protected]> | 2026-07-10 20:28:47 +0200 |
| commit | f18210c30e67de4bede7c6080d85629f7086676c (patch) | |
| tree | c9aedf21ed9f905424f8ab6fdb633254e127fbc6 /pkg/commands/get.go | |
| parent | 36d70e64340033f1e5b928524436c0b2f44c831e (diff) | |
| download | redis-clone-f18210c30e67de4bede7c6080d85629f7086676c.tar.xz redis-clone-f18210c30e67de4bede7c6080d85629f7086676c.zip | |
separated commands into their own files TODO: refactor all commands to work like this
Diffstat (limited to 'pkg/commands/get.go')
| -rw-r--r-- | pkg/commands/get.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/pkg/commands/get.go b/pkg/commands/get.go new file mode 100644 index 0000000..9dc2bcd --- /dev/null +++ b/pkg/commands/get.go @@ -0,0 +1,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 + }
\ No newline at end of file |
