func init() { const path = "/tmp/testdb2-rocksdb" if err := os.RemoveAll(path); err != nil { log.PanicErrorf(err, "remove '%s' failed", path) } else { conf := rocksdb.NewDefaultConfig() if testdb, err := rocksdb.Open(path, conf, true, false); err != nil { log.PanicError(err, "open rocksdb failed") } else { testbl2 = rpdb.New(testdb) } } l, err := net.Listen("tcp", ":0") if err != nil { log.PanicError(err, "open listen port failed") } port = l.Addr().(*net.TCPAddr).Port go func() { server := redis.MustServer(&Handler{}) for { c, err := l.Accept() if err != nil { log.PanicError(err, "accept socket failed") } go func() { defer c.Close() r, w := bufio.NewReader(c), bufio.NewWriter(c) s := &fakeSession2{} for { if req, err := redis.Decode(r); err != nil { return } else { if rsp, err := server.Dispatch(s, req); err != nil { return } else if rsp != nil { if err := redis.Encode(w, rsp); err != nil { return } } } } }() } }() }
"math" "math/rand" "os" "strconv" "testing" "github.com/wandoulabs/redis-port/pkg/libs/log" "github.com/wandoulabs/redis-port/pkg/libs/testing/assert" "github.com/wandoulabs/redis-port/pkg/redis" "github.com/wandoulabs/rpdb/pkg/rpdb" "github.com/wandoulabs/rpdb/pkg/store/rocksdb" ) var ( testbl *rpdb.Rpdb server = redis.MustServer(&Handler{}) keymap = make(map[string]bool) ) type fakeSession struct { db uint32 } func (s *fakeSession) DB() uint32 { return s.db } func (s *fakeSession) SetDB(db uint32) { s.db = db }