国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Backend Development C#.Net Tutorial Redis tutorial (4): Hashes data type

Redis tutorial (4): Hashes data type

Dec 28, 2016 pm 02:34 PM
redis

1. Overview:

We can think of the Hashes type in Redis as a map container with String Key and String Value. So this type is very suitable for storing information about value objects. Such as Username, Password and Age, etc. If the Hash contains few fields, this type of data will also occupy very little disk space. Each Hash can store 4294967295 key-value pairs.

2. Related command list:

Command prototype Time complexity Command description Return value
HSET key field value O(1) Set the Field/Value pair for the specified Key. If the Key does not exist, this command will create a new Key with the Field/Value in the parameter. Yes, if the Field in the parameter already exists in the Key, the original value will be overwritten with the new value. 1 means that the new Field has been set with a new value, 0 means that the Field already exists, and will be overwritten with the new value. Original value
HGET key field O(1) Returns the associated value of the specified Field in the specified Key. Return the associated value of the Field in the parameter. If the Key or Field in the parameter does not exist, return nil.
HEXISTSkey field O(1) Determine whether the specified Field in the specified Key exists. 1 means it exists, 0 means the Field or Key in the parameter does not exist.
HLEN key O(1) Get the number of Fields contained in the Key. Returns the number of Fields contained in Key. If Key does not exist, returns 0.
HDEL key field [field ...] O(N) N in time complexity represents the field to be deleted in the parameter quantity. Delete multiple fields specified in the parameters from the Hashes Value of the specified Key. If the fields do not exist, they will be ignored. If the Key does not exist, it is treated as empty Hashes and returns 0. The number of Fields actually deleted.
HSETNXkey field value O(1) Only when the Key or Field in the parameter does not exist, set the specified Key Define the Field/Value pair, otherwise the command will not perform any operation. 1 means that the new Field has been set with a new value, 0 means that the Key or Field already exists, and this command does not perform any operation.
HINCRBYkey field increment O(1) Increase the value of the Value associated with the specified Field in the specified Key. If the Key or Field does not exist, this command will create a new Key or Field, initialize its associated Value to 0, and then specify the operation of increasing the number. The numbers supported by this command are 64-bit signed integers, that is, the increment can be negative. Return the value after the operation
HGETALLkey O(N) The N in the time complexity indicates that the Key contains Field quantity. Get all Field/Value contained in this key. The return format is a Field, a Value, and so on. List of Field/Value
HKEYSkey O(N) The N in the time complexity indicates that the Key contains Field quantity. Returns all Fields names for the specified Key. List of Fields.
HVALSkey O(N) The N in the time complexity represents the number of Fields contained in the Key. Returns all Values ??names of the specified Key. List of Values.
MGETkey field [field ...] O(N) The N in the time complexity represents the number of fields requested. Gets a set of Values ??associated with the Fields specified in the parameter. If the requested Field does not exist, its value returns nil. If the Key does not exist, the command treats it as an empty hash and therefore returns a set of nil. Returns a set of Values ??associated with the requested Fields. The return order is equal to the request order of the Fields.
HMSET key field value [field value ...] O(N) N in time complexity represents the Field being set quantity. Set the Field/Value pairs given in the parameters pair by pair. If one of the Fields already exists, the original value will be overwritten with the new value. If the Key does not exist, create a new Key and set the Field/Value in the parameters.

3. Command examples:

1. HSET/HGET/HDEL/HEXISTS/HLEN/HSETNX:

 #在Shell命令行啟動(dòng)Redis客戶端程序
    /> redis-cli
    #給鍵值為myhash的鍵設(shè)置字段為field1,值為stephen。
    redis 127.0.0.1:6379> hset myhash field1 "stephen"
    (integer) 1
    #獲取鍵值為myhash,字段為field1的值。
    redis 127.0.0.1:6379> hget myhash field1
    "stephen"
    #myhash鍵中不存在field2字段,因此返回nil。
    redis 127.0.0.1:6379> hget myhash field2
    (nil)
    #給myhash關(guān)聯(lián)的Hashes值添加一個(gè)新的字段field2,其值為liu。
    redis 127.0.0.1:6379> hset myhash field2 "liu"
    (integer) 1
    #獲取myhash鍵的字段數(shù)量。
    redis 127.0.0.1:6379> hlen myhash
    (integer) 2
    #判斷myhash鍵中是否存在字段名為field1的字段,由于存在,返回值為1。
    redis 127.0.0.1:6379> hexists myhash field1
    (integer) 1
    #刪除myhash鍵中字段名為field1的字段,刪除成功返回1。
    redis 127.0.0.1:6379> hdel myhash field1
    (integer) 1
    #再次刪除myhash鍵中字段名為field1的字段,由于上一條命令已經(jīng)將其刪除,因?yàn)闆]有刪除,返回0。
    redis 127.0.0.1:6379> hdel myhash field1
    (integer) 0
    #判斷myhash鍵中是否存在field1字段,由于上一條命令已經(jīng)將其刪除,因?yàn)榉祷?。
    redis 127.0.0.1:6379> hexists myhash field1
    (integer) 0
    #通過hsetnx命令給myhash添加新字段field1,其值為stephen,因?yàn)樵撟侄我呀?jīng)被刪除,所以該命令添加成功并返回1。
    redis 127.0.0.1:6379> hsetnx myhash field1 stephen
    (integer) 1
    #由于myhash的field1字段已經(jīng)通過上一條命令添加成功,因?yàn)楸緱l命令不做任何操作后返回0。
    redis 127.0.0.1:6379> hsetnx myhash field1 stephen
    (integer) 0

2. HINCRBY:

 #刪除該鍵,便于后面示例的測(cè)試。
    redis 127.0.0.1:6379> del myhash
    (integer) 1
    #準(zhǔn)備測(cè)試數(shù)據(jù),該myhash的field字段設(shè)定值1。
    redis 127.0.0.1:6379> hset myhash field 5
    (integer) 1
    #給myhash的field字段的值加1,返回加后的結(jié)果。
    redis 127.0.0.1:6379> hincrby myhash field 1
    (integer) 6
    #給myhash的field字段的值加-1,返回加后的結(jié)果。
    redis 127.0.0.1:6379> hincrby myhash field -1
    (integer) 5
    #給myhash的field字段的值加-10,返回加后的結(jié)果。
    redis 127.0.0.1:6379> hincrby myhash field -10
    (integer) -5

3. HGETALL/HKEYS/HVALS/HMGET/HMSET:

   #刪除該鍵,便于后面示例測(cè)試。
    redis 127.0.0.1:6379> del myhash
    (integer) 1
    #為該鍵myhash,一次性設(shè)置多個(gè)字段,分別是field1 = "hello", field2 = "world"。
    redis 127.0.0.1:6379> hmset myhash field1 "hello" field2 "world"
    OK
    #獲取myhash鍵的多個(gè)字段,其中field3并不存在,因?yàn)樵诜祷亟Y(jié)果中與該字段對(duì)應(yīng)的值為nil。
    redis 127.0.0.1:6379> hmget myhash field1 field2 field3
    1) "hello"
    2) "world"
    3) (nil)
    #返回myhash鍵的所有字段及其值,從結(jié)果中可以看出,他們是逐對(duì)列出的。
    redis 127.0.0.1:6379> hgetall myhash
    1) "field1"
    2) "hello"
    3) "field2"
    4) "world"
    #僅獲取myhash鍵中所有字段的名字。
    redis 127.0.0.1:6379> hkeys myhash
    1) "field1"
    2) "field2"
    #僅獲取myhash鍵中所有字段的值。
    redis 127.0.0.1:6379> hvals myhash
    1) "hello"
    2) "world"

The above is the Redis tutorial (4): Hashes data type For more related content, please pay attention to the PHP Chinese website (m.miracleart.cn)!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Laravel8 optimization points Laravel8 optimization points Apr 18, 2025 pm 12:24 PM

Laravel 8 provides the following options for performance optimization: Cache configuration: Use Redis to cache drivers, cache facades, cache views, and page snippets. Database optimization: establish indexing, use query scope, and use Eloquent relationships. JavaScript and CSS optimization: Use version control, merge and shrink assets, use CDN. Code optimization: Use Composer installation package, use Laravel helper functions, and follow PSR standards. Monitoring and analysis: Use Laravel Scout, use Telescope, monitor application metrics.

How to use the Redis cache solution to efficiently realize the requirements of product ranking list? How to use the Redis cache solution to efficiently realize the requirements of product ranking list? Apr 19, 2025 pm 11:36 PM

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

What should I do if the Redis cache of OAuth2Authorization object fails in Spring Boot? What should I do if the Redis cache of OAuth2Authorization object fails in Spring Boot? Apr 19, 2025 pm 08:03 PM

In SpringBoot, use Redis to cache OAuth2Authorization object. In SpringBoot application, use SpringSecurityOAuth2AuthorizationServer...

Recommended Laravel's best expansion packs: 2024 essential tools Recommended Laravel's best expansion packs: 2024 essential tools Apr 30, 2025 pm 02:18 PM

The essential Laravel extension packages for 2024 include: 1. LaravelDebugbar, used to monitor and debug code; 2. LaravelTelescope, providing detailed application monitoring; 3. LaravelHorizon, managing Redis queue tasks. These expansion packs can improve development efficiency and application performance.

Laravel environment construction and basic configuration (Windows/Mac/Linux) Laravel environment construction and basic configuration (Windows/Mac/Linux) Apr 30, 2025 pm 02:27 PM

The steps to build a Laravel environment on different operating systems are as follows: 1.Windows: Use XAMPP to install PHP and Composer, configure environment variables, and install Laravel. 2.Mac: Use Homebrew to install PHP and Composer and install Laravel. 3.Linux: Use Ubuntu to update the system, install PHP and Composer, and install Laravel. The specific commands and paths of each system are different, but the core steps are consistent to ensure the smooth construction of the Laravel development environment.

Redis's Role: Exploring the Data Storage and Management Capabilities Redis's Role: Exploring the Data Storage and Management Capabilities Apr 22, 2025 am 12:10 AM

Redis plays a key role in data storage and management, and has become the core of modern applications through its multiple data structures and persistence mechanisms. 1) Redis supports data structures such as strings, lists, collections, ordered collections and hash tables, and is suitable for cache and complex business logic. 2) Through two persistence methods, RDB and AOF, Redis ensures reliable storage and rapid recovery of data.

How to configure slow query log in centos redis How to configure slow query log in centos redis Apr 14, 2025 pm 04:54 PM

Enable Redis slow query logs on CentOS system to improve performance diagnostic efficiency. The following steps will guide you through the configuration: Step 1: Locate and edit the Redis configuration file First, find the Redis configuration file, usually located in /etc/redis/redis.conf. Open the configuration file with the following command: sudovi/etc/redis/redis.conf Step 2: Adjust the slow query log parameters in the configuration file, find and modify the following parameters: #slow query threshold (ms)slowlog-log-slower-than10000#Maximum number of entries for slow query log slowlog-max-len

In a multi-node environment, how to ensure that Spring Boot's @Scheduled timing task is executed only on one node? In a multi-node environment, how to ensure that Spring Boot's @Scheduled timing task is executed only on one node? Apr 19, 2025 pm 10:57 PM

The optimization solution for SpringBoot timing tasks in a multi-node environment is developing Spring...

See all articles