Study

[Study | OMEP] week 1: the basics of redis

  • -
728x90

영어 발표 스터디를 하고 있다. (참고로 OMEP: Oh My English Present 는 사실 내가 그냥 지은 이름이다.)

내 발표들을 다시 정리해두면 좋을 것 같아, 블로그에도 업로드한다.

week1: the basics of redis

Characteristics

Redis is a data structure with the following characteristics

  1. Located on a remote server.
  2. Existing as a process
  3. Executed within in memory-based process.
  4. A key-value data management system that is non-relational and allows for simple storage and retrieval of data without complex querying.

Based on these characteristics, Redis supports five main data structures

String, Set, Sorted Set, Hash, and List.

Two primary purposes on using redis

also, there are two primary purposes on using redis

  1. Using Redis as a Cache:
    • Redis is an in-memory data store, which makes data access fast and efficient.
  2. Using Redis for Persistent Data Storage:
    • Redis can persistently store data on disk. This feature can be employed to store and manage critical data .

In summary, Redis is a versatile tool offering fast data access and persistent storage capabilities. Depending on your service requirements, you can use Redis as a cache or as a persistent data storage solution.

Operational Tips for Redis

1. Effective Memory Management

  • Redis allocates and deallocates memory without using a memory pool, so it's essential to be mindful of memory fragmentation and Max Memory settings.
  • If you want to reduce memory fragmentation
    • It's better to have similarly sized data than differently sized data. So you should try to keep your memory at a similar size.
    • It is safer to have multiple instances with small memory than one instance with large memory. It can be a pain to manage, but it can be more reliable.

2. Beware of O(N) Commands

  • Redis operates as a single-threaded application, which means that commands with long execution times will cause other commands to wait.

Since Redis can only execute one command at a time, it is disadvantageous to write commands that require long processing times. So what are some typical O(N) commands that can be long?

  • KEYS: This command traverses all items. Be careful though, as a large number of items will trigger an exception on the server.
  • For example, if you have more than a million keys and you use the KEYS command to check them, your monitoring script will end up calling it once a second.
  • FLUSHALL, FLUSHDB : flush all data.
  • Delete Collections: Deletes all items in the Collection. For example, if you want to delete 1 million items, this command will take a second or two to process, so you won't be able to do anything during that time.
  • Get All Collections: What if you want to get all 100,000 items every time? It's going to be slow.

So how we can replace KEYS?

By using the scan command instead of KEYS, you can turn one long command into a series of short commands, with other get/set-like commands between each short command. It's a very efficient way to do this.

In the same vein, if you need to get all the items in a Collection, you can get only a part of the Collection (a Sorted Set), or you can split a large Collection into several other collections. It's best to keep it to a few thousand items per collection.

  • Especially be cautious with O(N) commands. To replace commands like KEYS, consider using SCAN, and explore alternative methods for data deletion. This can significantly enhance Redis's performance.

To make the most of Redis, it's crucial to apply these operational tips and effectively manage your Redis configurations.

summary

  1. you can use redis as a cache and persistent data storage
  2. Effectively manage Memory
  3. Beware of O(N) Commands
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.