1. Install the Linux system first (for CentOS, for example)
2. Installing the Redis standalone version step
A>yum installing GCC yum-y install gcc-c++
b> upload the downloaded Redis source package.
C> Extract the source package TAR-ZXVF redis-xxx.tar.gz
D>cd/redis-xxx
E>make
F>make Install Prefix=/usr/local/redis
Then go to the/usr/local/redis directory to find the Redis-server, and then execute, you can start the Redis server, and then open a connection interface, execute REDIS-CLI can open the client connection.
You can also start the server by configuring the associated redis-conf, copy the redis-conf file from the Redis file to/usr/local/redis/bin, and modify AppendOnly No to appendonly Yes
Executes the command./redis-server redis.conf
If there is a problem with the Redis Desktop Manager connection, if Redis does not have a username and password, it may be that your Linux firewall is not turned off, use Telnet to your Redis IP, and see if it does not pass
If not, use the/etc/init.d/iptables Stop command to turn off the firewall again (or add it in the configuration file)
3.redis Common data type: String/hash/list/set/stortedset
4.java Connecting Redis
a> Add Jedis jar Package
B> working with Redis through Java code
Import Redis.clients.jedis.Jedis;
public class Rediscli {
public static void Main (string[] args) {
String key = "Test";
String value= "Hello World";
TestString (key, value);
}
Jedis connection
Test string
public static void TestString (string key, String value) {
Jedis Jedis = new Jedis ("192.168.150.131", 6379);
Jedis.set (key, value);
Jedis.close ();
}
}
You can also do this by configuring a connection pool, and you need to download a jar Commons-pool2-2.4.2.jar
Import Redis.clients.jedis.Jedis;
Import Redis.clients.jedis.JedisPool;
Import Redis.clients.jedis.JedisPoolConfig;
public class RedisCli1 {
public static void Main (string[] args) {
String key = "Pool";
String value= "Hello World";
TestString (Key,value);
}
Connect to a Redis by connecting pools
Manipulating strings
public static void TestString (string key, String value) {
Jedispoolconfig config = new Jedispoolconfig ();
Config.setmaxtotal (100);
Controls the maximum number of Jedis instances in a pool that have an idle (idle) state.
Config.setmaxidle (10);
Represents the maximum wait time when a Jedis instance is borrow (introduced), or a direct throw if the wait time is exceeded jedisconnectionexception
Config.setmaxwaitmillis (100);
Config.settestonborrow (TRUE);
Jedispool pool = new Jedispool ("192.168.150.131", 6379);
Jedis Jedis = Pool.getresource ();
String val = jedis.set (key, value);
System.out.println (Val);
Pool.returnresource (Jedis);
}
}
To this end via Java simple connect Redis
public class Rediscli {public static void main (string[] args) {String key = "Test"; String value= "Hello World"; teststring (key, value);} Jedis connection//test string public static void TestString (string key, String value) {Jedis Jedis = new Jedis ("192.168.150.131", 6379) ; Jedis.set (key, value); Jedis.close ();}}
Redis Standalone Installation and Java (Jedis) calls