Interactive Viewing Experience for the World Cup Using Redis

Interactive Viewing Experience

Business Architecture

Application Scenarios

  1. Session cache
  2. Full Page Cache (FPC)
  3. Mobile phone verification code
  4. Access frequency limit/blacklist/whitelist
  5. Message queueing
  6. Merchandise inventory management
  7. GEO function added with LBS (location-based service) development

Live Chat

RANGEBYSCORE userID:10000:operation:comment 61307510405600 +inf //Get the operation records within 1 minute
Redis> ZADD userID:10000:operation:comment 61307510402300 "This is a comment" //score is timestamp (integer) 1
Redis> ZRANGEBYSCORE userID:10000:operation:comment 61307510405600 +inf //Get the operation records within 1 minute
# KEYS[1] indicates the limited number, passed in by the caller
local key1 ,key2 = 'access:limit' ,'access:expire'
if redis.call('EXISTS' ,key2) > 0 then
return redis.call('DECR' ,key1) ;
else
redis.call('SET' ,key2 ,1)
redis.call('EXPIRE' ,key2 ,60)
redis.call('SET' ,key1 ,KEYS[1])
return KEYS[1]
end

Game Status Live Update

Message Notifications (Number of Unread Messages)

Likes (Number of Likes)

Red Envelope Inventory Management

  1. Small red envelopes are pre-generated and inserted into the database. The user IDs corresponding to the red envelopes are null.
  2. Each big red envelope corresponds to two Redis queues, one is for the unconsumed red envelopes, and the other is for the consumed red envelopes. At the beginning, all small red envelopes are put into the unconsumed red envelope queue. The unconsumed red envelope queue is a Json string, the activeID is the game number, the money is the red envelope amount, and the product is the number of products. For example: {activeId:’16', money:’300'} or {activeID:’16',product:’50'}
  3. Use a map in Redis to filter users who have already snatched a red envelope.
  4. When a user snatches the red envelope, first determine whether or not the user has already snatched a red envelope. If not, then take a small red envelope from the unconsumed red packet queue, then push it to the other queue, and finally put the user ID into the deduplicated map.
  5. Use a single thread to batch take the red envelopes from the consumed queue, and then batch update the user IDs of the red envelopes in the database.
-- Function: Try to get the red envelope, if it succeeds, return the Json string; if not, return null
-- Parameters: red envelope queue name, consumed queue name , deduplicated map name, user ID
-- Return value: nil or Json string, including user ID: userId, red envelope ID: id, red envelope amount: money
-- If the user has already snatched a red envelope, return nil
if redis.call('hexists', KEYS[3], KEYS[4]) ~= 0 then
return nil
else
-- take a small red envelope
local hongBao = redis.call('rpop', KEYS[1]);
if hongBao then
local x = cjson.decode(hongBao);
-- add user ID information
x['userId'] = KEYS[4];
local re = cjson.encode(x);
-- put the user ID to the deduplicated set
redis.call('hset', KEYS[3], KEYS[4], KEYS[4]);
-- put the red envelope to the consumed queue
redis.call('lpush', KEYS[2], re);
return re;
end
end
return nil

Message Push

High Availability and Elastic Scaling

High Availability: Remote Data Disaster Recovery and Multiple Active Standbys

Elasticity: Resource Scaling, Read/Write Splitting

Summary

About the Author:

--

--

--

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

JMeter Listener Types | Part 1

What is Visual SQL (Pros and Cons)?

DashboardFox Visual SQL

Python Christmas

Draining The Life Out of Computer Science?

Writing a GraphQL Layer in Front of An Existing REST API

Integration of ML Kit into Ionic Application (Face-Related Service) — Part 4

Amazon SQS Industry Case Study…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

More from Medium

Provision a Object Storage cluster with Leaseweb Dedicated Server API

Enable GRPC towards your HTTP/1.1 API

Getting started with Akka Cluster

Akka Cluster Member States

Websocket Connection Using Shared Worker