ST. PETERSBURG, Fla. - Wilmer Flores was in the lineup at shortstop for the Mets Friday night instead of Ruben Tejada because of "The Matrix."

Not the Keanu Reeves movie franchise. Terry Collins has a top-secret Mets-generated book that suggests many things, including what type of pitchers certain Mets batters should do well against. He calls it "The Matrix."

Since neither Flores nor Tejada had ever faced Rays starter Jake Odorizzi, "The Matrix" was activated. It spit out that Flores was a better bet against the righthander.

So that's why Flores was batting in the ninth inning of a tied game. And that's why Flores was able to dunk a two-out, go-ahead single to right to give the Mets a 4-3 comeback win over the Rays before a pro-Mets crowd of 23,145 at Tropicana Field.

The Mets, who tied it earlier in the ninth on rookie Michael Conforto's RBI double, have won seven in a row. The Mets opened a 2 1/2-game lead on the Nationals, who lost Friday night.

It was the first time in team history the Mets overcame three separate deficits in each of the last three innings to win a game, according to the Elias Sports Bureau.

Jeurys Familia earned his 30th save after a wild bottom of the ninth. With a runner on first and no outs, Brandon Guyer grounded to third -- three times. The first two (one a double play and one a forceout) were correctly called foul balls. Juan Uribe got the out at second on Guyer's third grounder.

There were two battles going on at the Trop. The first was between the Mets fans and Rays fans. The Mets fans seemed to have the upper hand as chants of "Let's Go, Mets!" overwhelmed whatever people chant for the Rays.

Uribe and Daniel Murphy homered for the Mets. Both were game-tying shots, with Murphy's coming in the eighth inning to tie it at 2.

Evan Longoria put the Rays ahead in the bottom half with a solo homer off Tyler Clippard (1-0), but the Mets scored two unearned runs in the ninth off closer Brad Boxberger (4-8).

Lucas Duda led off with a squibber to the left of the mound that Boxberger threw past first base for an error. Duda moved to second on a wild pitch and scored one out later on Conforto's double.

Travis d'Arnaud hit an infield single to move Conforto to third before Kelly Johnson lined to short for the second out. That brought up Flores, the Mets folk hero who had been greeted with a standing ovation in his first at-bat. After dunking the go-ahead hit in front of a diving Guyer in rightfield, the next chant that was heard was Flores' name.

Jacob deGrom allowed two runs on home runs by Grady Sizemore and James Loney in his 6 1/3-inning stint.

Trailing 1-0, Flores nearly tied it in the sixth when he hit a high drive into the corner in left. Sizemore got back to the short wall and made an incredible, home-run robbing catch by leaping into the stands. Uribe cranked a high slider deep into the seats in left to tie it at 1.

Odorizzi retired the first seven Mets before Johnson singled in the third. After Flores singled, Curtis Granderson's deep fly ball to left allowed both runners to tag up. Murphy, the DH Friday night flied out to end the inning.