This commit is contained in:
Sascha L. Teichmann 2015-06-21 18:37:43 +02:00
commit 5c239a7b60
2 changed files with 32 additions and 48 deletions

View File

@ -51,9 +51,12 @@ func (c *Connection) Run() {
}
func logError(err error) bool {
if err != nil {
log.Printf("ERROR: %s\n", err)
return false
}
return true
}
func (c *Connection) Hget(hash, key []byte) bool {
@ -135,11 +138,9 @@ func (c *Connection) Hkeys(hash []byte) bool {
}
func (c *Connection) Ping() bool {
if _, err := c.conn.Write(redisPong); err != nil {
_, err := c.conn.Write(redisPong)
return logError(err)
}
return true
}
func (c *Connection) HSpatial(hash, first, second []byte) bool {
var (
@ -162,26 +163,19 @@ func (c *Connection) HSpatial(hash, first, second []byte) bool {
}
}
if err = c.writeBulkString(nil); err != nil {
return logError(err)
}
return true
return logError(c.writeBulkString(nil))
}
func (c *Connection) writeError(err error) bool {
logError(err)
if _, err = c.conn.Write(redisError); err != nil {
_, err = c.conn.Write(redisError)
return logError(err)
}
return true
}
func (c *Connection) writeEmptyArray() bool {
if _, err := c.conn.Write(redisEmptyArray); err != nil {
_, err := c.conn.Write(redisEmptyArray)
return logError(err)
}
return true
}
func (c *Connection) writeBool(b bool) bool {
var err error
@ -190,11 +184,8 @@ func (c *Connection) writeBool(b bool) bool {
} else {
_, err = c.conn.Write(redisFalse)
}
if err != nil {
return logError(err)
}
return true
}
func redisLength(prefix byte, s int) []byte {
buf := append(make([]byte, 0, 16), prefix)
@ -214,24 +205,17 @@ func (c *Connection) writeBoolArray(arr []bool) bool {
}
func (c *Connection) writeOk() bool {
if _, err := c.conn.Write(redisOk); err != nil {
_, err := c.conn.Write(redisOk)
return logError(err)
}
return true
}
func (c *Connection) writeQueued() bool {
if _, err := c.conn.Write(redisQueued); err != nil {
_, err := c.conn.Write(redisQueued)
return logError(err)
}
return true
}
func (c *Connection) writeBlock(data []byte) bool {
if err := c.writeBulkString(data); err != nil {
return logError(err)
}
return true
return logError(c.writeBulkString(data))
}
func (c *Connection) writeBulkString(data []byte) (err error) {

View File

@ -17,13 +17,13 @@ import (
var globalLock sync.RWMutex
const (
fetchSql = "SELECT data FROM blocks WHERE pos = ?"
existsSql = "SELECT 1 FROM blocks WHERE pos = ?"
updateSql = "UPDATE blocks SET data = ? WHERE pos = ?"
insertSql = "INSERT INTO blocks (pos, data) VALUES (?, ?)"
countSql = "SELECT count(*) FROM blocks"
keysSql = "SELECT pos FROM blocks"
rangeSql = "SELECT pos, data FROM blocks WHERE pos BETWEEN ? AND ? ORDER BY pos"
fetchSQL = "SELECT data FROM blocks WHERE pos = ?"
existsSQL = "SELECT 1 FROM blocks WHERE pos = ?"
updateSQL = "UPDATE blocks SET data = ? WHERE pos = ?"
insertSQL = "INSERT INTO blocks (pos, data) VALUES (?, ?)"
countSQL = "SELECT count(*) FROM blocks"
keysSQL = "SELECT pos FROM blocks"
rangeSQL = "SELECT pos, data FROM blocks WHERE pos BETWEEN ? AND ? ORDER BY pos"
)
type SqliteBackend struct {
@ -69,37 +69,37 @@ func NewSqliteBackend(
return
}
if res.existsStmt, err = res.db.Prepare(existsSql); err != nil {
if res.existsStmt, err = res.db.Prepare(existsSQL); err != nil {
res.closeAll()
return
}
if res.fetchStmt, err = res.db.Prepare(fetchSql); err != nil {
if res.fetchStmt, err = res.db.Prepare(fetchSQL); err != nil {
res.closeAll()
return
}
if res.insertStmt, err = res.db.Prepare(insertSql); err != nil {
if res.insertStmt, err = res.db.Prepare(insertSQL); err != nil {
res.closeAll()
return
}
if res.updateStmt, err = res.db.Prepare(updateSql); err != nil {
if res.updateStmt, err = res.db.Prepare(updateSQL); err != nil {
res.closeAll()
return
}
if res.countStmt, err = res.db.Prepare(countSql); err != nil {
if res.countStmt, err = res.db.Prepare(countSQL); err != nil {
res.closeAll()
return
}
if res.keysStmt, err = res.db.Prepare(keysSql); err != nil {
if res.keysStmt, err = res.db.Prepare(keysSQL); err != nil {
res.closeAll()
return
}
if res.rangeStmt, err = res.db.Prepare(rangeSql); err != nil {
if res.rangeStmt, err = res.db.Prepare(rangeSQL); err != nil {
res.closeAll()
return
}