Açıklaması şöyle
Redis Hashes offer built-in functionality for sorting and searching data, making it easy to find specific data points or organize data based on certain criteria.Redis Hashes offers transaction support, allowing you to perform multiple operations on data in a single transaction, ensuring consistency and reducing the risk of data corruption.Redis Hashes are highly reliable, with built-in data replication and backup features to ensure that your data is always available and recoverable in the event of a failure.Redis Hashes offer built-in security features, including support for SSL/TLS encryption and password authentication, making it a secure solution for applications that handle sensitive data.
1. HSET
Açıklaması şöyle
The HSET command sets the value of a field in a hash. If the field does not exist, it creates a new field and sets its value. If the field already exists, it overwrites its value.
Örnek
Şöyle yaparız. This command sets the name of user1 to “John”.
HSET user1 name "John"
2. HGET
Açıklaması şöyle
The HGET command gets the value of a field in a hash. If the field exists, it returns its value. If the field does not exist, it returns nil.
Açıklaması şöyle
The HMSET command sets multiple fields in a hash.
Örnek
Şöyle yaparız. This command sets the name, email, and age of user1.
HMSET user1 name "John" email "john@example.com" age 30
4. HMGET
Açıklaması şöyle
The HMGET command gets the values of multiple fields in a hash.
Örnek
Şöyle yaparız. This command gets the name, email, and age of user1.
HMGET user1 name email age
5. HDEL
Açıklaması şöyle
The HDEL command deletes one or more fields in a hash.
Açıklaması şöyle
The HEXISTS command checks if a field exists in a hash.
Örnek
Şöyle yaparız. This command checks if the name field exists in user1.
HEXISTS user1 name
7. HKEYS
Açıklaması şöyle
The HKEYS command gets all the keys in a hash.
Açıklaması şöyle
The HVALS command gets all the values in a hash.
Açıklaması şöyle
The HLEN command gets the number of fields in a hash.
Açıklaması şöyle
The HINCRBY command increments the value of a field in a hash by a specified amount.
Örnek
Şöyle yaparız. This command increments the age of the user1 by 5.
HINCRBY user1 age 5
11. HINCRBYFLOAT
Açıklaması şöyle
This command increments the value of a floating-point field in a hash by a specified amount.
Örnek
Şöyle yaparız. This command increments the weight of user1 by 2.5
HINCRBYFLOAT user1 weight 2.5
Örnek
Şöyle yaparız
// create a Redis Hash named “customer1” using the HMSET HMSET customer1 name "John Doe" email "johndoe@example.com" address "123 Main St" phone "555-1234" orders "5" // use the HGET command to get the name and email of the customer HGET customer1 name //Output: “John Doe” HGET customer1 email // Output: “johndoe@example.com” // use the HSET command to update the phone number of the customer HSET customer1 phone "555-5678" // use the HINCRBY command to increment the order count for the customer HINCRBY customer1 orders 1 // se the HMGET command to get the customer’s address and order history HMGET customer1 address orders // Output: [“123 Main St”, “6”] // use the HDEL command to delete the customer’s phone number HDEL customer1 phone // use the HEXISTS command to check if a field exists in the customer1 hash HEXISTS customer1 email // Output: 1 (true) HEXISTS customer1 phone // Output: 0 (false)
Hiç yorum yok:
Yorum Gönder