Skip to content

Commit e833d03

Browse files
committed
upgraded to v1.10
1 parent 58d6238 commit e833d03

File tree

11 files changed

+65
-442
lines changed

11 files changed

+65
-442
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Features
1919
=========
2020
- Core data structure: `KV`, `List`, `Hashmap` with advanced implementations.
2121
- Advanced Publish/Subscribe using webhook and websocket!
22-
- Pluggable Storage Engine (`badgerdb`, `boltdb`, `leveldb`, `null`, `sqlite`)
22+
- Pluggable Storage Engine (`badgerdb`, `boltdb`, `leveldb`, `null`)
2323
- Very compatible with any `redis client` including `redis-cli`
2424
- Standalone with no external dependencies
2525
- Helpers commands for `Time`, `Encode <hex|md5|sha1|sha256|sha512> <payload>`, `RANDINT`, `RANDSTR`
@@ -192,6 +192,8 @@ Supported Commands
192192
- `GC`, runs the Garbage Collector.
193193
- `ECHO [<arg1> <arg2> ...]`
194194
- `INFO`
195+
- `FLUSHDB`, clear the database
196+
- `FLUSHALL`, clear all databases
195197

196198
TODO
197199
=====
@@ -204,6 +206,4 @@ TODO
204206
- [x] Adding BoltDB engine
205207
- [x] Adding LevelDB engine
206208
- [x] Adding Null engine
207-
- [x] Adding SQLite engine
208-
- [ ] Adding TiKV engine
209209
- [ ] Adding RAM engine

commands_doc.go.wip

-193
This file was deleted.

commands_utils.go

+13
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,16 @@ func infoCommand(c Context) {
166166
func echoCommand(c Context) {
167167
c.WriteString(strings.Join(c.args, " "))
168168
}
169+
170+
// flushdbCommand - FLUSHDB
171+
func flushdbCommand(ctx Context) {
172+
c := ctx.Context().(map[string]interface{})
173+
flushDB(c["db"].(string))
174+
ctx.WriteString("OK")
175+
}
176+
177+
// flushallCommand - FLUSHALL
178+
func flushallCommand(ctx Context) {
179+
flushall()
180+
ctx.WriteString("OK")
181+
}

helpers_db.go

+17-6
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@ package main
55

66
import (
77
"errors"
8+
"os"
89
"path/filepath"
910
"strings"
1011

11-
"github.com/alash3al/redix/kvstore/sqlite"
12-
13-
"github.com/alash3al/redix/kvstore/null"
14-
1512
"github.com/alash3al/redix/kvstore"
1613
"github.com/alash3al/redix/kvstore/badgerdb"
1714
"github.com/alash3al/redix/kvstore/boltdb"
1815
"github.com/alash3al/redix/kvstore/leveldb"
16+
"github.com/alash3al/redix/kvstore/null"
1917
)
2018

2119
// selectDB - load/fetches the requested db
@@ -48,11 +46,24 @@ func openDB(engine, dbpath string) (kvstore.DB, error) {
4846
return leveldb.OpenLevelDB(dbpath)
4947
case "null":
5048
return null.OpenNull()
51-
case "sqlite":
52-
return sqlite.OpenSQLite(dbpath)
5349
}
5450
}
5551

52+
// flushDB clear the specified database
53+
func flushDB(n string) {
54+
dbpath := filepath.Join(*flagStorageDir, n)
55+
os.RemoveAll(dbpath)
56+
databases.Delete(n)
57+
58+
selectDB(n)
59+
}
60+
61+
// flushall clear all databases
62+
func flushall() {
63+
os.RemoveAll(*flagStorageDir)
64+
os.MkdirAll(*flagStorageDir, 0755)
65+
}
66+
5667
// returns a unique string
5768
func getUniqueString() string {
5869
return snowflakeGenerator.Generate().String()

kvstore/badgerdb/badgerdb.go

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ func OpenBadger(path string) (*BadgerDB, error) {
5555
return db, nil
5656
}
5757

58+
// Close ...
59+
func (db *BadgerDB) Close() {
60+
db.Close()
61+
}
62+
5863
// Size - returns the size of the database (LSM + ValueLog) in bytes
5964
func (db *BadgerDB) Size() int64 {
6065
lsm, vlog := db.badger.Size()

kvstore/boltdb/boltdb.go

+5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ func OpenBolt(path string) (*BoltDB, error) {
4545
return db, nil
4646
}
4747

48+
// Close ...
49+
func (db *BoltDB) Close() {
50+
db.Close()
51+
}
52+
4853
// Size - returns the size of the database (LSM + ValueLog) in bytes
4954
func (db *BoltDB) Size() int64 {
5055
var size int64

kvstore/db.go

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type DB interface {
1717
Scan(ScannerOpt ScannerOptions) error
1818
Size() int64
1919
GC() error
20+
Close()
2021
}
2122

2223
// ScannerOptions - represents the options for a scanner

kvstore/leveldb/leveldb.go

+5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ func (ldb *LevelDB) Size() int64 {
5353
return size
5454
}
5555

56+
// Close ...
57+
func (ldb *LevelDB) Close() {
58+
ldb.Close()
59+
}
60+
5661
// GC - runs the garbage collector
5762
func (ldb *LevelDB) GC() error {
5863
return ldb.db.CompactRange(util.Range{})

kvstore/null/null.go

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ func (ldb *Null) Size() int64 {
2222
return 0
2323
}
2424

25+
// Close ...
26+
func (ldb *Null) Close() {}
27+
2528
// GC - runs the garbage collector
2629
func (ldb *Null) GC() error {
2730
return nil

0 commit comments

Comments
 (0)