mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2025-01-11 09:20:17 +01:00
Enabaled interleaving in SQLite backend.
This commit is contained in:
parent
8cd23d257f
commit
5094f05414
19
main.go
19
main.go
@ -25,12 +25,13 @@ const (
|
||||
func main() {
|
||||
|
||||
var (
|
||||
port int
|
||||
host string
|
||||
driver string
|
||||
cacheSize int
|
||||
version bool
|
||||
gcDuration string
|
||||
port int
|
||||
host string
|
||||
driver string
|
||||
cacheSize int
|
||||
version bool
|
||||
interleaved bool
|
||||
gcDuration string
|
||||
)
|
||||
|
||||
flag.IntVar(&port, "port", 6379, "port to bind")
|
||||
@ -38,6 +39,7 @@ func main() {
|
||||
flag.StringVar(&host, "host", "", "host to bind")
|
||||
flag.IntVar(&cacheSize, "cache", 32, "cache size in MB")
|
||||
flag.BoolVar(&version, "version", false, "Print version and exit.")
|
||||
flag.BoolVar(&interleaved, "interleaved", false, "Backend stores key in interleaved form.")
|
||||
flag.StringVar(&gcDuration, "gc-duration", GCDuration, "Duration between forced GCs.")
|
||||
flag.Parse()
|
||||
|
||||
@ -63,10 +65,7 @@ func main() {
|
||||
}
|
||||
|
||||
if driver == "sqlite" {
|
||||
if backend, err = NewSqliteBackend(
|
||||
args[0],
|
||||
common.EncodeStringToBytes,
|
||||
common.DecodeStringFromBytes); err != nil {
|
||||
if backend, err = NewSqliteBackend(args[0], interleaved); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
|
35
sqlite.go
35
sqlite.go
@ -26,15 +26,16 @@ const (
|
||||
)
|
||||
|
||||
type SqliteBackend struct {
|
||||
db *sql.DB
|
||||
encoder common.KeyEncoder
|
||||
decoder common.KeyDecoder
|
||||
existsStmt *sql.Stmt
|
||||
fetchStmt *sql.Stmt
|
||||
insertStmt *sql.Stmt
|
||||
updateStmt *sql.Stmt
|
||||
countStmt *sql.Stmt
|
||||
keysStmt *sql.Stmt
|
||||
db *sql.DB
|
||||
encoder common.KeyEncoder
|
||||
decoder common.KeyDecoder
|
||||
interleaved bool
|
||||
existsStmt *sql.Stmt
|
||||
fetchStmt *sql.Stmt
|
||||
insertStmt *sql.Stmt
|
||||
updateStmt *sql.Stmt
|
||||
countStmt *sql.Stmt
|
||||
keysStmt *sql.Stmt
|
||||
}
|
||||
|
||||
type SqliteSession struct {
|
||||
@ -55,12 +56,9 @@ func (ss *SqliteSession) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewSqliteBackend(
|
||||
path string,
|
||||
encoder common.KeyEncoder,
|
||||
decoder common.KeyDecoder) (sqlb *SqliteBackend, err error) {
|
||||
func NewSqliteBackend(path string, interleaved bool) (sqlb *SqliteBackend, err error) {
|
||||
|
||||
res := SqliteBackend{}
|
||||
res := SqliteBackend{interleaved: interleaved}
|
||||
|
||||
if res.db, err = sql.Open("sqlite3", path); err != nil {
|
||||
return
|
||||
@ -96,8 +94,13 @@ func NewSqliteBackend(
|
||||
return
|
||||
}
|
||||
|
||||
res.encoder = encoder
|
||||
res.decoder = decoder
|
||||
if interleaved {
|
||||
res.encoder = common.EncodeStringToBytes
|
||||
res.decoder = common.DecodeStringFromBytes
|
||||
} else {
|
||||
res.encoder = common.EncodeStringToBytesFromInterleaved
|
||||
res.decoder = common.DecodeStringFromBytesToInterleaved
|
||||
}
|
||||
|
||||
sqlb = &res
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user