Comments (5)
config/cache.go
中设置 default
为 redis
, 然后使用 facades.Cache
即可,详见文档:缓存系统
from goravel.
config/cache.go
中设置default
为redis
, 然后使用facades.Cache
即可,详见文档:缓存系统
我想使用redis的原生命令怎么用呢,比如lpush,rpop
from goravel.
可以这样
package routes
import (
"fmt"
"time"
"github.com/gin-gonic/gin"
"github.com/go-redis/redis/v8"
"github.com/goravel/framework/support/facades"
)
func Web() {
facades.Route.GET("/", func(ctx *gin.Context) {
client := redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%s:%s", facades.Config.GetString("database.redis.default.host"), facades.Config.GetString("database.redis.default.port")),
Password: facades.Config.GetString("database.redis.default.password"),
DB: facades.Config.GetInt("database.redis.default.database"),
})
client.Set(ctx, "goravel", "redis", time.Minute)
})
}
from goravel.
可以这样
package routes import ( "fmt" "time" "github.com/gin-gonic/gin" "github.com/go-redis/redis/v8" "github.com/goravel/framework/support/facades" ) func Web() { facades.Route.GET("/", func(ctx *gin.Context) { client := redis.NewClient(&redis.Options{ Addr: fmt.Sprintf("%s:%s", facades.Config.GetString("database.redis.default.host"), facades.Config.GetString("database.redis.default.port")), Password: facades.Config.GetString("database.redis.default.password"), DB: facades.Config.GetInt("database.redis.default.database"), }) client.Set(ctx, "goravel", "redis", time.Minute) }) }
这样也没问题,但是不太优雅
from goravel.
嗯,的确,逐步优化下,目前来说可以封装个 helper 先用
from goravel.
Related Issues (20)
- 🐛 [Bug] Model的Retrieved event不会被触发 HOT 3
- ✨ [Feature] enhance the ability of the command feature HOT 1
- 🐛 [Bug] data error when calling facades.Auth().Parse() multiple times with different guard HOT 1
- ✨ [Feature] The queue log needs to be controled by APP_DEBUG HOT 1
- 🐛 [Bug] The context that set by facades.Orm().WithContext() isn't passed to orm events HOT 1
- ✨ [Feature] Supports configuring the json serialization/deserialization package in config/app.go HOT 2
- 🐛 [Bug] Minio does not implement filesystem.Driver HOT 2
- ✨ [Feature] Use contributors api to automatically generate contributors images in README HOT 4
- 🐛 [Bug] The new line print of Log is incorrect HOT 1
- ✨ [Feature] The trace of log can be clicked as a link HOT 1
- ✨ [Feature] Add a -f flag for make commands, to avoid cover the existing file by mistake HOT 1
- ✨ [Feature] Map the Installer to the Docs HOT 2
- ✨ [Feature] DB supports configure SSL HOT 1
- 🐛 [Bug] The traces don't cleaned when calling Log.Info after Log.Error HOT 1
- 🐛 [Bug] 模型事件获取ID和模型事件触发bug HOT 7
- 🐛 [Bug] Nil pointer dereference on validation HOT 4
- ✨ [Feature] Orm implements convenient expansion of other drivers HOT 1
- ✨ [Feature] Optimize the backslash when using facades.Route().Prefix("/product") HOT 1
- ✨ [Feature] - Any support for sqlx HOT 1
- ✨ [Feature] Remove gookit/color, use pterm/pterm instead HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from goravel.