- What's New
- Function Overview
- Product Bulletin
- Service Overview
-
GeminiDB Redis API
- Service Overview
- Billing
- Getting Started with GeminiDB Redis API
-
Working with GeminiDB Redis API
- Permission Management
- Buying a GeminiDB Redis Instance
-
Instance Connection and Management
- Connection Methods
- Connecting to a GeminiDB Redis Instance on the DAS Console
- Connecting to a GeminiDB Redis Instance Over a Private Network
- Connecting to a GeminiDB Redis Instance Over a Public Network
-
Connection Information Management
- Configuring a Private Domain Name for a GeminiDB Redis Instance
- Configuring a Public Domain Name for a GeminiDB Redis Instance
- Configuring Security Group Rules for a GeminiDB Redis Instance
- Viewing the IP Address and Port Number of a GeminiDB Redis Instance
- Binding an EIP to a GeminiDB Redis Instance
- Encrypting Data over SSL for a GeminiDB Redis Instance
- Connecting a GeminiDB Redis Instance over SSL
- Changing the Security Group of a GeminiDB Redis Instance
- Configuring Private Network Access to a GeminiDB Redis Instance
-
Data Migration
- Overview of the Redis Data Migration Solution
- (Recommended) Using DRS to Migrate Data from a GeminiDB Redis Instance to an Open-Source Redis Instance
- Migrating the Alibaba Cloud Database Redis/Tair To GeminiDB Redis
- (Recommended) Using DRS to Migrate Data from Open-source Redis or Redis Cluster to GeminiDB Redis API
- Migrating Data from Open-source Redis to GeminiDB Redis API Using Redis-Shake
- Using Redis-Shake to Import an RDB or AOF File to a GeminiDB Redis Instance
- (Recommended) Importing Data to Restore RDB Files to a GeminiDB Redis Instance
- From Kvrocks to GeminiDB Redis API
- From Pika to GeminiDB Redis API
- From SSDB to GeminiDB Redis API
- From LevelDB to GeminiDB Redis API
- From Kvrocks to GeminiDB Redis API
- Migration from an AWS ElastiCache for Redis Database to a GeminiDB Redis Instance
- Verifying Redis Data Consistency After Migration
- Instance Management
-
Modifying Instance Settings
- Upgrading a Minor Version
- Modifying a GeminiDB Redis Instance Name
- Changing the Administrator Password of a GeminiDB Redis Database
- Changing the CPU and Memory Specifications of an Instance
- Setting a Maintenance Window
- Scaling Instances
- Scaling Disk Space
- Performing a Primary/Standby Switchover for GeminiDB Redis Instances
- Data Backup
- Data Restoration
- Diagnosis Analysis
- Account and security
-
Parameter Management
- Modifying Parameters of GeminiDB Redis Instances
- Creating a Parameter Template
- Viewing Parameter Change History
- Exporting a Parameter Template
- Comparing Parameter Templates
- Replicating a Parameter Template
- Resetting a Parameter Template
- Applying a Parameter Template
- Viewing Application Records of a Parameter Template
- Modifying the Description of a Parameter Template
- Deleting a Parameter Template
- Logs and Audit
- Viewing Metrics and Configuring Alarms
- Tag Management
- Quota
- MySQL Memory Acceleration
-
Development Reference
- Development and O&M Rules
- Compatible Commands
-
Examples of Connecting to an Instance Using Programming Languages
- Connecting to an Instance Using Jedis
- Connecting to an Instance Using Redisson
- Connecting to an Instance Using Hiredis
- Connecting to an Instance Using Node.js
- Connecting to an Instance Using PHP
- Connecting to an Instance Using Python
- Connecting to an Instance Using Go
- Connecting to an Instance Using C#
- Connecting to an Instance Using Sentinel
- Lua Script Compilation Specifications
- Keyspace Notification
- EXHASH Commands
- Large Bitmap Initialization
- Configuring Parameters for a Client Connection Pool
- Using Parallel SCAN to Accelerate Full Database Scanning
- Accessing a GeminiDB Redis Instance Using a Pipeline
- Processing Transactions on a GeminiDB Redis Instance
- Retry Mechanism for GeminiDB Redis Clients
- GeminiDB Redis API Pub/Sub
- Implementing Distributed Locks Using Lua Scripts for GeminiDB Redis API
- Best Practices
- Performance White Paper
-
FAQs
-
About GeminiDB Redis API
- What Are the Differences Between GeminiDB Redis API, Open-Source Redis, and Other Open-Source Redis Cloud Services?
- How Is the Performance of GeminiDB Redis API Compared with Open-Source Redis?
- What Redis Versions and Commands Are Compatible with GeminiDB Redis API? Whether Application Code Needs to Be Refactored for Connecting to a Redis Client?
- Can Data Be Migrated from a Self-Built Redis Instance to a GeminiDB Redis Instance? What Are the Precautions?
- What Is the Availability of a GeminiDB Redis Instance?
- Are Total Memory and Total Capacity of a GeminiDB Redis Instance the Same? What Is the Relationship Between Memory and Capacity?
- How Do I Select Proper Node Specifications and Node Quantity When Purchasing a GeminiDB Redis Instance?
- Is a Primary/Standby or Cluster Deployment Mode Preferred for GeminiDB Redis Instances with Several GB of Storage Space?
- How Does GeminiDB Redis API Persist Data? Will Data Be Lost?
- What Is the Memory Eviction Policy of GeminiDB Redis API?
- Does GeminiDB Redis API Support Modules Such as a Bloom Filter?
- Billing
-
Database Usage
- Why Is the Key Not Returned Using Scan Match?
- How Do I Process Existing Data Shards After Migrating Workloads to GeminiDB Redis API?
- Does GeminiDB Redis API Support Fuzzy Queries Using KEYS?
- Does the GeminiDB Redis API Support Multiple Databases?
- Why the Values Returned by Scan Operations Are Different Between GeminiDB Redis API and Open-Source Redis 5.0?
- Why Are Error Messages Returned by Some Invalid Commands Different Between GeminiDB Redis API and Open-Source Redis 5.0?
- How Do I Resolve the Error "CROSSSLOT Keys in request don't hash to the same slot"?
- How Many Commands Can Be Contained in a GeminiDB Redis Transaction?
- Which Commands Require Hash Tags in GeminiDB Redis Cluster Instances?
- What Do I Do If the Error "ERR Unknown Command Sentinel" Is Displayed?
- Why Return Values of Blocking Commands Differ Between Primary/Standby GeminiDB Redis Instances and Open-Source Redis Instances?
- How Long Does It Take to Scale Up GeminiDB Redis Instance Storage? Will Services Be Affected?
- How Long Does It Take to Add GeminiDB Redis Nodes at the Same Time? What Are the Impacts on Services?
- What Are the Differences Between Online and Offline Specification Changes of GeminiDB Redis Nodes? How Long Will the Changes Take? What Are the Impacts on Services?
- What Are the Differences Between Online and Offline Patch Installation of GeminiDB Redis Nodes? How Long Will the Upgrades Take? What Are the Impacts on Services?
- Can I Download Backups of a GeminiDB Redis Instance to a Local PC and Restore Data Offline?
- What Is the Data Backup Mechanism of GeminiDB Redis API? What Are the Impacts on Services?
- Why Does the CPU Usage Remain High Despite Low Service Access Volume on a GeminiDB Redis Preferential Instance with 1 CPU and 2 Nodes?
- Why Does the Number of Keys Decrease and Then Become Normal on the Monitoring Panel on the GUI of GeminiDB Redis API?
- Why Is CPU Usage of GeminiDB Redis Nodes Occasionally High?
- How Do I Upgrade GeminiDB Redis API from 5.0 to 6.2?
- When Does a GeminiDB Redis Instance Become Read-Only?
-
Database Connection
- How Do I Connect to a GeminiDB Redis Instance?
- How Do I Use Multiple Node IP Addresses Provided by GeminiDB Redis API?
- How Does Load Balancing Work in GeminiDB Redis API?
- How Can I Create and Connect to an ECS?
- Can I Change the VPC of a GeminiDB Redis Instance?
- Why Can't I Connect to the Instance After an EIP Is Bound to It?
- How Do I Access a GeminiDB Redis Instance from a Private Network?
- Do I Need to Enable Private Network Access Control for a Load Balancer After Setting a Security Group?
- What Should I Do If the Client Connection Pool Reports Error " Could not get a resource from the pool"?
- Common Client Errors and Troubleshooting Methods
- Backup and Restoration
- Regions and AZs
-
Data Migration
- What Do I Do if the GeminiDB Redis Link Cannot Be Found on DRS?
- What Do I Do if the Error "ERR the worker queue is full, and the request cannot be executed" Is Displayed?
- What Do I Do If the Error "ERR the request queue of io thread is full, and the request cannot be executed" Is Displayed?
- What Do I DO If the Error "read error, please check source redis log or network" Is Displayed?
- What Do I Do If the Error "slaveping_thread.cc-ThreadMain-90: error: Ping master error" Is Displayed?
- What Do I Do If the Forward Migration Speed of the Synchronization Status Is Too Slow?
- What Do i Do When the Forward Migration Speed of the Synchronization Status Is Too Fast, and the Error Message "ERR Server Reply Timeout, Some Responses May Lose, but Requests Have Been Executed" Is Displayed?
- Can Data Be Migrated from Self-Built Redis 4.0, 5.0, and 6.2 to GeminiDB Redis API?
- How Do I Migrate Data from Self-Built Primary/Standby and Cluster Redis Instances to GeminiDB Redis Instances?
- Why Cannot DRS Migrate Data from Third-Party Redis Such as ApsaraDB for Redis and TencentDB for Redis?
- Which of the Following Factors Need to Be Considered When Data Is Migrated from Self-Built Primary/Standby Redis Instances to a GeminiDB Redis cluster?
- Only 20% to 30% of 100 GB of Data Was Migrated to GeminiDB Redis. Is the Migration Incomplete?
-
Memory Acceleration
- Will All Data Be Cached to GeminiDB Redis Instances After Memory Acceleration Is Enabled and MySQL Database Data Is Updated?
- If Memory Acceleration Is Enabled, GeminiDB Redis Instance Data Increases Continuously. Do I Need to Scale Out the Capacity? How Do I Manage Cached Data?
- Is Memory Acceleration Recommended When Customers' Service Data Can Be Synchronized Between MySQL and Redis? In Which Scenarios Can Memory Acceleration Be enabled?
- How Long Is the Latency of Synchronization from RDS for MySQL to GeminiDB Redis API? What Factors Affect the Latency?
- Will the Source MySQL Database Be Affected After Memory Acceleration Is Enabled?
- GeminiDB Redis Instances with Memory Acceleration Enabled Needs to Process a Large Number of Binlogs in a Short Period of Time. Will a Large Number of Resources Be Occupied and Online Services Be Affected?
- Instance Freezing, Release, Deletion, and Unsubscription
-
About GeminiDB Redis API
-
GeminiDB Influx API
- Service Overview
- Billing
- Getting Started with GeminiDB Influx API
-
Working with GeminiDB Influx API
- Permissions Management
- Buying an Instance
- Connecting to an Instance
- Instance Lifecycle Management
- Instance Modifications
- Migrating Data
- Database Commands
- Cold and Hot Data Separation
- Certificate Management
- Data Backup
- Data Restoration
- Exporting Data
-
Parameter Template Management
- Creating a Parameter Template
- Modifying Parameters of GeminiDB Influx Instances
- Viewing Parameter Change History
- Exporting a Parameter Template
- Comparing Parameter Templates
- Replicating a Parameter Template
- Resetting a Parameter Template
- Applying a Parameter Template
- Viewing Application Records of a Parameter Template
- Modifying a Parameter Template Description
- Deleting a Parameter Template
- Log Management
- Monitoring and Alarm Reporting
- CTS
- Managing Tags
- Quotas
- Best Practices
- Performance White Paper
-
FAQs
-
Product Consulting
- What Do I Need to Note When Using GeminiDB Influx API?
- What Does the Availability of GeminiDB Influx Instances Mean?
- Can GeminiDB Influx API Convert Multiple Columns to Multiple Rows?
- How Much Data Can a GeminiDB Influx Instance Hold?
- Can I Access GeminiDB Influx Instances Using Grafana?
- How Do I Use GeminiDB Influx Hints?
- What Do I Do If Error "select *" query without time range is not allowed Is Reported?
- What Do I Do If the Error Message "ERR: Max-select-series Limit Exceeded" Is Displayed?
- What Do I Do If "delete is forbidden" Is Reported?
- Billing
- Database Connection
- Backup and Restoration
- Regions and AZs
- Instance Freezing, Release, Deletion, and Unsubscription
-
Product Consulting
-
GeminiDB Cassandra API
- Service Overview
- Billing
- Getting Started with GeminiDB Cassandra API
-
Working with GeminiDB Cassandra API
- Permissions Management
- Buying a GeminiDB Cassandra Instance
-
Instance Connection and Management
- Connection Methods
- Connecting to a GeminiDB Cassandra Instance on the DAS Console
- Connecting to a GeminiDB Cassandra Instance over a Private Network
- Connecting to a GeminiDB Cassandra Instance over a Public Network
- Connecting to a GeminiDB Cassandra Instance Using Java
- Connecting to a GeminiDB Cassandra Instance Using Go
- Connecting to a GeminiDB Cassandra Instance Using Spark
-
Connection Information Management
- Setting Security Group Rules for a GeminiDB Cassandra Instance
- Binding an EIP to a GeminiDB Cassandra Instance
- Viewing the IP Address and Port Number of a GeminiDB Cassandra Instance
- Changing the Port of a GeminiDB Cassandra Instance
- Changing the Security Group of a GeminiDB Cassandra Instance
- Encrypting Data over SSL for a GeminiDB Cassandra Instance
- Downloading the SSL Certificate
- Data Migration
- Instance Lifecycle Management
- Instance Modifications
- Intra-region DR
- Cross-region Dual-active DR
- Data Backup
- Data Restoration
-
Parameter Management
- Modifying Parameters of GeminiDB Cassandra Instances
- Creating a Parameter Template
- Viewing Parameter Change History
- Exporting a Parameter Template
- Comparing Parameter Templates
- Replicating a Parameter Template
- Resetting a Parameter Template
- Applying a Parameter Template
- Viewing Application Records of a Parameter Template
- Modifying a Parameter Template Description
- Deleting a Parameter Template
- Log and Audit
- Viewing Metrics and Configuring Alarms
- Enterprise Project
- Managing GeminiDB Cassandra Instance Tags
- Managing User Resource Quotas of a GeminiDB Cassandra Instance
- Best Practices
- Performance White Paper
-
FAQs
- Product Consulting
- Billing
-
Database Usage
- Why Does the Overall Instance Performance Deteriorate When QPS Increases After the Batch Size Is Decreased?
- What Can I Do if Error "field larger than field limit (131072)" Is Reported During Data Import?
- What Should I Pay Attention to When Creating a GeminiDB Cassandra Table?
- How Do I Detect and Resolve BigKey and HotKey Issues?
- How Do I Set Up a Materialized View?
- How Do I Use a Secondary Index?
- How Can I Use the Search Index of Lucene?
- How Do I Set Paging Query with Java?
- How Do I Set Paging Query with Python?
- Database Connection
- Backup and Restoration
- Regions and AZs
- Instance Freezing, Release, Deletion, and Unsubscription
- GeminiDB (DynamoDB API Compatible) Instance
- HBase-Compatible Instance
-
GeminiDB Mongo API
- Service Overview
- Billing
- Getting Started with GeminiDB Mongo API
-
Working with GeminiDB Mongo API
- Permissions Management
- Migrating Data
- Instance Lifecycle
- Instance Modifications
- Connections
- Database Commands
- Data Backup
- Data Restoration
-
Parameter Template Management
- Creating a Parameter Template
- Modifying Parameters of GeminiDB Mongo Instances
- Viewing Parameter Change History
- Exporting a Parameter Template
- Comparing Parameter Templates
- Replicating a Parameter Template
- Resetting a Parameter Template
- Applying a Parameter Template
- Viewing Application Records of a Parameter Template
- Modifying a Parameter Template Description
- Deleting a Parameter Template
- Monitoring and Alarm Configuration
- Audit
- Log Management
- Billing Management
- Quotas
- Best Practices
- Performance White Paper
- FAQs
- Change History
- Technical White Paper
-
API Reference
- Before You Start
- API Overview
- Calling APIs
- Quick Start
-
APIs v3 (Recommended)
- API Versions
- Versions and Specifications
-
Instances
- Creating an Instance
- Deleting an Instance
- Querying Instances and Details
- Scaling Up Storage Space of an Instance
- Adding Nodes for an Instance
- Deleting Nodes from a Specified Instance
- Obtaining Sessions of a Node
- Querying Session Statistics of an Instance Node
- Closing Sessions of an Instance Node
- Querying Instance Specifications That Can Be Changed
- Changing Specifications of an Instance
- Resetting the Administrator Password of an Instance
- Editing the Name of an Instance
- Changing the Security Group of an Instance
- Upgrading Minor Version
- Patching Databases in Batches
- Creating Cold Storage
- Scaling Up Cold Storage
- Binding/Unbinding an EIP
- Enabling or Disabling SSL
- Restarting an Instance
- Configuring an Autoscaling Policy for Storage Space
- Changing a Database Port
- Checking Password Strength
- Configuring Access to a Replica Set Across CIDR Blocks
- Deleting the Node that Fails to Be Added
- Querying IP Addresses Required for Creating an Instance or Adding Nodes
- Querying the Autoscaling Policy of Storage Space
- Scaling Storage Space of an Instance
- Querying High-Risk Commands
- Modifying High-Risk Commands
- Querying Hot Keys of a Redis Instance
- Disabling Commands for a Redis Instance
- Querying Disabled Commands for a Redis Instance
- Deleting Disabled Commands for a Redis Instance
- Setting the Maintenance Period of an Instance
- Performing a Primary/Standby Switchover
- Starting or Stopping a Node
- Querying Big Keys of a GeminiDB Redis Instance
- Querying the Password-Free Configuration of a GeminiDB Redis Instance
- Modifying the Password-Free Configuration of a GeminiDB Redis Instance
- Querying the Memory Mapping List and Details
- Creating a Memory Acceleration Rule
- Deleting a Memory Mapping
- Creating a Memory Mapping
- Modifying a Memory Acceleration Rule
- Querying Memory Mapping Rules and Details
- Deleting a Memory Acceleration Rule
- Enabling or Disabling Instance Data Export
- Enabling or Disabling Second-Level Monitoring
- Querying Configurations of Second-Level Monitoring
- Connection Management
-
Backups and Restorations
- Querying Backups
- Querying Backups (Recommended)
- Querying an Automated Backup Policy
- Configuring an Automated Backup Policy
- Querying Instances that Can Be Restored
- Querying the Time Window When a Backup Can Be Restored
- Creating a Manual Backup
- Deleting a Manual Backup
- Restoring Data to an Existing Instance
- Querying the Recycling Policy
- Modifying the Recycling Policy
- Querying Instances in the Recycle Bin
- Obtaining GeminiDB Cassandra Instance Database Information That Is Restored Using Tables
- Obtaining GeminiDB Cassandra Instance Table Information That Is Restored Using Tables
- Restoring the Current Redis Instance to a Point in Time
- Setting the Policy for Restoring Redis Data to a Specified Time Point
- Querying the Policy for Restoring Redis Data to a Specified Time Point
- Querying the Restoration Time Range of a Redis Instance
- Querying the Storage Space Used for Restoring a Redis Instance to a Specified Time Point
- Stopping a Backup
- Deleting Manual Backups in Batches
-
Parameter Templates
- Obtaining Parameter Templates
- Creating a Parameter Template
- Modifying Parameters in a Parameter Template
- Applying a Parameter Template
- Resetting a Custom Parameter Template
- Modifying Parameters of a Specified Instance
- Querying Instance Parameter Settings
- Obtaining Parameters of a Specified Parameter Template
- Deleting a Parameter Template
- Querying Instances that a Parameter Template Can Be Applied To
- Viewing Parameter Change History of an Instance
- Viewing Application Records of a Parameter Template
- Comparing Parameter Templates
- Replicating a Parameter Template
- Querying API that Support Parameter Templates
- Managing Databases and Accounts
- Tags
-
Logs
- Querying Database Slow Logs
- Querying Slow Query Logs of a GeminiDB Redis Instance
- Querying Slow Query Logs of a GeminiDB Influx Instance
- Querying Slow Query Logs of a GeminiDB Cassandra Instance
- Querying Slow Query Logs of a GeminiDB Mongo Instance
- Querying Database Error Logs
- Querying Error Logs of a GeminiDB Mongo Instance
- Setting the Desensitization Status of Slow Query Logs
- Querying the Desensitization Status of Slow Query Logs
- Associating Instances with an LTS Log Stream
- Disassociating Instances from an LTS Log Stream
- Querying LTS Log Configurations
- Quotas
- Disaster Recovery
- Task Management
- Enterprise Projects
- Instance Load Balancing Management
- API v3 (Unavailable Soon)
- Permission Policies and Supported Actions
- Appendixes
- SDK Reference
- Videos
- General Reference
Copied.
EXHASH for Ad Frequency Control
EXHASH, a hash data type, provides general HASH functions and allows you to specify expiration times and version numbers for fields. It supports flexible data structures and can help you simplify service development in various scenarios.
This section describes how to use EXHASH commands of GeminiDB Redis API to simplify service development of frequency control and shopping cart.
EXHASH Commands
For details, see EXHASH commands.
Scenarios
- Frequency control
Frequency control allows users to restrict the number of operations performed within a certain period (for example, one day, one week, or one month), and limit the number of times an ad or information displayed on a platform within a specified period. This helps prevent overexposure and ad fatigue, optimizes ad performance, improves the conversion rate, and avoid malicious activities, such as manipulating online traffic, comments and likes.
Frequency control involves three elements: user ID (key), ad ID (field), and the number of times an activity is triggered (value). You can configure frequency control policies for an ad by referring the figure below.
Figure 1 HASH solution- HASH solution 1 makes it easy to implement frequency control. You can use the EXPIRE command to set the expiration time of User_1 to one day and the HINCRBY command to increase how many times an ad is pushed. Before each ad push, you can use HGET to obtain this number. Data is retained for one day and then is automatically deleted. However, you can set only one expiration time for each user (each key). Flexible frequency control policies cannot be set for a specified period, for example, three pushes within eight hours.
- HASH solution 2 allows you to splice timestamps into the value and use the HASH command to implement flexible frequency control. However, it increases the workload of service development.
- The EXHASH solution allows you to set the expiration time for fields. In the frequency control scenario, GeminiDB Redis API allows you to configure a different push frequency for each ad and in different time segments. Assume that the frequency control policy configured for AD_2 is twice within 8 hours. Before pushing AD_2 to User_1, you can obtain the value 2 by running the EXHGET command, AD_2 will not be pushed to User_1 any more. After eight hours, the field for User_1 expires and the field information cannot be obtained by EXHGET. In this case, AD_2 will be pushed to User_1 again.
- Shopping cart
The following describes and compares several Redis solutions in the shopping cart scenario.
- STRING solution
The shopping cart works easily with STRING commands. The platform combines the user ID and item ID as a key, for example, User_1#Earphones_1. The key value is the number of items to be purchased. There is an expiration time for items on flash sales.
Figure 2 STRING solution- Related commands
incrby User_N#Product_N [Number] #Increases the product quantity. set User_N#Product_N [Number] #Sets the product quantity. expire User_N#Product_N Time_N # Sets the expiration time of a specified item in the shopping cart of a specified user. get User_N#Product_N #Obtains the product quantity. scan 0 match User_N* # Queries all items of User_N. del User_N#Product_N #Deletes a specified item from the shopping cart of a specified user.
- Possible issues are as follows:
- Extra splicing increases the encoding and decoding development workload.
- When a user requests to obtain the shopping item list, the SCAN command prefix is used to scan all keys and the GET command is used to obtain the corresponding value.
- To obtain the list length, the number of prefix keys should be scanned.
- There are a large number of duplicate username prefixes occupying the storage space.
- Related commands
- HASH solution
This solution uses the user ID as the key and the item ID as the field. The value indicates the number of the item in the shopping cart. For items in flash sales, the expiration time is combined to the value of the field.
Figure 3 HASH solution- Related commands
hset User_N Product_N [Number#Time_N] # Sets the quantity and expiration time of a specified item in the shopping cart of a specified user. hincrby User_N Product_N [Number] # Adds the number of a specified item to the shopping cart of a specified user. hgetUser_N Product_N # Obtains information about a specified item in the shopping cart of a specified user. hgetall User_N #Obtains all item information of a specified user. hlen User_N # Obtains the number of items in the shopping cart of a specified user. hdel User_N Product_N #Deletes a specified item from the shopping cart of a specified user.
- This solution is better than the STRING solution in the following ways:
- Only one HGETALL command is required to obtain the shopping cart list of a user.
- The HLEN command can be used to obtain the item list length of a user.
- There are few duplicate username prefixes.
However, the solution is complex for processing items in flash sales. For example, If the quantity for Keyboard_1 of User_1 needs to be added instead of using the HINCRBY command directly, you should obtain the value of Keyboard_1 by executing the HGET command first and decode the value. Then, specify the quantity to be added and encode the value using HSET.
- Related commands
- EXHASH solution
Similar to the HASH solution, the user ID is used as the key, the item ID is used as the field, and the value is the number of the item in the shopping cart. This solution allows you to set an expiration time for items in flash sales by running the HSET command.
Figure 4 EXHASH solution- Related commands
exhset User_N Product_N ex Time_N # Sets the quantity and expiration time of a specified item in the shopping cart of a specified user. exhincrby User_N Product_N [Number] keepttl # Increases the number of specified items in the shopping cart of a specified user and retain the original expiration time. exhget User_N Product_N #Obtains information about specified items in the shopping cart of a specified user. exhgetall User_N #Obtains all item information of a specified user. exhlen User_N # Obtains the number of items in the shopping cart of a specified user. exhdel User_N Product_N #Deletes a specified item from the shopping cart of a specified user. del User_N #Empties the shopping cart of a specified user.
- Compared with the HASH solution, this solution allows you to set the expiration time for each field. The EXHASH command makes it easy to use and reconstruct on the service side.
- Related commands
- STRING solution
Code Example for Ad Frequency Control
import redis import datetime import os def get_cur_time(): return "[" + datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3] + "]" def get_redis(): """ This method is used to connect to a Redis instance. * host: Instance connection address. * port: Port of the instance. The default value is 6379. * password: Password for connecting to the instance. """ # There will be security risks if the username and password used for authentication are directly written into code. Store the username and password in ciphertext in the configuration file or environment variables. # In this example, the username and password are stored in the environment variables. Before running this example, set environment variables EXAMPLE_USERNAME_ENV and EXAMPLE_PASSWORD_ENV as needed. password = os.getenv('EXAMPLE_PASSWORD_ENV') return redis.Redis(host='***', port=6379, password=password) ''Global frequency control policy. Display ad 1 for up to 2 times within three seconds and ad 2 for five times within five seconds. frequency_stratege = {"ad_1" : [2, 3], "ad_2" : [5, 5]} def push_ad_to_user(userId: str, adId: str): ''' This method is used to push a specified ad to a specified user. * userId: User ID. * adId: Ad ID. ''' # If no frequency control policies are set for an ad, directly push the ad to the user. if adId not in frequency_stratege: print("no need control frequency, push ", adId, "to", userId) return True # Obtain how many times an ad is pushed for a user by user ID and ad ID. # Command usage: EXHGET key field. cnt = get_redis().execute_command("EXHGET " + userId + " " + adId) # If an ad has not been pushed to a user, directly push the ad to the user. if cnt == None: # Command usage: EXHINCRBY key field num [EX time]. # Usage description: EXHINCRBY User ID Ad ID Push times (1) Expiration time of the ad cmd = "EXHINCRBY " + userId + " " + adId + " 1 EX " + str(frequency_stratege[adId][1]) cur_cnt = get_redis().execute_command(cmd) print(get_cur_time(),"push", adId, "to", userId, "first time during", str(frequency_stratege[adId][1]), "seconds") return True # The result returned from Redis Python client is in bytes. Convert the result to a string and then to an integer. cnt = int(cnt.decode("utf-8")) if cnt < frequency_stratege[adId][0]: # Command usage: EXHINCRBY key field num KEEPTTL Retain the original expiration time of the field. cmd = "EXHINCRBY " + userId + " " + adId + " 1 KEEPTTL" cur_cnt = get_redis().execute_command(cmd) print(get_cur_time(), "push", adId, "to", userId, "current cnt:", cur_cnt) return True print(get_cur_time(), "Control frequency, can't push", adId, "to", userId, ", max cnt:", frequency_stratege[adId][0]) return False if __name__ == "__main__": for i in range(3): push_ad_to_user("usr_1", "ad_1") for i in range(6): push_ad_to_user("usr_1", "ad_2") for i in range(3): push_ad_to_user("usr_1", "ad_1") for i in range(12): push_ad_to_user("usr_1", "ad_2")
The script output is as follows:
The Python script executes slowly, and the expiration time of ad 2 is set to 5 seconds. Ad 2 can thus be successfully pushed to the user at December 15, 2023 07:09:56.530, 5 seconds after the first push time of December 15, 2023 07:09:51.349.
[2023-12-15 07:09:50.086] push ad_1 to usr_1 first time during 3 seconds [2023-12-15 07:09:50.503] push ad_1 to usr_1 current cnt: 2 [2023-12-15 07:09:50.794] Control frequency, can't push ad_1 to usr_1 , max cnt: 2 [2023-12-15 07:09:51.349] push ad_2 to usr_1 first time during 5 seconds [2023-12-15 07:09:51.745] push ad_2 to usr_1 current cnt: 2 [2023-12-15 07:09:52.128] push ad_2 to usr_1 current cnt: 3 [2023-12-15 07:09:52.889] push ad_2 to usr_1 current cnt: 4 [2023-12-15 07:09:53.417] push ad_2 to usr_1 current cnt: 5 [2023-12-15 07:09:53.632] Control frequency, can't push ad_2 to usr_1 , max cnt: 5 [2023-12-15 07:09:54.120] push ad_1 to usr_1 first time during 3 seconds [2023-12-15 07:09:54.769] push ad_1 to usr_1 current cnt: 2 [2023-12-15 07:09:54.915] Control frequency, can't push ad_1 to usr_1 , max cnt: 2 [2023-12-15 07:09:55.211] Control frequency, can't push ad_2 to usr_1 , max cnt: 5 [2023-12-15 07:09:55.402] Control frequency, can't push ad_2 to usr_1 , max cnt: 5 [2023-12-15 07:09:55.601] Control frequency, can't push ad_2 to usr_1 , max cnt: 5 [2023-12-15 07:09:55.888] Control frequency, can't push ad_2 to usr_1 , max cnt: 5 [2023-12-15 07:09:56.087] Control frequency, can't push ad_2 to usr_1 , max cnt: 5 [2023-12-15 07:09:56.530] push ad_2 to usr_1 first time during 5 seconds [2023-12-15 07:09:57.133] push ad_2 to usr_1 current cnt: 2 [2023-12-15 07:09:57.648] push ad_2 to usr_1 current cnt: 3 [2023-12-15 07:09:58.107] push ad_2 to usr_1 current cnt: 4 [2023-12-15 07:09:58.623] push ad_2 to usr_1 current cnt: 5 [2023-12-15 07:09:58.865] Control frequency, can't push ad_2 to usr_1 , max cnt: 5 [2023-12-15 07:09:59.096] Control frequency, can't push ad_2 to usr_1 , max cnt: 5
This section describes the features, usage, and application scenarios of the EXHASH command provided by GeminiDB Redis API. EXHASH provides a similar syntax to the native Redis HASH and the use is isolated from that of HASH. It allows you to specify expiration times and version numbers for fields. GeminiDB Redis API is dedicated to developing more easy-to-use enterprise-class features, helping customers implement easy O&M and efficiently develop services.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot