String type of Redis (non-relational database) data type

Source: Internet
Author: User
Tags redis

Redis a memory database that stores data in a way that key-value key-value pairs. Since Redis data is stored in memory, access is very fast, so redis is used to cache the system and store hotspot data, which can greatly improve the response speed of the website.

Redis is commonly referred to as a data structure server because values (value) can be types such as strings (string), hashes (hash), lists (list), collections (sets), and ordered collections (sorted sets).

String substring type common basic operations

1.set Key Value #------------------------------------set a key and the corresponding value

127.0.0.1:6379> Select 1ok127.0.0.1:6379[1]> set name ' www ' ok127.0.0.1:6379[1]> set name1 ' eee ' OK127.0.0.1 :6379[1]> set name2 ' RRR ' ok127.0.0.1:6379[1]> keys *] "name2" 2) "name1" 3) "name"

  

2.get Key #-------------------------------------Gets the value corresponding to a key

127.0.0.1:6379[1]> Get name "www" 127.0.0.1:6379[1]> get name1 "eee" 127.0.0.1:6379[1]> get Name2 "RRR"

  

3.setnx Key Value #---------------------------------set a nonexistent key, return 0 if present, setting failed

127.0.0.1:6379[1]> setnx name sss (integer) 0127.0.0.1:6379[1]> setnx name3 sss (integer) 1127.0.0.1:6379[1]> Get Name3 "SSS"

  

4.setex Key Time Value #---------------------------set a key worth the time

127.0.0.1:6379[1]> setex name6 wwwwwwwwok127.0.0.1:6379[1]> ttl name6 (integer) 10127.0.0.1:6379[1]> ttl Name6 (integer) 8127.0.0.1:6379[1]> ttl name6 (integer) 5127.0.0.1:6379[1]> ttl name6 (integer)-2

  

5.setrange key position Value #----------------------inserting a value at the specified position of the key

127.0.0.1:6379[1]> setrange name6 0 zzzzzzzz (integer) 10127.0.0.1:6379[1]> get Name6 "ZZZZZZZZWW"

  

6.MSETNX key 1 value 1 key 2 value 2 .... #--------------key values that do not exist in batch settings

127.0.0.1:6379[2]> msetnx we ' er ' er ' rt ' (integer) 1127.0.0.1:6379[2]> get we "127.0.0.1:6379[2]> get E" R "ER" 127.0.0.1:6379[2]> get RT "RT"

  

7.getset key New Value #---------------------get the key value and set it to the new value

127.0.0.1:6379[2]> Getset We ew "we" 127.0.0.1:6379[2]> get we "EW"

  

8.getrange key 0 4 #---------------------Gets the value at the specified range position

127.0.0.1:6379[2]> set name ' 12345678 ' ok127.0.0.1:6379[2]> getrange name 1 3 "234"

  

9.mget key 1 Key 2 .... #---------------------the value of the bulk fetch key

127.0.0.1:6379[2]> mget We er rt1) "ew" 2) "ER" 3) "RT"

10.INCR Key #---------------------do self-add 1 for the specified key value

127.0.0.1:6379[2]> Set ID 12ok127.0.0.1:6379[2]> incr ID (integer) 13127.0.0.1:6379[2]> incr ID (integer) 14127.0.0.1:6379[2]> Get ID "14"

  

11.incrby Key Value #----------------------set the specified key plus the specified value

127.0.0.1:6379[2]> Incrby ID (integer) 28127.0.0.1:6379[2]> get id "28"

  

12.DECR Key #----------------------The value of the specified key to do a self-subtract 1 operation

127.0.0.1:6379[2]> decr ID (integer) 27127.0.0.1:6379[2]> decr ID (integer) 26127.0.0.1:6379[2]> get id "26"

  

13.decrby Key Value #-----------------------set the specified key value minus the specified value

127.0.0.1:6379[2]> Decrby ID (integer) 14127.0.0.1:6379[2]> get ID "14"

  

14.append Key Value #-----------------------append to the specified key value

127.0.0.1:6379[2]> set name ' Yuliang ' ok127.0.0.1:6379[2]> append name Good (integer) 11127.0.0.1:6379[2]> get Name "Yulianggood"

15.strlen Key #-----------------------to find the length of the key value

127.0.0.1:6379[2]> strlen Name (integer) 11

  

String type of Redis (non-relational database) data type

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.