自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Redis數(shù)據(jù)庫(kù)學(xué)習(xí)提高工作效率

數(shù)據(jù)庫(kù) Redis
Redis是一個(gè)開源的使用ANSI C語言編寫、支持網(wǎng)絡(luò)、可基于內(nèi)存亦可持久化的日志型、Key-Value數(shù)據(jù)庫(kù),并提供多種語言的API。

 Redis

Redis是一個(gè)開源的使用ANSI C語言編寫、支持網(wǎng)絡(luò)、可基于內(nèi)存亦可持久化的日志型、Key-Value數(shù)據(jù)庫(kù),并提供多種語言的API。

從2010年3月15日起,Redis的開發(fā)工作由VMware主持。從2013年5月開始,Redis的開發(fā)由Pivotal贊助。

Redis特性

  • Redis支持?jǐn)?shù)據(jù)的持久化,可以將內(nèi)存中的數(shù)據(jù)保存在磁盤中,重啟的時(shí)候可以再次加載進(jìn)行使用。
  • Redis不僅僅支持簡(jiǎn)單的key-value類型的數(shù)據(jù),同時(shí)還把value分為list,set,zset,hash等數(shù)據(jù)結(jié)構(gòu)存儲(chǔ)。
  • 因?yàn)镽edis交換數(shù)據(jù)快,所以在服務(wù)器中常用來存儲(chǔ)一些需要頻繁調(diào)取的數(shù)據(jù),提高效率。

Redis安裝

在Linux下安裝Redis非常簡(jiǎn)單,主要命令就下面4個(gè):

Redis數(shù)據(jù)庫(kù)需要gcc編譯,因此第一步檢查是否安裝gcc環(huán)境

  1. [root@VM_0_16_centos ~]# rpm -qa|grep gcc* 
  2. //無則安裝。 
  3. [root@VM_0_16_centos ~]# yum install gcc-c++ 

創(chuàng)建目錄,下載源碼(通過華為鏡像),解壓源碼

  1. [root@VM_0_16_centos redis]# mkdir /usr/lib/redis 
  2. [root@VM_0_16_centos redis]# cd /usr/lib/redis/ 
  3. [root@VM_0_16_centos redis]# wget https://mirrors.huaweicloud.com/redis/redis-5.0.5.tar.gz 
  4. [root@VM_0_16_centos redis]# tar -zxvf redis-5.0.5.tar.gz  

進(jìn)入文件夾,編譯

  1. [root@VM_0_16_centos redis]# cd ./redis-5.0.5/ 
  2. [root@VM_0_16_centos redis-5.0.5]# make 

上面4命令如果安裝正常的話代表make編譯成功了!

修改配置文件

1、將源碼目錄下redis配置文件redis.conf拷貝到/usr/local/software/redis/目錄下。cp redis.conf /usr/local/software/redis/ 2、修改配置項(xiàng),根據(jù)需要;如果不修改,使用默認(rèn)配置也可以

安裝,并檢查是否安裝了服務(wù)

  1. [root@VM_0_16_centos redis-5.0.5]# make PREFIX=/usr/local/redis install 
  2. //查看是否有此服務(wù) 
  3. [root@VM_0_16_centos bin]# ls /usr/local/redis/bin 
  4. redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis-sentinel  redis-server 
  5. //把解壓目錄下配置文件復(fù)制到安裝路徑下 
  6.  
  7. [root@VM_0_16_centos usr]# cp /usr/lib/redis/redis-5.0.5/redis.conf  /usr/local/redis/ 
  8. // 由于前端啟動(dòng)模式啟動(dòng)后不可以隨意關(guān)閉(進(jìn)程斷開),所以需要配置后端模式啟動(dòng) 

下面,配置Redis外網(wǎng)訪問,修改后端啟動(dòng)(即守護(hù)進(jìn)程開啟),取消ip綁定

  1. [root@VM_0_16_centos ~]# vim /usr/local/redis/redis.conf 
  2. 注釋掉bind 127.0.0.1 或改為bind 0.0.0.0 
  3. #bind 127.0.0.1 
  4. 更改protected-mode yes為 
  5. # 關(guān)閉保護(hù)模式 
  6. protected-mode no 
  7.  
  8. 更改daemonize no為 
  9. daemonize yes 

設(shè)置密碼requirepass 要很長(zhǎng)的密碼

啟動(dòng),并指定配置文件

  1. [root@VM_0_16_centos ~]# cd /usr/local/redis/ 
  2.  
  3. [root@VM_0_16_centos redis]# ./bin/redis-server ./redis.conf 
  4.  
  5. 1675:C 15 Sep 2019 22:50:52.157 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 
  6.  
  7. 1675:C 15 Sep 2019 22:50:52.157 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=1675, just started 
  8. 1675:C 15 Sep 2019 22:50:52.157 # Configuration loaded 

通過端口(6379)查看服務(wù)是否啟動(dòng)

  1. [root@VM_0_16_centos redis]# ps -ef|grep redis 
  2. root     1676     1  0 22:50 ?        00:00:00 ./bin/redis-server *:6379 
  3. root      1900  1219  0 22:52 pts/6    00:00:00 grep –color=auto redis 

本地客戶端連接和redis服務(wù)關(guān)閉

  1. [root@VM_0_16_centos redis]# ./bin/redis-cli 
  2. 127.0.0.1:6379> eixt 
  3. [root@VM_0_16_centos redis]# ./bin/redis-cli shutdown 

通過外部(ip)連接,(需要開放云服務(wù)器相應(yīng)端口)

  1. [root@VM_0_16_centos redis]# ./bin/redis-cli -h 49.ip.ip.2 -p 6379 -a 密碼 
  2. Warning: Using a password with ‘-a’ or ‘-u’ option on the command line interface may not be safe. 
  3. 49.ip.ip.2:6379>  

上面步驟參考:騰訊云服務(wù)器安裝redis,https://cloud.tencent.com/developer/article/1532497。

Redis數(shù)據(jù)模型

Redis支持五種數(shù)據(jù)類型:string(字符串),hash(哈希),list(列表),set(集合)及zset(sorted set:有序集合)。

  1. String ------> 字符串
  2. Hash ------> 哈希
  3. List ------> 列表
  4. set ------> 集合
  5. Zset ------> 有序集合

 

  • 連接redis:redis-cli
  • 退出:exit
  • 操作服務(wù)端:service redis start/stop/restart
  • 切換數(shù)據(jù)庫(kù):select n

 

Redis五大數(shù)據(jù)類型使用

全局key操作

對(duì)5 個(gè)數(shù)據(jù)類型都使用的命令

  1. 查看所有的key:keys * 
  2. 刪除鍵值對(duì):del key 
  3. 改名:rename  key  new_key 
  4. 設(shè)置過期時(shí)間:expire key seconds 

String類型

strings是redis最基本的數(shù)據(jù)類型,一個(gè)key對(duì)應(yīng)一個(gè)value

  1. 設(shè)置數(shù)據(jù):set  key  value 
  2. 查看數(shù)據(jù):get  key 
  3. 追加數(shù)據(jù):append  key  value 
  4. 刪除數(shù)據(jù):del key

List類型

  1. 添加數(shù)據(jù):rpush key value [value…] 
  2. lpush key value [value…]     頭部添加數(shù)據(jù) 
  3.  
  4. 查看數(shù)據(jù):lrange key start stop 
  5. lindex key index      查看某個(gè)數(shù)據(jù)  
  6.  
  7. 修改數(shù)據(jù):lset key index value 
  8. 刪除數(shù)據(jù):rpop key 
  9. lpop key 頭部刪除數(shù)據(jù)  

Hash類型

  1. 添加數(shù)據(jù):hset key field value  
  2. 查看域值:hget key field 
  3. hgetall key  查看所有的field和value 
  4. 查看所有的value:hvals key 
  5. 查看所有的field:hkeys key 

Set類型

  1. 添加數(shù)據(jù):sadd key member [member …] 
  2. 查看數(shù)據(jù):smembers key 
  3. 隨機(jī)刪除:spop key 
  4. 指定刪除:srem key member [member …] 

Sorted Set類型

  1. 添加數(shù)據(jù):zadd key score member [score2 member2 …]  
  2. 查看數(shù)據(jù):zrange key start stop  
  3. zrangebyscore key min max 通過scores值查看 
  4. 刪除數(shù)據(jù):zrem key member [member …] 
  5. 通過索引刪除多個(gè)數(shù)據(jù):zremrangebyrank key min max 
  6. zremrangebyscore key min max  -- 通過scores值刪除 

「flushall 刪除所有數(shù)據(jù)」

Redis可視化

我使用的是redis desktop manager。這個(gè)工具應(yīng)該是現(xiàn)在使用率最廣的可視化工具了。下載鏈接為:https://rdm.dev/pricing。

 

Python連接redis

Python連接redis數(shù)據(jù)庫(kù)的庫(kù)是redis,沒有Pyredis。

安裝:pip install redisPython連接redis前,確保配置Redis外網(wǎng)訪問成功。

  1. import redis 
  2.  
  3. # 普通連接 
  4. conn = redis.Redis(host="192.168.92.90", port=6379,password="123456"
  5. conn.set("x","hello"
  6. val = conn.get("x"
  7. print(val) # hello 
  8.  
  9.  
  10. import redis 
  11.  
  12. # 連接池 
  13. pool = redis.ConnectionPool(host="192.168.23.166", port=6379,password="123456",max_connections=1024) 
  14. conn = redis.Redis(connection_pool=pool) 
  15. print(conn.get("x1")) 

 本文已收錄 GitHub:https://github.com/MaoliRUNsen/runsenlearnpy100

 

責(zé)任編輯:姜華 來源: Python之王
相關(guān)推薦

2009-05-14 11:43:56

2009-05-15 16:36:34

EclipseIDE效率

2011-03-22 14:57:58

2011-09-13 19:46:57

2012-03-12 13:35:10

開發(fā)

2023-10-24 17:45:31

AI

2019-04-03 09:58:00

GitHub代碼開發(fā)者

2014-03-20 16:18:30

碼農(nóng)工作效率

2009-07-06 13:38:29

JSPInitJSPDestory

2012-07-04 15:42:22

Web

2021-06-07 14:36:58

iPadSiri辦公

2019-12-29 15:41:42

終端命令Unix系統(tǒng)

2016-09-23 20:22:51

WordPressMarkdown工作效率

2013-05-23 09:24:03

BYODBYOD策略思科BYOD

2019-08-30 14:25:03

Vim命令Linux

2019-07-17 05:02:14

物聯(lián)網(wǎng)工作效率IOT

2009-11-20 14:52:35

SharePointVPN業(yè)務(wù)流程

2025-02-18 10:56:18

2020-12-11 10:00:17

工具代碼Windows

2025-02-21 09:54:12

點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)