Skip to content
/ sider Public

Database in memory with persistence on disk made in Golang

Notifications You must be signed in to change notification settings

jaavier/sider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What is Sider?

Sider is a in-memory database with persistence option. This is a personal project I'm coding to practice Golang by doing.

What can Sider do?

  • Read/Add keys
  • Read List (complete or by range)
  • Push/Pop lists (LEFT and RIGHT)
  • Get length of a list
  • Get index of element in list
  • Expire lists/keys
  • Get length of list
  • Delete key
  • Delete list
  • Delete item from list by index
  • Delete item from list by its content
  • Backup lists and keys in JSON files.
  • Import last backup when starting Sider again

How to use Sider?

  1. Go to your project directory: cd ~/my-project
  2. Install dependency with go get -u github.com/jaavier/sider
  3. Import in your code import "github.com/jaavier/sider"

IMPORTANT UPDATE 👾

I updated all functions to return a value and a error (if there's one). If you cloned this project before, please update your dependencies executing go get -u -d ./... in your project's folder

Persist data on disk

go sider.SaveData(customPath string) // execute as goroutine

Important: If you call sider.SaveData() without param, it will store data at /tmp

Import data from last session

go sider.ImportData(customPath string) // execute as goroutine

Important: If you call sider.ImportData() without param, it will find data at /tmp

Add Key

sider.Set(key, value string) (bool, error)

Read Key

sider.Get(key string) (string, error)

Push an item at left

sider.LPush(key string, value string) (bool, error)

Push an item at right

sider.RPush(key string, value string) (bool, error)

Get length of a list

sider.LLen(listName string) (int, error)

Get index of element in list

sider.IndexOf(listName string, element string) (int, error)

Replace element in list

sider.ReplaceList(listName string, index int, element string) (bool, error)

Read List

sider.GetList(listName string, start string, stop string) ([]string, error)

Parameters start and stop are optionals

Expire Key

sider.ExpireKey(key string, timestamp int64) (bool, error)

Expire List

sider.ExpireList(listName string, timestamp int64) (bool, error)

Pop list

Pop at right

sider.Pop(options ...string) (string, error)

Pop at left

sider.Pop(listName string, "left") (string, error)

Get list's length

func CountList(listName string) (int, error)

Delete key

func DeleteKey(key string) error

Delete list

func DeleteList(listName string) error

Delete item from list by its content

func DeleteItemByContent(listName string, item string) bool

Delete item from list by its index

func DeleteItemByIndex(listName string, index int) bool

If you don't know the index, you can find it with sider.IndexOf

TODO

  • Add function to reverse lists pic