开发者

Is it possible to call Redis from within MySQL?

开发者 https://www.devze.com 2023-02-02 12:15 出处:网络
Is it possible to fetch data from Redis fr开发者_开发技巧om within MySQL (using a native function or some other mechanism)? I would like to be able to use this information in ORDER BY statements for p

Is it possible to fetch data from Redis fr开发者_开发技巧om within MySQL (using a native function or some other mechanism)? I would like to be able to use this information in ORDER BY statements for paging with LIMIT. Otherwise I will have to fetch all the data from MySQL, fetch additional data for each row from Redis, sort in my application and keep the page I need.

It would be much more efficient if MySQL could say call a function for every row to get data from Redis, do the sorting and only send me the page I need.


Even if this is possible (with open source everything is technically possible), it's unlikely to improve performance much over the cleaner approach of sorting within your app. If your data set is small, returning everything is not a problem. If your data set is large, you probably need to be sorting by an indexed column to get decent performance out of sql, and you can't index a function.

Also, if the result set isn't huge the dominant performance issue is usually latency rather than processing or data transfer. One query from sql and one mget from redis should be reasonably quick.

If you really want just one query when a page is viewed you will need to have both record and sorting data in one place - either add the data from redis as a column in sql or cache your queries in redis lists.

0

精彩评论

暂无评论...
验证码 换一张
取 消