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

歡迎訪問 生活随笔!

生活随笔

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

数据库

Redis入门到精通只需要三篇博客

發(fā)布時間:2025/3/20 数据库 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Redis入门到精通只需要三篇博客 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

2019獨角獸企業(yè)重金招聘Python工程師標準>>>

(Redis介紹:略)

Redis-win-x64位程序的下載地址(缺分,分多的可以給我貢獻點):

http://download.csdn.net/download/qq_33601179/10165429

linux下的安裝百度一大堆,也不貼出來了,畢竟我沒用過,隨便貼一篇也不太好。

(1)win下安裝redis

非常簡單,只需要cmd命令行工具運行代碼,吧服務(wù)程序跑起來就OK,代碼為:(親測有效)

redis-server.exe redis.windows.conf

具體的安裝步驟,請看博客:

http://blog.csdn.net/jinwufeiyang/article/details/52156817

(2)簡單使用Redis

這個我也不廢話,直接看下面這個博客:(親測有效)

http://www.runoob.com/redis/redis-java.html

(3)性能優(yōu)化

Redis連接池,Redis本身就自帶連接池。(親測有效)

推薦將所需要的配置參數(shù)寫到配置文件中,下面附上我封裝的一個Redis連接池的類,由三個部分組成:類BaseRedis(使用Redis連接池:JedisPool)、類PropertiesUtils(用于讀取配置文件)、redis.properties(參數(shù)配置文件)

import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig;/*** Created by Admin on 2017/12/19.*/ public class BaseRedis {private static JedisPool pool;//redis連接池/*** 從連接池中獲取對象** @return*/public static Jedis getJedis() {/*** 判定連接池是否已經(jīng)初始化*/if (pool == null) {PropertiesUtils propertiesUtils=new PropertiesUtils("redis.properties");/*** 從配置文件中讀取配置參數(shù)*/Integer maxTotal=propertiesUtils.getValueForInt("maxTotal");if(maxTotal==null){maxTotal=100;}Integer maxWaitMillis=propertiesUtils.getValueForInt("maxWaitMillis");if(maxWaitMillis==null){maxWaitMillis=1000;}Integer maxIdle=propertiesUtils.getValueForInt("maxIdle");if(maxIdle==null){maxIdle=10;}Integer port=propertiesUtils.getValueForInt("port");if(port==null){port=6379;}String redisUrl=propertiesUtils.getValue("redisUrl");if(redisUrl==null){redisUrl="localhost";}// 建立連接池配置參數(shù)JedisPoolConfig config = new JedisPoolConfig();// 設(shè)置最大連接數(shù)config.setMaxTotal(maxTotal);// 設(shè)置最大阻塞時間,記住是毫秒數(shù)millisecondsconfig.setMaxWaitMillis(maxWaitMillis);// 設(shè)置空間連接config.setMaxIdle(maxIdle);// 創(chuàng)建連接池pool = new JedisPool(config, redisUrl, port);}return pool.getResource();}} import java.io.InputStream; import java.util.*;/*** 讀取配置文件中的屬性*/ public class PropertiesUtils {private String filePath;/*** 構(gòu)造函數(shù)需要傳入待讀取的配置文件的名稱** @param propertiesFilePath*/public PropertiesUtils(String propertiesFilePath) {// ../../這個是根據(jù)當前類所在的目錄相對定位到配置文件的路徑,具體按需修改this.filePath = "../../../../" + propertiesFilePath;}/*** 讀取指定的配置參數(shù)** @param key* @return*/public String getValue(String key) {String str = "";try {Properties pro = new Properties();InputStream ins = this.getClass().getResourceAsStream(filePath);pro.load(ins);str = pro.getProperty(key);ins.close();} catch (Exception e) {e.printStackTrace();}return str;}/*** 讀取指定的配置參數(shù)** @param key* @return*/public Integer getValueForInt(String key) {String str = getValue(key);try {return Integer.parseInt(str);} catch (Exception e) {e.printStackTrace();}return null;}/*** 讀取所有的配置參數(shù)** @return*/public Map<String, String> getAllValue() {//讀取屬性文件a.propertiesMap<String, String> map = new HashMap<String, String>();try {Properties prop = new Properties();InputStream ins = this.getClass().getResourceAsStream(filePath);prop.load(ins); ///加載屬性列表Iterator<String> it = prop.stringPropertyNames().iterator();while (it.hasNext()) {String key = it.next();String value = prop.getProperty(key);map.put(key, value);}ins.close();} catch (Exception e) {e.printStackTrace();}return map;} } #redis配置文件 #URL redisUrl=localhost #端口號 port=6379 #最大連接數(shù) maxTotal=100 #超時時間,單位毫秒 maxWaitMillis=1000 #最大xxx maxIdle=10

?

轉(zhuǎn)載于:https://my.oschina.net/u/1462828/blog/1592455

與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的Redis入门到精通只需要三篇博客的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。