1、前言

Redis是常用基于内存的Key-Value数据库,比Memcache更先进,支持多种数据结构,高效,快速。用Redis可以很轻松解决高并发的数据访问问题;做为时时监控信号处理也非常不错。

2、安装

//在Ubuntu Linux终端中安装Redis服务器端
sudo apt-get install redis-server

安装完成后,Redis服务器会自动启动,我们检查Redis服务器程序

//在终端中检查Redis服务器系统进程
ps -aux|grep redis

可以看到:

//在终端中通过启动命令检查Redis服务器状态
netstat -nlt|grep 6379

显示: tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN

//通过启动命令检查Redis服务器状态
sudo /etc/init.d/redis-server status

显示: redis-server is running

3、通过命令行客户端访问Redis

安装Redis服务器,会自动地一起安装Redis命令行客户端程序。

在本机输入redis-cli命令就可以启动,客户端程序访问Redis服务器。

~ redis-cli
redis 127.0.0.1:6379> # 命令行的帮助
redis 127.0.0.1:6379> help
redis-cli 2.2.12
Type: "help @" to get a list of commands in
"help " for help on
"help " to get a list of possible help topics
"quit" to exit # 查看所有的key列表
redis 127.0.0.1:6379> keys *
(empty list or set)

基本的Redis客户端命令操作

  1. 增加一条字符串记录key1
# 增加一条记录key1
redis 127.0.0.1:6379> set key1 "hello"
OK # 打印记录
redis 127.0.0.1:6379> get key1
"hello"

   2 . 增加一条数字记录key2

# 增加一条数字记录key2
set key2 1
OK # 让数字自增
redis 127.0.0.1:6379> INCR key2
(integer) 2
redis 127.0.0.1:6379> INCR key2
(integer) 3 # 打印记录
redis 127.0.0.1:6379> get key2
"3"

   3. 增加一条列表记录key3

# 增加一个列表记录key3
redis 127.0.0.1:6379> LPUSH key3 a
(integer) 1 # 从左边插入列表
redis 127.0.0.1:6379> LPUSH key3 b
(integer) 2 # 从右边插入列表
redis 127.0.0.1:6379> RPUSH key3 c
(integer) 3 # 打印列表记录,按从左到右的顺序
redis 127.0.0.1:6379> LRANGE key3 0 3
1) "b"
2) "a"
3) "c"

   4.增加一条哈希表记录key4

# 增加一个哈希记表录key4
redis 127.0.0.1:6379> HSET key4 name "John Smith"
(integer) 1 # 在哈希表中插入,email的Key和Value的值
redis 127.0.0.1:6379> HSET key4 email "abc@gmail.com"
(integer) 1 # 打印哈希表中,name为key的值
redis 127.0.0.1:6379> HGET key4 name
"John Smith" # 打印整个哈希表
redis 127.0.0.1:6379> HGETALL key4
1) "name"
2) "John Smith"
3) "email"
4) abc@gmail.com

   5.增加一条哈希表记录key5

# 增加一条哈希表记录key5,一次插入多个Key和value的值
redis 127.0.0.1:6379> HMSET key5 username antirez password P1pp0 age 3
OK # 打印哈希表中,username和age为key的值
redis 127.0.0.1:6379> HMGET key5 username age
1) "antirez"
2) "3" # 打印完整的哈希表记录
redis 127.0.0.1:6379> HGETALL key5
1) "username"
2) "antirez"
3) "password"
4) "P1pp0"
5) "age"
6) "3"

   6.删除记录

# 查看所有的key列表
redis 127.0.0.1:6379> keys *
1) "key2"
2) "key3"
3) "key4"
4) "key5"
5) "key1" # 删除key1,key5
redis 127.0.0.1:6379> del key1
(integer) 1
redis 127.0.0.1:6379> del key5
(integer) 1 # 查看所有的key列表
redis 127.0.0.1:6379> keys *
1) "key2"
2) "key3"
3) "key4"

4、修改Redis的配置

1、 使用Redis的访问账号

默认情况下,访问Redis服务器是不需要密码的,为了增加安全性我们需要设置Redis服务器的访问密码。设置访问密码为redis。

用vi打开Redis服务器的配置文件redis.conf

~ sudo vi /etc/redis/redis.conf

#取消注释requirepass
requirepass redis

2、 让Redis服务器被远程访问
默认情况下,Redis服务器不允许远程访问,只允许本机访问,所以我们需要设置打开远程访问的功能。

用vi打开Redis服务器的配置文件redis.conf

~ sudo vi /etc/redis/redis.conf

#注释bind
#bind 127.0.0.1

修改后,重启Redis服务器。

~ sudo /etc/init.d/redis-server restart
Stopping redis-server: redis-server.
Starting redis-server: redis-server.

未使用密码登陆Redis服务器

~ redis-cli

redis 127.0.0.1:6379> keys *
(error) ERR operation not permitted

发现可以登陆,但无法执行命令了。

登陆Redis服务器,输入密码

~  redis-cli -a redisredis

redis 127.0.0.1:6379> keys *
1) "key2"
2) "key3"
3) "key4"

登陆后,一切正常。

我们检查Redis的网络监听端口

//检查Redis服务器占用端口
~ netstat -nlt|grep 6379
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN

我们看到从之间的网络监听从 127.0.0.1:6379 变成 0 0.0.0.0:6379,表示Redis已经允许远程登陆访问。

我们在远程的另一台Linux访问Redis服务器

~ redis-cli -a redisredis -h 192.168.1.199

redis 192.168.1.199:6379> keys *
1) "key2"
2) "key3"
3) "key4"

Linux—Ubuntu14.0.5安装Redis的更多相关文章

  1. Linux—Ubuntu14.0.5安装mongo

    1.安装mongo sudo apt-get install mongo 2.如果遇到找不到安装包运行,那就更新资源列表 sudo apt-get update 3.安装成功会自动运行mongo pg ...

  2. Linux—Ubuntu14.0.5安装MySQL

    1.更新资援列表 sudo apt-get update 2.安装mysql的操作命令(下一步选中“Y”) sudo apt-get install mysql-server 3.输入MySQLroo ...

  3. Linux—Ubuntu14.0.5安装gitlab

    1.下载gitlab-ce,到该连接选择版本   https://mirror.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu/pool/trusty/main/g/git ...

  4. centos / Linux 服务环境下安装 Redis 5.0.3

    原文:centos / Linux 服务环境下安装 Redis 5.0.3 1.首先进入你要安装的目录 cd /usr/local 2.下载目前最新稳定版本 Redis 5.0.3 wget http ...

  5. ubuntu14.04server版安装redis

    此博客记录首次在ubuntu14.04上安装redis过程. 以下采用两种方式进行安装 方法一:进入redis的官网下载(地址:https://redis.io/download)目前版本为4.0.9 ...

  6. Ubuntu14.0下安装Zend Framework 2

    Ubuntu14.0下安装Zend Framework 2为了安装这个东西,忙活了快一天了,参考中文博客一直没有安装成功,有些博客的时间也是已经很早了,后来google看英文版的才安装成功,这里记录一 ...

  7. Linux CentOS-7.0上安装Tomcat7

    Linux CentOS-7.0上安装Tomcat7   安装说明 安装环境:CentOS-7.0.1406安装方式:源码安装 软件:apache-tomcat-7.0.29.tar.gz 下载地址: ...

  8. Arch Linux中通过AUR安装Redis Desktop Manager失败

    笔者在安装Redis Desktop Manager时出现了Failed to connect to chromium.googlesource.com port 443: Connection ti ...

  9. CentOS7(Linux)源码安装Redis

    介绍 项目中经常需要用到Redis做缓存数据库,可是还有小伙伴不会在Linux上安装Redis,毕竟我们开发的项目都是要在服务器上运行的,今天就来讲讲如何在CentOS7环境使用源码进行安装Redis ...

随机推荐

  1. [ACM] ZOJ 3819 Average Score (水题)

    Average Score Time Limit: 2 Seconds      Memory Limit: 65536 KB Bob is a freshman in Marjar Universi ...

  2. spark定制之五:使用说明

    背景 spark-shell是一个scala编程解释运行环境,能够通过编程的方式处理逻辑复杂的计算,但对于简单的类似sql的数据处理,比方分组求和,sql为"select g,count(1 ...

  3. JQuery实现复制到剪贴板功能

    在网页中实现复制到剪贴板功能,有两种方法, 第1种方法:使用JavaScript自带的方法,但是这种方法只能在IE下使用. document.execCommand("Copy") ...

  4. 【Geforce】关于如何在Geforce Experience中登录

    相信不少人无法登录这个该死的Geforce Experience.这里提供几个解决方案: 1.在“服务”中启动运行 NVIDIA NetworkService Container 方式改为手动或者自动 ...

  5. 交叉熵代价函数——当我们用sigmoid函数作为神经元的激活函数时,最好使用交叉熵代价函数来替代方差代价函数,以避免训练过程太慢

    交叉熵代价函数 machine learning算法中用得很多的交叉熵代价函数. 1.从方差代价函数说起 代价函数经常用方差代价函数(即采用均方误差MSE),比如对于一个神经元(单输入单输出,sigm ...

  6. Device /dev/sdb1 not found (or ignored by filtering)

    /etc/lvm/lvm.conf filters

  7. Node.js安全清单

    前言 安全性,总是一个不可忽视的问题.许多人都承认这点,但是却很少有人真的认真地对待它.所以我们列出了这个清单,让你在将你的应用部署到生产环境来给千万用户使用之前,做一个安全检查. 以下列出的安全项, ...

  8. php write excel

    /** * 写excel方法 */ function writeExcel($tabArr, $dataArr,$path) { require_once CODE_BASE2 . '/util/ph ...

  9. Java.HttpClient绕过Https证书解决方案一

    方案1 import javax.net.ssl.*; import java.io.*; import java.net.URL; import java.security.KeyManagemen ...

  10. Python生成器(yield)

    对于调用一个普通的Python函数,一般是从函数的第一行代码开始执行,结束于return语句.异常或者函数所有语句执行完毕.一旦函数将控制权交还给调用者,就意味着全部结束.函数中做的所有工作以及保存在 ...