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

Introduction of common data types in redis

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

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

Common commands of the String type:

Type key_name: check what type of key is

> help @ STRING # View help of type string

Set key value [EX | NX | XX]: set a key value

EX indicates the expiration time, in s

NX means that the key is not created when it exists, or if it does not exist.

XX indicates that it is modified when this key exists

Setnx: created when the specified key does not exist

Mset: set more than one key at a time

Get: get the value of a key

Mget: value that gets more than one key at a time

Getset: returns the original value of the specified key while setting the specified key new value

Append: appends new content to the values of the specified key

Del: delete a key

Exist: determines whether a key exists. If it exists, it returns 1. If it does not exist, it returns 0.

Strlen: returns the length of a key

Keys *: view all key

Key of integer type:

Incr: add 1 automatically

Decr: automatically minus 1

Key of string type, the operation of incr,decr is not supported

Common commands of the Lists type:

> help @ list# to view help for list types

Lpush: add data to key from the left

Lpop: pop up data from the left

Rpush: add data to key from the right

Rpop: pop up data from the right

Llen: view the length of the specified list

Lrange: fetches the data range of the specified key

Lindex: fetches the value of the specified subscript of the specified list; for example: lindex L10, fetches the first value of the list L1

Ltrim: retains data within a specified range

Lset: modifies the value of the specified index to the specified value

Common commands of the Sets (unordered) type:

> help @ set# to see help for unordered collection types

Sadd: adding data to the collection

Spop: an element pops up at random

Srem: removes a known value from the collection (not pops up randomly)

Scard: count how many values there are in a collection

Smembers: view all data in the collection

Sismember: determines whether the specified data exists in the collection-- > 0 means it does not exist, and 1 indicates it exists.

Sinter (intersection): shows the intersection between two sets; that is, data that exists at the same time

Sunion (Union): displays all data after removing duplicates from two sets

Sdiff (subtraction): displays the difference between the preceding set and the subsequent set

Smove: move the value of one collection to another

Commands commonly used in the Sorted _ set (ordered set) type:

> help @ sorted_set # for help on ordered collection types

Zadd: add an element to the collection, and you can specify multiple values at the same time; at the same time, give this element a score (because sorted_set is sorted by scores, the score comes before the value)

Example: > zadd weekday 1 mon,2 tue (score of mon is 1 score of score is 2)

Zcard: gets the number of members in an ordered set

Zrank: gets the index of an element in an ordered collection

Zscore: view the score of an element

Zrange: returns the data of the specified index range

Common commands of the hash type:

> help @ hash# to view hash type command help

Hset: sets the field value of the specified key

Usage: hset key field value

Hsetnx: set only when the specified key does not exist

Hget: gets the value of the specified field

Usage: hget key field

Hdel: deletes the specified field of the specified key

Hlen: gets the number of specified key fields

Hmset: setting multiple fields at a time

Hmget: get more than one field value at a time

Hexists: determines whether a field exists in the specified key

Hkeys: get all the field names

Hvals: get the values of all fields

Hgetall: gets all the fields and values of the specified key

Hyperloglog data structure:

Hyperloglog is similar to the set type, but saves memory than the set type

Hyperloglog can use very small memory space to complete the statistics of independent total, but there is a certain error rate.

Add hyperloglog data:

> pfadd 2016_03_06:unique:ids "uuid-1"uuid-2"uuid-3"uuid-4"

> pfadd 2016_03_07:unique:ids "uuid-4"uuid-5"uuid-6"uuid-7"

Count how many pieces of data there are in hyperloglog:

> pfcount 2016_03_07:unique:ids

Find the union of 2 or more hyperloglog:

Syntax: PFMERGE destkey sourcekey [sourcekey...]

> pfmerge union 2016_03_06:unique:ids 2016_03_07:unique:ids

Before use, you need to make sure:

1. Only to calculate the independent total, there is no need to obtain a single piece of data

two。 It can tolerate a certain error rate. After all, hyperloglog has a great advantage in terms of memory.

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

Network Security

Wechat

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

12
Report