日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

NoSQL(一):NoSQL数据库、redis

發布時間:2025/3/21 数据库 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 NoSQL(一):NoSQL数据库、redis 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

NoSQL概述

數據庫類型

?RDBMS

關系型數據庫管理系統

- Relational ?Database ?Management ?System
- 按照預先設置的組織結構,將數據存儲在物理介質
- 數據之間可以做關聯操作
- 銀行就是典型的關系型數據庫

主流的RDBMS軟件

- MySQL
- MariaDB
- Oracle
- DB2
- SQL ?Server

NoSQL

非關系型數據庫

- NoSQL(NoSQL=Not ?Only ?SQL)意為“不僅僅是SQL”
- 泛指非關系型數據庫
- 不需要預先定義數據存儲結構
- 每條記錄可以有不同的數據類型和字段數據
- 微信聊天等適合使用非關系型數據庫

主流的NoSQL軟件

- Memcached
- Redis
- MongoDB
- COuchDB
- Neo4j
- FlockDB

非關系型數據庫和關系型數據庫優缺點

數據庫類型特點優點缺點
關系型數據庫1.關系型數據庫,是指采用了關系模型來組織數據的數據庫
2.關系型數據庫的最大特點就是事物的一致性
3.簡單來說,關系模型值的就是二維表格模型,而一個關系型數據庫就是由二維表及其之間的聯系所組成的一個數據組織
1.容易理解,二維表結構是非常貼近邏輯世界的一個概念,關系模型相對網狀、層次等其他模型來說更容易理解
2.使用方便,通用的SQL語言使得操作關系型數據庫非常方便
3.易于維護,豐富的完整性(實體完整性、參照完整性和用戶定義的完整性)大大減低了數據冗余和數據不一致的概率
4.支持SQL,可用于復雜的查詢
1.為了維護一致性所付出的巨大代價就是其讀寫性能較差
2.固定的表結構
3.高并發讀寫需求
4.海量數據的高效率讀寫
非關系型數據庫1.使用鍵值對存儲數據
2.分布式
3.一般不支持ACID特性
4.是一種數據結構化存儲方法的集合
1.無需經過SQL層的解析,讀寫性能高
2.基于鍵值對,數據沒有耦合性,容易擴展
3.存儲數據的格式:nosql的存儲格式是key,value形式、圖片形式等,而關系型數據庫只支持基礎類型
1.不提供SQL支持,學習和使用成本較高
2.無事務處理,附加功能bi和報表等支持也不好

部署redis服務

redis介紹

redis

  • Remote? Dictionary? ?Server(遠程字典服務器)
  • 是一款高性能的(key/values)分布式內存數據庫
  • 支持數據持久化(定期把內存里的數據存儲到硬盤)
  • 支持多種數據類型string、list、hash...
  • 支持master-slave模式數據備份
  • 可再生的數據以及被頻繁使用的數據被存入內存中,加快網站的訪問速度,訪問時從內存存儲數據庫內查找
  • 中文網站?http://www.redis.cn/
  • 網盤鏈接鏈接 https://pan.baidu.com/s/11QYBLKiBOoF2QoI49GNOQQ?
    提取碼:zwxf

搭建redis服務器

1.在51上安裝redis軟件 [root@host51 ~]# systemctl stop mysqld [root@host51 ~]# rpm -q gcc #查看編譯安裝工具是否安裝 未安裝軟件包 gcc [root@host51 ~]# yum -y install gcc [root@host51 ~]# cd /opt [root@host51 opt]# tar -zxvf redis-4.0.8.tar.gz [root@host51 opt]# cd redis-4.0.8/ [root@host51 redis-4.0.8]# ls 00-RELEASENOTES COPYING Makefile redis.conf runtest-sentinel tests BUGS deps MANIFESTO runtest sentinel.conf utils CONTRIBUTING INSTALL README.md runtest-cluster src [root@host51 redis-4.0.8]# make install [root@host51 redis-4.0.8]# redis- #redis相關命令 redis-benchmark redis-check-rdb redis-sentinel redis-check-aof redis-cli redis-server ------------------------------------------------------------------ 2.初始化配置 [root@host51 redis-4.0.8]# ./utils/install_server.sh #一路回車 ... Port : 6379 #端口 Config file : /etc/redis/6379.conf #主配置文件 Log file : /var/log/redis_6379.log #日志文件 Data dir : /var/lib/redis/6379 #數據庫目錄 Executable : /usr/local/bin/redis-server #服務啟動程序 Cli Executable : /usr/local/bin/redis-cli #命令行連接命令 Starting Redis server... #初始化會默認將服務啟動 [root@host51 redis-4.0.8]# ls /etc/redis/6379.conf /etc/redis/6379.conf[root@host51 redis-4.0.8]# ls /var/log/redis_6379.log /var/log/redis_6379.log[root@host51 redis-4.0.8]# ls /var/lib/redis/6379/ [root@host51 redis-4.0.8]# ls /usr/local/bin/ redis-benchmark redis-check-rdb redis-sentinel redis-check-aof redis-cli redis-server [root@host51 redis-4.0.8]# ss -nutlp | grep 6379 #查看端口 tcp LISTEN 0 128 127.0.0.1:6379 *:* users:(("redis-server",pid=5489,fd=6))[root@host51 redis-4.0.8]# ps -C redis-server #查看進程PID TTY TIME CMD5489 ? 00:00:00 redis-server[root@host51 redis-4.0.8]# /etc/init.d/redis_6379 stop #關閉redis服務 Stopping ... Redis stopped [root@host51 redis-4.0.8]# ss -nutlp | grep 6379 [root@host51 redis-4.0.8]# /etc/init.d/redis_6379 start #啟動redis服務 Starting Redis server... [root@host51 redis-4.0.8]# ss -nutlp | grep 6379 tcp LISTEN 0 128 127.0.0.1:6379 *:* users:(("redis-server",pid=5581,fd=6))-------------------------------------------------------------------- 3.連接redis服務 連接服務操作: [root@host51 redis-4.0.8]# redis-cli 127.0.0.1:6379> ping #測試是否連接成功,默認連接127.0.0.1的6379端口 PONG #出現pong即代表連接成功 可以正常管理數據

常用命令

- set? ?key名? ?key值? ? ? ? ? ? ? ? ? ?#存儲一個key值

- mset? ?key名列表? ? ? ? ? ? ? ? ? ? ?#存儲多個key值

- get? ? key名? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #獲取key值

- mget? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #獲取多個key值

- select? ? 數據庫編號0-15? ? ? ? ?#切換庫,有0-15共16個庫,默認是0號庫

- keys? ?*? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #顯示所有key名

- keys? ? a?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#顯示指定key名

- exists? ?key名? ? ? ? ? ? ? ? ? ? ? ? ? ?#測試key名是否存在

- ttl? ? key名? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #查看key生存時間

- type? ?key名? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#查看key類型

- move? key名? ? ? ? ? ? ? ? ? ? ? ? ? ? #移動key到指定庫

- expire? key名? ? 數字? ? ? ? ? ? ? ? #設置key有效時間

- del? ? key名? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #刪除指定的key

- flushall? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#刪除內存里所有的key

- flushdb? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #刪除所在庫的所有key

- save? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #保存所有的key到硬盤

- shutdown? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #停止服務

常用命令: 127.0.0.1:6379> set class 111111 #存數據 OK 127.0.0.1:6379> keys * #查看內存中所有變量 1) "class" 127.0.0.1:6379> get class #取數據 "111111" 127.0.0.1:6379> set age 55 OK 127.0.0.1:6379> keys * 1) "class" 2) "age" 127.0.0.1:6379> get age "55" 127.0.0.1:6379> exit #斷開連接 127.0.0.1:6379> mset name tian sex girl age 111 存儲多個數據 OK 127.0.0.1:6379> keys * 1) "class" 2) "age" 3) "name" 4) "sex" 127.0.0.1:6379> get age "111" 127.0.0.1:6379> mget name sex #獲取多個數據 1) "tian" 2) "girl"127.0.0.1:6379> select 15 #切換庫,有0-15共16個庫,默認是0號庫 OK 127.0.0.1:6379[15]> select 0 OK 127.0.0.1:6379> select 15 OK 127.0.0.1:6379[15]> keys * (empty list or set) 127.0.0.1:6379[15]> select 0 OK 127.0.0.1:6379> keys name 1) "name" 127.0.0.1:6379> keys a? #顯示指定的key名 (empty list or set) 127.0.0.1:6379> keys a?? 1) "age" 127.0.0.1:6379> keys a* #顯示所有以a開頭的變量名 1) "age" 127.0.0.1:6379> keys ??? #顯示所有變量名是三位的 1) "age" 2) "sex" 127.0.0.1:6379> get age "111" 127.0.0.1:6379> set age 120 OK 127.0.0.1:6379> get age "120" 127.0.0.1:6379> exists name #查看變量名是否存在,1為存在,0為不存在 (integer) 1 127.0.0.1:6379> exists age (integer) 1 127.0.0.1:6379> exists user x (integer) 0 127.0.0.1:6379> exists user name #查看多個變量名時,只要有一個存在就顯示1 (integer) 1 127.0.0.1:6379> ttl age #查看變量的生存時間,-1為永久存在,需要手動刪除,-2為生存時間已經過期,默認為-1,存在內存中 (integer) -1 127.0.0.1:6379> get age "120" 127.0.0.1:6379> type name #查看變量的類型,string為字符類型 string 127.0.0.1:6379> lpush hostname x y z (integer) 3 127.0.0.1:6379> type hostname list 127.0.0.1:6379> select 2 OK 127.0.0.1:6379[2]> select 0 OK 127.0.0.1:6379> move age 2 #將age變量移動到2號庫 (integer) 1 127.0.0.1:6379> keys * #此時0號庫已經沒有了age類型 1) "class" 2) "hostname" 3) "name" 4) "sex" 127.0.0.1:6379> select 2 OK 127.0.0.1:6379[2]> keys * 1) "age" 127.0.0.1:6379[2]> select 0 OK 127.0.0.1:6379> select 2 OK 127.0.0.1:6379[2]> ttl age (integer) -1 127.0.0.1:6379[2]> expire age 15 #將age類型的有效時間設為15秒 (integer) 1 127.0.0.1:6379[2]> ttl age #再次查看,此時剩9秒 (integer) 9 127.0.0.1:6379[2]> ttl age #此時該變量已經過了有效時間 (integer) -2 127.0.0.1:6379[2]> keys * (empty list or set) 127.0.0.1:6379[2]> select 0 OK 127.0.0.1:6379> del name #刪除name變量 (integer) 1 127.0.0.1:6379> flushdb #刪除所在庫里所有的變量名 OK 127.0.0.1:6379> keys * (empty list or set) 127.0.0.1:6379> flushall #刪除內存里所有變量名 OK 127.0.0.1:6379> set x 19 OK 127.0.0.1:6379> keys * 1) "x" 127.0.0.1:6379> get x "19" 127.0.0.1:6379> save #手動保存變量到硬盤,在/var/lib/redis/6379/目錄中 OK [root@host51 ~]# ls /var/lib/redis/6379/ dump.rdb 127.0.0.1:6379> shutdown #停止服務 not connected> ping #此時再次ping顯示服務拒絕 Could not connect to Redis at 127.0.0.1:6379: Connection refused not connected> exit [root@host51 redis-4.0.8]# ss -nutlp | grep 6379 #再次查看端口 [root@host51 redis-4.0.8]# /etc/init.d/redis_6379 start Starting Redis server... [root@host51 redis-4.0.8]# redis-cli 127.0.0.1:6379> ping PONG

修改redis服務的運行參數

名稱說明
NETWORK網絡
GENERAL常規
SNAPSHOTTNG快照
REPLICATION復制
SECURITY安全
CLIENTS客戶端
MWMORY? MANAGEMENT內存管理

數據單位

常用配置

- port? ?6379? ? ? ? ? ? ? ? ? ? ? ? ? ?#端口

- bind? ?127.0.0.1? ? ? ? ? ? ? ? ? ?#IP地址

- daemonize? yes? ? ? ? ? ? ? ? ? ?#守護進程方式運行

- databases? ?16? ? ? ? ? ? ? ? ? ? #數據庫個數

- logfile? /var/log/redis_6379.log? ? ? ?#日志文件

- maxclients? ? 10000? ? ? ? ? ? ? ? ? ? ? ? #并發連接數量

- dir? ?/var/lib/redis/6379? ? ? ? ? ? ? ? ? ? #數據庫目錄

內存管理

- volatile-lru? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #最近最少使用(針對設置了TTL的key)

- allkeys-lru? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #刪除最少使用的key(針對所有的key)

- allkeys-lfu? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #從所有的key中清除使用頻率最少的key

- volatile-lfu? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #從所有配置了過期時間的key中清除使用頻率最少的key

- volatile-random? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#在設置了TTL的key里隨機移除

- allkeys-random? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#隨機移除key

- volatile-ttl (minor? TTL)? ? ? ? ? ? ?#移除最近過期的key

-noeviction? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#不刪除

-----------------------------------------------------------------------------------------------------

優化設置

- maxmemory? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #最大內存

- maxmemory-policy? ? ? ? ? ? ? ? ? ? ? ?#定義使用策略

- maxmemory-samples? ? ? ? ? ? ? ? ? ?#選取key模板的個數(針對lru和ttl策略)

修改服務IP地址端口號設置連接密碼

[root@host51 ~]# /etc/init.d/redis_6379 stop #修改配置文件前停止服務!! Stopping ... Redis stopped[root@host51 ~]# vim /etc/redis/6379.conf 70 bind 192.168.4.51 #允許192.168.4.51主機登錄本機redis 93 port 6351 #修改redis端口號為6351 501 requirepass 123456 #192.168.4.51主機登錄時連接的密碼為123456[root@host51 ~]# sed -n '70p;93p;501p' /etc/redis/6379.conf bind 192.168.4.51 port 6351 requirepass 123456[root@host51 ~]# /etc/init.d/redis_6379 start #重啟服務 Starting Redis server...[root@host51 ~]# ss -nutlp | grep 6351 #現在的端口號變為6351 tcp LISTEN 0 128 192.168.4.51:6351 *:* users:(("redis-server",pid=5707,fd=6))連接: [root@host51 ~]# redis-cli #此時再使用原來的命令進入redis是進不去的 Could not connect to Redis at 127.0.0.1:6379: Connection refused[root@host51 ~]# redis-cli -h 192.168.4.51 -p 6351 192.168.4.51:6351> ping #進入成功后要輸入密碼才可以進行操作 (error) NOAUTH Authentication required. 192.168.4.51:6351> auth 123456 OK 192.168.4.51:6351> ping PONG[root@host51 ~]# redis-cli -h 192.168.4.51 -p 6351 -a 123456 192.168.4.51:6351> ping PONG

部署LNMP+redis

部署LNMP

安裝軟件

Nginx源碼包軟件鏈接:https://pan.baidu.com/s/1GaOyufUBOln4bv4Ln3bEAA?
提取碼:tgnj

redis源碼包鏈接:https://pan.baidu.com/s/1sHmIQXhjKCpwwQMnWti0Yg?
提取碼:z25q?
?

1.在50主機部署LNMP 要求必須要有Nginx源碼包以及redis包 [root@host50 opt]# rpm -q gcc 未安裝軟件包 gcc [root@host50 opt]# rpm -q pcre-devel 未安裝軟件包 pcre-devel [root@host50 opt]# rpm -q zlib-devel 未安裝軟件包 zlib-devel [root@host50 opt]# yum -y install gcc pcre-devel zlib-devel #安裝依賴 [root@host50 opt]# tar -zxvf /opt/nginx-1.12.2.tar.gz #解壓 [root@host50 opt]# cd nginx-1.12.2/ [root@host50 nginx-1.12.2]# ./configure [root@host50 nginx-1.12.2]# make && make install #編譯安裝 [root@host50 nginx-1.12.2]# yum -y install php-fpm

修改配置

[root@host50 nginx-1.12.2]# vim +65 /usr/local/nginx/conf/nginx.conf65 location ~ \.php$ {66 root html;67 fastcgi_pass 127.0.0.1:9000;68 fastcgi_index index.php;69 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;70 include fastcgi.conf; 71 } [root@host50 nginx-1.12.2]# ls /usr/local/nginx/conf/ fastcgi.conf (獲取Nginx內置變量的值) koi-utf nginx.conf uwsgi_params fastcgi.conf.default koi-win nginx.conf.default uwsgi_params.default fastcgi_params mime.types scgi_params win-utf fastcgi_params.default mime.types.default scgi_params.default[root@host50 nginx-1.12.2]# systemctl start php-fpm #開啟php服務[root@host50 nginx-1.12.2]# ss -nutlp | grep 9000 tcp LISTEN 0 128 127.0.0.1:9000 *:* users:(("php-fpm",pid=4277,fd=0),("php-fpm",pid=4276,fd=0),("php-fpm",pid=4275,fd=0),("php-fpm",pid=4274,fd=0),("php-fpm",pid=4273,fd=0),("php-fpm",pid=4272,fd=6))[root@host50 nginx-1.12.2]# /usr/local/nginx/sbin/nginx -t #查看配置文件是否書寫錯誤 nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

啟動服務

[root@host50 nginx-1.12.2]# systemctl start php-fpm #開啟php服務[root@host50 nginx-1.12.2]# ss -nutlp | grep 9000 tcp LISTEN 0 128 127.0.0.1:9000 *:* users:(("php-fpm",pid=4277,fd=0),("php-fpm",pid=4276,fd=0),("php-fpm",pid=4275,fd=0),("php-fpm",pid=4274,fd=0),("php-fpm",pid=4273,fd=0),("php-fpm",pid=4272,fd=6)) [root@host50 nginx-1.12.2]# /usr/local/nginx/sbin/nginx #起服務[root@host50 nginx-1.12.2]# ss -nutlp | grep 80 tcp LISTEN 0 128 *:80 *:* users:(("nginx",pid=4290,fd=6),("nginx",pid=4289,fd=6))

測試配置

root@host50 nginx-1.12.2]# vim /usr/local/nginx/html/test.php #書寫一個測試腳本 <?php $i=99 ; echo $i ; ?> 測試LNMP環境是否搭建成功: [root@host50 nginx-1.12.2]# netstat -nutlp | grep 80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4289/nginx: master [root@host50 nginx-1.12.2]# netstat -nutlp | grep 9000 tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 4272/php-fpm: maste [root@host50 nginx-1.12.2]# curl 192.168.4.50/test.php 99用真機訪問測試頁面http://192.168.4.50/test.php

?

配置支持redis

運行redis服務

安裝功能模塊,PHP擴展 [root@host50 nginx-1.12.2]# which php /usr/bin/which: no php in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin) [root@host50 nginx-1.12.2]# yum -y install php #安裝依賴 [root@host50 nginx-1.12.2]# which php /usr/bin/php [root@host50 nginx-1.12.2]# php -m | grep -i redis #此時沒有安裝支持連接redis的模塊 [root@host50 nginx-1.12.2]# cd /opt #查看是否有php-redis軟件包 [root@host50 opt]# ls nginx-1.12.2 nginx-1.12.2.tar.gz php-redis-2.2.4.tar.gz redis-4.0.8.tar.gz [root@host50 opt]# rpm -q php php-devel automake autoconf php-5.4.16-45.el7.x86_64 未安裝軟件包 php-devel 未安裝軟件包 automake 未安裝軟件包 autoconf [root@host50 opt]# yum -y install php-devel automake autoconf #安裝依賴 [root@host50 opt]# tar -zxf php-redis-2.2.4.tar.gz #安裝擴展包 [root@host50 opt]# cd phpredis-2.2.4/ [root@host50 phpredis-2.2.4]# ls arrays.markdown CREDITS mkdeb.sh redis_array_impl.c serialize.list common.h debian package.xml redis_array_impl.h tests config.h debian.control php_redis.h redis.c config.m4 library.c README.markdown redis_session.c config.w32 library.h redis_array.c redis_session.h COPYING mkdeb-apache2.sh redis_array.h rpm[root@host50 phpredis-2.2.4]# phpize #生成配置文件php-config及configure命令 Configuring for: PHP Api Version: 20100412 Zend Module Api No: 20100525 Zend Extension Api No: 220100525 [root@host50 phpredis-2.2.4]# ./configure --with-php-config=/usr/bin/php-config [root@host50 phpredis-2.2.4]# make && make install Installing shared extensions: /usr/lib64/php/modules/ [root@host50 phpredis-2.2.4]# ls /usr/lib64/php/modules/ curl.so fileinfo.so json.so phar.so redis.so zip.so

調用模塊

修改php.ini文件 [root@host50 phpredis-2.2.4]# vim +728 /etc/php.ini728 extension_dir = "/usr/lib64/php/modules" #模塊文件目錄729 ; On windows:730 extension="redis.so" #模塊文件名 [root@host50 phpredis-2.2.4]# systemctl restart php-fpm //重啟php-fpm服務 [root@host50 phpredis-2.2.4]# php -m | grep -i redis //查看已加載的模塊 redis

測試配置

查看192.168.4.50主機的redis服務是否運行 [root@host50 ~]# netstat -utnlp | grep redis-server tcp 0 0 192.168.4.50:6350 0.0.0.0:* LISTEN 11523/redis-server [root@host50 ~]# redis-cli -h 192.168.4.50 -p 6350 -a 123456 //訪問服務 192.168.4.50:6350> ping PONG 192.168.4.50:6350> exit 編寫PHP腳本測試 [root@host50 phpredis-2.2.4]# vim /usr/local/nginx/html/x.php <?php $redis = new redis(); $redis-> connect("192.168.4.51","6351"); $redis-> auth("123456"); $redis-> set("tian" , "haha"); echo OK ; ?>在redis服務器查看數據[root@host50 phpredis-2.2.4]# curl http://localhost/x.php #訪問Nginx服務 OK [root@host51 ~]# redis-cli -h 192.168.4.51 -p 6351 -a 123456 #連接redis服務 192.168.4.51:6351> keys * #查看變量 1) "x" 2) "tian" 192.168.4.51:6351> get tian #獲取值 "haha"

總結

redis相對于MySQL的優缺點

  • redis主要用來做緩存,他有持久化,但也只是為了緩存的可靠性。redis是一種內存數據庫,最大的優點在于數據全放在內存,速度快,效率高。尤其是在某些特定的場合,比如熱點的數據量非常大,而數據在內存和磁盤之間切換代價比較高的場景下,適合應用redis
  • redis主要的缺點是數據不能超過內存大小。傳統關系型數據庫在于它對于數據庫的一致性保障,它的數據模型范式是遵循嚴格事物規則的結構化數據,由于其數據的高度抽象畫,它調度到內存的數據一般場合不會占用很大的內存空間。redis和MySQL各自有不同的業務場景,誰都無法取代

redis數據類型

  • string字符類型
  • 常用命令
  • get、set、incr、decr、mget等

?

  • Hash數列類型
  • 常用命令
  • hget、hset、hgetall

?

  • List列表類型
  • 常用命令
  • ipush、rpush、lpop、rpop、lrange、BLPOP(阻塞版)等

?

  • Set集合類型
  • 常用命令
  • sadd、srem、spop、sdiff、smembers、sunion等

?

  • Sorted? set? 有序集合類型
  • 常用命令
  • zadd、zrange、zrem、zcard等

redis應用領域

  • 緩存(數據查詢、短連接、新聞內容、商品內容等)
  • 分布式集群架構中的session分離
  • 聊天室的在線好友列表
  • 任務隊列(秒殺、搶購、12306等)
  • 應用排行榜
  • 網站訪問統計
  • 數據過期處理(可以精確到毫秒)
  • 總結

    以上是生活随笔為你收集整理的NoSQL(一):NoSQL数据库、redis的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。