C#redis Hash Hashes

Source: Internet
Author: User

First, foreplay

We can consider the hashes type in Redis as a map container with string key and string value. Therefore, this type is ideal for storing information about value objects. such as username, password, and age. If a hash contains very few fields, the data of that type will take up only a small amount of disk space. Each hash can store 4,294,967,295 key-value pairs.

Second, the theory

command prototype Time complexity command description return value
hset key field value O (1) Sets the field/value pair for the specified key, and if key does not exist, the command creates a new key with the field/value pair in the argument, overwriting its original value with the new value if the field in the argument already exists in the key. 1 indicates that the new field is set with a new value, 0 indicates that field already exists, and overwrites the original value with the new value.
hget key field O (1) Returns the associated value for the specified field in the specified key. Returns the associated value of field in the parameter, or nil if the key or field in the argument does not exist.
hexists key field O (1) Determines whether the specified field in the specified key exists. 1 is present, and 0 indicates that the field or key in the parameter does not exist.
Hlen Key O (1) Gets the number of field that the key contains. Returns the number of field keys contained in the key, or 0 if key does not exist.
hdel key field [field ...] O (N) N In time complexity indicates the number of fields to be deleted in the parameter. Removes the multiple fields specified in the parameter from hashes value of the specified key if the nonexistent field is ignored. If the key does not exist, it is treated as an empty hashes and returns 0. The number of field actually deleted.
hsetnx key field value O (1) A Field/value pair is set for the specified key only if the key or field in the argument does not exist, otherwise the command will not do anything. 1 indicates that the new field is set to a new value, and 0 indicates that the key or field already exists and that the command does nothing.
hincrby key field increment O (1) Increments the value of value that is associated with the specified field in the specified key. If the key or field does not exist, the command creates a new key or a new field, initializes its associated value to 0, and then specifies the operation to increment the number. The number supported by this command is a 64-bit signed integer, which means that increment can be negative. Returns the value after the operation.
Hgetall Key O (N) N In time complexity indicates the number of field numbers that key contains. Gets all the field/value that the key contains. Its return format is a field, a value, and so on. A list of field/value.
Hkeys Key O (N) N In time complexity indicates the number of field numbers that key contains. Returns all fields names for the specified key. A list of field.
hvals Key O (N) N In time complexity indicates the number of field numbers that key contains. Returns all the values for the specified key. The list of value.
hmget key field [field ...] O (N) N In time complexity indicates the number of field requests. Gets a set of values that is associated with the fields specified in the parameter. If the requested field does not exist, its value returns nil. If key does not exist, the command treats it as an empty hash and returns a set of nil. Returns and requests a set of values that are associated with a fields, whose return order is equivalent to the order of fields in the request.
hmset key field value [field value ...] O (N) N in time complexity indicates the number of field sets that are set. Set the Field/value pairs given in the parameters on a per-pair basis. If one of the field already exists, the original value is overwritten with the new value. If key does not exist, create a new key and set the Field/value in the parameter.

Third, the actual exercise

127.0.0.1:6379> Hset201015060132name Cuiyanwei (integer)1127.0.0.1:6379> Hget201015060132name"Cuiyanwei"127.0.0.1:6379> hexists201015060132name (integer)1127.0.0.1:6379> hexists201015060132Age (integer)0127.0.0.1:6379> Hlen201015060132(integer)1127.0.0.1:6379> Hset201015060132Age -(integer)1127.0.0.1:6379> Hlen201015060132(integer)2127.0.0.1:6379> Hdel201015060132Age (integer)1127.0.0.1:6379> Hlem201015060132(Error) ERR unknown command'Hlem'127.0.0.1:6379> Hlen201015060132(integer)1127.0.0.1:6379> hsetnx201015060132name Cuiyan (integer)0127.0.0.1:6379> Hget201015060132name"Cuiyanwei"127.0.0.1:6379> hsetnx201015060132Age -(integer)1127.0.0.1:6379> Hincrby201015060132Age5(integer) -127.0.0.1:6379> Hincrby201015060132Age-5(integer) -127.0.0.1:6379> Hgetall2010150601321)"name"2)"Cuiyanwei"3)" Age"4)" -"127.0.0.1:6379> Hkeys2010150601321)"name"2)" Age"127.0.0.1:6379> hvals2010150601321)"Cuiyanwei"2)" -"127.0.0.1:6379> Hmget201015060132name Age1)"Cuiyanwei"2)" -"127.0.0.1:6379> Hmget201015060132Passworld1) (nil)127.0.0.1:6379> Hmset201015060132Name Cuiyanwei Age -Passworld123456OK127.0.0.1:6379> Hmget201015060132name Age Passworld1)"Cuiyanwei"2)" -"3)"123456"127.0.0.1:6379>

C#redis Hash Hashes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.