Home  >  Article  >  Database  >  Where is redis data stored?

Where is redis data stored?

(*-*)浩
(*-*)浩Original
2019-11-30 09:17:565691browse

Where is redis data stored?

#Is redis data stored in memory?

First of all, you must understand that redis is a database. Redis is an in-memory database. All data basically exists in the memory and will be regularly refreshed to the hard disk in the form of appends or snapshots. middle. (Recommended learning: Redis video tutorial)

Since redis is an in-memory database, the speed of reading and writing is very fast, so it is often used to make data. Caching of pages etc.

The most commonly used data types in Redis are as follows:

String

Hash

List

Set

Sorted set

pub/sub

Transactions

First of all, Redis uses a redisObject object internally to represent all keys and values. The main information of redisObject As shown above:

type represents the specific data type of a value object, and encoding is the way different data types are stored inside redis.

For example: type=string means that the value is stored as an ordinary string, then the corresponding encoding can be raw or int. If it is int, it means that the actual redis internally stores and represents this character according to the numerical type class. String, of course, the premise is that the string itself can be represented by a numerical value, such as: "123" "456" such strings.

The vm field needs special explanation here. Only when the virtual memory function of Redis is turned on can this field actually allocate memory. This function is turned off by default.

We can find that Redis uses redisObject to represent all key/value data, which is a waste of memory. Of course, these memory management costs are mainly to provide a unified management interface for different data types of Redis. The actual author It also provides a variety of methods to help us save memory usage as much as possible.

For more Redis-related technical articles, please visit the Redis Getting Started Tutorial column to learn!

The above is the detailed content of Where is redis data stored?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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