Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Five data types of redis

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Five data types of redis

Redis client establishment

. / redis-cli-h 192.168.1.22-p 6380-raw

1.String

Application scenarios:

Statistics of the number of website visits, the current number of online people, the number of Weibo, the number of fans, etc., the global incremental ID and so on.

Common commands:

SET key value

GET key

MSET key1 value1 [key2 value2]

MGET key1 key2

INCR key

DECR key

SETNX key value # set the value of key only if key does not exist

2.Hash

Application scenario

Save the user's details. Using ID as key,value is saved in the form of a set of field-value.

Common commands (H)

HSET key field value

HGET key field

HGETALL key

HMSET key field1 value1 [field2 value2]

HMGET key field1 [filed2]

3.List

Application scenario

Get the latest comments list, get the last 10 users logged in, get the number of active users in the last 7 days, etc.

Common commands (LUnix R)

LPUSH key value1 [value2] # inserts one or more values into the list header

LPOP key # moves out and gets the first element of the list

RPUSH key value1 [value2] # add one or more values to the end of the list

RPOP key # remove and get the last element of the list

LREM key count value # remove list elements

LRANGE key start stop # gets the elements within the specified range of the list

4.Set

Application scenario

a. Using uniqueness, you can access the list of active users for the day.

b. Using the set operation, you can take the intersection of different circles of interest, you can take the new users of the day, and so on.

Common commands (S)

SADD key member1 [member2] # add one or more members to the collection

SDIFF key1 [key2] # returns the difference of all given sets

SINTER key1 [key2] # returns the intersection of all given sets

SUNION key1 [key2] # returns the union of all given collections

SISMEMBER key member # determines whether the member element is a member of the collection key

SMEMBERS key # returns all members of the collection

SREM key member1 [member2] # remove one or more members from the collection

5.Sorted Set

Application scenario

Sales ranking, points ranking, timeline, etc.

Common command

ZADD key score1 member1 [score2 member2] # add one or more members to an ordered collection, or update the scores of existing members

ZINCRBY key increment member # add an incremental increment to the score of a specified member in an ordered collection

ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT] # returns the members in the specified interval of the ordered set through the fraction range

ZINTERSTORE destination numkeys key [key...] # calculate the intersection of one or more given ordered sets and store the result set in the new ordered set key

ZUNIONSTORE destination numkeys key [key...] # calculate the union of one or more given ordered sets and store them in the new key

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report