-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Open
Description
Describe the feature
Currently, reids cannot collaborate with the pool library to implement connection pooling
Use Case
pub fn (mut db DB) validate() !bool {
db.ping()!
return true
}
pub fn (mut db DB) reset() ! {
}
Proposed Solution
No response
Other Information
module redis_pool
import db.redis
import pool
import time
pub struct RedisConfig {
pub mut:
host string
port u16
password string
tls bool
version int = 2
max_conns int = 100
min_idle_conns int = 10
max_lifetime time.Duration = 60 * time.minute
idle_timeout time.Duration = 30 * time.minute
get_timeout time.Duration = 3 * time.second
}
@[heap]
pub struct RedisPool {
mut:
inner &pool.ConnectionPool
}
pub fn new_redis_pool(config RedisConfig) !&RedisPool {
create_conn := fn [config] () !&pool.ConnectionPoolable {
mut redis_client := redis.connect(redis.Config{
host: config.host
port: config.port
password: config.password
tls: config.tls
version: config.version
})!
conn := &redis_client
return conn
}
pool_conf := pool.ConnectionPoolConfig{
max_conns: config.max_conns
min_idle_conns: config.min_idle_conns
max_lifetime: config.max_lifetime
idle_timeout: config.idle_timeout
get_timeout: config.get_timeout
}
inner_pool := pool.new_connection_pool(create_conn, pool_conf)!
return &RedisPool{
inner: inner_pool
}
}
pub fn (mut p RedisPool) acquire() !(&redis.DB, &pool.ConnectionPoolable) {
conn := p.inner.get()!
return conn as &redis.DB, conn
}
pub fn (mut p RedisPool) release(conn &pool.ConnectionPoolable) ! {
p.inner.put(conn)!
}
pub fn (mut p RedisPool) close() {
p.inner.close()
}
Acknowledgements
- I may be able to implement this feature request
- This feature might incur a breaking change
Version used
V 0.5.0 2332ecf
Environment details (OS name and version, etc.)
| V full version | V 0.5.0 3c12b80.2332ecf |
|---|---|
| OS | linux, Deepin 25 |
| Processor | 4 cpus, 64bit, little endian, Intel(R) Core(TM) i5-6300HQ CPU @ 2.30GHz |
| Memory | 0.29GB/11.57GB |
| V executable | /home/Jengro/.vmr/versions/v_versions/v_latest/v |
| V last modified time | 2026-02-02 01:25:57 |
| V home dir | OK, value: /home/Jengro/.vmr/versions/v_versions/v_latest |
| VMODULES | OK, value: /home/Jengro/.vmodules |
| VTMP | OK, value: /tmp/v_1000 |
| Current working dir | OK, value: /home/Jengro |
| Git version | git version 2.51.0 |
| V git status | weekly.2026.05-96-g2332ecff-dirty |
| .git/config present | true |
| cc version | cc (Deepin 12.3.0-17deepin15) 12.3.0 |
| gcc version | gcc (Deepin 12.3.0-17deepin15) 12.3.0 |
| clang version | Deepin clang version 17.0.6 (5deepin6) |
| tcc version | tcc version 0.9.28rc 2025-02-13 HEAD@f8bd136d (x86_64 Linux) |
| tcc git status | thirdparty-linux-amd64 696c1d84 |
| emcc version | N/A |
| glibc version | ldd (Debian GLIBC 2.38-6deepin17) 2.38 |
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
Avey777Avey777
Metadata
Metadata
Assignees
Labels
No labels