diff --git a/docs/docs/commands/generic/getdel.mdx b/docs/docs/commands/generic/getdel.mdx new file mode 100644 index 00000000..5c4b77d6 --- /dev/null +++ b/docs/docs/commands/generic/getdel.mdx @@ -0,0 +1,46 @@ +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +# GETDEL + +### Syntax +``` +GETDEL key +``` + +### Module +generic + +### Categories +fast +write + +### Description +Get the value of key and delete the key. This command is similar to [GET], but deletes key on success. + +### Examples + + + + Get the value at the specified key: + ```go + db, err := sugardb.NewSugarDB() + if err != nil { + log.Fatal(err) + } + value, err := db.GetDel("key") + ``` + + + Get the value at the specified key: + ``` + > GETDEL key + ``` + + diff --git a/docs/docs/commands/generic/getex.mdx b/docs/docs/commands/generic/getex.mdx new file mode 100644 index 00000000..03576256 --- /dev/null +++ b/docs/docs/commands/generic/getex.mdx @@ -0,0 +1,65 @@ +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +# GETEX + +### Syntax +``` +GETEX key [EX | PX | EXAT | PXAT | PERSIST] +``` + +### Module +generic + +### Categories +fast +write + +### Description +Get the value of key and optionally set its expiration. GETEX is similar to [GET], but is a write command with additional options. + +### Options + - `EX` - Set the specified expire time, in seconds. + - `PX` - Set the specified expire time, in milliseconds. + - `EXAT` - Set the specified Unix time at which the key will expire, in seconds. + - `PXAT` - Set the specified Unix time at which the key will expire, in milliseconds. + - `PERSIST` - Remove the time to live associated with the key. + +### Examples + + + +The embedded API utilizes the GetExOption interface, which acts as a wrapper for the various expiry options of the GETEX command. +

+ GetExOption includes the following constants: + - `EX` - Set the specified expire time, in seconds. + - `PX` - Set the specified expire time, in milliseconds. + - `EXAT` - Set the specified Unix time at which the key will expire, in seconds. + - `PXAT` - Set the specified Unix time at which the key will expire, in milliseconds. + - `PERSIST` - Remove the time to live associated with the key. +

+ Get the value at the specified key: + ```go + db, err := sugardb.NewSugarDB() + if err != nil { + log.Fatal(err) + } + value, err := db.GetEx("key", nil, 0) + + // optionally set expiry + value, err = db.GetEx("key", sugardb.EX, 10) + ``` +
+ + Get the value at the specified key and set the expiry: + ``` + > GETEX key EX 10 + ``` + +