Click “like” to see, form a habit, the public account search [dime technology] pay attention to more original technical articles. This article has been included in GitHub org_Hejianhui /JavaStudy.

preface

The major Redis 6 changes are SSL, ACLs, RESP3, client caching, thread I/O, clustering support in Redis Benchmark and improved Redis CLI clustering support, and Redis cluster agent.

1. Multithreaded IO

Redis 6.0 provides multithreading support, redis 6 prior to the version, strictly speaking is also multithreading, but the execution of the user command when the request single thread model, there are some threads used to perform background tasks, such as unlink delete large key, RDB persistence, etc..

Redis 6.0 provides multithreaded read and write IO, but the final execution of user commands is still a single thread, so there is no multithreaded data competition, still very efficient.

Prior to Redis 6.0, the following operations are performed in a single thread

Redis 6.0 thread execution mode: You can configure the multi-thread model by using the following parameters:

Io-threads 4 // There are three IO threads and one thread is the main thread. The main thread is responsible for reading and writing I/OS and executing commandsCopy the code

By default, as configured above, there are three IO threads, and these three IO threads only perform write operations in the IO, that is, read and command execution are performed by the main thread. Finally multithreading writes the data back to the client.The following parameters are enabled:

Io-threads-do-reads yes // Will support I/O threads to perform read and write tasks.Copy the code

2. client side caching

Client caching: Redis 6 provides features for server to track key changes and client to cache data, which requires client implementationThe execution process is as follows:

  1. When a client accesses a key, the server records the key and client.
  2. After the client gets the data, the client cache;
  3. In this case, when the key is accessed again, the key is returned directly, avoiding the interaction with the Redis server and saving server resources.
  4. When data is modified by other requests, the server will actively notify the client of the invalid key.
  5. The client performs local invalidation and retrieves the latest data at the next request.

Only oracle supports it at present:

< the dependency > < groupId > IO. Lettuce < / groupId > < artifactId > lettuce - core < / artifactId > < version > 6.0.0. RELEASE < / version > </dependency>Copy the code
public static void main(String[] args) throws InterruptedException {
    RedisClient redisClient = RedisClient.create("Redis: / / 192.168.109.200");

    Map<String, String> clientCache = new ConcurrentHashMap<>();

    StatefulRedisConnection<String, String> myself = redisClient.connect();

    CacheFrontend<String, String> frontend =
            ClientSideCaching.enable(CacheAccessor.forMap(clientCache),
            myself,
            TrackingArgs.Builder.enabled().noloop());

    String key="csk";
    int count = 0;
    while (true){

        System.out.println(frontend.get(key));
        TimeUnit.SECONDS.sleep(3);
        if(count++ == Integer.MAX_VALUE){ myself.close(); redisClient.shutdown(); }}}Copy the code

Note: the redis. IO/switchable viewer/clie…

3. ACL permission control

An ACL controls the access and execution permissions of commands. By default, any command can be executed. Compatible with earlier versions.

You can set an ACL in either of the following ways:

  1. Command mode

    ACL SETUSER + A specific permission rule, which can be persisted through ACL SAVE

  2. Compile the ACL configuration file and run ACL LOAD to LOAD it

There are two methods of ACL storage. However, the two methods cannot be configured at the same time. Otherwise, an error is reported and the process exits

  1. Redis configuration file: redis.conf
  2. ACL configuration file. In redis. Conf, run aclfile /path to configure the path of the ACL file

Command mode:

ACL SETUSER Alice // Creates a user whose user name is AliceCopy the code

The user semantics created with the above command are:

  1. In the off state, it is disabled and cannot be authenticated with Auth
  2. Cannot access any commands
  3. You cannot access arbitrary keys
  4. No password

The above user Alice makes no sense.

Create a user with access to the cached: prefix and set the password:

acl setuser alice on >pass123  ~cached:* +get 
Copy the code
auth alice pass123
set a a
(error) NOPERM this user has no permissions to run the 'set' command or its subcommand
get a a 
(error) NOPERM this user has no permissions to access one of the keys used as arguments
get cached:name
vvv
Copy the code

The set command is not authorized. Key A is not authorized. Cached :name is authenticated.

More consistent with reading habits of the format

ACL GETUSER alice
Copy the code

Add multiple access modes separated by Spaces. Note that Alice does not have admin permission to switch to another user for login

ACL SETUSER alice ~objects:* ~items:* ~public:*
Copy the code

Constraints on type commands

ACL SETUSER Alice on +@all -@dangerous > Password ~*Copy the code

Here +@all: contains all commands and uses -@ to remove dangerous commands defined in the Redis command table

You can run the following command to view the commands that belong to a certain category

Acl cat // View all categories acl cat dangerous // View all dangerous commandsCopy the code

Open subcommand

ACL SETUSER myuser -client +client|setname +client|getname
Copy the code

Disable the client command, but enable the setname and getName subcommands in the client command. You can only disable the setname and getName subcommands first and then append them, because new commands may be added later.

4. RESP3 agreement

RESP is a Protocol used by the Redis server to communicate with clients. Redis 5 uses RESP2, while Redis 6 is starting to support RESP3 in addition to being compatible with RESP2.

The purpose of RESP3:

  • One is to provide more semantic responses for clients to develop functions that are difficult to achieve using old protocols.
  • Another reason is to implement client-side-caching.

Note: github.com/antirez/RES…

6. Improves the RDB log loading speed

Depending on the actual composition of the file (larger or smaller values), you can expect a 20/30% improvement. Information is also faster when there are many client connections, an old problem that has now been solved.

7.Redis Cluster Proxy module

In a Redis cluster, clients can be very fragmented, and a cluster agent has been introduced that abstracts the Redis cluster for clients as if it were talking to a single instance. Multiplexing is also performed when simple and the client uses only simple commands and functions. Redis Cluster proxy

8. Numerous new modules apis are provided

Note: the redis. IO/switchable viewer/modu…