aboutsummaryrefslogtreecommitdiff
path: root/pkg/commands/command-registry.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/commands/command-registry.go')
-rw-r--r--pkg/commands/command-registry.go73
1 files changed, 72 insertions, 1 deletions
diff --git a/pkg/commands/command-registry.go b/pkg/commands/command-registry.go
index baf7133..068fe7c 100644
--- a/pkg/commands/command-registry.go
+++ b/pkg/commands/command-registry.go
@@ -4,6 +4,13 @@ import (
"errors"
"redisClone/pkg/core"
)
+
+var dbInstance core.RedisDB
+
+func SetDB(db core.RedisDB) {
+ dbInstance = db
+}
+
func SingleKey(args []string) []string {
return []string{args[1]}
}
@@ -16,6 +23,10 @@ func NoKeys(args []string) []string {
return nil
}
+func RenameKeys(args []string) []string {
+ return []string{args[1], args[2]}
+}
+
type CommandDef struct{
MinArgs int
ExtractKeys func(args []string)[]string
@@ -72,7 +83,7 @@ var Registry = map[string]CommandDef{
},
"RENAME": {
MinArgs: 3,
- ExtractKeys: SingleKey,
+ ExtractKeys: RenameKeys,
Execute: Rename,
},
"RPUSH": {
@@ -100,4 +111,64 @@ var Registry = map[string]CommandDef{
ExtractKeys: SingleKey,
Execute: Lrange,
},
+ "FLUSHALL": {
+ MinArgs: 1,
+ ExtractKeys: NoKeys,
+ Execute: Flushall,
+ },
+ "EXPIRE": {
+ MinArgs: 3,
+ ExtractKeys: SingleKey,
+ Execute: Expire,
+ },
+ "HSET": {
+ MinArgs: 4,
+ ExtractKeys: SingleKey,
+ Execute: Hset,
+ },
+ "HGET": {
+ MinArgs: 3,
+ ExtractKeys: SingleKey,
+ Execute: Hget,
+ },
+ "HGETALL": {
+ MinArgs: 2,
+ ExtractKeys: SingleKey,
+ Execute: Hgetall,
+ },
+ "HKEYS": {
+ MinArgs: 2,
+ ExtractKeys: SingleKey,
+ Execute: Hkeys,
+ },
+ "HVALUES": {
+ MinArgs: 2,
+ ExtractKeys: SingleKey,
+ Execute: Hvalues,
+ },
+ "TYPE": {
+ MinArgs: 2,
+ ExtractKeys: SingleKey,
+ Execute: Type,
+ },
+ "DBSIZE": {
+ MinArgs: 1,
+ ExtractKeys: NoKeys,
+ Execute: Dbsize,
+ },
+ "KEYS": {
+ MinArgs: 2,
+ ExtractKeys: NoKeys,
+ Execute: Keys,
+ },
+ "LREM": {
+ MinArgs: 4,
+ ExtractKeys: SingleKey,
+ Execute: Lrem,
+ },
+ "PING": {
+ MinArgs: 1,
+ ExtractKeys: NoKeys,
+ Execute: Ping,
+ },
} \ No newline at end of file