(Windows Maven project) install and operate Jedis database, mavenjedis

Source: Internet
Author: User

(Windows Maven project) install and operate Jedis database, mavenjedis
Redis is a memory database that caches the data you write into the memory and periodically writes data to the disk, this article describes how to use Maven to compile and run a Java file in a Windows environment to perform operations on the Redis database.
First, we need to download the Redis tool: http://redis.io/download. then we can decompress it. We will see that the decompressed directory contains such a file:
The two executable files, redis-server.exe/redis-cli.exe, are the redis service and redis client. To run redis, We need to execute the server File, as shown in:
Next, open the redis-cli file to interact with the redis-server:

In, we can see that I have executed the following commands on the client: keys * (list keys in the database), get zhanghu1 (get the value corresponding to the key), and other shell commands can be performed by Google or Baidu.

Maven is an effective tool for project management. It can download program dependency packages according to the user's definition. Here it is Maven's: https://maven.apache.org/download.cgi. After the download is complete, decompress the package and load the bin directory to the environment variable. The verification method is to enter mvn-version in the command line, if the interface shown in the following figure appears, the installation is complete.
Maven projects have their own directory building rules (Maven provides an automated build tool: mvn archetype), and its configuration file is pom. xml, which is located under the root directory of the project. We need to use Java to operate Redis, and we need to use the Jedis class. We need to add the dependency under pom, then pom. xml becomes like 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>

Then, we use the interfaces provided by Jedis to write and read data to the database. Redis itself provides a wide range of data types, such as strings, collections, and linked lists. You can query the building rules of Maven projects and interfaces provided by Jedis.
Next, I will demonstrate how to compile and execute code to perform database operations:
1. We need to go to the project root directory and execute mvn compile. If this is the first execution, Maven will download the corresponding compilation tool.
2. run: mvn exec: java-Dexec. mainClass = "package name. class Name "(use mvn exec: java-Dexec if you have input parameters. mainClass = "package name. class Name "-Dexec. args = "arg0 arg1 arg2 ")
The process of compilation and execution is displayed:
1. compilation process:

2. Execution Process:

When we see that the project has been successfully executed in the build success era, let's verify if Redis has the data:


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.