大量的 key => value 值用什么方式存储?
有大量 key=>value 形式的值对,如:xxxx=>aaaaaaa,值一旦建立就不会更改,数量的话后期会达到百万级别,且经常会访问到,并发不高,但要保证数据完整。用什么方案去存比较好?
回复内容:
有大量 key=>value 形式的值对,如:xxxx=>aaaaaaa,值一旦建立就不会更改,数量的话后期会达到百万级别,且经常会访问到,并发不高,但要保证数据完整。用什么方案去存比较好?
其实把问题再问得完整一点自然就有答案了
被访问的方式,除了“经常会访问到,并发不高”之外,访问的形式是单key查询还是查多条?数据是否有序?是否有类似“搜索key前缀为foo”的需求?有“列出10个key”的需求?有“列出全部key”的需求?访问是随机key的还是集中在部分热点key值?冷热key值的比例大概怎样?目前并发不高,是否需要考虑后期并发增加以后的方案?
数据完整,是否需要备份?key增加的频率如何?新增加的key是否立刻需要能访问?
key和value的长度分别是多少?百万条1K是一条内存条,可百万条1M就是一块磁盘了
一般而言,条件不是特别极端的话,选单redis&备份,单mysql&备份,或是mysql+redis都行,各有长短,看你想要什么和你手里有什么资源来找平衡点了
PS:别忘了mysql还分ssd上的mysql和机械磁盘上的mysql,也是各有优劣的
redis 比较方便 一般放内存里 也可以放硬盘
并发不高,数据库,百万级别单表够了;并发高的话,前面加一层memcached
从你的需求上面主要针对两个点:值一旦建立就不会更改,以及保证数据完整。
数据库是跑不掉的,目前在保证数据完整性方面数据库是首选,同时也是最通用最值得信赖的。而针对数量的话后期会达到百万级别,且经常会访问到,并发不高这三个点可以考虑使用内存数据库提供访问效率,如redis,数据结构使用普通的k-v结构即可。
memcached
根据key哈希到不同的文件中, 根据访问量来决定要不要加一层内存cache
用mysql存储,然后前面加redis做缓存。
只是Key-Value的话,可以不用放数据库.找一些kv型的nosql就可以用.有持久化的话,可以考虑redis,或者SSDB之类的.Nosql上可以很容易做基于key的分片来解决你的数据容量和访问量的问题.
直接用apc吧,这样比较简单!

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



There are many reasons why MySQL startup fails, and it can be diagnosed by checking the error log. Common causes include port conflicts (check port occupancy and modify configuration), permission issues (check service running user permissions), configuration file errors (check parameter settings), data directory corruption (restore data or rebuild table space), InnoDB table space issues (check ibdata1 files), plug-in loading failure (check error log). When solving problems, you should analyze them based on the error log, find the root cause of the problem, and develop the habit of backing up data regularly to prevent and solve problems.

MySQL uses shared locks and exclusive locks to manage concurrency, providing three lock types: table locks, row locks and page locks. Row locks can improve concurrency, and use the FOR UPDATE statement to add exclusive locks to rows. Pessimistic locks assume conflicts, and optimistic locks judge the data through the version number. Common lock table problems manifest as slow querying, use the SHOW PROCESSLIST command to view the queries held by the lock. Optimization measures include selecting appropriate indexes, reducing transaction scope, batch operations, and optimizing SQL statements.

In MySQL database operations, string processing is an inevitable link. The SUBSTRING_INDEX function is designed for this, which can efficiently extract substrings based on separators. SUBSTRING_INDEX function application example The following example shows the flexibility and practicality of the SUBSTRING_INDEX function: Extract specific parts from the URL For example, extract domain name: SELECTSUBSTRING_INDEX('www.mysql.com','.',2); Extract file extension to easily get file extension: SELECTSUBSTRING_INDEX('file.pdf','.',-1); Processing does not exist

MySQL can run without network connections for basic data storage and management. However, network connection is required for interaction with other systems, remote access, or using advanced features such as replication and clustering. Additionally, security measures (such as firewalls), performance optimization (choose the right network connection), and data backup are critical to connecting to the Internet.

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

The MySQL primary key cannot be empty because the primary key is a key attribute that uniquely identifies each row in the database. If the primary key can be empty, the record cannot be uniquely identifies, which will lead to data confusion. When using self-incremental integer columns or UUIDs as primary keys, you should consider factors such as efficiency and space occupancy and choose an appropriate solution.

For production environments, a server is usually required to run MySQL, for reasons including performance, reliability, security, and scalability. Servers usually have more powerful hardware, redundant configurations and stricter security measures. For small, low-load applications, MySQL can be run on local machines, but resource consumption, security risks and maintenance costs need to be carefully considered. For greater reliability and security, MySQL should be deployed on cloud or other servers. Choosing the appropriate server configuration requires evaluation based on application load and data volume.

MySQL can return JSON data. The JSON_EXTRACT function extracts field values. For complex queries, you can consider using the WHERE clause to filter JSON data, but pay attention to its performance impact. MySQL's support for JSON is constantly increasing, and it is recommended to pay attention to the latest version and features.
