Getting Started with Redis

Source: Internet
Author: User
Tags install redis redis server
1. Install gcc

Redis is deployed on a Linux system in a real production environment, so start with a Linux

Redis installation requires GCC, first ensure that GCC is installed on Linux

Enter GCC, prompting for no command, stating that GCC is not installed on the system.


To install GCC using yum:

#root账户下, install GCC, C + + compiler, and kernel files

Su Root

Yum-yinstall gcc gcc-c++ kernel-devel

After GCC installation is complete, enter GCC directly and the command is recognized by the system

2. Upload Redis installation package

Upload packages downloaded from Redis official website (https://redis.io/) via the FTP tool (XFTP or FILEZAFTP) to Linux server

Here I upload the Redis installation package to the planned path/usr/redis


Decompression Redis installation package:

Tar xzvfredis-4.0.2.tar.gz

3. Install Redis

This section refers to the official document, there is no content, if you encounter problems, Google generally have the answer.

Download, extract and compile Redis with:

$ wget http://download.redis.io/releases/redis-4.0.2.tar.gz
$ tar xzf redis-4.0.2.tar.gz
$ CD redis-4.0.2
$ make

Thebinaries that are now compiled are available in the SRC directory. Run Redis with:

$ src/redis-server

You are caninteract with Redis using the built-in client:

$ src/redis-cli
Redis> set Foo Bar
Ok
Redis> get foo
"Bar"

4. Run Redis in the daemon process

Modify the redis.conf configuration file to

Daemonize No modification to Yes

Start Redis:

5. Using Redis in Java

Redis website provides support for a variety of programming languages, here we choose Java

Select Jedis This library:

You can download Jedis and then add it to your project, or you can use Maven to get Jedis directly:

Maven Configuration entry:

<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>

Then write a simple unit test:

Import Org.junit.Test;
Import Redis.clients.jedis.Jedis;

/**
* Created by Huqijun on 10/3/2017.
*
/public class Jedistest {

@Test public
void Testjedis ()
{
Jedis Jedis = new Jedi        S ("IP", 6379);
Jedis.set ("Hello", "World");
String out = jedis.get ("Hello");
System.out.println (out);
}
}

Run this test to prompt

Redis.clients.jedis.exceptions.JedisConnectionException:java.net.ConnectException:Connection Refused:connect

You need to open the 6379 port on the Redis server.

Linux system How to hit the beginning of the mouth of Google below the answer, you can refer to the

http://ww123.blog.51cto.com/5559238/1873405

This post

Then rerun the test, and the test passes.

It's the end of the Redis to get started here. Want to have a deeper understanding of the use of Redis, such as pub/sub message mechanism, distributed locks and other features read the official document.

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.