標籤:redis tcl redis啟動
</pre><pre name="code" class="java">java web如何結合redis?**********第一步:安裝redis到linux伺服器.因為redis依賴tcl,所以首先需要安裝tcl.將tcl8.5.10-src.tar.gz拷貝到/opt/tcl目錄下執行如下指令:[email protected]:~/tcl# tar -zxvf tcl8.5.10-src.tar.gz [email protected]:~/tcl# cd tcl8.5.10/unix/[email protected]:~/tcl/tcl8.5.10/unix# ./configure[email protected]:~/tcl/tcl8.5.10/unix# make[email protected]:~/tcl/tcl8.5.10/unix# make install將redis-3.0.1.tar.gz拷貝到/opt/redis目錄下執行如下指令:[email protected]:~/redis# tar -zxvf redis-3.0.1.tar.gz [email protected]:~/redis# cd redis-3.0.1[email protected]:~/redis/redis-3.0.1# make [email protected]:~/redis/redis-3.0.1# make test[email protected]:~/redis/redis-3.0.1# make install**********第二步:啟動redis.注意:預設情況下redis編譯時間會將redis-server等命令拷貝至/usr/local/bin目錄下.同時,redis啟動預設是在前台,可以通過修改如下設定檔將redis啟動模式改為後台.[email protected]:~/redis/redis-3.0.1# vi redis.conf 將daemonize no修改為daemonize yes表示啟動後在後台運行.啟動redis需要指定設定檔,如下:[email protected]:/usr/local/bin# ./redis-server /opt/redis/redis-3.0.1/redis.conf [email protected]:/usr/local/bin# ps -ef | grep redisroot 5968 1 0 10:41 ? 00:00:00 ./redis-server *:6379 root 5972 5820 0 10:41 pts/1 00:00:00 grep redis[email protected]:/usr/local/bin# **********第三步:停止redis.[email protected]:/usr/local/bin# redis-cli -h 192.168.1.3 -p 6379 shutdown[email protected]:/usr/local/bin# ps -ef | grep redisroot 4799 4658 0 19:53 pts/1 00:00:00 grep redis**********第四步:串連redis.[email protected]:/usr/local/bin# redis-cli -h 192.168.1.3 -p 6379192.168.1.3:6379> set username ISOK192.168.1.3:6379> get username"IS"192.168.1.3:6379> **********第五步:建立java項目,引入jedis2.7.2.jar.馬上開啟你的redis學習之旅吧!public class Test {private static Jedis jedis = null;public static void main(String[] args) {jedis = new Jedis("192.168.1.3"); jedis.set("username", "IluckySi"); System.out.println(jedis.get("username")); //IluckySi }}
redis安裝和java web如何結合redis?