mirror of
https://github.com/elyby/chrly.git
synced 2024-12-23 13:40:11 +05:30
Resolves #5. Return Redis connection to the pool after commands are executed
This commit is contained in:
parent
ed0b9bb040
commit
6515e3e5bd
@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Fixed
|
### Fixed
|
||||||
- `/textures` request no longer proxies request to Mojang in a case when there is no information about the skin,
|
- `/textures` request no longer proxies request to Mojang in a case when there is no information about the skin,
|
||||||
but there is a cape.
|
but there is a cape.
|
||||||
|
- [#5](https://github.com/elyby/chrly/issues/5): Return Redis connection to the pool after commands are executed
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
- `hash` field from `/textures` response because the game doesn't use it and calculates hash by getting the filename
|
- `hash` field from `/textures` response because the game doesn't use it and calculates hash by getting the filename
|
||||||
|
41
db/redis.go
41
db/redis.go
@ -27,8 +27,6 @@ type RedisFactory struct {
|
|||||||
connection *pool.Pool
|
connection *pool.Pool
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: maybe we should manually return connection to the pool?
|
|
||||||
|
|
||||||
// TODO: Why isn't a pointer used here?
|
// TODO: Why isn't a pointer used here?
|
||||||
func (f RedisFactory) CreateSkinsRepository() (interfaces.SkinsRepository, error) {
|
func (f RedisFactory) CreateSkinsRepository() (interfaces.SkinsRepository, error) {
|
||||||
return f.createInstance()
|
return f.createInstance()
|
||||||
@ -102,38 +100,53 @@ type redisDb struct {
|
|||||||
const accountIdToUsernameKey = "hash:username-to-account-id"
|
const accountIdToUsernameKey = "hash:username-to-account-id"
|
||||||
const mojangUsernameToUuidKey = "hash:mojang-username-to-uuid"
|
const mojangUsernameToUuidKey = "hash:mojang-username-to-uuid"
|
||||||
|
|
||||||
// TODO: return connection to the pool after usage
|
|
||||||
func (db *redisDb) FindByUsername(username string) (*model.Skin, error) {
|
func (db *redisDb) FindByUsername(username string) (*model.Skin, error) {
|
||||||
return findByUsername(username, db.getConn())
|
conn, _ := db.conn.Get()
|
||||||
|
defer db.conn.Put(conn)
|
||||||
|
|
||||||
|
return findByUsername(username, conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *redisDb) FindByUserId(id int) (*model.Skin, error) {
|
func (db *redisDb) FindByUserId(id int) (*model.Skin, error) {
|
||||||
return findByUserId(id, db.getConn())
|
conn, _ := db.conn.Get()
|
||||||
|
defer db.conn.Put(conn)
|
||||||
|
|
||||||
|
return findByUserId(id, conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *redisDb) Save(skin *model.Skin) error {
|
func (db *redisDb) Save(skin *model.Skin) error {
|
||||||
return save(skin, db.getConn())
|
conn, _ := db.conn.Get()
|
||||||
|
defer db.conn.Put(conn)
|
||||||
|
|
||||||
|
return save(skin, conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *redisDb) RemoveByUserId(id int) error {
|
func (db *redisDb) RemoveByUserId(id int) error {
|
||||||
return removeByUserId(id, db.getConn())
|
conn, _ := db.conn.Get()
|
||||||
|
defer db.conn.Put(conn)
|
||||||
|
|
||||||
|
return removeByUserId(id, conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *redisDb) RemoveByUsername(username string) error {
|
func (db *redisDb) RemoveByUsername(username string) error {
|
||||||
return removeByUsername(username, db.getConn())
|
conn, _ := db.conn.Get()
|
||||||
|
defer db.conn.Put(conn)
|
||||||
|
|
||||||
|
return removeByUsername(username, conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *redisDb) GetUuid(username string) (string, error) {
|
func (db *redisDb) GetUuid(username string) (string, error) {
|
||||||
return findMojangUuidByUsername(username, db.getConn())
|
conn, _ := db.conn.Get()
|
||||||
|
defer db.conn.Put(conn)
|
||||||
|
|
||||||
|
return findMojangUuidByUsername(username, conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *redisDb) StoreUuid(username string, uuid string) {
|
func (db *redisDb) StoreUuid(username string, uuid string) {
|
||||||
storeMojangUuid(username, uuid, db.getConn())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (db *redisDb) getConn() util.Cmder {
|
|
||||||
conn, _ := db.conn.Get()
|
conn, _ := db.conn.Get()
|
||||||
return conn
|
defer db.conn.Put(conn)
|
||||||
|
|
||||||
|
storeMojangUuid(username, uuid, conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func findByUsername(username string, conn util.Cmder) (*model.Skin, error) {
|
func findByUsername(username string, conn util.Cmder) (*model.Skin, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user