Java programming Details-refactoring-why If-else is not a good code

Source: Internet
Author: User
Tags cas redis cluster

I. What to do in a slow existence system

    1. A small amount of data storage, high-speed read and write access. This is the main application scenario for Redis, which guarantees high-speed access through all in-momery data, while providing the capability of data landing.

    2. Massive data storage, distributed system support, data consistency guarantee, convenient cluster node Add/Remove. Redis3.0 later began to support the cluster, the realization of semi-automatic data fragmentation, but need smart-client support.

Second, from different angles to detail the Redis

Network model: Redis uses a single-threaded IO multiplexing model, which encapsulates a simple Aeevent event processing framework that implements the Epoll, Kqueue, and select, and the single-threaded speed advantage can be maximized for purely IO operations. However, Redis also provides some simple computing functions, such as sorting, aggregation, etc., for these operations, the single-threaded model can actually seriously affect the overall throughput, CPU calculation process, the entire IO schedule is blocked.

Memory management: Redis uses on-site memory to store data, and rarely use free-list and other ways to optimize memory allocation, there will be a certain degree of memory fragmentation, Redis and according to the storage command parameters, the data with the expiration time is stored separately, and call them temporary data, Non-temporary data is never removed, even if there is not enough physical memory, so that swap will not eliminate any non-temporal data (but will attempt to eliminate some temporary data), which is more appropriate for Redis as storage instead of the cache.

Data consistency issues: On the consistency issue, the personal feel redis is not memcached implemented well, memcached provides the CAS command, can guarantee multiple concurrent access operations the same data consistency problem. Redis does not provide CAS commands, and this is not guaranteed, but Redis provides the functionality of a transaction that guarantees the atomicity of a sequence of commands and is not interrupted by any action.

Supported key types: Redis, in addition to Key/value, also supports numerous data structures such as list,set,sorted Set,hash, which provides the keys for enumeration operations, but cannot be used online, if you need to enumerate the data on the line, Redis provides tools to scan its dump files, enumerate all the data, and Redis also provides features such as persistence and replication.

Client Support: Redis officially provides rich client support, including the majority of programming language clients, for example, I chose the official recommended Java client Jedis in this test. It provides a rich interface, the method allows developers to not need to have a relationship between the internal data fragmentation, read data routing, etc. Simply call it and it's very handy.

Data replication: Starting from 2.8, the slave periodically (once per second) initiates an ACK confirming that the replication stream (replication stream) is processing progress

Read/write separation: Redis supports read and write separations, and is simple to use, simply configure the Redis read server and the write server in the configuration file, with multiple servers separated by commas as follows:

Horizontal dynamic expansion: Lasted three years, and finally waited for the Redis 3.0 to be expected. The new version mainly realizes the function of cluster, and then automatically migrates the data after adding or deleting the cluster nodes. The core of enabling Redis cluster online reconfiguration is the ability to move slots from one node to another. Because a hash slot is actually a collection of keys, what the Redis cluster really does when it hashes (rehash) is to move some keys from one node to another.

Data elimination Strategy: When the Redis memory dataset size rises to a certain size, it will implement a data-phase-out strategy.

Java Advanced Architecture
Links: https://www.jianshu.com/p/8079a3fb4c95
Source: Pinterest
The copyright of the book is owned by the author, and any form of reprint should be contacted by the author for authorization and attribution.

Java programming Details-refactoring-why If-else is not a good code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.