RedisBloom
RedisBloom copied to clipboard
How to select redis db?
trafficstars
Redis db default 0, if I want to use db1 or db 3 (redis command select db 1), what should I do?
How do you run Redis? Are you using Redis Cloud?
How do you run Redis? Are you using Redis Cloud?
Code demo
func NewRedisFilter() *RedisFilter {
auth := "abxc987lpox"
var client = redisbloom.NewClient("102.13.2x.1x:6379", "", &auth)
return &RedisFilter{Client: client}
}
func main(){
fingerprint := "20f2022e350r"
rds := NewRedisFilter()
val, err := rds.Exists(fingerprint)
...
...
}
Redis run
redis run command: ./src/redis-server, redis from https://download.redis.io/releases/redis-6.2.3.tar.gz
redisbloom.NewClient("102.13.2x.1x:6379", "", &auth) db name write in this? or other place?
Oh i see,use redigo:
package test
import (
"fmt"
"testing"
"time"
redisbloom "github.com/RedisBloom/redisbloom-go"
redigo "github.com/gomodule/redigo/redis"
)
func NewRedisPool(host, secret string) *redigo.Pool {
return &redigo.Pool{
MaxIdle: 5,
IdleTimeout: 240 * time.Second,
MaxActive: 20,
Dial: func() (redigo.Conn, error) {
c, err := redigo.Dial("tcp", host)
if err != nil {
return nil, err
}
if secret != "" {
if _, err := c.Do("AUTH", secret); err != nil {
c.Close()
return nil, err
}
// select db in here
if _, err := c.Do("SELECT", 1); err != nil {
c.Close()
return nil, err
}
}
return c, err
},
TestOnBorrow: func(c redigo.Conn, t time.Time) error {
_, err := c.Do("PING")
return err
},
}
}
func NewRedisBloom(rdp *redigo.Pool) *redisbloom.Client {
return redisbloom.NewClientFromPool(rdp, "seeds")
}
func TestRedis(t *testing.T) {
rdp := NewRedisPool("4x.1x.2x.1x:6379", "abc578")
rbc := NewRedisBloom(rdp)
ir, err := rbc.BfExistsMulti("seeds", []string{"rdp6"})
fmt.Print(ir, err)
}
@asyncins do you need further help?