Redis common usage instructions

1 Overview
Remote DIctionary Server (Redis) is a key-value storage system written by Salvatore Sanfilippo. Redis is an open source log-type, Key-Value database written in ANSI C language, complying with BSD protocol, supporting network, memory-based and persistent, and providing APIs in multiple languages.
Redis is a high-performance key-value database. The emergence of redis has largely compensated for the lack of key/value storage such as memcached (a free and open source, high-performance, distributed memory object caching system), and can be a good complement to relational databases in some occasions (For example: displaying lists, processing expired items, queues, etc. under large data volumes). It provides Java, C/C++, C#, PHP, JavaScript, Perl, Object-C, Python, Ruby, Erlang and other clients, which are very convenient to use. This article mainly introduces the installation method and some common usage methods in the java language.
2 Download and install
2.1 Download address

Download address: https://redis.io/;

2.2 Installation and startup
The downloaded Redis supports 32bit and 64bit. Choose according to your actual situation, cp the 64bit content to the custom drive letter installation directory and name it redis, such as C:\reids.

Open a cmd window, use the cd command to switch the directory to redis and run redis-server.exe.

Then open a cmd window and switch the directory to redis to run, and run the redis-cli.exe -h 127.0.0.1 -p 6379 command. The connection is successful as shown below.

2.3 Setting the password
You can set or modify the password through commands, as shown in the figure below.

You can verify the password through the command, as shown below after a successful connection.

3 Redis client
3.1 download and install
Download address: https://redisdesktop.com/download.

Click on the client installation program, next step.... to complete the opening of the client interface, omit the installation screenshots.

3.2 Operation and use

Open the client, the main interface is as follows:

3.2.1 Configure the connection
1. Click the green plus sign Connect to Redis Server button, the configuration window will pop up, enter the corresponding information, and click OK;
a) Name: connection alias;
b) Host: redis server address;
c) Port: Redis port, The default is 6379;

d) Auth: connection password, if a password is set, it needs to be filled in.

2. After successful connection, you can view the data in the database.

3.2.2 Adding and modifying data

1. Right-click on the data and select the Add new key option.

2. Fill in Key and Value, take String as an example, and click save.

3. As shown in the figure below, the addition is successful. If you need to modify the value, you can directly modify it in the text and click save, but if you modify the key, click the Rename button.

3.2.3 Filtering data

1. Right-click on the data and select the Filter keys option.

2. Fill in the information to be queried in the pop-up window and click OK, here is the fuzzy query.

3. After the filter is added, the filter content will be displayed on the database.

4. To cancel the filter, right-click the database again and select Reset keys filter.

3.2.4 Deleting data

Enter the corresponding data, click the Delete button.

4 Java Code Operation
4.1 Sample Project

Create a sample project redis and import the jedis-2.1.0.jar package, as shown in the following figure:

As shown below, click OK.

4.2 Test the connection
Write a mian function to test the connection

The console returns the following information, indicating that the connection is successful.

4.3 Set method

用于设置给定 key 的值。如果 key 已经存储其他值, SET 就覆写旧值,且无视类型。

4.4 getSet方法

Redis Getset 命令用于设置指定 key 的值,并返回 key 旧的值。

4.5 hset方法
Redis Hset 命令用于为哈希表中的字段赋值 ,如果哈希表不存在,一个新的哈希表被创建并进行 HSET 操作,如果字段已经存在于哈希表中,旧值将被覆盖。

1. 如果字段是哈希表中的一个新建字段,并且值设置成功,返回 1 。

2. 如果哈希表中域字段已经存在且旧值已被新值覆盖,返回 0 。

5 附件说明介绍
1. 样例工程:java的操作redis的样例代码;
2. jedis-2.1.0.jar:redis样例工程所以来jar包;
3. redis-2.4.5-win32-win64.zip:redis数据库服务器;
4. redis64-2.6.12.1.rar:redis客户端。

附件截图如下:

附件及文档     下载

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326352185&siteId=291194637