In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
How to use Redis and RedisGraph modules at the same time? In view of this problem, today the editor summarizes this article explained by examples. The steps of solving the problem are very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
In this demo I show a small interface that allows you to search for animals and view the relationships between them through a biological classification system (realm, phylum, class, order, etc.). The full text is based in part on the first paragraph of Wikipedia. For example, search for "pet cat" and "Blue Whale" and you will find that they are both mammals, while if you search for "pet cat" and "snow leopard", you will find that they both belong to the same family: cats.
This demo project is surprisingly simple, but I should point out that the integration between RediSearch and RedisGraph is still in its early stages and is not ready for use in a production environment at the time of this writing. Therefore, I recommend that you determine whether this approach meets your needs with the understanding that the integration of RediSearch and RedisGraph will mature in the coming months.
Let's discuss how to build from source code again. The first thing to do is to build RediSearch and RedisGraph based on the correct branches in the code library. RediSearch uses the current main branch, while RedisGraph is the redisconf branch. If you want to build the solution according to your needs, you can build these two modules from the source code. Both RedisGraph and RediSearch have detailed instructions on how to build, which is not difficult, but it just takes a little time.
The location of the configuration module is in the redis.conf file, and to ensure that RedisGraph is loaded before RediSearch, you need to place the loadmodule configuration item of RediSearch before the loadmodule configuration item of RedisGraph in the module section of the redis.conf file. After editing the redis.conf, you need to restart the Redis server for the configuration to take effect.
In the demo I demonstrated earlier, I used the RedisGraph-bulk-loader script to load the following from CSV to RedisGraph, including the dataset we collected. This data set includes only mammals because the data quality of other animals is low (non-mammal species are rarely well described by Wikipedia).
Here is an example of loading data:
$cd redisgraph-bulk-loader/ $python3 bulk_insert.py MAMMALS-Q-n / path/to/demo/dataload/Class.csv-n / path/to/demo/dataload/Family.csv-n / path/to/demo/dataload/Genus.csv-n / path/to/demo/dataload/Order.csv-n / path/to/demo/dataload/Species.csv-r / path/to/demo/dataload/IN_CLASS.csv-r / path/to/demo/dataload/IN_FAMILY.csv -r / path/to/demo/dataload/IN_GENUS.csv-r / path/to/demo/dataload/IN_ORDER.csv-a yourpassword 1 nodes created with label 'Class' 157 nodes created with label' Family' 1272 nodes created with label 'Genus' 29 nodes created with label' Order' 5616 nodes created with label 'Species' 29 relations created for type' IN_CLASS' 1272 relations created for type 'IN_FAMILY' 5616 relations created for type' IN_GENUS' 157 relations created for type 'IN_ORDER' Construction of graph' MAMMALS' complete: 7075 nodes created 7074 relations created in 0.443749 seconds $redis-cli-a yourpassword GRAPH.QUERY MAMMALS "CALL db.idx.fulltext.createNodeIndex ('Species','description')" Warning: Using a password with'-a'or'- u 'option on the command line interface may not be safe. 1) (empty list or set) 2) (empty list or set) 3) 1) "Query internal execution time: 324.970000 milliseconds"
(gist: https://gist.github.com/stockholmux/0727a4a784a46f8cb9e8329d393a513a)
Here, key MAMMALS contains our entire chart. Some important considerations:
The-Q switch on bulk_insert.py is important because it allows smart references when reading CSV.
Call redis-cli to index all nodes in batch, thus ingesting more than 7000 documents for full-text search.
Now let's get up and run a UI. As with almost all Node.js applications, we install npm first. Installation takes about a few seconds, because we not only have to manage the server-side files of Node. There are also front-end Vue.js components. If you haven't spent a lot of time on front-end JavaScript recently, you probably won't be able to use a FTP and HTML file to implement these functions. Fortunately, the modern front end does value tools, so we can install VueCLI (I recommend following the VueCLI getting started guide).
After your front-end tools are ready, let's move on to the front end of npm installation and startup:
$npm run build
This will create the dist directory for all our front-end files. Now we have the data in Redis, and our front-end files are ready to start the service, so we can connect to the Redis server:
$node server.js-p 6379-a yourpassword-hyourhostOrlocalhost
Let's first discuss some questions about the server we just turned on. It is built on Express.js and mainly uses WebSocket for communication. I have also integrated a visual engine debugging tool that allows you to view the commands being executed in a separate browser window. You can point your browser to the address http://localhost:4444.
All in all, it's very short relative to what it does-- only 75 lines of code. Our solution doesn't need to be that long, because what we really do is accept the WebSocket connection, run the Redis command based on the messages passed, and then pass those messages back with the results. Redis (Graph) does all the complicated work. Let's take a look at the orders being carried out.
To search for keywords, we run this command:
> GRAPH.QUERY MAMMALS "CALL db.idx.fulltext.queryNodes ('Species','cat house pet')"
There's nothing to it. Our key is a mammal, and we call a specific function using a special syntax, whose first argument is the label of the node we are looking for, and the other parameter is the string we are actually searching for. You can pass valid RediSearch parameters to query, but keep in mind that this is currently a full-text search, so don't use geospatial, tags, or numeric clauses.
Once we have identified the two animals we want to compare, we can use a simple command to query:
> GRAPH.QUERY MAMMALS "MATCH (s:Species)-[*]-> (x)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.