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

Redis installation and basic use

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

The concept of redis:

Redis is an open source memory-based and persistent log, Key-Value database

Redis tool:

Redis-benchmark # tools for redis performance testing

Redis-sentinel # for cluster management

Redis-cli # redis client

Redis-server # redis server

Redis-check-aof # AOF file used to fix the problem

Redis-check-dump # dump.rdb file used to fix the problem

Install redis

1. Install dependency package tcl,8.5 version or above

Tar zxvf tcl8.6.0-src.tar.gz-C / usr/src/ # decompression

Cd / usr/src/tcl8.6.0/unix/ # enter the source code directory

. / configure & & make & & make install # configuration compilation installation

2. Install redis

Rpm-ivh jemalloc-3.6.0-1.el6.x86_64.rpm # install dependent libraries

Rpm-ivh redis-3.2.8-1.el6.remi.x86_64.rpm # install redis

Service redis start # start the service

Ss-nalt | grep 6379 # check whether the service is started

Redis main data types:

1. String (strings)

two。 List (lists)

3. Collection (sets)

4. Ordered set (sorted sets)

5. Hash (hashes)

Command rules for redis key:

1.key should not be too long to avoid excessive memory consumption and reduce search efficiency.

two。 In a project, it is best for key to use a unified naming pattern

Basic use of redis-cli:

Redis-cli is mainly used to connect redis-server and operate with multiple redis-server.

Common options:

-- help # get help information

-h # specify redis database address, default is localhost

-p # designated port, default is 6379

-a # specifies the authentication password, which is empty by default

-n # specifies the login database. Default is database 0.

Third, the basic operation of redis

String

Set key value [EX seconds] # create a string, and EX sets the timeout

Get key # gets the value of the specified key

List

Rpush key value1 value2. # create an ordered list, first in, first out (commonly used)

Lpush key value1 value2. # create an ordered list, first in, then out

Lrange key start stop # get the elements in the list

Collection:

Sadd key value # create a collection

Smembers key # gets the value of the collection

Sismember key value # determines whether the value of value is within this set

Sinter key1 key2 # returns intersection

Sunion key1 key2 # returns union

Sdiff key1 key2 # returns subtractions

Hash:

Hset key hash_name hash_value # creates a hash mapping relationship, similar to dictionary data in python

Hgetall key # gets the value of the specified hash

General commands:

Help @ server # View a set of command help

Help set # View help for specified commands

Del key # Delete the specified key

Expire key # sets the timeout for the specified key

Ttl key # View the timeout of key

Persist key # Unspecify the timeout for key

Type key # returns the type of the specified key

Rename key1 key2 # rename key1 to key2

Flushdb # clear the key of the current database

Flushall # clear key for all databases

Dbsize # returns the number of key of the current database

Redis subscription and Publishing

Channel: consumers in a channel can receive the producer's information in this channel.

Subscribe Channel # subscribe to a channel

Psubscribe Channel # defines one or more channels by matching

Example: psubscribe * # subscribe to all channels

Psubscribe s [io] # subscribe to si and so

Publish Channel message # sends a message to the specified channel

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

Database

Wechat

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

12
Report