Redis入門

来源:http://www.cnblogs.com/ivictor/archive/2016/02/03/5179990.html
-Advertisement-
Play Games

一、安裝 目前,官方最新穩定版本為3.0.7 # wget http://download.redis.io/releases/redis-3.0.7.tar.gz # cd /usr/local/ # tar xvf /root/redis-3.0.7.tar.gz # cd redis-3.0.


一、安裝

目前,官方最新穩定版本為3.0.7

# wget http://download.redis.io/releases/redis-3.0.7.tar.gz

# cd /usr/local/

# tar xvf /root/redis-3.0.7.tar.gz

# cd redis-3.0.7/

# make

 

二、啟動

安裝完成後,在src目錄下會生成啟動執行程式,包括redis-server,redis-sentinel, redis-benchmark,redis-cli等

# src/redis-server 

該啟動方式是前臺啟動,如果關閉當前終端,則redis會自動關閉

正如登錄信息開頭Warning所顯示的,這種方式啟動沒有使用配置文件,所以並不推薦。預設監聽6379埠

24649:C 03 Feb 16:32:30.242 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
24649:M 03 Feb 16:32:30.243 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.0.7 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 24649
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

24649:M 03 Feb 16:32:30.246 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
24649:M 03 Feb 16:32:30.246 # Server started, Redis version 3.0.7
24649:M 03 Feb 16:32:30.246 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
24649:M 03 Feb 16:32:30.246 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
24649:M 03 Feb 16:32:30.247 * The server is now ready to accept connections on port 6379

 

關於redis-server的更多用法,可通過redis-server -h查看

# src/redis-server -h

Usage: ./redis-server [/path/to/redis.conf] [options]
       ./redis-server - (read config from stdin)
       ./redis-server -v or --version
       ./redis-server -h or --help
       ./redis-server --test-memory <megabytes>

Examples:
       ./redis-server (run the server with default conf)
       ./redis-server /etc/redis/6379.conf
       ./redis-server --port 7777
       ./redis-server --port 7777 --slaveof 127.0.0.1 8888
       ./redis-server /etc/myredis.conf --loglevel verbose

Sentinel mode:
       ./redis-server /etc/sentinel.conf --sentinel

 

配置文件中常用參數如下:

daemonize:是否以後臺daemon方式運行,預設是前臺方式運行,即預設值為no

pidfile:pid文件位置,預設為:/run/redis.pid

port:監聽的埠號,預設為6379

bind 127.0.0.1 配置監聽網卡的ip,針對有多個網卡的場景

logfile:log文件位置,預設值為stdout,使用“標準輸出”,預設後臺模式會輸出到/dev/null

loglevel notice ,指定日誌記錄級別,Redis總共支持四個級別:debug,verbose,notice,warning,預設為notice

     Debug:記錄很多信息,用於開發和測試

     Verbose:很多精簡的有用信息,不像debug會記錄那麼多

     Notice:普通的verbose,常用於生產環境

     Warning:只有非常重要或者嚴重的信息會記錄到日誌

 

三、設置開機自啟動

 將啟動腳本複製到/etc/init.d目錄下

# cp /usr/local/redis-3.0.7/utils/redis_init_script /etc/init.d/redisd

編輯啟動腳本

# vim /etc/init.d/redisd

#!/bin/sh
# chkconfig:2345 90 10
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

REDISPORT=6379
EXEC=/usr/local/redis-3.0.7/src/redis-server
#EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/redis-3.0.7/src/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"

 

主要做了兩項修改,

一、添加了# chkconfig:2345 90 10

二、指定了redis-server和redis-cli的位置

EXEC=/usr/local/redis-3.0.7/src/redis-server

CLIEXEC=/usr/local/redis-3.0.7/src/redis-cli

註意:

PIDFILE=/var/run/redis_${REDISPORT}.pid指定了pid文件的位置

CONF="/etc/redis/${REDISPORT}.conf"指定了配置文件的位置

 

創建配置文件

# cd /etc/

# mkdir redis

# cp /usr/local/redis-3.0.7/redis.conf redis/6379.conf

 

修改配置文件

主要是設置redis以後臺進程運行和pid文件的位置

daemonize yes
pidfile /var/run/redis_6379.pid

 

以服務方式啟動redis

# /etc/init.d/redisd start

Starting Redis server...

# ps -ef |grep redis

root      29836      1  0 18:23 ?        00:00:00 /usr/local/redis-3.0.7/src/redis-server *:6379
root      29846   4110  0 18:23 pts/0    00:00:00 grep --color=auto redis

 

客戶端連接測試

# cd /usr/local/redis-3.0.7/src/

# ./redis-cli 

127.0.0.1:6379> set 123 hello
OK
127.0.0.1:6379> get 123
"hello"

預設連接到localhost 6379,查看伺服器信息,可通過info命令。

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 兩年前,蘋果為現代的使用者完全改變了設計語言。對於設計者來說,這使得他們更容易關註動畫和功能而不是其他的細枝末節。 我已經被問過很多次怎樣開始設計或者是有什麼捷徑可以成為更好的設計師。雖然沒有銀彈,然而有很多的技巧和規則設計將影響您普遍設計的方式。 即使你設計一個完全不同的平臺上,如果您已經瞭解了在
  • 年前一直在加班趕項目,斷更一月有餘,新年將至,在這裡祝各位看官新年快樂,大吉大利 在這裡推薦兩本好書,是博主準備年假期間學習的,斟酌了許久,買了這兩本,確實是非常好的進階書,推薦給大家 1.OC高級編程:一本面向iOS中級開發者的書,這本書只有三章,分別是記憶體管理,Block和GCD。但是書中詳細的
  • 一些不常見確又很實用的代碼塊。 1.精確獲取屏幕尺寸(例如:3.5、4.0、5.0寸屏幕) public static double getScreenPhysicalSize(Activity ctx) { DisplayMetrics dm = new DisplayMetrics(); ctx
  • case 這個關鍵詞,用的地方不少~大部分的用途都通過以下的方式去應用 DECLARE @i INT = 3 SELECT CASE @i WHEN 1 THEN 1 WHEN 2 THEN 2 WHEN 3 THEN 3 END AS 測試1; 測試1 ----------- 3 DECLARE
  • 原文出處:http://www.cnblogs.com/jianglan/archive/2011/08/22/2149834.html .cs文件的主要代碼: public class User_List //這個類是對應是Extjs的Grid的field裡面的,field有幾項就寫幾項 { pu
  • Query #41 Memory Clerk Usage -- Memory Clerk Usage for instance -- Look for high value for CACHESTORE_SQLCP (Ad-hoc query plans) SELECT TOP(10) mc.[ty
  • 正如文章《通用的業務編號規則設計實現(附源碼)》 文章里需要一個多實例和線程安全的序列化生成器,在SQL Server 2012+ 版本 有一個通過.NET程式集的序列號transact-sql 函數 http://msdn.microsoft.com/zh-cn/library/ff878091.
  • 上一篇,我們對hive的數據導出,以及集群Hive數據的遷移進行描述。瞭解到了基本的hive導出操作。這裡,我們將對hive的CLI及JDBC這些實用性很強的兩個方便進行簡要的介紹。 下麵我們開始介紹hive的CLI和JDBC。
一周排行
    -Advertisement-
    Play Games
  • Dapr Outbox 是1.12中的功能。 本文只介紹Dapr Outbox 執行流程,Dapr Outbox基本用法請閱讀官方文檔 。本文中appID=order-processor,topic=orders 本文前提知識:熟悉Dapr狀態管理、Dapr發佈訂閱和Outbox 模式。 Outbo ...
  • 引言 在前幾章我們深度講解了單元測試和集成測試的基礎知識,這一章我們來講解一下代碼覆蓋率,代碼覆蓋率是單元測試運行的度量值,覆蓋率通常以百分比表示,用於衡量代碼被測試覆蓋的程度,幫助開發人員評估測試用例的質量和代碼的健壯性。常見的覆蓋率包括語句覆蓋率(Line Coverage)、分支覆蓋率(Bra ...
  • 前言 本文介紹瞭如何使用S7.NET庫實現對西門子PLC DB塊數據的讀寫,記錄了使用電腦模擬,模擬PLC,自至完成測試的詳細流程,並重點介紹了在這個過程中的易錯點,供參考。 用到的軟體: 1.Windows環境下鏈路層網路訪問的行業標準工具(WinPcap_4_1_3.exe)下載鏈接:http ...
  • 從依賴倒置原則(Dependency Inversion Principle, DIP)到控制反轉(Inversion of Control, IoC)再到依賴註入(Dependency Injection, DI)的演進過程,我們可以理解為一種逐步抽象和解耦的設計思想。這種思想在C#等面向對象的編 ...
  • 關於Python中的私有屬性和私有方法 Python對於類的成員沒有嚴格的訪問控制限制,這與其他面相對對象語言有區別。關於私有屬性和私有方法,有如下要點: 1、通常我們約定,兩個下劃線開頭的屬性是私有的(private)。其他為公共的(public); 2、類內部可以訪問私有屬性(方法); 3、類外 ...
  • C++ 訪問說明符 訪問說明符是 C++ 中控制類成員(屬性和方法)可訪問性的關鍵字。它們用於封裝類數據並保護其免受意外修改或濫用。 三種訪問說明符: public:允許從類外部的任何地方訪問成員。 private:僅允許在類內部訪問成員。 protected:允許在類內部及其派生類中訪問成員。 示 ...
  • 寫這個隨筆說一下C++的static_cast和dynamic_cast用在子類與父類的指針轉換時的一些事宜。首先,【static_cast,dynamic_cast】【父類指針,子類指針】,兩兩一組,共有4種組合:用 static_cast 父類轉子類、用 static_cast 子類轉父類、使用 ...
  • /******************************************************************************************************** * * * 設計雙向鏈表的介面 * * * * Copyright (c) 2023-2 ...
  • 相信接觸過spring做開發的小伙伴們一定使用過@ComponentScan註解 @ComponentScan("com.wangm.lifecycle") public class AppConfig { } @ComponentScan指定basePackage,將包下的類按照一定規則註冊成Be ...
  • 操作系統 :CentOS 7.6_x64 opensips版本: 2.4.9 python版本:2.7.5 python作為腳本語言,使用起來很方便,查了下opensips的文檔,支持使用python腳本寫邏輯代碼。今天整理下CentOS7環境下opensips2.4.9的python模塊筆記及使用 ...