Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1254 Add support for GEOSEARCH #1315

Draft
wants to merge 32 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3d188c9
add: initial code for geosearch command
Dev79844 Nov 21, 2024
6b81954
Merge branch 'master' into geosearch
Dev79844 Nov 30, 2024
0ced2ed
#1115: handling integer parsing in SETBIT in certain situation (#1155)
kaushal-003 Dec 1, 2024
d8a018f
Removing encoding for Byte List and BF
arpitbbhayani Nov 27, 2024
9cb967d
Gotten rid of all Encodings and functions
arpitbbhayani Nov 27, 2024
9165860
Running the lint
arpitbbhayani Nov 27, 2024
4dbd02c
Encoding traces removed from tests
arpitbbhayani Nov 27, 2024
d22f62b
Fixing BF unit tests
arpitbbhayani Nov 27, 2024
48931fe
Simplifying GetType function
arpitbbhayani Nov 27, 2024
1cad6ef
LINSERT Test fixes
arpitbbhayani Nov 27, 2024
ef6caac
Fixing all unit tests
arpitbbhayani Nov 27, 2024
578ebd0
Removing integration tests for Encoding
arpitbbhayani Nov 27, 2024
fba3185
Removing ENCODING from commands and docs
arpitbbhayani Nov 27, 2024
5e08245
Removing unused method
arpitbbhayani Nov 27, 2024
88c6b76
fixed the build error due to unknown type
piyushhhxyz Dec 2, 2024
01717c8
add: documentation for setex command (#1350)
tarun-29 Dec 3, 2024
22609cd
Add documentation for JSON.OBJLEN command (#1345)
paulwalrath Dec 3, 2024
9f6f8e5
ELiminating redundant checks
arpitbbhayani Dec 3, 2024
b32a610
Creating a type for ObjectType instead of vanilla uint8
arpitbbhayani Dec 3, 2024
fda048f
Removing the additional check
arpitbbhayani Dec 3, 2024
48cf5e3
Bloomfilter naming conventions
arpitbbhayani Dec 3, 2024
c4d7592
Unit test fixes. Strangely mem utilization reduced.
arpitbbhayani Dec 3, 2024
ee9ba3e
Some errors as constants and bloom -> bloomfilter
arpitbbhayani Dec 4, 2024
fe5fc43
Integration tests fixes
arpitbbhayani Dec 4, 2024
9f3b3d2
fix: modify the config default value keep consistency (#1352)
jujiale Dec 3, 2024
5cd87a5
fixed conflicts
Dev79844 Dec 5, 2024
c53b334
Remove --enable-multithreading flag usage in README (#1349)
rahul-mallick-15 Dec 3, 2024
765fd17
Object Type changed and casted during RDB serialization
arpitbbhayani Dec 4, 2024
fe85228
Lint fixes
arpitbbhayani Dec 4, 2024
f1e0981
add: initial code for geosearch command
Dev79844 Nov 21, 2024
619d888
add: initial code for geosearch command
Dev79844 Nov 21, 2024
bc966ef
Removing encoding for Byte List and BF
arpitbbhayani Nov 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ build: ## generate the dicedb binary for the current OS and architecture
@echo "Building for $(GOOS)/$(GOARCH)"
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o ./dicedb

build-debug: ## generate the dicedb binary for the current OS and architecture
@echo "Building for $(GOOS)/$(GOARCH)"
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -gcflags="all=-N -l" -o ./dicedb

##@ Testing

# Changing the parallel package count to 1 due to a possible race condition which causes the tests to get stuck.
# TODO: Fix the tests to run in parallel, and remove the -p=1 flag.
test: ## run the integration tests
go test -v -race -count=1 -p=1 ./integration_tests/...
go test -race -count=1 -p=1 ./integration_tests/...

test-one: ## run a single integration test function by name (e.g. make test-one TEST_FUNC=TestSetGet)
go test -v -race -count=1 --run $(TEST_FUNC) ./integration_tests/...
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Although DiceDB is a drop-in replacement of Redis, which means almost no learnin
The easiest way to get started with DiceDB is using [Docker](https://www.docker.com/) by running the following command.

```bash
docker run -p 7379:7379 dicedb/dicedb --enable-multithreading --enable-watch
docker run -p 7379:7379 dicedb/dicedb --enable-watch
```

The above command will start the DiceDB server running locally on the port `7379` and you can connect
Expand All @@ -60,10 +60,10 @@ To run DiceDB for local development or running from source, you will need
```bash
git clone https://github.com/dicedb/dice
cd dice
go run main.go --enable-multithreading --enable-watch
go run main.go --enable-watch
```

You can skip passing the two flags if you are not working with multi-threading or `.WATCH` features.
You can skip passing the flag if you are not working with `.WATCH` feature.

1. Install GoLangCI

Expand Down
8 changes: 4 additions & 4 deletions docs/src/content/docs/commands/JSON.OBJKEYS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: JSON.OBJKEYS
description: The `JSON.OBJKEYS` command command in DiceDB retrieves the keys of a JSON object located at a specified path within the document stored under the given key. This command is useful when you want to list the fields within a JSON object stored in a database.
description: The `JSON.OBJKEYS` command in DiceDB retrieves the keys of a JSON object located at a specified path within the document stored under the given key. This command is useful when you want to list the fields within a JSON object stored in a database.
---

The `JSON.OBJKEYS` command in DiceDB allows users to access the keys of a JSON object stored at a specific path within a document identified by a given key. By executing this command, users can easily retrieve a list of the fields present in the JSON object, making it a valuable tool for exploring and managing the structure of JSON data stored in the database.
Expand All @@ -26,7 +26,7 @@ JSON.OBJKEYS key [path]
| ------------------------------------------------------ | ------------------------------------------------------------------------------------------------------- |
| Success | ([]String) `Array of strings containing the keys present within the JSON object at the specified path.` |
| Key does not exist | Error: `(error) ERR could not perform this operation on a key that doesn't exist` |
| Wrong number of arguments | Error: `(error) ERR wrong number of arguments for JSON.ARRTRIM command` |
| Wrong number of arguments | Error: `(error) ERR wrong number of arguments for JSON.OBJKEYS command` |
| Key has wrong type | Error: `(error) ERR Existing key has wrong Dice type` |
| Operation attempted on a key with an incompatible type | Error: `(error) ERR WRONGTYPE Operation against a key holding the wrong kind of value` |

Expand All @@ -41,7 +41,7 @@ JSON.OBJKEYS key [path]

1. `Wrong number of arguments`:

- Error Message: `(error) ERR wrong number of arguments for JSON.ARRINSERT command`
- Error Message: `(error) ERR wrong number of arguments for JSON.OBJKEYS command`
- Raised if the number of arguments are less or more than expected.

2. `Key doesn't exist`:
Expand All @@ -52,7 +52,7 @@ JSON.OBJKEYS key [path]
3. `Key has wrong Dice type`:

- Error Message: `(error) ERR Existing key has wrong Dice type`
- Raised if thevalue of the specified key doesn't match the specified value in DIceDb
- Raised if thevalue of the specified key doesn't match the specified value in DiceDb

4. `Path doesn't exist`:

Expand Down
123 changes: 123 additions & 0 deletions docs/src/content/docs/commands/JSON.OBJLEN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
---
title: JSON.OBJLEN
description: The `JSON.OBJLEN` command in DiceDB retrieves the number of keys stored in the JSON object located at key.
---

The `JSON.OBJLEN` command in DiceDB retrieves the number of keys stored in the JSON object located at key. By default, it counts the keys in the whole JSON object, but you can optionally specify a JSONPath to narrow the operation to a subset of the JSON object.

This functionality is particularly useful for developers working with complex JSON structures who need to quickly gauge the size of those structures.

## Syntax

```bash
JSON.OBJLEN key [path]
```

## Parameters

| Parameter | Description | Type | Required |
| --------- | ------------------------------------------------------- | ------ | -------- |
| `key` | The name of the key holding the JSON document. | String | Yes |
| `path` | JSONPath pointing to an array within the JSON document. | String | No |

## Return values

| Condition | Return Value |
| ------------------------------- | ------------------------------------------------------------------------------------------- |
| Command is successful | `Integer` denoting the number of keys length of the list at the specified key. |
| Wrong number of arguments | Error: `(error) ERR wrong number of arguments for JSON.OBJLEN command` |
| Key does not exist | Error: `(error) ERR could not perform this operation on a key that doesn't exist` |
| Key is not for a JSON object | Error: `(error) ERR WRONGTYPE Operation against a key holding the wrong kind of value` |
| Path malformed or doesn't exist | Error: `(error) ERR Path 'foo' does not exist` |

## Behaviour

- Root Path (Default): If no path is provided, JSON.OBJLEN retrieves keys from the root object of the JSON document.
- Path Validation: If the specified path does not point to an object (e.g., if it points to a scalar, array, or does not exist), the command returns `(nil)` for that path.
- Non-existing Key: If the specified key does not exist in the database, an error is returned.
- Invalid JSON Path: If the provided JSONPath expression is invalid, an error message with the details of the parse error is returned.

## Errors

1. `Wrong number of arguments`:

- Error Message: `(error) ERR wrong number of arguments for JSON.OBJLEN command`
- Happens if the number of arguments is less or more than required. (It must have at least one argument, or at most two arguments).

2. `Key doesn't exist`:

- Error Message: `(error) ERR could not perform this operation on a key that doesn't exist`
- Happens if the specified key does not exist in the DiceDB database.

3. `Key has wrong Dice type`:

- Error Message: `(error) ERR WRONGTYPE Operation against a key holding the wrong kind of value`
- Happens if an operation attempted on a key with an incompatible type.

4. `ERR Path 'foo' does not exist`:
- Error Message: `(error) ERR Path 'foo' does not exist`
- Happens if the path string provided (ie. 'foo') could not be parsed into a valid JSONPath, or if the JSONPath does not exist in the object.

## Example Usage

### Basic usage

Get number of keys in the Root JSON Object. You can specify the JSON root using the symbol `$`.

```bash
127.0.0.1:7379> JSON.SET a $ '{"name": "Alice", "age": 30, "address": {"city": "Wonderland", "zipcode": "12345"}}'
"OK"
127.0.0.1:7379> JSON.OBJLEN a $
1) 3
```
It returns 3, because there are three root keys in the root JSON object: `name`, `age`, and `address`.

Or, if you don't want to specify a JSON path, it may be omitted. The path defaults to the root, and the result is given as a scalar:
```bash
127.0.0.1:7379> JSON.OBJLEN a
3
```


### Keys inside nested object

To count the number of keys inside a nested object, specify a JSON Path. The root of the JSON object is referred to by the `$` symbol.

```bash
127.0.0.1:7379> JSON.SET b $ '{"name": "Alice", "address": {"city": "Wonderland", "state": "Fantasy", "zipcode": "12345"}}'
"OK"
127.0.0.1:7379> JSON.OBJLEN b $.address
1) 3
```
Here, it returns 3 because it's counting the three keys inside the `$.address` JSON object: `city`, `state`, and `zipcode`.

### When path is not a JSON object

When `path` points to an existing element in a JSON object, but that element is not itself a JSON object, the result is `(nil)`.

```bash
127.0.0.1:7379> JSON.SET c $ '{"name": "Alice", "age": 30}'
"OK"
127.0.0.1:7379> JSON.OBJLEN c $.age
1) (nil)
```

### When path doesn't exist

When `path` does not exist, the result is an empty list or set.

```bash
127.0.0.1:7379> JSON.SET d $ '{"name": "Alice", "address": {"city": "Wonderland"}}'
"OK"
127.0.0.1:7379> JSON.OBJLEN d $.nonexistentPath
(empty list or set)
```

### Invalid Usage: When key doesn't exist

When `key` does not exist, the result is an error.

```bash
127.0.0.1:7379> JSON.OBJLEN nonexistent_key $
(error) ERR could not perform this operation on a key that doesn't exist
```
12 changes: 0 additions & 12 deletions docs/src/content/docs/commands/OBJECT.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ OBJECT <subcommand> <key>
- `<subcommand>`: The specific operation you want to perform on the key. The available subcommands are:

- `REFCOUNT`: Returns the number of references of the value associated with the specified key.
- `ENCODING`: Returns the internal representation (encoding) used to store the value associated with the specified key.
- `IDLETIME`: Returns the number of seconds since the object was last accessed.
- `FREQ`: Returns the access frequency of a key, if the LFU (Least Frequently Used) eviction policy is enabled.

Expand All @@ -27,7 +26,6 @@ OBJECT <subcommand> <key>
The return value depends on the subcommand used:

- `REFCOUNT`: Returns an integer representing the reference count of the key.
- `ENCODING`: Returns a string representing the encoding type of the key.
- `IDLETIME`: Returns an integer representing the idle time in seconds.
- `FREQ`: Returns an integer representing the access frequency of the key.

Expand All @@ -38,7 +36,6 @@ When the `OBJECT` command is executed, DiceDB inspects the specified key and ret
### Subcommand Behaviours

- `REFCOUNT`: This subcommand returns the number of references to the key's value. A higher reference count indicates that the value is being shared among multiple keys or clients.
- `ENCODING`: This subcommand reveals the internal representation of the key's value, such as `int`, `embstr`, `raw`, `ziplist`, `linkedlist`, etc.
- `IDLETIME`: This subcommand provides the time in seconds since the key was last accessed. It is useful for identifying stale keys.
- `FREQ`: This subcommand returns the access frequency of the key, which is useful when using the LFU eviction policy.

Expand All @@ -61,15 +58,6 @@ OBJECT REFCOUNT mykey

This response indicates that the value associated with `mykey` has a reference count of 1.

### Using the `ENCODING` Subcommand

```bash
OBJECT ENCODING mykey
"embstr"
```

This response indicates that the value associated with `mykey` is stored using the `embstr` encoding.

### Using the `IDLETIME` Subcommand

```bash
Expand Down
87 changes: 87 additions & 0 deletions docs/src/content/docs/commands/SETEX.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
title: SETEX
description: The SETEX command in DiceDB is used to set the value of a key and its expiration time in seconds. This command is atomic and is commonly used to create time-sensitive key-value pairs.
sidebar:
badge:
text: Deprecated
variant: danger
---

The SETEX command in DiceDB is used to set the value of a key and its expiration time in seconds. This command is atomic and is commonly used to create time-sensitive key-value pairs.

## Syntax

```bash
SETEX key seconds value
```

## Parameters

| Parameter | Description | Type | Required |
| --------- | ------------------------------------------------------------------------- | ------- | -------- |
| `key` | The name of the key to be set. | String | Yes |
| `seconds` | Expiration time for the key in seconds. | Integer | Yes |
| `value` | The value to be set for the key. | Integer | No |

## Return values

| Condition | Return Value |
| ------------------------------------------- | ----------------------------------------------- |
| Command is successful | `OK` |
| Syntax or specified constraints are invalid | error |

## Behaviour

- The SETEX command sets the value of a key and specifies its expiration time in seconds.
- If the specified key already exists, the value is overwritten, and the new expiration time is set.
- If the key does not exist, it is created with the specified expiration time.
- If the provided expiration time is invalid or not an integer, the command will return an error.
- This command is equivalent to using SET key value EX seconds but provides a more concise and dedicated syntax.

## Errors

1. `Missing or invalid expiration time`:

- Error Message: `(error) ERR value is not an integer or out of range`
- Occurs if the expiration time is not a valid positive integer.

2. `Missing required arguments`:

- Error Message: `(error) ERR wrong number of arguments for 'SETEX' command`
- Occurs if any of the required arguments (key, seconds, or value) are not provided.

## Example Usage

### Basic Usage

Set a key `foo` with the value `bar` to expire in `10` seconds:

```bash
127.0.0.1:7379> SETEX foo 10 bar
OK
```

Set a key `foo` with the value `new_value`, overwriting the existing value and resetting the expiration time:

```bash
127.0.0.1:7379> SETEX foo 20 new_value
OK
```

### Invalid usage

Setting a key with an invalid expiration time will result in an error:

```bash
127.0.0.1:7379> SETEX foo -10 bar
(error) ERROR invalid expire time in 'setex' command
```

Attempting to use the command with missing arguments will result in an error:
```bash
127.0.0.1:7379> SETEX foo 10
(error) ERROR wrong number of arguments for 'setex' command
```

### Notes:
`SETEX` can be replaced via [`SET`](/commands/set) with `EX` option.
2 changes: 1 addition & 1 deletion docs/src/content/docs/get-started/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ We are looking for Early Design Partners, so, if you want to evaluate DiceDB, [b
The easiest way to get started with DiceDB is using [Docker](https://www.docker.com/) by running the following command.

```bash
docker run -p 7379:7379 dicedb/dicedb --enable-multithreading --enable-watch
docker run -p 7379:7379 dicedb/dicedb --enable-watch
```

The above command will start the DiceDB server running locally on the port `7379` and you can connect
Expand Down
6 changes: 3 additions & 3 deletions docs/src/content/docs/get-started/reactive-hello-world.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ But, before we start, make sure you have

### Starting DiceDB

Start the DiceDB server with the two flags `--enable-multithreading` and `--enable-watch`
to enable multi-threading and watch mode, respectively. Your command would look something
Start the DiceDB server with the flag `--enable-watch`
to enable watch mode. Your command would look something
like this

```bash
docker run -p 7379:7379 dicedb/dicedb --enable-multithreading --enable-watch
docker run -p 7379:7379 dicedb/dicedb --enable-watch
```

Also, connect to the database using the CLI as mentioned in the above installation steps or
Expand Down
5 changes: 0 additions & 5 deletions docs/src/pages/redis-compatability.astro
Original file line number Diff line number Diff line change
Expand Up @@ -776,11 +776,6 @@ const description = "";
<td>MSETNX</td>
<td><a href="/commands/"></a></td>
</tr>
<tr>
<td><a href="/commands/"></a></td>
<td>OBJECT|ENCODING</td>
<td><a href="/commands/"></a></td>
</tr>
<tr>
<td><a href="/commands/"></a></td>
<td>OBJECT|FREQ</td>
Expand Down
13 changes: 13 additions & 0 deletions integration_tests/commands/http/append_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@ func TestAPPEND(t *testing.T) {
{Command: "del", Body: map[string]interface{}{"key": "bitkey"}},
},
},
{
name: "SET and SETBIT commands followed by GET",
commands: []HTTPCommand{
{Command: "SET", Body: map[string]interface{}{"key": "key", "value": "10"}},
{Command: "SETBIT", Body: map[string]interface{}{"key": "key", "values": []string{"1", "1"}}},
{Command: "GET", Body: map[string]interface{}{"key": "key"}},
{Command: "SETBIT", Body: map[string]interface{}{"key": "key", "values": []string{"0", "1"}}},
},
expected: []interface{}{"OK", float64(0), "q0", float64(0)},
cleanup: []HTTPCommand{
{Command: "del", Body: map[string]interface{}{"key": "key"}},
},
},
{
name: "APPEND After SET and DEL",
commands: []HTTPCommand{
Expand Down
Loading