Current location - Quotes Website - Collection of slogans - How to connect to redis database
How to connect to redis database
1. Comment out the bound Ip in the configuration file redis.conf?

2. change the protection mode to no in the configuration file redis.conf?

3. Set the requirepass access authorization password in the configuration file redis.conf (you can set it at will), or you can log in to the redis client and use the command to set it as follows:?

. /redis-cli?

Config set requires pass123/123 to be a password?

After the above three steps, it is basically possible, but there are special circumstances. The accessed port number 6379 may be intercepted by the firewall, so it is necessary to close the firewall of the system or cancel the interception of port 6379, which is not repeated here. ?

Next, you can create a project implementation action redis database. The development tool I use here is eclipse. Creating a java Project project in eclipse is shown below:?

After the project is created, create a lib folder in src peer directory, import the jar package needed to operate the database (download it at night), operate the database with jedis, and realize database connection pool with commons-pool. ?

Start redis server:?

Create RedisDemoSimple.java codes as follows:

Parcel? com . redis . redis db;

Import? redis . clients . jedis . jedis; Public? Class? RedisDemoSimple? {male? Static electricity Invalid? main(String[]? args)? {//ip address is virtual machine ip? The port is a redis port.

Judith. Judith. =? New? jedis(" 192. 168.228 . 129 ",6379); //redis access rights? Is the requirepass configured in redis.conf of the redis configuration file.

jedis . auth(" my redis ");

Jedis.set("redis_first ","Hello ");

System.out.println("key? redis _ first:"+jedis . get(" redis _ first "));

}

} The console is printed as follows:

Start the redis client to query the values inserted into the database:?

The connection here is successful.