Home >Database >Redis >What are redis serialization and various serialization situations?

What are redis serialization and various serialization situations?

PHPz
PHPzforward
2023-05-26 09:40:181329browse

Basic serialization

What are redis serialization and various serialization situations?

The default use of jdk serialization will cause the string to be escaped

What are redis serialization and various serialization situations?

In In actual development, when we want to store objects in redis, they must be serialized.

  • Of course, if we convert the object into a json string, what is stored is equivalent to a string. Not serializing does not affect normal operation

  • However, usually we have to serialize the objects we create.

  • If we don’t serialize, store the object

What are redis serialization and various serialization situations?

What are redis serialization and various serialization situations?

## In actual development, we may use json for conversion, but we don't want to use jdk serialization yet (the default is jdk serialization). At this point we need to use the configuration class.

We create a redisTemplate object to overwrite the original redis template object in the bean container.

Distinguish between various serialization situations

Case 1: The class is not serialized and a javabean object is directly stored. The result is: error

a.

What are redis serialization and various serialization situations?

b.

What are redis serialization and various serialization situations?

c.

What are redis serialization and various serialization situations?

d. No serialization, converted to json Object storage. The console is normal, but the black window has garbled characters

What are redis serialization and various serialization situations?

#e. Serialize and convert to json object storage. Black window and garbled code.

What are redis serialization and various serialization situations?

Case 2: Class serialization, directly storing a javebean object Result: The console displays normally, but the black window has garbled characters

a.

What are redis serialization and various serialization situations?

b.

What are redis serialization and various serialization situations?

What are redis serialization and various serialization situations?##c.

What are redis serialization and various serialization situations?Case 3 uses jackon serialization (custom serialization) and the content is output normally.

a.

What are redis serialization and various serialization situations?b.

What are redis serialization and various serialization situations?When case four is used normally, we usually The object is converted into json storage, and a certain java object is not directly stored.

a. We use the same method as above in case 3

b. All objects must be serialized, that is,

The above is the detailed content of What are redis serialization and various serialization situations?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete