From f744ed8a06dc6d896ab416b5a8457cb19fac56e3 Mon Sep 17 00:00:00 2001 From: Kelvin Clement Mwinuka Date: Wed, 5 Jul 2023 01:14:32 +0800 Subject: [PATCH] Created list plugin with comprehensive list of commands to be handled by the plugin --- server/Makefile | 1 + server/plugins/commands/list/list.go | 56 ++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 server/plugins/commands/list/list.go diff --git a/server/Makefile b/server/Makefile index 2430143..3313b5c 100644 --- a/server/Makefile +++ b/server/Makefile @@ -1,6 +1,7 @@ build-plugins: go build -buildmode=plugin -o bin/plugins/commands/command_ping.so plugins/commands/ping/ping.go go build -buildmode=plugin -o bin/plugins/commands/command_setget.so plugins/commands/setget/setget.go + go build -buildmode=plugin -o bin/plugins/commands/command_list.so plugins/commands/list/list.go build-server: go build -o bin/server ./*.go diff --git a/server/plugins/commands/list/list.go b/server/plugins/commands/list/list.go new file mode 100644 index 0000000..bc1f9bf --- /dev/null +++ b/server/plugins/commands/list/list.go @@ -0,0 +1,56 @@ +package main + +import ( + "bufio" +) + +type Server interface { + GetData(key string) interface{} + SetData(key string, value interface{}) +} + +type plugin struct { + name string + commands []string + description string +} + +var Plugin plugin + +func (p *plugin) Name() string { + return p.name +} + +func (p *plugin) Commands() []string { + return p.commands +} + +func (p *plugin) Description() string { + return p.description +} + +func (p *plugin) HandleCommand(cmd []string, server interface{}, conn *bufio.Writer) { +} + +func init() { + Plugin.name = "ListCommand" + Plugin.commands = []string{ + "lpush", // (LPUSH key value1 [value2]) Prepends one or more values to the beginning of a list, creates the list if it does not exist. + "lpushx", // (LPUSHX key value) Prepends a value to the beginning of a list only if the list exists. + "lpop", // (LPOP key) Removes and returns the first element of a list. + "llen", // (LLEN key) Return the length of a list. + "lrange", // (LRANGE key start end) Return a range of elements between the given indices. + "lmove", // (LMOVE key1 key2 LEFT/RIGHT LEFT/RIGHT) Move element from one list to the other specifying left/right for both lists. + "lrem", // (LREM key count value) Remove elements from list. + "lset", // (LSET key index value) Sets teh value of an element in a list by its index. + "ltrim", // (LTRIM key start end) Trims a list to the specified range. + "lincr", // (LINCR key index) Increment the list element at the given index by 1. + "lincrby", // (LINCRBY key index value) Increment the list element at the given index by the given value. + "lindex", // (LINDEX key index) Gets list element by index. + "rpop", // (RPOP key) Removes and gets the last element in a list. + "rpoplpush", // (RPOPLPUSH key1 key2) Removes last element of one list, prepends it to another list and returns it. + "rpush", // (RPUSH key value [value2]) Appends one or multiple elements to the end of a list. + "rpushx", // (RPUSHX key value) Appends an element to the end of a list, only if the list exists. + } + Plugin.description = "Handle List commands" +}