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

Installation and basic usage of Redis

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly introduces "installation and basic usage of Redis". In daily operation, I believe many people have doubts about the installation and basic usage of Redis. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "installation and basic usage of Redis"! Next, please follow the editor to study!

Tar xvzf redis-5.0.9.tar.gz

Cd redis-5.0.9/

Make

Make PREFIX=/usrl/local/redis install

Ln-s / usr/local/redis/bin/* / usr/bin/

Cd / mnt/redis-5.0.9/utils/ keeps entering the car

Ln-s / etc/init.d/redis_6379 / usr/bin/ establish the soft connection of startup command

Configuration file for vim / etc/redis/6379.conf Redis

Redis-cli-h 192.168.1.10-p 6379 # Log in to the local Redis

Redis supports five data types: string (string) and hash (hash). List (list), set

(set) and zset (sortedset: ordered set), etc.

192.168.1.10 6379 > help @ list # get command help

Set demo zhou # storing data

Setnx demo zhou # if the key has no value, the assignment is successful

192.168.1.10 6379 > get demo # get data

"zhou"

Keys * # query all the key values in the database, * represents all

Keys d * # queries all key values that begin with d

Keys d? #? Represents a wildcard and represents a match of a character

Keys d???

Exists demo # tests whether the key value exists, with 1 for existence and 0 for non-existence.

Del demo # Delete the specified key in the current library

Type demo # query value type

Rename demo test # change the key name to demo to test

Renamenx # means that only if the new key name is empty

Dbsize # View the number of key in the current library

DUMP key # returned and serialized value

Expire key secondes # sets the survival time of key. Default is-1 key permanent storage.

Pexpire key milliseconds # sets the survival time of key in milliseconds

Ttl key # check the expiration time of key

Persist key # set key to permanent save

Randomkey # returns a random key

Move key library name # move key to the specified library name

Getrange key start end # intercepting string

Self-increasing / self-decreasing:

INCR EEY_NAME

The Iner command increases the numeric value stored in key by 1. 0. If key does not exist, the value of key will first be initialized to

0 and then perform the INCR operation

INCR KEY Nane increment value

The INCRBY command adds the number stored in key to the specified increment value

Self-subtracting: DECR KEY_NAME

Self-deduction: DECRBY KEY_ MANE impairment

The DECR command subtracts the number stored in key by 1

DECRBY DECRBY KEY Nane increment value

String concatenation: APPEND EEF NANE YALOE

The kppend command is used to append the specified key to the end, and if it does not exist, assign a value to it

SETNX key value / / one of the solutions for distributed locking

The value of lesy is set only if koy does not exist. Setnx (SET if Not eXists) precedent when the specified key does not exist.

2.2. Hash (Hash)

2.2.1. Brief introduction

Redis hash is-a mapping table for field and value of type string, and hash is especially suitable for use

In storing objects. Each hash in Redis can store 232-1 key-value pairs (more than 4 billion)

Can be thought of as a MAP container with KEY and VALUE, which is very suitable for storing information about value objects

Such as: U

Uname, upass, age

Wait. This type of data takes up very little disk space (compared to JSON)

2.2.2. Hash command

2.2.2. Hash command

Assignment syntax:

HGET KEY FIELD VALUE

/ / set FILD/VALUE for the specified KEY

HMSET KEY FIELD VALUE (FIELD1, VALLEI1).... Combine multiple field value simultaneously

The (field-value) pair is set to the hash table key.

HMSET users uname guo age 20 address "Beijing"

Value syntax:

HGET KEY FIELD / / gets the value stored in HASH, and gets VALUE according to FIELD

HNGET key field [fieldl]

/ / get the values of all given fields in key

HGET ALL key

/ / returns all fields and values in the HASH table

HKEYS key / / get all the fields in the hash table

HLEN key / / get the number of fields in the hash table

Delete syntax:

HDEL KEY field1 [field2] / / Delete one or more HASH fields

Other grammars:

HSENX key field value

Set the value of the hash table field only if the field field does not exist

HINCRBY key field increment

Adds an incremental increment to the integer value of the specified field in the hash table key.

HINCRBYFLOAT key field increment

Adds an incremental increment to the floating-point value of the specified field in the hash table key.

HEXISTS key field / / check whether the specified field exists in the hash table key

At this point, the study of "installation and basic usage of Redis" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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

Servers

Wechat

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

12
Report