[Redis] two, Redis advanced features

(C) Redis advanced features

  Earlier we introduced the five basic data types Redis, and flexible use of five data types are based on the use Redis, in addition, there are some characteristics Redis, master these characteristics can have a better understanding of the Redis, such as Redis Affairs, Redis partition, Redis data backup, and so on.

1 Redis Hyperloglog

  Redis 2.8.9 from version began to join HyperLogLog, it sounds a bit strange, in fact it is a used to do statistical algorithm base (the base is the number of elements in the data set is not repeated, such as data set {1, 3, 5 , 7, 5, 7, 8}, the cardinality of the set of the data set {1, 3, 5, 7, 8}, the base 5).

  Redis do statistical base has its unique advantages, the number of elements in the input or volume is very very large space required Redis calculation base is always fixed, and is very small, each HyperLogLog key only takes 12 KB of memory , can be calculated approximately 2 ^ 64 different base elements, but only the calculation base, does not enter the storage element itself.



2, Redis data backup and recovery

  Redis supports backing up data, and data can be restored from a backup. This is mainly related to a save command.

  When the save command input, will be installed in the wear member dump.rdb redis directory file, the file data is backed up. If you want to restore data, simply dump.rdb move to the installation directory, and then restart the redis-server can be. Therefore, we use this data backup and recovery can easily migrate the database.

3, Redis security and authentication

  In order to ensure the safety of Redis service, you can add a password to redis, so that when a client connects to need to enter a password for authentication when redis service, in order to connect the pass.

  Redis service password is specified by the configuration file, the password argument is the configuration file requirepass, the default is an empty string, only need to change this parameter you can set a password, the need for post-auth authentication password before you can perform the appropriate action .



4, Redis performance test

  We say that Redis biggest feature is a high performance, read speed is 110 000 times / s, write speed is 81000 times / s. Redis provides a performance testing tool redis-benchmark, the performance tests performed by the plurality of commands simultaneously. This tool has many alternative test parameters: -h (specified host), - p (designated port), - s (designated Socket), - c (the specified number of concurrent connections), - n (specified requests), - d ( value specifies the set and get that number of bytes) and so on.



5, Redis affairs

  Redis transaction allows clients to execute multiple commands in sequence, and conform to the following rules:

  • It is placed in a batch operation before sending queue buffer EXEC command.
  • After receiving EXEC command to enter the transaction execution, transaction arbitrary command execution fails, the rest of the command is still being executed.
  • During the execution of a transaction, other command request submitted by the client will not be inserted into the transaction execution command sequence.

  From start to execute a transaction will go through three stages: the start of a transaction, the command team, the enforcement branch. Specifically, the first to MULTI begin a transaction, then multiple commands into teams to the transaction, and finally by the EXEC triggering transaction commands, together with all the commands in the transaction.

  Redis execute a single command is atomic, but Redis without adding any mechanism for maintaining atomicity in transaction, so the implementation of Redis transaction is not atomic . Transactions can be understood execute the script as a packaged volume, but the bulk of the instruction is not atomic operation, the middle will not lead to the failure of an instruction previously done instruction rollback, it will not cause subsequent instructions do.



6, Redis publish and subscribe

  在另外一篇关于Kafka的博客:【Apache Kafka】 Kafka简介及其基本原理中,介绍了什么是消息队列,并对发布-订阅这种消息模式有相关的介绍,这里我们说Redis也可以用作简单的消息队列,发送者(pub)发送消息,订阅者(sub)接收消息。Redis 客户端可以订阅任意数量的频道,当有新消息发送到该频道时,客户端就可以收到消息。






7、Redis管道技术

  Redis是一种基于客户端-服务端模型以及请求/响应协议的TCP服务。这意味着通常情况下一个请求会遵循以下步骤:

  • 客户端向服务端发送一个查询请求,并监听Socket返回,通常是以阻塞模式,等待服务端响应。
  • 服务端处理命令,并将结果返回给客户端。

  Redis 管道技术可以达到这样的效果:在服务端未响应时,客户端可以继续向服务端发送请求,并最终一次性读取所有服务端的响应。



8、Redis分区

  我们说Redis是一个分布式缓存、分布式数据库,那么到目前我们还没有看到其分布式体现在哪里,Redis数据保存在内存中,如果只有一台机器,很容易达到其存储上限。因此,Redis分区允许构建redis集群,将数据分别保存到多个Redis实例中去,每个实例保存key的一个子集,这样就可以利用更多的计算机来存储数据,从而构造更大的数据库。

  除了数据量更大,Redis分区还可以带来更强大的计算能力和更高的网络带宽。

  关于如何进行分区,Redis提供了两种类型。一种是范围分区,就是映射一定范围的对象到特定的Redis实例。比如,ID从0到10000的用户会保存到实例R0,ID从10001到 20000的用户会保存到R1,以此类推。还有一种方法是哈希分区,用一个hash函数将key转换为一个数字,对这个整数取模,转换到对应的Redis实例中的一个。

Guess you like

Origin www.cnblogs.com/gzshan/p/10973838.html