Redis Database Essays

Source: Internet
Author: User
Tags delete key redis server

I. What is NOSQL?:

Feature: No strict table structure is used. Without SQL statements as queries

Redis supports data persistence to save data from memory on disk

Common supported types of stored data (value): string hash set Orderset

Two. Installing under Windows

1. Copying software

Copy to Redis folder under D

2. Start the service in CMD (requires Super Administrator to start)

D:\redis>redis-server.exe

3. Also open a terminal cmd, using the client to connect to the Redis server

D:\redis>redis-eli.exe

Three. Data types for Redis

1.string type

Set setting value

Set username Asion

Set age 20

Get Get Value

Get username

Get age

INCR self-increment

INCR Age

Incrby specify a number to increment from

Incrby age 10

DECR Self-reduction

DECR Age

Decrby Specify self-decrement

Decrby age 10


ID name pass Email sex

1 asion admin [email protected] m

Corresponding to the table saved in Redis

Set User:id:1:name asion

Set User:id:1:pass admin

Set user:id:1:email [email protected]

Set User:id:1:sex m


Remove Data:

Keys user:id:1*


Get User:id:1:name

2.hash type

Hset Setting Value:

Hset user:userinfo name Asion

Hget Get Value:

Hget user:userinfo Name

Hmset set multiple values for hash:

Hmset user:userinfo name asion age Email [email protected]

Hgetall gets the entire hash value that can be

Hgetall User:userinfo

3.link Linked list type:

Head pressure as data:

Lpush Link1 A

Lpush Link1 B

Tail:

Rpush Link2 A

Rpush Link2 B

Lrange get all the elements in the list

Lrange Link1 0-1

Lpop deletes the first element of the list inside the head and returns the element

Lpop Link1

Rpop Delete Trailer

Rpop Link1

4.set type

Sadd adding elements to a collection

SADD DD YUANSU1

SADD DD YUANSU2

Smembers View:

Smembers DD

Find common friends:

Friend of SINTER element 1 friend element 2

All friends:

Friend of sunion element 1 friend element 2

Recommended Friends: Use Difference

Friend of Sdiff element 1 friend element 2

5.orderset type: The elements in an ordered set are orderly and unique, and are also deterministic

1.zadd Adding an ordered collection

Zadd php17 1 asion

Zadd PHP17 2 bill

Zadd PHP17 8 Mark

2.zrange get elements inside an ordered set

Zrange php17 0-1

3.zrange key 0-1 withscores acquisition weights

Zrange php17 0-1 Withscores

Four. Working with Redis using PHP

1. Copy the appropriate extension file to the Ext directory of PHP

Php_igbinary.dll

Php_redis.dll

2. Modify the configuration file php.ini

Extension=php_igbinary.dll

Extension=php_redis.dll

3. Restart Apache

Five. Some small commands for Redis

Linux Environment: cd/usr/local/redis/bin/

Connection server:./redis-cli

1.keys * See all the keys

2.del Delete key (successful return 1 unsuccessful return 0)

3.exists detects if key exists (presence return 1 does not exist return 0)

4.type viewing the type of value

5.flushdb empty The key of the current database, only use it when testing, never use it on the line.

6. Current database, note that Redis defaults to 16 databases (subscript starting from 0), but this is not used. Switch with select number

7.flushall Clear all database keys, use caution

8.dbsize View the number of keys for the current data

Seven. Installing Redis under the Linux environment

1.ftp Upload

Phpredis-2.2.4.tar.gz

Redis-3.0.7.tar.gz

2. Copy redis-3.0.7.tar.gz phpredis-2.2.4.tar.gz to/USR/LOCAL/SRC decompression

Then go to CD redis-3.0.7

Compile:

Make

Specify the installation path for installation

Make Prefix=/usr/local/redis Install

Set up Redis profile directories and configuration files.

Copy Mkdir/etc/redis

CP redis.conf/etc/redis/

Cd/etc/redis/bin

Vim/etc/redis/redis.conf

Daemonize Yes

Start the service

./redis-server/etc/redis/redis.conf

PS Axu | grep Redis

Using Client Actions

./redis-cli

3. Unzip the phpredis-2.2.4.tar.gz

Enter the extracted directory and use/usr/local/php/bin/phpize to collect information

Use the./configure--with-php-config=/usr/local/php/bin/php-config to collect operating system information

Compiling and installing

Make && make install

Vim/usr/local/php/lib/php.ini

Extension = redis.so

Eight. Redis security issues

In the Linux environment:

Vim/etc/redis/redis.conf

Add Password:

Requirepass Admin

Wq

Pkill-9 Redis

/usr/local/redis/bin/redis-server/etc/redis/redis.conf

Auth admin or/usr/local/redis/bin/redis-cli-a admin

Nine. The persistence of Redis

The Redis data itself is stored in memory, but Redis provides persistent functionality to keep the data on disk, and the next time the Redis service is started, the data on the disk is automatically loaded into memory.

In the Linux environment:

Enter configuration file vim/etc/redis/redis.conf

Save 900 1

Save 300 10

Save 60 10000

Persist the data inside the memory to disk

Dbfilename Dump.rdb

The meaning of Save 900 1 means: If the operation of the key is 1 times above 900s or 900s, the memory data is persisted to disk.

The meaning of Save 300 10 means: if the operation of the key is 10 times above 300s or 300s, the memory data is persisted to disk.

The meaning of Save 60 10000 means: If the operation of the key is 10,000 times above 60s or 60s, the memory data is persisted to disk.


Redis Database Essays

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.