diff --git a/README.md b/README.md index 5f47c44..300049c 100644 --- a/README.md +++ b/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 \ No newline at end of file diff --git a/README_CN.md b/README_CN.md index a017dd1..6404574 100644 --- a/README_CN.md +++ b/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 \ No newline at end of file diff --git a/server/accesslog.go b/server/accesslog.go index 58b34b7..9e517a8 100644 --- a/server/accesslog.go +++ b/server/accesslog.go @@ -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()) } } diff --git a/server/client.go b/server/client.go index ca3d72d..3f5c43c 100644 --- a/server/client.go +++ b/server/client.go @@ -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 {