Navid fiIsaraee
Navid fiIsaraee
خواندن ۳ دقیقه·۴ سال پیش

ردیس Redis

Redis
Redis


Short Document

What ?

An In Memory Database

Why ?

Need for Speed

How ?

Store Key-Value data in memory for much faster access

When ?

Caching data in high demand

Large data crawling

Searching

Temporary information

Who ?

Backend developers, duh !

How To ?

I.Set a key and a value based on built-in data types (SET, LPUSH,..)

II.Get stored value by providing key

III.Possibly set a expiry timer in order to limit the storage shortage

IV.To limit access of bad people create users and set certain rule via ACL commands (ACL SETUSER … )

V. If your data is really important usingtransaction. (MULTI)

VI. Finally Backup configs and all database cause you know RAM, if you lose power, stored data and configs will be lost.

Which ?

Open Source

TCP connection

Written in ANSI-C , Scripting via Lua

Most of commands happens synced (Create a lock)

Few happens async (FLUSH, BGSAVE, UNLINK, …)

What if …

You want more than a simple key-value(data-types)?

String

> SET <key> <value> (EX : <seconds> ,PX : <miliseconds>)

> GET <key>

List : order is insertion

> LPUSH <key> <value> :key is a list and will append to head

> RPUSH <key> <value>:key is a list and will append to tail

> LRANGE <key> <int:start> <int:end> : get list by index

Set : unordered , unique

> SADD <key> <member>

> SMEMBERS <key> : get set

Hash : maps between string fields and string values

> HSET

> HGET

Sorted set : ordered by score, unique like set

Bitmap : Sting based with certain semantic to store image

HyperLogLogs: Sting based with certain semantic

Custom-DataType: You can create a custom data semantic ….

You are a team inside a company (authentication)?

> ACL (parameters) :access control list

List : show list of users

GetUser <username> : user params

SetUser <username> : create or update a user

on / off : enable of disable a user (default = off) ><password> : add a new password to user <<password> : remove this password if exists +<command> : add ability to use a specific command

> Auth <username> <password> : Well Signing up ...

You have multiple apps but one RAM ?

> SELECT <index> : chose from 15 different db, like namespaces, same thing just separated !

You are tired of a key (delete) ?

> DEL : delete a key

> UNLINK : delete a key

> EXISTS <key> <key> ... : check if a key is present (returns int : 0 not found , 1 or more means number of given keys that were available)

You need ACID ?

> MULTI : will create a queue of commands, So they will all execute correctly , or if error occurs none of them.

> EXEC :will execute given queue

> DISCARD : ifyou just not in the mood and want out …

You want ensourance (Backup)?

> SAVE : will save whole database in a file [sync]

> BGSAVE : will save whole database in a file [Async]

> LASTSAVE : check the unix time of last successful backup

> CONFIG GET dir :get directory of saved files

You are a big boy (mass data insertion)?

User pipe mode to feed data into redis db like so :

$ cat data.txt | redis-cli –pipe

The text should include redis protocol in order to parse file in ASCII format

"*3\r\n$3\r\nSET\r\n$3\r\nGreeting\r\n$5\r\nHello\r\n"

Which translates to :

>SET Greeting Hello

You are board ?

> LOLWUT : will show you cheer you up

You are mad (want everything gone) ?

>FLUSHALL : removes all keys everywhere …

>FLUSHDB :removes all keys in selected db(1-15)…

You want more ?

Simple my friend, go visit Redis Commandsfor much more information and in depth explanations.

OH Wait …

INSTALATION :

$ Sudo apt install redis ( Job Done ! )

I’d be sad if you try this in command line cause it doesn’t work :(((

redisredisdbdatabaseInMemoryin memory database
شاید از این پست‌ها خوشتان بیاید