1. RedisMod

RedisMod is a series of Redis enhancement modules. With the support of RedisMod, the function of Redis will become very powerful. Currently RedisMod includes the following enhanced modules:

  • RediSearch: a full-featured search engine
  • RedisJSON: native support for JSON type
  • RedisTimeSeries: time series database support
  • RedisGraph: graph database support
  • RedisBloom: native support for probabilistic data
  • RedisGears: Programmable data processing
  • RedisAI: Real-time model management and deployment for machine learning

2.RedisJSON What is RedisJson

Recently, the official website gave the performance test report of RedisJson (RedisSearch), which can be said to crush other NoSQL. The following is the core content of the report, the conclusion first

  • For isolated writes, RedisJSON is 5.4x faster than MongoDB and faster than ElasticSearch
    200 times more
  • For isolated reads, RedisJSON is 12.7x faster than MongoDB and faster than ElasticSearch
    500 times more

In mixed workload scenarios, real-time updates do not affect RedisJSON search and read performance, while ElasticSearch does. The following is the specific data

  • RedisJSON supports ~50x more operations/sec than MongoDB and 7x/sec than ElasticSearch
    RedisJSON* has ~90x lower latency than MongoDB and 23.7x lower latency than ElasticSearch

Additionally, RedisJSON's read, write, and load search latencies are much more stable than ElasticSearch and MongoDB in higher percentiles. RedisJSON can also handle higher and higher overall throughput when increasing the write ratio, while ElasticSearch reduces the overall throughput it can handle when the write ratio increases

Combined with latency and throughput improvements, RedisJSON* is 5.4x faster than Mongodb and over 200x faster than ElasticSearch for isolated writes

  1. Insert json data into it
JSON.SET product:1 $ '{"id":1,"productSn":"7437788","name":"Xiaomi 8","subTitle":"Full screen gaming smartphone 6GB+64GB black full Netcom 4G dual Card dual standby","brandName":"Xiaomi","price":2699,"count":1}'
JSON.SET product:2 $ '{"id":2,"productSn":"7437789","name":"Redmi 5A","subTitle":"Full Netcom 3GB+32GB Champagne Gold Mobile Unicom Telecom 4G Mobile phone dual SIM dual standby","brandName":"Xiaomi","price":649,"count":5}'
JSON.SET product:3 $ '{"id":3,"productSn":"7437799","name":"Apple iPhone 8 Plus","subTitle":"64GB Red Special Edition Mobile Unicom Telecom 4G Phone", "brandName":"apple","price":5499,"count":10}'
  1. Next, you can get the value of the JSON type key-value pair through the JSON.GET command
JSON.GET product:1

You can also get only the specified property of the value. In RedisJSON, you need to start with . when getting the property in the JSON object.

For example, get the two properties of name and suTitle

JSON.GET product:1 .name .subTitle

RediSearch

Through the RediSearch module, Redis can become a powerful full-text search engine, and natively supports Chinese search, let's experience it below!

Before using RediSearch to search data, we have to create an index first. The syntax of index building is a bit complicated. Let's look at it first.

FT.CREATE {index}
  [ON {data_type}]
     [PREFIX{count}{prefix}[{prefix}..]
     [LANGUAGE {default_lang}]
  SCHEMA {identifier} [AS {attribute}]
      [TEXT | NUMERIC | GEO | TAG ] [CASESENSITIVE]
      [SORTABLE] [NOINDEX]] ...

Use the FT.CREATE command to create an index. The meaning of the parameters in the syntax is as follows

  • index: index name;
  • data_type: The data type for indexing, currently supports JSON or HASH
  • PREFIX: through which you can select the data prefix that needs to be indexed, such as PREFIX * product: indicates that the data prefixed with product: in the key is indexed
  • LANGUAGE: Specifies the default language of the TEXT type attribute, which can be set to Chinese using Chinese
  • identifier: Specifies the attribute name
  • attribute: specifies the attribute alias
  • TEXT | NUMERIC | GEO | TAG: These are all types of attribute optional
  • SORTABLE: The specified attribute can be sorted

After reading the grammar, it may not be easy to understand. Just try to index the previous product data and you will understand.

FT.CREATE productIdx ON JSON PREFIX 1 "product:" LANGUAGE chinese SCHEMA $.id AS id NUMERIC $.name AS name TEXT $.subTitle AS subTitle TEXT $.price AS price NUMERIC SORTABLE $.brandName AS brandName TAG
Likes(0)

Comment list count 0 Comments

No Comments

WeChat Self-Service

WeChat Consult

TaoBao

support@elephdev.com

发表
评论
Go
Top