PHP redis 缓存数据库(成功)



$redis = new Redis();
$redis->connect( '127.0.0.1', 6379 )or die( "could net connect redis server" );

 

$connect = mysql_connect( '127.0.0.1', 'root', '12345678' );
mysql_set_charset( 'utf8', $connect );
mysql_select_db( table );

$query = "select * from user1 limit 3";

$result = mysql_query( $query );

while ( $row = mysql_fetch_assoc( $result ) ) {

 


json_encode( $row, JSON_UNESCAPED_UNICODE );
$id= $row['id'];

$redis->rpush( $id, $row['id'] );
$redis->rpush( $id, $row['age'] );
$redis->rpush( $id, $row['name'] );
$redis->rpush( $id, $row['detail'] );
$data = $redis->lrange( $id ,0,-1);

 

echo "number is $id";

echo "
";

print_r($data);
// echo "detail is $data";

echo "
";


}

?>

 

你可能感兴趣的:(PHP redis 缓存数据库(成功))