diff --git a/README.md b/README.md index 5d0d33e5..157e3c0f 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,7 @@ Benchmark script options: ## CONNECTION * [AUTH](https://sugardb.io/docs/commands/connection/auth) +* [ECHO](https://sugardb.io/docs/commands/connection/echo) * [HELLO](https://sugardb.io/docs/commands/connection/hello) * [PING](https://sugardb.io/docs/commands/connection/ping) * [SELECT](https://sugardb.io/docs/commands/connection/select) @@ -204,6 +205,7 @@ Benchmark script options: ## GENERIC +* [COPY](https://sugardb.io/docs/commands/generic/copy) * [DECR](https://sugardb.io/docs/commands/generic/decr) * [DECRBY](https://sugardb.io/docs/commands/generic/decrby) * [DEL](https://sugardb.io/docs/commands/generic/del) @@ -212,14 +214,22 @@ Benchmark script options: * [FLUSHALL](https://sugardb.io/docs/commands/generic/flushall) * [FLUSHDB](https://sugardb.io/docs/commands/generic/flushdb) * [GET](https://sugardb.io/docs/commands/generic/get) +* [GETDEL](https://sugardb.io/docs/commands/generic/getdel) +* [GETEX](https://sugardb.io/docs/commands/generic/get) * [INCR](https://sugardb.io/docs/commands/generic/incr) * [INCRBY](https://sugardb.io/docs/commands/generic/incrby) +* [INCRBYFLOAT](https://sugardb.io/docs/commands/generic/incrbyfloat) * [MGET](https://sugardb.io/docs/commands/generic/mget) +* [MOVE](https://sugardb.io/docs/commands/generic/move) * [MSET](https://sugardb.io/docs/commands/generic/mset) +* [OBJECTFREQ](https://sugardb.io/docs/commands/generic/objectfreq) +* [OBJECTIDLETIME](https://sugardb.io/docs/commands/generic/objectidletime) * [PERSIST](https://sugardb.io/docs/commands/generic/persist) * [PEXPIRE](https://sugardb.io/docs/commands/generic/pexpire) +* [PEXPIREAT](https://sugardb.io/docs/commands/generic/pexpireat) * [PEXPIRETIME](https://sugardb.io/docs/commands/generic/pexpiretime) * [PTTL](https://sugardb.io/docs/commands/generic/pttl) +* [RANDOMKEY](https://sugardb.io/docs/commands/generic/randomkey) * [RENAME](https://sugardb.io/docs/commands/generic/rename) * [SET](https://sugardb.io/docs/commands/generic/set) * [TTL](https://sugardb.io/docs/commands/generic/ttl) @@ -319,11 +329,8 @@ Benchmark script options: ## STRING +* [APPEND](https://sugardb.io/docs/commands/string/append) * [GETRANGE](https://sugardb.io/docs/commands/string/getrange) * [SETRANGE](https://sugardb.io/docs/commands/string/setrange) * [STRLEN](https://sugardb.io/docs/commands/string/strlen) * [SUBSTR](https://sugardb.io/docs/commands/string/substr) - - - - diff --git a/docs/docs/commands/connection/echo.mdx b/docs/docs/commands/connection/echo.mdx new file mode 100644 index 00000000..de3c7e52 --- /dev/null +++ b/docs/docs/commands/connection/echo.mdx @@ -0,0 +1,42 @@ +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +# ECHO + +### Syntax +``` +ECHO [message] +``` + +### Module +connection + +### Categories +connection +fast + +### Description +Sends a message to the SugarDB server and it returns the same message back. + +### Examples + + + + ```go + // Not available in embedded mode. + ``` + + + Echo with message: + + ``` + > ECHO "Hello, World!" + ``` + + diff --git a/docs/docs/commands/generic/copy.mdx b/docs/docs/commands/generic/copy.mdx new file mode 100644 index 00000000..a3e50f37 --- /dev/null +++ b/docs/docs/commands/generic/copy.mdx @@ -0,0 +1,85 @@ +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +# COPY + +### Syntax +``` +COPY source destination [DB destination-db] [REPLACE] +``` + +### Module +generic + +### Categories +slow +write +keyspace + +### Description +Copies the value stored at the source key to the destination key. +Returns 1 if copied and 0 if not copied. +Also returns 0 if the destination key already exists in the database and the REPLACE option is not set. + +### Options +- `DB destination-db`: the destination database to copy the key to +- `REPLACE`: replace the destination key if it already exists + +### Examples + + + + The API provides a struct called COPYOptions that wraps these options in a convenient object. + ```go + type COPYOptions struct { + Database string + Replace bool + } + ``` + + Copy the value stored at key 'hello' to the new key 'bye' + ```go + db, err := sugardb.NewSugarDB() + if err != nil { + log.Fatal(err) + } + db.Set("hello", "world") + key = db.Copy("hello", "bye") + ``` + + Copy the value stored at key 'hello' in database 0 and replace the value at key 'bye' in database 1 + ```go + db, err := sugardb.NewSugarDB() + if err != nil { + log.Fatal(err) + } + err := db.SelectDB(1) + ok, err := db.Set("bye", "goodbye") + err := db.SelectDB(0) + ok, err := db.Set("hello", "world") + ret, err = db.Copy("hello", "bye", db.COPYOptions{Database: "1", Replace: true}) + ``` + + + Copy the value stored at key 'hello' to the key 'bye' + ``` + > SET "hello" "world" + > COPY "hello" "bye" + ``` + + Copy the value stored at key 'hello' in database 0 and replace the value at key 'bye' in database 1 + ``` + > SELECT 1 + > SET "bye" "goodbye" + > SELECT 0 + > SET "hello" "world" + > COPY "hello" "bye" DB 1 REPLACE + ``` + + \ No newline at end of file diff --git a/docs/docs/commands/generic/incrbyfloat.mdx b/docs/docs/commands/generic/incrbyfloat.mdx new file mode 100644 index 00000000..2eaf0aff --- /dev/null +++ b/docs/docs/commands/generic/incrbyfloat.mdx @@ -0,0 +1,50 @@ +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +# INCRBYFLOAT + +### Syntax +``` +INCRBYFLOAT key increment +``` + +### Module +generic + +### Categories +fast +write + +### Description +Increments the floating point number stored at key by increment. If the key does not exist, it is set to 0 before performing +the operation. An error is returned if the key contains a value of the wrong type or contains a string +that can not be represented as a floating point number. + +### Options + +### Examples + + + + Increment the value of the key `mykey` by 10.33: + ```go + db, err := sugardb.NewSugarDB() + if err != nil { + log.Fatal(err) + } + value, err := db.IncrByFloat("mykey", "10.33") + ``` + + + Increment the value of the key `mykey` by 10.33: + ``` + > INCRBYFLOAT mykey 10.33 + ``` + + \ No newline at end of file diff --git a/docs/docs/commands/generic/randomkey.mdx b/docs/docs/commands/generic/randomkey.mdx new file mode 100644 index 00000000..97792343 --- /dev/null +++ b/docs/docs/commands/generic/randomkey.mdx @@ -0,0 +1,47 @@ +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +# RANDOMKEY + +### Syntax +``` +RANDOMKEY +``` + +### Module +generic + +### Categories +slow +read +keyspace + +### Description +Returns a random key from the currently selected database. If no keys are available, an empty string is returned. + +### Examples + + + + Get a random key from the database: + ```go + db, err := sugardb.NewSugarDB() + if err != nil { + log.Fatal(err) + } + key, err := db.RandomKey() + ``` + + + Get a random key from the database: + ``` + > RANDOMKEY + ``` + + \ No newline at end of file diff --git a/docs/docs/commands/string/append.mdx b/docs/docs/commands/string/append.mdx new file mode 100644 index 00000000..78e167cd --- /dev/null +++ b/docs/docs/commands/string/append.mdx @@ -0,0 +1,48 @@ +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +# APPEND + +### Syntax +``` +APPEND key value +``` + +### Module +string + +### Categories +write +fast +string + +### Description +Appends a value to the end of a string. If the doesn't exist, it creates the key with the value (acts as a SET). +Returns the length of the string after the append operation. + +### Examples + + + + Append a value to the end of a string: + ```go + db, err := sugardb.NewSugarDB() + if err != nil { + log.Fatal(err) + } + len, err := db.Append("key", "value") + ``` + + + Append a value to the end of a string: + ``` + > APPEND "key" "value" + ``` + + diff --git a/docs/docs/commands/string/getrange.mdx b/docs/docs/commands/string/getrange.mdx index d4991872..91efc2ac 100644 --- a/docs/docs/commands/string/getrange.mdx +++ b/docs/docs/commands/string/getrange.mdx @@ -9,12 +9,12 @@ GETRANGE key start end ``` ### Module -sortedset +string ### Categories read slow -sortedset +string ### Description Return the substring of the string value stored at key. The substring is specified by the start and end indexes. diff --git a/docs/docs/commands/string/setrange.mdx b/docs/docs/commands/string/setrange.mdx index 0229dde7..a2b987b0 100644 --- a/docs/docs/commands/string/setrange.mdx +++ b/docs/docs/commands/string/setrange.mdx @@ -9,12 +9,12 @@ SETRANGE key offset value ``` ### Module -sortedset +string ### Categories write slow -sortedset +string ### Description Overwrites part of a string value with another by offset. Creates the key if it doesn't exist. diff --git a/docs/docs/commands/string/strlen.mdx b/docs/docs/commands/string/strlen.mdx index 5bd2f876..83401af0 100644 --- a/docs/docs/commands/string/strlen.mdx +++ b/docs/docs/commands/string/strlen.mdx @@ -9,12 +9,12 @@ STRLEN key ``` ### Module -sortedset +string ### Categories fast read -sortedset +string ### Description Returns length of the key's value if it's a string. diff --git a/docs/docs/commands/string/substr.mdx b/docs/docs/commands/string/substr.mdx index b1a6e04a..5e0bf22d 100644 --- a/docs/docs/commands/string/substr.mdx +++ b/docs/docs/commands/string/substr.mdx @@ -9,12 +9,12 @@ SUBSTR key start end ``` ### Module -sortedset +string ### Categories read slow -sortedset +string ### Description Return the substring of the string value stored at key. The substring is specified by the start and end indexes.