From 89b3019a3ab77a3e72720342fc0e5bea996fa4f2 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 12 Jul 2026 13:48:32 +0200 Subject: refactored all functions to use the command registry --- pkg/commands/command-registry.go | 73 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) (limited to 'pkg/commands/command-registry.go') 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 -- cgit v1.2.3