Sider is a in-memory database with persistence option. This is a personal project I'm coding to practice Golang by doing.
- 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
- Go to your project directory:
cd ~/my-project
- Install dependency with
go get -u github.com/jaavier/sider
- Import in your code
import "github.com/jaavier/sider"
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
go sider.SaveData(customPath string) // execute as goroutine
Important: If you call sider.SaveData()
without param, it will store data at /tmp
go sider.ImportData(customPath string) // execute as goroutine
Important: If you call sider.ImportData()
without param, it will find data at /tmp
sider.Set(key, value string) (bool, error)
sider.Get(key string) (string, error)
sider.LPush(key string, value string) (bool, error)
sider.RPush(key string, value string) (bool, error)
sider.LLen(listName string) (int, error)
sider.IndexOf(listName string, element string) (int, error)
sider.ReplaceList(listName string, index int, element string) (bool, error)
sider.GetList(listName string, start string, stop string) ([]string, error)
Parameters start and stop are optionals
sider.ExpireKey(key string, timestamp int64) (bool, error)
sider.ExpireList(listName string, timestamp int64) (bool, error)
Pop at right
sider.Pop(options ...string) (string, error)
Pop at left
sider.Pop(listName string, "left") (string, error)
func CountList(listName string) (int, error)
func DeleteKey(key string) error
func DeleteList(listName string) error
func DeleteItemByContent(listName string, item string) bool
func DeleteItemByIndex(listName string, index int) bool
If you don't know the index, you can find it with sider.IndexOf