Imitation of Weibo social platform system design[2] — Use the hash data structure of Redis to implement the post-like function

Use the hash data structure of Redis to implement the post-like function

Keith
Javarevisited

--

background:

Redis basic data structure

five data structures

These five data structures are STRING (string), LIST (list), SET (set), HASH (hash), ZSET (ordered set);

  • String: including strings, integers, and floating-point numbers;
  • List: a linked list, each node on the linked list is a string, which follows the access format of the queue — first in, first out, that is, inserting from the end of the linked list, and popping the head of the linked list;
  • Collection: It is a container inside, it does not allow the same elements to exist, and each value is unique;
  • Hash: It is an unordered hash table composed of key-value pairs, and its keys are also not allowed to be repeated;
  • Sorted set: Sorted on the basis of the set;

Redis Hset Command

grammar

The basic syntax of the Redis Hset command is as follows:

redis 127.0.0.1:6379> HSET KEY_NAME FIELD VALUE

example

instance
redis 127.0.0.1:6379> HSET myhash field1 "foo"
OK
redis 127.0.0.1:6379> HGET myhash field1
"foo"

redis 127.0.0.1:6379> HSET website google "www.g.cn" #set a new domain
(integer) 1

redis 127.0.0.1:6379>HSET website google "www.google.com" # cover an old domin

The structure design of the like table

Related APIs of redisTemplate:

Java implementation

Why use stringredistemplate?

--

--