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

Implement SCAN command #108

Open
kelvinmwinuka opened this issue Sep 11, 2024 · 7 comments
Open

Implement SCAN command #108

kelvinmwinuka opened this issue Sep 11, 2024 · 7 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers

Comments

@kelvinmwinuka
Copy link
Collaborator

Scans the keys in the currently selected database.
Reference: https://redis.io/docs/latest/commands/scan/

Client-Server Spec:

Command File: ./internal/modules/generic/commands.go
Test File: ./internal/modules/generic/commands_test.go

Command: scan
Module: constants.GenericModule
Categories: contants.KeyspaceCategory, constants.ReadCategory, constants.SlowCategory
Description: (SCAN cursor [MATCH pattern] [COUNT count] [TYPE type]) scan the keys in the currently selected database
Sync: false

Embedded Spec:

Command File: ./echovault/api_generic.go
Test File: ./echovault/api_generic_test.go

Documentation

Add documentation to ./docs/docs/commands/generic/scan.mdx

@kelvinmwinuka kelvinmwinuka added documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers labels Sep 11, 2024
@NicoleStrel
Copy link
Contributor

Hi @kelvinmwinuka! I'd like to work on this if it's free

@kelvinmwinuka
Copy link
Collaborator Author

Hey @NicoleStrel this is free, you can pick it up.

@NicoleStrel
Copy link
Contributor

@kelvinmwinuka Hey! So I started looking into this, and for the SCAN command,it iterates using a cursor index and returns another cursor index to continue iterating later on.

So, we need to keep track of the order of the kvstore so that on the next call the user can retrieve the next keys

I was thinking of adding an index attribute in KeyData - likely that would change a lot of the code though.

type KeyData struct {
        Index int 
	Value    interface{}
	ExpireAt time.Time
}

thoughts/any other ideas?

@kelvinmwinuka
Copy link
Collaborator Author

I don't mind this solution. As long as we make sure to avoid index clashes. I don't think this will break anything.

Try it out and we'll examine it in a code review.

@NicoleStrel
Copy link
Contributor

or actually, I saw the discussion about the skip list - #139

since it also maintains order (O(N)) this could work in place of the map of the KeyData struct - what do you think?

adding the index/potentially using the skip list should probably be done first before the SCAN implementation

@guycipher
Copy link

@NicoleStrel a skip list probably wont surpass the speed of a go map. For a data structure that keeps things sorted yeah a skip list could work well but in my tests go's map is blazing fast if key's don't have to be sorted, it depends how you'd want to do it. I'm not too familiar with Redis to be completely honest with y`all. @kelvinmwinuka knows this :P

@guycipher
Copy link

guycipher commented Oct 31, 2024

If you want a really fast in-memory sorted data structured a BStar tree or BStarPlus tree would be amazing. I am working on this on the side and the write and read speed surpass that of a skiplist in-memory. Once I get confident in the implementation I will share, this could work in SugarDB as an optional data structure, possibly? Skiplists are easier, surely :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants