introduction of Redis package in Project
Download the jar package and import your own project based on the jar package path given in the previous article. (Jedis-2.7.2.jar)
second, connect with Redis
(1) Connection IP and port number, connection password modification
By Redis the IP address and port number of the server, on this computer, the default is 127.0.0.1 (localhost), and the port number defaults to 6379.
Remember the redis.conf configuration file that was mentioned in the previous article? All the changes are on the side here. Open the redis.conf file and search for the following to make changes, as follows:
(2) after the revised login requirements
Note that the default connection password is not, that is, the top of the Requirepass foobared for the annotation status, footbared for the current password. If this is an annotation state, then the client connection is not required to enter a password. However, if the comments are released here, you will need to login with the password, as follows:
As shown in the figure above, no password can be logged in, but getting the data is not allowed (get LSF means to obtain the value of the key corresponding to the name LSF, set key value is the opposite, such as set LSF "Lingshufeng" Represents a key value pair that is stored in a key of Lsf,value as Lingshufeng
No password login Direct error is not allowed, this means that the need for password login, specifically for the operation of the map, in the back plus-a foobared, that is-a password, you can log in.
In addition, you can get the LSF corresponding data, here why is "\xc1\xec ..." that state, in fact, I deposit in the LSF for the form of Chinese characters, stored here that becomes so, but in fact is the Chinese character, but here is shown as such, if you want it to show, You can add--raw when the client is logged in. As follows:
Three, Java in the use of
Note that using Java to import the appropriate jar package first, I am using the Jedis-2.7.2.jar package, the previous article has a download link, you can view.
Can be written as follows. This completes the Java and Redis simple interaction ...
Note: The IP port number is not modified here, the IP default is localhost or 127.0.0.1, the port number defaults to 6379. If you set a password, you also need to add a line of code to enter the password, otherwise the connection is unsuccessful. As follows:
Jedis.auth ("foobared");
That is, the connection password is foobared, in addition, if the server does not have a password, you here to set the password will not login successfully. This is very well understood.