Redis Installation and simple test

Source: Internet
Author: User
Tags redis version redis server

Absrtact: Redis is a very popular memory database in the industry and is generally used as an intermediate caching system to enhance the throughput and responsiveness of the overall business system. This article will briefly describe the main process of installation and give a brief test code.


1. System Environment and version description

The operating system chooses Ubuntu 14.04, and the Redis version selects the latest stable version of the current 2.8.9. The client chooses the Redis Java version Jedis 2.4.2.

2. Installation steps for Redis

A. Download the Redis installation package

wget http://download.redis.io/releases/redis-2.8.9.tar.gz
B. Under the directory, unzip the package to generate a new directory redis-2.8.9

Tar Xvfz redis-2.8.9.tar.gz

C. Go to the directory after decompression and compile

CD redis-2.8.9

sudo make


Note: If there are no obvious errors, the compilation succeeds

D. Installation

sudo make install

Note: Generally, in the Ubuntu system, you need to use sudo elevation of privilege

E. After the installation is successful, you can run the test to confirm that the Redis function is normal

sudo make test

F. Initiation of Redis services

Find Redis Installed directory: Find/-name ' redis* '------Locate files in the root directory that contain Redis in the name

After searching, it was found that Redis was installed in the/usr/local/bin/directory.

Next, start the Redis service:

/usr/local/bin/redis-server

Description: From the screenshot above, you can find that the boot port is the default 6379. The user can specify a specific profile at startup and specify the boot port.

G. View the Redis process

Ps-ef | grep Redis

Note: If you can see the process, the boot is OK.


3. Simple Redis test procedure

Readers can create eclipse projects on their own, introduce Jedis client packages, and test the program as follows:

public class Redistest {private Jedis Jedis = null;
	Private String Key1 = "Key1";

	Private String Key2 = "Key2";
	Public Redistest () {Jedis = new Jedis ("localhost");
		public static void Main (string[] args) {redistest redistest = new Redistest ();
		Redistest.isreachable ();
		Redistest.testdata ();
		Redistest.deldata ();
	Redistest.testexpire ();
		public Boolean isreachable () {Boolean isreached = true;
			try {jedis.connect ();
			Jedis.ping ();
		Jedis.quit ();
			catch (Jedisconnectionexception e) {e.printstacktrace ();
		Isreached = false;
		} System.out. println ("The current Redis Server is reachable:" + isreached);
	return isreached;

		public void TestData () {Jedis.set ("Key1", "data1");
		System.out.println ("Check Status of data existing:" + jedis.exists (key1));

		System.out.println ("Get Data key1:" + jedis.get ("Key1"));
		Long s = Jedis.sadd (Key2, "data2"); System.out.println ("Add key2 Data:" + jedis.scard (Key2) + "with StatuS "+ s);

		public void Deldata () {Long Count = Jedis.del (Key1);
	System.out.println ("Get Data Key1 The It is deleted:" + Jedis.get (key1));

		public void Testexpire () {Long Count = Jedis.expire (Key2, 5);
		try {thread.currentthread (). Sleep (6000);
		catch (Interruptedexception e) {e.printstacktrace ();
		} if (Jedis.exists (Key2)) {System.out. println ("Get Key2 in Expire Action:" + jedis.scard (Key2));
		else {System.out.println ("Key2 is expired with value:" + Jedis.scard (Key2));
 }
	}

}

4. Summary

This paper briefly introduces the installation and deployment of Redis, and based on the simple test procedure of Jedis, explains the basic use of redis, more content, can consult the relevant data.


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.