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