Esempio n. 1
0
func selectDB(v resp.CommandArgs, ex *CommandExtras) error {
	s := v[0].String()
	index, err := strconv.Atoi(s)
	if err != nil {
		return resp.NewError(ErrSelectInvalidIndex).WriteTo(ex.Buffer)
	}

	if index < 0 || index > 15 {
		return resp.NewError(ErrSelectInvalidIndex).WriteTo(ex.Buffer)
	}
	ex.DB = storage.SelectStorage(index)
	return resp.OkSimpleString.WriteTo(ex.Buffer)
}
Esempio n. 2
0
func newConnection(conn net.Conn, rs *rodisServer) {
	uuid := uuid.New()
	rc := &rodisConn{uuid: uuid, db: storage.SelectStorage(0), conn: conn, reader: bufio.NewReader(conn), server: rs}

	if rs.cfg.RequirePass == "" {
		rc.authed = true
	}

	rc.extras = &command.CommandExtras{rc.db, &rc.buffer, rc.authed, rs.cfg.RequirePass}

	rc.server.mu.Lock()
	rs.conns[uuid] = rc
	rc.server.mu.Unlock()

	log6.Debug("New connection: %v", uuid)

	go rc.handle()
}