Table of Contents
回复内容:
Home Backend Development PHP Tutorial 大量的 key => value 值用什么方式存储?

大量的 key => value 值用什么方式存储?

Jun 06, 2016 pm 08:18 PM
mysql php redis cache

有大量 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吧,这样比较简单!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

How to use the Redis cache solution to efficiently realize the requirements of product ranking list? How to use the Redis cache solution to efficiently realize the requirements of product ranking list? Apr 19, 2025 pm 11:36 PM

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

Redis's Role: Exploring the Data Storage and Management Capabilities Redis's Role: Exploring the Data Storage and Management Capabilities Apr 22, 2025 am 12:10 AM

Redis plays a key role in data storage and management, and has become the core of modern applications through its multiple data structures and persistence mechanisms. 1) Redis supports data structures such as strings, lists, collections, ordered collections and hash tables, and is suitable for cache and complex business logic. 2) Through two persistence methods, RDB and AOF, Redis ensures reliable storage and rapid recovery of data.

How to safely store JavaScript objects containing functions and regular expressions to a database and restore? How to safely store JavaScript objects containing functions and regular expressions to a database and restore? Apr 19, 2025 pm 11:09 PM

Safely handle functions and regular expressions in JSON In front-end development, JavaScript is often required...

The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

Why is the return value empty when using RedisTemplate for batch query? Why is the return value empty when using RedisTemplate for batch query? Apr 19, 2025 pm 10:15 PM

Why is the return value empty when using RedisTemplate for batch query? When using RedisTemplate for batch query operations, you may encounter the returned results...

In a multi-node environment, how to ensure that Spring Boot's @Scheduled timing task is executed only on one node? In a multi-node environment, how to ensure that Spring Boot's @Scheduled timing task is executed only on one node? Apr 19, 2025 pm 10:57 PM

The optimization solution for SpringBoot timing tasks in a multi-node environment is developing Spring...

Explain the purpose of foreign keys in MySQL. Explain the purpose of foreign keys in MySQL. Apr 25, 2025 am 12:17 AM

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

See all articles