可以使用
rand(),但是性能很差
select * from users order by rand() limit 5; <-- slow
我建议将所有用户ID的列表存储到序列化数组中,并缓存到磁盘文件中。(定期更新)
因此,您可以使用PHP取消对它的序列化,并使用PHP
array_rand选择5个随机用户。
要获取全部信息,您可以执行以下操作
select * from users where user_id in(...); <-- very fast

可以使用
rand(),但是性能很差
select * from users order by rand() limit 5; <-- slow
我建议将所有用户ID的列表存储到序列化数组中,并缓存到磁盘文件中。(定期更新)
因此,您可以使用PHP取消对它的序列化,并使用PHP
array_rand选择5个随机用户。
要获取全部信息,您可以执行以下操作
select * from users where user_id in(...); <-- very fast