Exemple #1
0
func NewRemoteSession(host string, poolSize int) (s *RemoteSession, err error) {
	s = &RemoteSession{
		host:      host,
		poolSize:  poolSize,
		counters:  counter.NewCounters(),
		available: true,
		Info: &RemoteInfo{
			Uptime: time.Now(),
		},
	}
	s.mus = make([]*sync.Mutex, s.poolSize)
	s.sessions = make([]*Session, s.poolSize)
	for i := 0; i < s.poolSize; i++ {
		s.mus[i] = &sync.Mutex{}
		s.sessions[i], err = s.createSession()
		if err != nil {
			s.available = false
			break
		}
	}
	if s.available {
		go s.secondTicker()
	}
	return
}
Exemple #2
0
func NewProxy(opt *Options) (s *GoRedisProxy) {
	s = &GoRedisProxy{}
	s.SetHandler(s)
	s.options = opt
	s.counters = counter.NewCounters()
	s.sessmgr = goredis_server.NewSessionManager()
	return
}
Exemple #3
0
func NewSlaveClientV2(server *GoRedisServer, session *Session) (s *SlaveClientV2, err error) {
	s = &SlaveClientV2{
		server:   server,
		session:  session,
		counters: counter.NewCounters(),
	}
	err = s.initLog()
	return
}
Exemple #4
0
func NewSlaveClient(server *GoRedisServer, session *Session) (s *SlaveClient, err error) {
	s = &SlaveClient{}
	s.server = server
	s.session = session
	s.buffer = make(chan *Command, 1000*10000)
	s.rdbjobs = make(chan int, 10)
	s.counters = counter.NewCounters()
	os.Mkdir(s.directory(), os.ModePerm)
	err = s.initLog()
	return
}
Exemple #5
0
// server := NewGoRedisServer(opt)
// server.Init()
// server.Listen(host)
func NewGoRedisServer(opt *Options) (server *GoRedisServer) {
	server = &GoRedisServer{}
	server.opt = opt
	// set as itself
	server.SetHandler(server)
	server.methodCache = make(map[string]reflect.Value)
	server.cmdChan = make(chan *Command, 1000)
	server.closingFunc = list.New()
	go server.processCommandChan()
	server.monmgr = NewSessionManager()
	server.syncmgr = NewSessionManager()
	server.slavemgr = NewSessionManager()
	server.sessmgr = NewSessionManager()
	server.info = NewInfo(server)
	// counter
	server.counters = counter.NewCounters()
	server.cmdCounters = counter.NewCounters()
	server.cmdCateCounters = counter.NewCounters()
	server.execCounters = counter.NewCounters()
	return
}
Exemple #6
0
func NewClient(srchost, desthost string, buffersize int) (s *SlaveClient, err error) {
	s = &SlaveClient{
		srchost:   srchost,
		desthost:  desthost,
		directory: "/tmp",
		buffer:    make(chan *Command, buffersize*10000),
		jobs:      make(chan int, 10),
		counters:  counter.NewCounters(),
		pullrate:  40 * 1024 * 1024, // 40MB
		pushrate:  40 * 1024 * 1024, // 40MB
	}
	// warmup
	conn, e1 := net.Dial("tcp", s.srchost)
	if e1 != nil {
		return nil, e1
	}
	s.src = NewSession(conn)
	return
}