-
Notifications
You must be signed in to change notification settings - Fork 2
【Redis】 Redisインストールと接続 20170901
NieHongFei edited this page Sep 7, 2017
·
2 revisions
$ sudo apt-get update
$ sudo apt-get install redis-server
$ redis-server
$ redis-cli
REDIS_URLを環境変数に設置する こんな感じ:
redis://h:p0940164a5ee7b9a8efcddc837d481e51fb4488ecb03a4d4f501c8a1cf3a74ee6@ec2-52-3-6-123.compute-1.amazonaws.com:55129
redis://127.0.0.1:6379
参考資料↓ http://www.yiibai.com/redis/redis_quick_guide.html
远程 heroku addons | grep heroku-redis 查看是否添加redis win下没有grep这个命令,换成findstr
heroku addons:create heroku-redis:hobby-dev -a <appname> 在指定的app下添加redis
heroku addons:info <对应的号> 例:soaring-duly-3158 查看创建状态
heroku config | grep REDIS 查询URL
配置到RUN→run configuration→environment
本地 https://github.com/ServiceStack/redis-windows/tree/master/downloads (http://pan.baidu.com/s/1mig98a0 )
打开一个 cmd 窗口 使用cd命令切换到 redis目录 运行 redis-server.exe redis.windows.conf
可以把 redis 的路径加到系统的Path环境变量里, redis.windows.conf 可以省略
或者直接双击运行redis-server.exe
测试:另启一个cmd窗口,原来的不要关闭,不然就无法访问服务端了。
切换到redis目录下运行 redis-cli.exe -h 127.0.0.1 -p 6379 。链接redis服务器 -h hostname -p 端口号 -a 密码
设置键值对 set myKey abc
取出键值对 get myKey 显示abc
将RUN→run configuration→environment的URL改到本地
value格式: redis://h:<密码>@<hostname>:<端口号>
*代码中有 redisManager.setPassword(uri.getUserInfo().split(":")[1]);,所以密码不能为空
设置密码
redis-cli.exe -h 127.0.0.1 -p 6379 连接服务器
config set requirepass <密码> 设置密码
config get requirepass 查询密码,无权访问
redis-cli.exe -h 127.0.0.1 -p 6379 -a <密码> 加上密码链接
config get requirepass 查询密码,能看到设置的密码