浅谈 Redis 与 MySQL 的耦合性以及利用管道完成 MySQL 到 Redis
㈠ Redis 与 MySQL 的耦合性 ? ?? ? ?? ? ? 在业务架构早期、我们便该吃着碗里的看着锅里的、切莫让MySQL 有梦、而Redis 无心 ? ? 毕竟、有些关系型的结构不适合放到Redis跑、男女搭配、干活不累嘛、推荐让MySQL与Redis喜结连理 ? ?? ? ? 其次、这 2 人、一
㈠ Redis 与 MySQL 的耦合性? ??
? ??
? ? 在业务架构早期、我们便该"吃着碗里的看着锅里的"、切莫让MySQL 有梦、而Redis 无心
? ? 毕竟、有些关系型的结构不适合放到Redis跑、"男女搭配、干活不累"嘛、推荐让MySQL与Redis喜结连理
? ??
? ? 其次、这 2 人、一般是在不同场景做选择、而不会在性能上选择、
? ? 只有在 2 者都可用的情况下、综合性能、硬件成本、运维成本等选择
? ? 比如、网页游戏启用 Redis+MySQL:
? ? 游戏中的:好友关系、排行榜、计数器、队列、cache都很适合通过 Redis来实现
? ??
? ? 再举个例子是新浪微博的架构、比如用户关注关系:
? ? 在 MySQL中是 这样一行一行存储的。而在 Redis中你可以存成一个set,或者zset等
? ? ? ? ??
? ? 大体流程是由 MySQL 复制到 Redis 的
? ? 基本结构应该是:
? ? 1. 发微博-- > 进入消息队列-- > 存入MySQL-- > 复制到Redis
? ? 2. 查询 -- > 查询缓存-- > 查询Redis -- > 查询MySQL
? ??
? ??
? ??
? ? ㈡ 快速迁移 MySQL →→ Redis?
? ??
? ? ? ?① MySQL 要导出的表 david_lin
mysql> desc david_lin; +---------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+-------------+------+-----+---------+-------+ | id | int(11) | NO | PRI | NULL | | | myname | varchar(25) | NO | UNI | NULL | | | mymoney | int(11) | NO | | 0 | | +---------+-------------+------+-----+---------+-------+ mysql> select * from david_lin; +----+--------+---------+ | id | myname | mymoney | +----+--------+---------+ | 1 | david | 100000 | | 2 | rocky | 200000 | +----+--------+---------+
? ? ? ? ??
? ? ? ? ? ? 每行数据中执行的 Redis命令如下:
? ? ? ? ? ? HSET david_lin [myname] [mymoney]
[root@odd ~]# cat mysql_to_redis.sql SELECT CONCAT( "*4\r\n", '$', LENGTH(redis_cmd), '\r\n', redis_cmd, '\r\n', '$', LENGTH(redis_key), '\r\n', redis_key, '\r\n', '$', LENGTH(hkey), '\r\n', hkey, '\r\n', '$', LENGTH(hval), '\r\n', hval, '\r' ) FROM ( SELECT 'HSET' AS redis_cmd, 'david' AS redis_key, myname AS hkey, mymoney AS hval FROM david_lin ) AS t
? ? ? ?③ 开始导入
[root@odd ~]# mysql -uroot -poracle test --skip-column-names --raw <br> <br>? ? ? ?④ 在Redis 里查询 <p> </p><pre class="brush:php;toolbar:false">redis 127.0.0.1:6379> hgetall david 1) "david" 2) "100000" 3) "rocky" 4) "200000"
? ? 这里仅是个 demo、数据量小、不过、看这结果、有些类似行转列哈、列运算了、有木有 :)
? ??
? ? By David Lin
? ? 2013-05-30
? ? Good Lucky
作者:linwaterbin 发表于2013-5-30 22:11:24 原文链接
阅读:82 评论:0 查看评论
原文地址:浅谈 Redis 与 MySQL 的耦合性以及利用管道完成 MySQL 到 Redis 的高效迁移, 感谢原作者分享。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

PHP provides the following methods to delete data in MySQL tables: DELETE statement: used to delete rows matching conditions from the table. TRUNCATETABLE statement: used to clear all data in the table, including auto-incremented IDs. Practical case: You can delete users from the database using HTML forms and PHP code. The form submits the user ID, and the PHP code uses the DELETE statement to delete the record matching the ID from the users table.

Setting up a MySQL connection pool using PHP can improve performance and scalability. The steps include: 1. Install the MySQLi extension; 2. Create a connection pool class; 3. Set the connection pool configuration; 4. Create a connection pool instance; 5. Obtain and release connections. With connection pooling, applications can avoid creating a new database connection for each request, thereby improving performance.

Pipes in Go are a communication mechanism used to safely and efficiently transfer data between goroutines to improve application performance. There are two types of pipeline operations: Unbuffered: data must be sent and received synchronously. Buffered: The pipe has allocated storage space, allowing asynchronous send and receive. Example: When calculating the Fibonacci sequence, pipelines are used to communicate between the main goroutine and the calculation goroutine, thereby achieving concurrent calculations and significantly improving performance.

Nexo Exchange: Swiss cryptocurrency lending platform In-depth analysis Nexo is a platform that provides cryptocurrency lending services, supporting the mortgage and lending of more than 40 crypto assets, fiat currencies and stablecoins. It dominates the European and American markets and is committed to improving the efficiency, security and compliance of the platform. Many investors want to know where the Nexo exchange is registered, and the answer is: Switzerland. Nexo was founded in 2018 by Swiss fintech company Credissimo. Nexo Exchange Geographical Location and Regulation: Nexo is headquartered in Zug, Switzerland, a well-known cryptocurrency-friendly region. The platform actively cooperates with the supervision of various governments and has been in the US Financial Crime Law Enforcement Network (FinCEN) and Canadian Finance

Effective monitoring of Redis databases is essential for maintaining optimal performance, identifying potential bottlenecks, and ensuring overall system reliability. Redis Exporter Service is a robust utility designed to monitor Redis databases using Prometheus. This tutorial will guide you through the complete setup and configuration of Redis Exporter Service, ensuring you establish a monitoring solution seamlessly. By following this tutorial, you’ll achieve a fully operational monitoring setup to effectively monitor the performance metrics of your Redis database.

PiNetwork is about to launch PiBank, a revolutionary mobile banking platform! PiNetwork today released a major update on Elmahrosa (Face) PIMISRBank, referred to as PiBank, which perfectly integrates traditional banking services with PiNetwork cryptocurrency functions to realize the atomic exchange of fiat currencies and cryptocurrencies (supports the swap between fiat currencies such as the US dollar, euro, and Indonesian rupiah with cryptocurrencies such as PiCoin, USDT, and USDC). What is the charm of PiBank? Let's find out! PiBank's main functions: One-stop management of bank accounts and cryptocurrency assets. Support real-time transactions and adopt biospecies
