一、搭建redis服务器

一、搭建redis服务器

RDBMS:关系数据库管理系统(Relational Database Management System),数据按照预先设置的组织结构,存储在物理存储介质上;数据之间可以做关联操作主流软件:Oracle 、DB2、WS-sqlserver、 MySQL

 NoSQL(NoSQL = Not Only SQL ):意思是 " 不仅仅是 SQL“,泛指非关系型数据库,不需要预先定义数据存储结构,表的每条记录都可以有不同的类型和结构

主流软件:Redis、MongoDB、Memcached、CouchDB、Neo4j、FlockDB

 Redis:Remode DIctionary Server( 远程字典服务器 )

使用 C 语言编写的,遵守 BSD 的开源软件;是一款高性能的 (Key/Values)分布式内存数据库;并支持数据持久化的 NoSQL 数据库服务软件(定期将内存中的数据自动写入硬盘)

Redis 特点:支持数据持久化,可以把内存里数据保存到硬盘中;不仅仅支持 key/values 类型的数据,同时还支持 list hash set zset 类型;支持 master-salve 模式数据备份

安装软件
[root@localhost ~]# tar -zxf redis-4.0.8.tar.gz
[root@localhost ~]# cd redis-4.0.8/
[root@localhost redis-4.0.8]#
[root@localhost redis-4.0.8]# rpm -q gcc gcc-c++
未安装软件包 gcc
未安装软件包 gcc-c++
[root@localhost redis-4.0.8]# yum -y install gcc gcc-c++
[root@localhost redis-4.0.8]# make
[root@localhost redis-4.0.8]# make install
初始化配置
[root@localhost redis-4.0.8]# ./utils/install_server.sh //初始化配置
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379] //端口
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] //主配文件
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] //日志文件
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] //数据库目录
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server] //服务程序所在目录
Selected config: #配置摘要信息
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli //命令行连接redis服务命令
Is this ok? Then press ENTER to go on or Ctrl-C to abort. //回车完成配置
Copied /tmp/6379.conf => /etc/init.d/redis_6379 //服务启动脚本
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
[root@localhost redis-4.0.8]#
启动redis服务(软件安装完成后服务自动运行)
[root@localhost redis-4.0.8]# /etc/init.d/redis_6379 status   //查看运行状态,跟start/stop  启动/停止

Redis is running (5341)
[root@localhost redis-4.0.8]# netstat -utnlp | grep :6379
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 5341/redis-server 1
[root@localhost redis-4.0.8]#
[root@localhost redis-4.0.8]# ps -C redis-server
PID TTY TIME CMD
5341 ? 00:00:00 redis-server
[root@localhost redis-4.0.8]#
连接本机redis服务
[root@localhost redis-4.0.8]# redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> get k1
"v1"
127.0.0.1:6379> SHUTDOWN
not connected> exit
[root@localhost redis-4.0.8]#

set keyname keyvalue // 存储

get keyname // 获取                       

select 数据库编号 0-15 // 切换库

keys * // 打印所有变量(当前库)

keys a? // 打印指定变量,1个问号1个字符   

Exists keyname // 测试是否存在(1存在,0不存在)

flushall // 删除所有变量                  

save // 保存变量                           

shutdown // 关闭服务

move keyname dbname // 移动变量到几号库   

expire keyname 10 // 设置有效时间(s)    del keyname   // 删除变量

ttl keyname//查看生存时间(-1:永不过期;-2已过期)                                          

 type keyname // 查看类型

 

posted @ 2021-06-30 09:38  落樰兂痕  阅读(232)  评论(0编辑  收藏  举报