forked from mirror/ledisdb
Merge branch 'develop'
This commit is contained in:
commit
6120d3a8c2
34
README.md
34
README.md
|
@ -33,16 +33,46 @@ Ledisdb is a high performance nosql like redis based on leveldb written by go. I
|
|||
|
||||
./ledis-server -config=/etc/ledis.json
|
||||
|
||||
//another shell
|
||||
redis-cli -p 6380
|
||||
|
||||
redis 127.0.0.1:6380> set a 1
|
||||
OK
|
||||
redis 127.0.0.1:6380> get a
|
||||
"1"
|
||||
|
||||
## Lib
|
||||
|
||||
import "github.com/siddontang/ledisdb/ledis"
|
||||
l, _ := ledis.OpenWithConfig(cfg)
|
||||
db, _ := l.Select(0)
|
||||
|
||||
db.Set(key, value)
|
||||
|
||||
db.Get(key)
|
||||
|
||||
|
||||
## Replication
|
||||
|
||||
set slaveof in config or dynamiclly
|
||||
|
||||
redis-cli -p 6381
|
||||
|
||||
redis 127.0.0.1:6381> slaveof 127.0.0.1:6380
|
||||
OK
|
||||
|
||||
## Benchmark
|
||||
|
||||
See benchmark.md for more.
|
||||
|
||||
## Todo
|
||||
|
||||
+ Expire + TTL
|
||||
+ Replication
|
||||
+ Admin
|
||||
|
||||
## Thanks
|
||||
|
||||
Gamil: cenqichao@gmail.com
|
||||
|
||||
## Feedback
|
||||
|
||||
Gmail: siddontang@gmail.com
|
33
README_CN.md
33
README_CN.md
|
@ -40,16 +40,45 @@ ledisdb是一个用go实现的类似redis的高性能nosql数据库,底层基
|
|||
|
||||
./ledis-server -config=/etc/ledis.json
|
||||
|
||||
//another shell
|
||||
redis-cli -p 6380
|
||||
|
||||
redis 127.0.0.1:6380> set a 1
|
||||
OK
|
||||
redis 127.0.0.1:6380> get a
|
||||
"1"
|
||||
|
||||
## 嵌入库
|
||||
|
||||
import "github.com/siddontang/ledisdb/ledis"
|
||||
l, _ := ledis.OpenWithConfig(cfg)
|
||||
db, _ := l.Select(0)
|
||||
|
||||
db.Set(key, value)
|
||||
|
||||
db.Get(key)
|
||||
|
||||
## Benchmark
|
||||
|
||||
可以通过查看benchmark.md获取最新的性能测试结果
|
||||
|
||||
## Replication
|
||||
|
||||
通过配置或者运行时输入slaveof开启slave的replication功能
|
||||
|
||||
redis-cli -p 6381
|
||||
|
||||
redis 127.0.0.1:6381> slaveof 127.0.0.1:6380
|
||||
OK
|
||||
|
||||
## Todo
|
||||
|
||||
+ Expire + TTL
|
||||
+ Replication
|
||||
+ Admin
|
||||
|
||||
## 感谢
|
||||
|
||||
Gamil: cenqichao@gmail.com
|
||||
|
||||
## 联系我
|
||||
|
||||
Gmail: siddontang@gmail.com
|
|
@ -1,9 +1,7 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/siddontang/go-log/log"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -31,21 +29,13 @@ func (l *accessLog) Close() {
|
|||
l.l.Close()
|
||||
}
|
||||
|
||||
func (l *accessLog) Log(remoteAddr string, usedTime int64, cmd string, args [][]byte, err error) {
|
||||
argsFormat := make([]string, len(args))
|
||||
argsI := make([]interface{}, len(args))
|
||||
for i := range args {
|
||||
argsFormat[i] = " %.24q"
|
||||
argsI[i] = args[i]
|
||||
}
|
||||
func (l *accessLog) Log(remoteAddr string, usedTime int64, request []byte, err error) {
|
||||
|
||||
argsStr := fmt.Sprintf(strings.Join(argsFormat, ""), argsI...)
|
||||
|
||||
format := `%s [%s%s] %d [%s]`
|
||||
format := `%s %q %d [%s]`
|
||||
|
||||
if err == nil {
|
||||
l.l.Info(format, remoteAddr, cmd, argsStr, usedTime, "OK")
|
||||
l.l.Info(format, remoteAddr, request, usedTime, "OK")
|
||||
} else {
|
||||
l.l.Info(format, remoteAddr, cmd, argsStr, usedTime, err.Error())
|
||||
l.l.Info(format, remoteAddr, request, usedTime, err.Error())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@ type client struct {
|
|||
reqC chan error
|
||||
|
||||
syncBuf bytes.Buffer
|
||||
|
||||
logBuf bytes.Buffer
|
||||
}
|
||||
|
||||
func newClient(c net.Conn, app *App) {
|
||||
|
@ -158,7 +160,22 @@ func (c *client) handleRequest(req [][]byte) {
|
|||
duration := time.Since(start)
|
||||
|
||||
if c.app.access != nil {
|
||||
c.app.access.Log(c.c.RemoteAddr().String(), duration.Nanoseconds()/1000000, c.cmd, c.args, err)
|
||||
c.logBuf.Reset()
|
||||
for i, r := range req {
|
||||
left := 256 - c.logBuf.Len()
|
||||
if left <= 0 {
|
||||
break
|
||||
} else if len(r) <= left {
|
||||
c.logBuf.Write(r)
|
||||
if i != len(req)-1 {
|
||||
c.logBuf.WriteByte(' ')
|
||||
}
|
||||
} else {
|
||||
c.logBuf.Write(r[0:left])
|
||||
}
|
||||
}
|
||||
|
||||
c.app.access.Log(c.c.RemoteAddr().String(), duration.Nanoseconds()/1000000, c.logBuf.Bytes(), err)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue