Experience Summary 51--redis Memory database

Source: Internet
Author: User
Tags download redis set set

Recently more busy, study a lot of Java things, slowly published.

Use a Linux system.

Redis memory database for simple key and value storage. High efficiency.


1. Download Redis

wget http://redis.googlecode.com/files/redis-2.2.12.tar.gz

2. Compiling the source program

||

Tar xzf redis-2.2.12.tar.gz

CD redis-2.2.12

Make

3. Start the Redis service

Src/redis-server

Port default 6379

The log is always printed.

4. Randomly start Redis as a Linux service

Vi/etc/rc.local
Insert a section of code
/root/redis-2.2.12/src/redis-server

5. Client Connection Verification

The customer service side uses.

Src/redis-cli
Enter Redis commands, such as Redis 127.0.0.1:6379>

6. View Redis Logs

SRC/REDIS-CLI shutdown

7. Common commands

Server-initiated, call-to-customer

Set name QJM

Get Name

Del name

exists name

Name is the key value.

8. Use Java Access.

Create a new Mavaen project.

Configure Pom.xml
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>1.0.2</version>
</dependency>


<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.7</version>
</dependency>

Write code to test.

public static void Testredis () {
Config config = new config ();
Config.setconnectionpoolsize (10);
Config.addaddress ("192.168.189.128:6379");
Redisson Redisson = redisson.create (config);
SYSTEM.OUT.PRINTLN ("Connect");


concurrentmap<string, object> map = Redisson.getmap ("Firstmap");
Map.put ("Sex", "male");
Map.put ("name", "QJM");
Map.put ("Age", 2);


concurrentmap<string, object> resultmap = Redisson.getmap ("Firstmap");
System.out.println ("resultmap=" + resultmap.keyset ());

2. Test Set Set
Set MySet = Redisson.getset ("MySet");
Myset.add ("Wuguowei");
Myset.add ("Lisi");

Set ResultSet = Redisson.getset ("MySet");
System.out.println ("resultset===" + resultset.size ());

3. Test queue queues
Queue myqueue = Redisson.getqueue ("Firstqueue");
Myqueue.add ("Wuguowei");
Myqueue.add ("Lili");
Myqueue.add ("Zhangsan");
Myqueue.peek ();
Myqueue.poll ();

Queue resultqueue=redisson.getqueue ("Firstqueue");
System.out.println ("resultqueue===" +resultqueue);

Close connection
Redisson.shutdown ();

}


Experience Summary 51--redis Memory database

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.