Installation and operational implementation of the Redis database (Windows maven project)

Source: Internet
Author: User

Redis is an in-memory database that caches the data you write into memory and then periodically writes it to disk. This article describes the operation of implementing a Redis database using MAVEN tools to compile and run Java files in a Windows environment.
First of all. We need to download the Redis tool: Http://redis.io/download, then unzip it. We will see that there are some files in the unpacked folder:
Of these, two operational files need to be considered, Redis-server.exe/redis-cli.exe. They are each Redis service and redisclient, to run Redis, we need to run the server file, for example, as seen in:
Next, we'll be able to interact with redis-server by opening the Redis-cli file:

In the, can see I run in the client: Keys * (list key in the database), get ZHANGHU1 (get key corresponding value), other shell commands can be Google or Baidu.

maven is an effective tool to implement project management, it can be self-based on the user's definition to download the program's dependency package and so on, here is maven: https://maven.apache.org/download.cgi. After the download, unzip, the Bin folder into the environment variables to be able to verify the way is entered at the command line: mvn-version, assume that the appearance of similar to the interface is seen when the installation is complete.
The MAVEN project has its own folder building rules (Maven provides its own proactive build tool: MVN archetype). Its configuration file is Pom.xml. It is located below the root folder of the project. We need to use Java to operate Redis, we need to use the Jedis class, we need to increase the dependency under the Pom, then pom.xml becomes this:
<project xmlns= "http://maven.apache.org/POM/4.0.0"         xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"         xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >    <modelVersion>4.0.0</modelVersion>    <groupid>com.xiaomi.first.storedatatoredis</ groupid>    <artifactId>StoreDataToRedis</artifactId>    <version>1.0-snapshot</ version>    <dependencies>        <dependency>            <groupId>redis.clients</groupId>            <artifactId>jedis</artifactId>            <version>2.7.2</version>        </dependency >    </dependencies></project>

After that, we use the interface provided by Jedis to write to the database, read, and so on.

Redis itself provides a rich range of data types, such as: strings. Collection. Linked lists, etc., you can query the MAVEN project's build rules and the interface provided by Jedis.


Following. I'll show you how to compile and run code to implement a database operation:
1. We need to go to the root folder of the project and run MVN compile, assuming that the first run, MAVEN will download the appropriate compilation tool
2. Run: mvn exec:java-dexec.mainclass= "package name. Class Name" (with input parameters: MVN exec:java-dexec.mainclass= "package name. Class name"-dexec.args= "arg0 arg1 Arg2 ")
The process of compiling and running is shown:
1. Compile the process:


2. Operation Process:

When we see build success, it means the project is running successfully. Below, let's verify that the data is available in Redis:


Installation and operational implementation of the Redis database (Windows maven project)

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.