redis basic data types Study Notes Continued

0 Environment

  • System Environment: centos7
  • Editor: xshell

1 Introduction

In redis the key -> different strings corresponding to different values ​​of the key data structure includes five kinds of different data structures (primary values ​​refer to different types of data)

2 string (String)

Redis key string is the most basic type of the key (key-value can be in the form of key words picture ..)

  • set (the set value is a string key)

set a key to the key assignment of new entrants to the actual situation may appear anywhere on the database (disorder)

Complexity: O (1)

覆盖规则 相同的key赋值 后来的覆盖前来的

不过现在提供nx选项 只有key对应的value没有值的执行设置

// 伪代码 只为容易理解 别钻牛角尖
if(set.get(key)== null){
  set.get(key) = value;
}

setnx --> 输出的结果 成功1 失败0
set key value [nx|xx] nx --> 成功 ok 失败 nil xx正好与之相反

  • get (key to obtain the value of the string)

Time complexity: O (1)

  • getset (get the old value and set the new value)

Complexity: o (1)

getset similar:

string.get(key);
string.set(key, value);
  • MSET (string key once for a plurality of setting values)

Time complexity o (n) Commandmset key value [key value...]

  • mget (disposable obtaining a plurality of values ​​of key strings)

Time complexity o (n) Commandmget key[key ...]

  • msetnx (only when the key is not present a plurality of string key setting)

Time complexity o (n) Commandmsetnx key value [key value...]

// 只是为了方便理解
list a = new arraylist();
string.foreach(key:keys){
  if(string.get(key)!= null){
    return;
  }
  a.add(string.get(key));
}
  • The STRLEN (Get byte length string values)

Complexity: o (1)

  • String index

0 indexed positive (first)
negative index starts to decrease progressively from the end most -1 from the back calculated increments from front to back (-xxx.size ...- 1)

  • GetRange (string value acquires the content index range)

Time complexity o (n)

Command GETRANGE key start endarray-like sections list [start: end]

Guess you like

Origin www.cnblogs.com/my-ordinary/p/12618244.html