Redis基础1(定义及基础)
生活随笔
收集整理的這篇文章主要介紹了
Redis基础1(定义及基础)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Redis
定義:Redis是一個(gè)軟件,幫助開發(fā)者對(duì)一臺(tái)機(jī)器的內(nèi)存進(jìn)行操作
安裝redis軟件方法:
超鏈接地址:https://www.cnblogs.com/L5251/articles/9146881.html
Python中下載依賴包
pip3 install redis測(cè)試Redis是否安裝成功
# 1、引入redis # 2、參數(shù)解釋: # host:服務(wù)器地址(安裝在linux系統(tǒng)上使用 ip addr 查看) # port:端口 默認(rèn)6379端口 # password:密碼import redisconn = redis.Redis(host='192.168.131.129', port=6379, password='123456') conn.set('ww', 'sssssssss', ex=500) # set類似一個(gè)字典 ex=超時(shí)時(shí)間(單位秒) # 最后兩行先注釋,運(yùn)行上幾行,然后注釋掉conn.set('ww', 'sssssssss', ex=500) # 打開最后兩行查看是否會(huì)打印值,打印的話證明Redis安裝成功 val = conn.get('ww') # 這是最后兩行 print(val)# 結(jié)果: # b'sssssssss' 測(cè)試源碼?引入連接池
# 使用連接池ConnectionPool import redispool = redis.ConnectionPool(host='192.168.131.129', port=6379, password='123456', max_connections=1000) conn = redis.Redis(connection_pool=pool) conn.set('foo', 'Bar') 代碼示例單例模式創(chuàng)建鏈接池(實(shí)際上是建立一個(gè)模塊)
import redisPOLL = redis.ConnectionPool(host='192.168.131.129', port=6379, password='123456', max_connections=1000) redis_pool.py # 使用連接池ConnectionPool import redis from .redis_pool import POLLwhile 1:key = input('請(qǐng)輸入key')value = input('請(qǐng)輸入value')# 創(chuàng)建連接池# 去連接池中獲取連接# 單例模式conn = redis.Redis(connection_pool=POLL)# 設(shè)置值conn.set(key, value) demo1.py文件位置:
redis特點(diǎn)
特點(diǎn)
- 持久化
- 單進(jìn)程,單線程
- 五大數(shù)據(jù)類型
?
轉(zhuǎn)載于:https://www.cnblogs.com/L5251/articles/9146825.html
總結(jié)
以上是生活随笔為你收集整理的Redis基础1(定义及基础)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 分治法求最大最小
- 下一篇: MySQL备份和还原数据库及慢查询日志使