Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between storing Integers and Strings in Redis

Tags:

redis

Any difference between these two commands?

LPUSH myset 123
LPUSH myset "123"

I want to store about 5 million integers and I want to do it in the most efficient way.

like image 576
borjagvo Avatar asked Aug 28 '15 15:08

borjagvo


People also ask

Can you store an integer in Redis?

Redis stores integers in their integer representation, so for string values that actually hold an integer, there is no overhead for storing the string representation of the integer.

Does Redis store everything as string?

In Redis, we have the advantage of storing both strings and collections of strings as values. A string value cannot exceed 512 MB of text or binary data. However, it can store any type of data, like text, integers, floats, videos, images, and audio files.

What can be stored in a Redis string?

Creating and Managing Strings However, strings in Redis are binary-safe, meaning a Redis string can hold any kind of data, from alphanumeric characters to JPEG images. The only limit is that strings must be 512 MB long or less.

Can Redis list store objects?

Object Storing Procedure. In the Redis, Everything can be stored as only key-value pair format. Key must be unique and storing an object in a string format is not a good practice anyway. Objects are usually stored in a binary array format in the databases.


1 Answers

No, there is no difference; both are stored as strings. From redis.io:

Redis Lists are simply lists of strings, sorted by insertion order.

Depending on your usage, you may want to consider using a set, rather than a list.

like image 69
Tim Cooper Avatar answered Sep 28 '22 03:09

Tim Cooper