1. introduction
redis is an open-source key-value database. It is often considered a Data Structure server. Because its value includes not only the basic string type but also the list, set, sorted set and hash types. Of course, all the elements of these types are of the string type. That is to say, the list and set Collection types can only contain the
string type. You can perform many atomic operations on these types. For example, append a string to a character value (APPEND Command ). Add or subtract a numeric string (when the incr command is processed by an integer). You can push the list type or operate the pop element (you can simulate the stack and queue ). For the set type, you can perform some set-related operations (intersection Union difference ). Memcache has commands similar to ++ and.
however, the value of memcache only includes the string type. There are far fewer redis value types. Same as memcahe for performance. Redis data is usually stored in memory. Of course, redis can write data in the memory to the disk at a certain interval to prevent data loss. Redis also supports master-slave replication ). Other features of redis include simple transaction support and pub/sub channel functions, and redis configuration management is very simple. There are also open-source client class libraries in various languages.
2. Installation
: http://redis.googlecode.com/files/redis-2.0.4.tar.gz
2.0 is currently the latest stable version
you can run the following command in Linux to install
$ Tar xzf redis-2.0.4. Tar. GZ
$ Redis-2.0.4 CD
$ Make
After make, the compiled redis service will appear in the redis-2.0.4 directoryProgramRedis-server, as well as the client program for testing redis-cli
Start the redis service.
$./Redis-Server
Note that the default configuration is used to start redis in this way. You can also use the following command to tell redis to start it using the specified configuration file through the startup parameter.
$./Redis-server redis. Conf
Redis. conf is a default configuration file. We can use our own configuration files as needed.
After starting the redis service process, you can use the test client redis-CLI to interact with the redis service.
For example
$./Redis-cli
Redis>Set Foo bar
OK
Redis>Get foo
"Bar"
Here is an example of a simple type of value for get and set commands. Foo is the key and bar is a string type value.
If you do not have Linux, you can use this online exercise. Of course, many management-related commands in the online version are not supported.
Http://try.redis-db.com/
3. Java client Hello, world
Client jar package address http://cloud.github.com/downloads/alphazero/jredis/jredis-1.0-rc2.jar. The version is a little old and supports redis 1.2.6. The latest version 2.0 has not been release
Create a new Java project in eclipse and add a jredis package reference. Below is a hello, World Program
Package Jredisstudy;
Import Org. jredis .*;
Import Org. jredis. Ri. alphazero. jredisclient;
Public Class APP {
Public Static Void Main (string [] ARGs ){
Try {
Jredis Jr = New Jredisclient ( "192.168.56.55" , 6379 );// Redis service address and port number
String key = "Mkey" ;
Jr. Set (key, "Hello, redis! " );
String v = New String (Jr. Get (key ));
String k2 = "Count" ;
Jr. incr (K2 );
Jr. incr (K2 );
System. Out. println (v );
System. Out. println ( New String (Jr. Get (K2 )));
}Catch (Exception e ){
// Todo: handle exception
}
}
}
The redis environment has been set up. Redis commands related to various types and specific application scenarios will be written later.
From: http://www.cnblogs.com/xhan/archive/2011/02/01/1948751.html