GithubHelp home page GithubHelp logo

hotpotatoc / kvstore Goto Github PK

View Code? Open in Web Editor NEW
17.0 3.0 0.0 3.83 MB

🗄️kvstore is an experimental in-memory database server compatible with the redis protocol (RESP).

License: MIT License

Go 97.36% Makefile 1.56% Dockerfile 1.08%
hashtables pair redis inmemory-db key-value database-server golang

kvstore's Introduction

kvstore

An experimental key-value database server that is compatible with the redis RESP protocol.

Getting started

Simply run the following command to start the server:

go run cmd/kvstore-server/main.go

To connect to the server, currently the kvstore-cli is yet to be implemented. So for now, you can use the redis-cli command to connect to the server.

redis-cli -p 7275 # Default kvstore server port is 7275

Current available commands are:

  • SET key value
  • GET key
  • DEL key
  • KEYS pattern
  • PING
  • FLUSHALL
  • CLIENT [ID | INFO | LIST | KILL <id | addr | user> <value> | GETNAME | SETNAME <name>]

To Do

  • Pipelining commands
  • AOF
  • ACL
  • Clustering
  • Implement kvstore-cli

NOTE

This project is not targeted for production use. This is only a proof of concept

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Support

Buy Me A Coffee

kvstore's People

Contributors

hotpotatoc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

kvstore's Issues

Table not increasing it's capacity when above the maximum load factor

Problem

Inserted entries with the key "a"-"z" with its respective values.

127.0.0.1:7275> list
0.000670s
1) [0]: "&{%!s(*hashtable.Entry=&{u u <nil>})}"
2) [1]: "&{%!s(*hashtable.Entry=&{n n <nil>})}"
3) [2]: "&{%!s(*hashtable.Entry=&{s s <nil>})}"
4) [3]: "&{%!s(*hashtable.Entry=&{t t <nil>})}"
5) [4]: "&{%!s(*hashtable.Entry=&{y y <nil>})}"
6) [5]: "&{%!s(*hashtable.Entry=&{r r <nil>})}"
7) [6]: "&{%!s(*hashtable.Entry=&{w w <nil>})}"
8) [7]: "&{%!s(*hashtable.Entry=&{x x <nil>})}"
9) [8]: "&{%!s(*hashtable.Entry=&{m m <nil>})}"
10) [9]: "&{%!s(*hashtable.Entry=&{v v <nil>})}"
11) [10]: "&{%!s(*hashtable.Entry=&{k k <nil>})}"
12) [11]: "&{%!s(*hashtable.Entry=&{l l <nil>})}"
13) [12]: "&{%!s(*hashtable.Entry=&{q q <nil>})}"
14) [13]: "&{%!s(*hashtable.Entry=&{z z <nil>})}"
15) [14]: "&{%!s(*hashtable.Entry=&{o o <nil>})}"
16) [15]: "&{%!s(*hashtable.Entry=&{p p <nil>})}"

Expected

26 records but got the default size of 16

LIST command only prints one data

Running the list command only displays a single data

127.0.0.1:7275> set a a
0.000559s
OK

127.0.0.1:7275> set b b
0.000374s
OK

127.0.0.1:7275> list
0.000393s
1) [3826002220]: "a"

expected

127.0.0.1:7275> list
1) [3826002220]: "a"
2) [some_hash_key_idx]: "b"

`Set` command not replacing already existing key

Running the set command does not replace an already existing key. instead, it's creating a new entry with the same key. Resulting in a duplicate entry.

Before

user::1 -> john

After

user::1 -> john
user::1 -> richard

LIST command bug

Error

Have yet to implement an iterator for list

127.0.0.1:7275> set user::1 juan
0.000368s
OK

127.0.0.1:7275> get user::1
0.000304s
"juan"

127.0.0.1:7275> list
0.000316s
1) [0]: "%!s(*hashtable.Bucket=<nil>)"
2) [1]: "%!s(*hashtable.Bucket=<nil>)"
3) [2]: "%!s(*hashtable.Bucket=<nil>)"
4) [3]: "%!s(*hashtable.Bucket=<nil>)"
5) [4]: "%!s(*hashtable.Bucket=<nil>)"
6) [5]: "&{%!s(*hashtable.Entry=&{user::1 juan <nil>})}"
7) [6]: "%!s(*hashtable.Bucket=<nil>)"
8) [7]: "%!s(*hashtable.Bucket=<nil>)"
9) [8]: "%!s(*hashtable.Bucket=<nil>)"
10) [9]: "%!s(*hashtable.Bucket=<nil>)"
11) [10]: "%!s(*hashtable.Bucket=<nil>)"
12) [11]: "%!s(*hashtable.Bucket=<nil>)"
13) [12]: "&{%!s(*hashtable.Entry=&{a a <nil>})}"
14) [13]: "%!s(*hashtable.Bucket=<nil>)"
15) [14]: "%!s(*hashtable.Bucket=<nil>)"
16) [15]: "%!s(*hashtable.Bucket=<nil>)"

Expected (Subject To Change)

127.0.0.1:7275> list
0.000316s
1) [user::1]: "juan"
2) [a]: "a"

Server panics on creating a new entry with the same deleted key

A Runtime error occurred when trying to set an entry with the same key as the former

CLI

127.0.0.1:7275> set key value
OK
127.0.0.1:7275> list
1 items
key -> "value"

127.0.0.1:7275> del key
1
127.0.0.1:7275> set key value

SERVER

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x68e891]

goroutine 8 [running]:
github.com/HotPotatoC/kvstore/pkg/hashtable.(*HashTable).insert(0xc00002aa00, 0xc000016ce0, 0x3, 0xc000016ce4, 0x5, 0x0)
        /home/juanchristian/go/src/github.com/HotPotatoC/kvstore/pkg/hashtable/hash_table.go:183 +0x1b1
github.com/HotPotatoC/kvstore/pkg/hashtable.(*HashTable).Set(0xc00002aa00, 0xc000016ce0, 0x3, 0xc000016ce4, 0x5)
        /home/juanchristian/go/src/github.com/HotPotatoC/kvstore/pkg/hashtable/hash_table.go:61 +0xb0
github.com/HotPotatoC/kvstore/database.(*database).Set(0xc0000100b0, 0xc000016ce0, 0x3, 0xc000016ce4, 0x5)
        /home/juanchristian/go/src/github.com/HotPotatoC/kvstore/database/database.go:46 +0x56
github.com/HotPotatoC/kvstore/command.setCommand.Execute(0x7e71d0, 0xc0000100b0, 0xc000062660, 0x2, 0x2, 0x1, 0x2, 0xc000062660)
        /home/juanchristian/go/src/github.com/HotPotatoC/kvstore/command/set_command.go:35 +0x118
github.com/HotPotatoC/kvstore/server.(*Server).onMessage(0xc00007d590, 0x7e7280, 0xc0000100c8, 0xc000200000, 0x9000, 0x9000)
        /home/juanchristian/go/src/github.com/HotPotatoC/kvstore/server/hooks.go:49 +0x3ac
github.com/HotPotatoC/kvstore/pkg/tcp.(*Server).handleConnection(0xc00007d620, 0x7e7280, 0xc0000100c8)
        /home/juanchristian/go/src/github.com/HotPotatoC/kvstore/pkg/tcp/tcp.go:90 +0x2c2
github.com/HotPotatoC/kvstore/pkg/tcp.(*Server).acceptConnections.func1(0xc00007d620, 0x7e7280, 0xc0000100c8)
        /home/juanchristian/go/src/github.com/HotPotatoC/kvstore/pkg/tcp/tcp.go:62 +0x65
created by github.com/HotPotatoC/kvstore/pkg/tcp.(*Server).acceptConnections
        /home/juanchristian/go/src/github.com/HotPotatoC/kvstore/pkg/tcp/tcp.go:60 +0x7a

Capitalized command bug

When using a capitalized command like GET instead of get it returns <nil>

127.0.0.1:7275> set person john
0.000293s


127.0.0.1:7275> get person
0.000353s
john

127.0.0.1:7275> GET person
0.000326s
<nil>```

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.