mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-23 16:50:18 +01:00
Merged.
This commit is contained in:
commit
5c239a7b60
@ -51,8 +51,11 @@ func (c *Connection) Run() {
|
||||
}
|
||||
|
||||
func logError(err error) bool {
|
||||
log.Printf("ERROR: %s\n", err)
|
||||
return false
|
||||
if err != nil {
|
||||
log.Printf("ERROR: %s\n", err)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *Connection) Hget(hash, key []byte) bool {
|
||||
@ -135,10 +138,8 @@ func (c *Connection) Hkeys(hash []byte) bool {
|
||||
}
|
||||
|
||||
func (c *Connection) Ping() bool {
|
||||
if _, err := c.conn.Write(redisPong); err != nil {
|
||||
return logError(err)
|
||||
}
|
||||
return true
|
||||
_, err := c.conn.Write(redisPong)
|
||||
return logError(err)
|
||||
}
|
||||
|
||||
func (c *Connection) HSpatial(hash, first, second []byte) bool {
|
||||
@ -162,25 +163,18 @@ 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 {
|
||||
return logError(err)
|
||||
}
|
||||
return true
|
||||
_, err = c.conn.Write(redisError)
|
||||
return logError(err)
|
||||
}
|
||||
|
||||
func (c *Connection) writeEmptyArray() bool {
|
||||
if _, err := c.conn.Write(redisEmptyArray); err != nil {
|
||||
return logError(err)
|
||||
}
|
||||
return true
|
||||
_, err := c.conn.Write(redisEmptyArray)
|
||||
return logError(err)
|
||||
}
|
||||
|
||||
func (c *Connection) writeBool(b bool) bool {
|
||||
@ -190,10 +184,7 @@ func (c *Connection) writeBool(b bool) bool {
|
||||
} else {
|
||||
_, err = c.conn.Write(redisFalse)
|
||||
}
|
||||
if err != nil {
|
||||
return logError(err)
|
||||
}
|
||||
return true
|
||||
return logError(err)
|
||||
}
|
||||
|
||||
func redisLength(prefix byte, s int) []byte {
|
||||
@ -214,24 +205,17 @@ func (c *Connection) writeBoolArray(arr []bool) bool {
|
||||
}
|
||||
|
||||
func (c *Connection) writeOk() bool {
|
||||
if _, err := c.conn.Write(redisOk); err != nil {
|
||||
return logError(err)
|
||||
}
|
||||
return true
|
||||
_, err := c.conn.Write(redisOk)
|
||||
return logError(err)
|
||||
}
|
||||
|
||||
func (c *Connection) writeQueued() bool {
|
||||
if _, err := c.conn.Write(redisQueued); err != nil {
|
||||
return logError(err)
|
||||
}
|
||||
return true
|
||||
_, err := c.conn.Write(redisQueued)
|
||||
return logError(err)
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user