Using Redis (base, key operation, String type operation)

Source: Internet
Author: User

Using Redis

Set type: No duplicate elements

List linked list type has repeat-tired type

Sort set type has no repeating elements

1.1 Store Data Read data

Data is stored in memory

Set name Laowen//OK indicates success

Set age//OK indicates success

Set add Beijing//OK indicates success

Get name//"Laowen" indicates success

Get Age//"22" indicates success

Get addr//"Beijing" indicates success

The name of the data is key

1.2 Key naming Convention (key operation)

Redis \ \ and spaces cannot be the name of the composition of the content

Key's name does not take too long to account for memory, query speed is slow

Key's name is not too short to be readable

Operate the keys operation

Exists key test Specifies if key exists

Del key1 Key2 ... Deletes the given key//returns the number of deleted keys (integer) n

Type key returns the value of the given key

Keys pattern returns all keys that match the specified pattern

Keys */keys A*/key *a returns the key value for the given pattern

Rename Oldkey newkey Change the name of key

Dbsize returns the number of keys in a single pre-database

Expire key seconds Specify an expiration time for key

TTL key returns the number of seconds remaining for key

Select Db-index Choose a database (up to 16 database number 0-15)

Select 5 operation of the 6th database (numbered 5)

Select n is used to switch the database used

Move key Db-index moves the key from the current database to the specified database

FLUSHDB Delete all keys in the current database

Flushall Delete all keys in all databases

1.3 String Type operation

String is the most basic type of Redis

The value of a single value is 1G

If you just use a string type, Redis can be seen as a memcache with persistence.

Action string

Set key value sets key corresponding to value of string type

Mset key1 value1 ... keyN valuen set values for multiple keys at once

Mget key1 value1 ... keyN valuen get multiple key values at once

INCR (meaning i++) key to the value of key to do Gaga operation and return the new value

DECR (meaning i--) key makes a subtraction operation on the value of key and returns a new value

Incrby key integer to the value of key plus the specified value

Indeby key integer to the value of key minus the specified value

Append key value appends value to the string value of the specified key

SUBSTR Key Start End returns the string value of the truncated key

Note SUBSTR content is intercepted including the start and end tag locations

Using Redis (base, key operation, String type operation)

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.