ubuntu下安装redis
来源:互联网 发布:录制手机屏幕视频软件 编辑:程序博客网 时间:2024/05/17 23:29
Ubuntu 下安装
在 Ubuntu 系统安装 Redi 可以使用以下命令:
$sudo apt-get update$sudo apt-get install redis-server
启动 Redis
$ redis-server
查看 redis 是否启动?
$ redis-cli
以上命令将打开以下终端:
redis 127.0.0.1:6379>
127.0.0.1 是本机 IP ,6379 是 redis 服务端口。现在我们输入 PING 命令。
redis 127.0.0.1:6379> pingPONG
以上说明我们已经成功安装了redis。
通过启动命令检查Redis服务器状态:
sudo /etc/init.d/redis-server statusredis-server is running
通过命令行客户端访问Redis
(1) 启动
安装Redis服务器,会自动地一起安装Redis命令行客户端程序。
在本机输入redis-cli命令就可以启动,客户端程序访问Redis服务器。
redis-cliredis 127.0.0.1:6379>
(2) 帮助
redis 127.0.0.1:6379> helpredis-cli 2.2.12Type: "help @" to get a list of commands in "help " for help on "help " to get a list of possible help topics "quit" to exit
(3) 查看所有的key列表
redis 127.0.0.1:6379> keys *(empty list or set)
(4) 增加一条字符串记录key1
//增加一条记录key1redis 127.0.0.1:6379> set key1 "hello"OK
(5) 打印记录
“`
redis 127.0.0.1:6379> get key1
“hello”
(6)增加一条数字记录key2
set key2 1
OK
(7) 让数字自增 ```redis 127.0.0.1:6379> INCR key2(integer) 2redis 127.0.0.1:6379> INCR key2(integer) 3
(8) 增加一条列表记录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 31) "b"2) "a"3) "c"
(9) 增加一条哈希表记录key4
//增加一个哈希记表录key4redis 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 key41) "name"2) "John Smith"3) "email"4) "abc@gmail.com"
(10) 增加一条哈希表记录key5,一次插入多个Key和value的值
redis 127.0.0.1:6379> HMSET key5 username antirez password P1pp0 age 3OK//打印哈希表中,username和age为key的值redis 127.0.0.1:6379> HMGET key5 username age1) "antirez"2) "3"//打印完整的哈希表记录redis 127.0.0.1:6379> HGETALL key51) "username"2) "antirez"3) "password"4) "P1pp0"5) "age"6) "3"
(11) 查看所有的key列表
redis 127.0.0.1:6379> keys *1) "key2"2) "key3"3) "key4"4) "key5"5) "key1"//删除key1,key5redis 127.0.0.1:6379> del key1(integer) 1redis 127.0.0.1:6379> del key5(integer) 1
修改Redis的配置
(1) 使用Redis的访问账号
默认情况下,访问Redis服务器是不需要密码的,为了增加安全性我们需要设置Redis服务器的访问密码。设置访问密码为redisredis。
用vi打开Redis服务器的配置文件redis.conf
~ sudo vi /etc/redis/redis.conf//取消注释requirepassrequirepass redisredis
(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:3306 变成 0 0.0.0.0:3306,表示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”
远程访问正常。通过上面的操作,我们就把Redis数据库服务器,在Linux Ubuntu中的系统安装完成。
转载请注明出处:
http://blog.fens.me/linux-redis-install/
redis命令
详见:http://redis.io/commands
- Ubuntu下安装Redis
- Ubuntu下安装redis
- Ubuntu下安装redis
- ubuntu下安装redis
- ubuntu下redis安装
- Ubuntu下 Redis安装
- ubuntu下安装redis
- ubuntu下安装redis
- Ubuntu下安装Redis
- ubuntu下安装redis
- ubuntu下安装redis
- ubuntu下安装redis
- Ubuntu下安装redis
- Ubuntu下Redis安装
- Ubuntu下安装Redis
- ubuntu下安装redis
- ubuntu下安装redis
- ubuntu下安装redis
- OC 中nil,Nil,NULL,NSNull的含义
- 论文阅读:Multi-view Convolutional Neural Networks for 3D Shape Recognition
- android 6.0 权限
- 超越之JSP总结(经典)
- LeetCode 329: Longest Increasing Path in a Matrix
- ubuntu下安装redis
- Sqoop 数据导入到Hive中报错 HIVE_CONF_DIR
- android 上传图片过大处理
- AsyncTask 坑 (二) AsyncTask对象生命周期
- 解决ios下的微信页面背景音乐无法自动播放问题
- MySQL5.6.30安装步骤(Windows Server 2008 64位)
- 数组类运算的实现
- java45hashCode和toString
- Linux Shell 脚本中字符串的连接方法