Redis安装与使用
Posted XIaoQi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Redis安装与使用相关的知识,希望对你有一定的参考价值。
Redis简介
Redis(全称:Remote Dictionary Server 远程字典服务)是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。从2010年3月15日起,Redis的开发工作由VMware主持。从2013年5月开始,Redis的开发由Pivotal赞助。
常用命令



vi redis.conf
/daemonize查询关键字
daemonize no 把no改为yes

指定文件开启服务
./src/redis-server redis.conf
ctrl+c 退出当前程序


可视化管理工具redis-desktop-manager安装与配置
双击redis-desktop-manager-0.8.8.384.exe即可
配置远程登录
vi /etc/redis/redis.conf #编辑redis配置文件
#bind 127.0.0.1 #注释这一行(69行)
配置密码登录
vi /etc/redis/redis.conf #编辑redis配置文件
#requirepass foobared #修改前
requirepass 123456 #修改后
配置完成密码后,以后登录就密码按下面的命令进行登录
./redis-cli -h 127.0.0.1 -p 6379 -a ***
重启redis
service redis-server restart
关闭防火墙
使用redis Desktop工具连接redis,点击底部加号添加新连接
Redis支持五种数据类型
string(字符串),hash(哈希),list(列表),set(集合)及zset(sorted set:有序集合)
3. 通过命令操作redis(命令不区分大小写)
redis默认的数据库有16,mongodb是3个:admin/local/test
redis-cli #打开redis终端
select index #选择指定的数据库,默认的数据库有16,mongodb是3个:admin/local/test
#字符串
set name #保存
get name #获得
type name #查看类型
keys *
del name
#哈希(Hash),Redis hash是一个string类型的field和value的映射表,hash特别适合用于存储对象
hset key attr1 value1 attr2 value2
hget key attr1
hgetall key
#列表(List)
lpush key value1 value2 value3
llen key
lindex key index
lrange key start stop #stop可以为-1,到末尾的意思
#Set是string类型的无序集合。集合成员是唯一的,这就意味着集合中不能出现重复的数据。
sadd key value #sadd idcard 100
sadd key value1 value2 vlaue3
scard key
sscan key cursor [MATCH pattern] [COUNT count]
exists key #检查key是否存在
以上是关于Redis安装与使用的主要内容,如果未能解决你的问题,请参考以下文章