批話學(xué)如逆水行舟,不進(jìn)則退
redis安裝,踩坑
- 官網(wǎng)和github所給貌似不是windows下的安裝包
- 所以上面的命令也不能用
- 主要參考材料
-
下載網(wǎng)站
https://github.com/MicrosoftArchive/redis/releases - 安裝過程就是簡單的下一步,記得選擇將redis路徑添加到環(huán)境變量中
- 在安裝目錄(cmd 或者git bash均可),執(zhí)行
redis-server redis.windows.conf
安裝成功后顯示,跟網(wǎng)上流傳的那個圖片不一樣
[1332] 30 Oct 18:50:55.997 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
[1332] 30 Oct 18:50:56.000 # Creating Server TCP listening socket *:6379: bind: No such file or directory
- 該目錄下執(zhí)行
redis-cli,
127.0.0.1:6379> ping成功后顯示PONG
簡單測試下
set myKey abcget myKey //abc
在koa下的使用
npm install koa-generic-session koa-redis
const session = require('koa-generic-session')
const Redis = require('koa-redis')
app.keys=['keys','keyskeys']
//修改koa前綴
app.use(session({
key:'mt',
prefix:'mtpr',
store:new Redis()
}))
在redis服務(wù)中查看存儲的key值
在redis對應(yīng)的cmd中
redis-cli
keys *
get 'somekey'
keys表示所有的key值,也可以通過get獲取key值對應(yīng)的內(nèi)容
直接操作redis,在users.js中,做以下設(shè)置
const Store = new Redis().client
router.get('/fix',async function(ctx){
const st=await Store.hset('fix','name',Math.random())
ctx.body={
code:0
}
})
在Git Bash中
curl http://localhost:3000/users/fix
在radis命令中
keys *
其中會有fix顯示
此時可以通過
hset fix
可以獲取對應(yīng)的內(nèi)容