在开始本篇之前,可先了解上一篇redis的基本知识(一、Java内存数据库实践之深入浅出Redis - Redis介绍)

http://josh-persistence.iteye.com/blog/2077321

一、Linux下的安装

当前版本最新是2.8.9,具有cluster功能的3.0版本仍是beta版。除了cluster的功能外,3.0版和2.8.9版没有太大的变化。

下载,解压和安装:

$ wget http://download.redis.io/releases/redis-2.8.9.tar.gz
$ tar xzf redis-2.8.9.tar.gz
$ cd redis-2.8.9
$ make

1.1: 编译后的可执行文件在src目录中,可以使用下面的命令运行Redis:

$ src/redis-server

如果不指定conf文件的话,则按默认配置启动,如果指定conf文件的话则按conf文件的配置启动:

1
./redis-server ../etc/redis.conf

Redis 服务端的默认连接端口是 6379。

1.2 客户端连接:

你可以使用内置的客户端连接Redis做测试:

$ src/redis-cli
redis> set foo bar
OK
redis> get foo
"bar"

这相当于连接本地的redis:

./redis-cli -h 127.0.0.1 -p 6379

1.3 查看运行的状态(日志):

如果在conf文件中设置了“daemonize no”的话,则运行状态信息会在终端直接打印;

如果设置了“daemonize yes”的话,则会以守护进程形式在后台运行,log输出位置则通过conf中的logfile设置,如:logfile /usr/local/redis/var/redis.log

1.4. 停止redis实例

./redis-cli shutdown

redis.conf文件的详细配置:参考:http://my.oschina.net/jing521/blog/91293

简单的配置如下:

daemonize yes
pidfile /usr/local/redis/var/redis.pid
port 6379
timeout 300
loglevel debug
logfile /usr/local/redis/var/redis.log
databases 16
save 900 1
save 300 10
save 60 10000
rdbcompression yes
dbfilename dump.rdb
dir /usr/local/redis/var/
appendonly no
appendfsync always

2. Windows的安装:

window上的安装、配置和linux类似,甚至更简单。

可以在Windows下进行安装

Redis安装文件解压后,有以下几个文件。见下图

redis-server.exe:服务程序
redis-check-dump.exe:本地数据库检查
redis-check-aof.exe:更新日志检查
redis-benchmark.exe:性能测试,用以模拟同时由N个客户端发送M个 SETs/GETs 查询 (类似于 Apache 的ab 工具).

在解压好redis的安装文件到E:\根目录后,还需要在redis根目录增加一个redis的配置文件redis.conf,文件具体内容附件中有,不过这里我仍然把配置文件的内容贴上来:

# Redis configuration file example

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize no

# When run as a daemon, Redis write a pid file in /var/run/redis.pid by default.
# You can specify a custom pid file location here.
pidfile /var/run/redis.pid

# Accept connections on the specified port, default is 6379
port 6379

# If you want you can bind a single interface, if the bind option is not
# specified all the interfaces will listen for connections.
#
# bind 127.0.0.1

# Close the connection after a client is idle for N seconds (0 to disable)
timeout 300

# Set server verbosity to 'debug'
# it can be one of:
# debug (a lot of information, useful for development/testing)
# notice (moderately verbose, what you want in production probably)
# warning (only very important / critical messages are logged)
loglevel debug

# Specify the log file name. Also 'stdout' can be used to force
# the demon to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile stdout

# Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT <dbid> where
# dbid is a number between 0 and 'databases'-1
databases 16

################################ SNAPSHOTTING #################################
#
# Save the DB on disk:
#
# save <seconds> <changes>
#
# Will save the DB if both the given number of seconds and the given
# number of write operations against the DB occurred.
#
# In the example below the behaviour will be to save:
# after 900 sec (15 min) if at least 1 key changed
# after 300 sec (5 min) if at least 10 keys changed
# after 60 sec if at least 10000 keys changed
save 900 1
save 300 10
save 60 10000

# Compress string objects using LZF when dump .rdb databases?
# For default that's set to 'yes' as it's almost always a win.
# If you want to save some CPU in the saving child set it to 'no' but
# the dataset will likely be bigger if you have compressible values or keys.
rdbcompression yes

# The filename where to dump the DB
dbfilename dump.rdb

# For default save/load DB in/from the working directory
# Note that you must specify a directory not a file name.
dir ./

################################# REPLICATION #################################

# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. Note that the configuration is local to the slave
# so for example it is possible to configure the slave to save the DB with a
# different interval, or to listen to another port, and so on.
#
# slaveof <masterip> <masterport>

# If the master is password protected (using the "requirepass" configuration
# directive below) it is possible to tell the slave to authenticate before
# starting the replication synchronization process, otherwise the master will
# refuse the slave request.
#
# masterauth <master-password>

################################## SECURITY ###################################

# Require clients to issue AUTH <PASSWORD> before processing any other
# commands. This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# requirepass foobared

################################### LIMITS ####################################

# Set the max number of connected clients at the same time. By default there
# is no limit, and it's up to the number of file descriptors the Redis process
# is able to open. The special value '0' means no limts.
# Once the limit is reached Redis will close all the new connections sending
# an error 'max number of clients reached'.
#
# maxclients 128

# Don't use more memory than the specified amount of bytes.
# When the memory limit is reached Redis will try to remove keys with an
# EXPIRE set. It will try to start freeing keys that are going to expire
# in little time and preserve keys with a longer time to live.
# Redis will also try to remove objects from free lists if possible.
#
# If all this fails, Redis will start to reply with errors to commands
# that will use more memory, like SET, LPUSH, and so on, and will continue
# to reply to most read-only commands like GET.
#
# WARNING: maxmemory can be a good idea mainly if you want to use Redis as a
# 'state' server or cache, not as a real DB. When Redis is used as a real
# database the memory usage will grow over the weeks, it will be obvious if
# it is going to use too much memory in the long run, and you'll have the time
# to upgrade. With maxmemory after the limit is reached you'll start to get
# errors for write operations, and this may even lead to DB inconsistency.
#
# maxmemory <bytes>

############################## APPEND ONLY MODE ###############################

# By default Redis asynchronously dumps the dataset on disk. If you can live
# with the idea that the latest records will be lost if something like a crash
# happens this is the preferred way to run Redis. If instead you care a lot
# about your data and don't want to that a single record can get lost you should
# enable the append only mode: when this mode is enabled Redis will append
# every write operation received in the file appendonly.log. This file will
# be read on startup in order to rebuild the full dataset in memory.
#
# Note that you can have both the async dumps and the append only file if you
# like (you have to comment the "save" statements above to disable the dumps).
# Still if append only mode is enabled Redis will load the data from the
# log file at startup ignoring the dump.rdb file.
#
# The name of the append only file is "appendonly.log"
#
# IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append
# log file in background when it gets too big.

appendonly no

# The fsync() call tells the Operating System to actually write data on disk
# instead to wait for more data in the output buffer. Some OS will really flush
# data on disk, some other OS will just try to do it ASAP.
#
# Redis supports three different modes:
#
# no: don't fsync, just let the OS flush the data when it wants. Faster.
# always: fsync after every write to the append only log . Slow, Safest.
# everysec: fsync only if one second passed since the last fsync. Compromise.
#
# The default is "always" that's the safer of the options. It's up to you to
# understand if you can relax this to "everysec" that will fsync every second
# or to "no" that will let the operating system flush the output buffer when
# it want, for better performances (but if you can live with the idea of
# some data loss consider the default persistence mode that's snapshotting).

appendfsync always
# appendfsync everysec
# appendfsync no

############################### ADVANCED CONFIG ###############################

# Glue small output buffers together in order to send small replies in a
# single TCP packet. Uses a bit more CPU but most of the times it is a win
# in terms of number of queries per second. Use 'yes' if unsure.
glueoutputbuf yes

# Use object sharing. Can save a lot of memory if you have many common
# string in your dataset, but performs lookups against the shared objects
# pool so it uses more CPU and can be a bit slower. Usually it's a good
# idea.
#
# When object sharing is enabled (shareobjects yes) you can use
# shareobjectspoolsize to control the size of the pool used in order to try
# object sharing. A bigger pool size will lead to better sharing capabilities.
# In general you want this value to be at least the double of the number of
# very common strings you have in your dataset.
#
# WARNING: object sharing is experimental, don't enable this feature
# in production before of Redis 1.0-stable. Still please try this feature in
# your development environment so that we can test it better.
# shareobjects no
# shareobjectspoolsize 1024

将附件中的redis_conf.rar解压下来放到redis的根目录中即可。到此,redis的安装已经完毕。下面开始使用redis数据库。

启动redis:
输入命令:redis-server.exe redis.conf
启动后如下图所示:

启动cmd窗口要一直开着,关闭后则Redis服务关闭。 
这时服务开启着,另外开一个窗口进行,设置客户端: 
输入命令:redis-cli.exe -h 202.117.16.133 -p 6379 
输入后如下图所示:

然后可以开始玩了:
设置一个Key并获取返回的值:

$ ./redis-cli set mykey somevalue
OK
$ ./redis-cli get mykey
Somevalue

如何添加值到list:

$ ./redis-cli lpush mylist firstvalue
OK
$ ./redis-cli lpush mylist secondvalue
OK
$ ./redis-cli lpush mylist thirdvalue
OK
$ ./redis-cli lrange mylist 0 -1
. thirdvalue
. secondvalue
. firstvalue
$ ./redis-cli rpop mylist
firstvalue
$ ./redis-cli lrange mylist 0 -1
. thirdvalue
. secondvalue

redis-benchmark.exe:性能测试,用以模拟同时由N个客户端发送M个 SETs/GETs 查询 (类似于 Apache 的 ab 工具).

./redis-benchmark -n 100000 –c 50
====== SET ======
100007 requests completed in 0.88 seconds (译者注:100004 查询完成于 1.14 秒 )
50 parallel clients (译者注:50个并发客户端)
3 bytes payload (译者注:3字节有效载荷)
keep alive: 1 (译者注:保持1个连接)
58.50% <= 0 milliseconds(译者注:毫秒)
99.17% <= 1 milliseconds
99.58% <= 2 milliseconds
99.85% <= 3 milliseconds
99.90% <= 6 milliseconds
100.00% <= 9 milliseconds
114293.71 requests per second(译者注:每秒 114293.71 次查询)

Windows下测试并发客户端极限为60

二、Java内存数据库实践之深入浅出Redis - Redis安装与配置相关推荐

  1. 超详细Redis入门教程——Redis 的安装与配置

    前言 本文小新为大家带来 超详细Redis入门教程--Redis 的安装与配置 相关知识,具体内容包括Redis 的安装,连接前的配置,Redis 客户端分类(包括:命令行客户端,图形界面客户端,Ja ...

  2. Redis的安装、配置 --转载

    原文地址:http://blog.sina.com.cn/s/blog_505bf9af0101ehhp.html redis的安装.配置 安装步骤如下: 下载redis安装包: $ cd /opt/ ...

  3. Linux下redis的安装及配置.

    在上一篇[Linux] linux下安装配置 zookeeper/redis/solr/tomcat/IK分词器 详细实例. 我们已经将redis所需tar包拷贝到了linux下的root 根目录下, ...

  4. [独孤九剑]持续集成实践(三)- Jenkins安装与配置(Jenkins+MSBuild+GitHub)

    本系列文章包含: [独孤九剑]持续集成实践(一)- 引子 [独孤九剑]持续集成实践(二)– MSBuild语法入门 [独孤九剑]持续集成实践(三)- Jenkins安装与配置(Jenkins+MSBu ...

  5. java le下载安装_跟老杨学java系列(五) JDK的安装与配置

    跟老杨学java系列(五) JDK的安装与配置 提示:本节内容对于java入门是非常关键的,对于刚接触java的同学一定要认真学习,欢迎大家留言探讨技术问题.其他问题概不回复. (书接上回)上节课程我 ...

  6. 售票java代码_初探12306售票算法(二)-java代码实践

    周五闲来无事,基于上一篇关于初探12306售票算法(一)-理论,进行了java编码实践供各位读者参考(以下为相关代码的简单描述) 1.订票工具类 1.1初始化一列车厢的票据信息 /** * 生成Tic ...

  7. python2.7.5 怎么装redis_python中Redis的简要介绍以及Redis的安装,配置

    简介: Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存的非关系型数据库,他通过key:value的形式存储.有着多种数据结构,如字符串,列表,集合等. 通过Redis我们可以进行 ...

  8. NOSQL——redis的安装,配置与简单操作

    内容预知 1.缓存的相关知识 1.1 缓存的概念 1.2 系统缓存 1.3 缓存保存位置及分层结构 DNS缓存 应用层缓存 数据层缓存 硬件缓存 2.关系型数据与非关系型数据库 2.1 关系型数据库 ...

  9. Centos7下 Redis的安装、配置开机自启动、开放远程连接

    一.Centos7下 Redis的安装: 1.下载安装包: wget http://download.redis.io/releases/redis-4.0.2.tar.gz 2.解压安装包并安装: ...

最新文章

  1. [three.js]学习笔记
  2. ztree 自定义参数_zTree树插件使用方法及自定义控件实践_蓝戒的博客
  3. 开始位置 环状图_消防泵房内设备、管网、阀门的设置及系统图
  4. Qt工作笔记-MineData相关基本操作
  5. commons.pool2 对象池的使用
  6. Spark推荐实战系列之Swing算法介绍、实现与在阿里飞猪的实战应用(附代码)
  7. C++ int string 转换
  8. 【AAAI2021】NLP所有方向论文列表(情感分析、句法、NER、对话/问答、关系抽取、KD等)...
  9. 张掖市职教中心计算机专业,张掖市职教中心参加2021年全市中等职业学校学生教师技能大赛成绩喜人...
  10. 使用原生JS封装Ajax
  11. [编程语言]C陷阱与缺陷
  12. 佩服Google敏锐和创意!人肉搜索引擎志愿者招募
  13. Minecraft在安卓手机上搭建java服务器
  14. 个人带领团队做过的事
  15. 暴雪这次可真不要脸。。。
  16. 【C语言小游戏】学生信息管理系统
  17. 中国第三代半导体行业运行现状及十四五规划研究分析报告2022-2028年版
  18. [问题]浏览器主页被劫持为2345
  19. Sentinel 极简入门
  20. 驭势科技携手奇辉机器人,联合发布面向多行业的智慧物流整体解决方案

热门文章

  1. 走进Web世界!一套基础到入门的JavaWeb
  2. 微型计算机自动执行原理,微机保护实现原理
  3. FFmpeg 搭建本地屏幕录制环境
  4. 【Windows Server 2019】邮件服务器配置与管理——配置及验证Winmail服务器(下)
  5. 2021-2027全球与中国场镜市场现状及未来发展趋势
  6. 图数据库JanusGraph的QuickStart案例“众神之图”(本地启动)
  7. 权限系统该如何设计?
  8. 恋与制作人 服务器错误,恋与制作人常见问题汇总
  9. python实现中值滤波_Python实现中值滤波去噪方式
  10. 硬盘的存储原理和内部架构