Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .secrets.baseline

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion docs/reference/online-stores/redis.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ online_store:
```
{% endcode %}

Connecting as a named Redis ACL user (Redis 6+, e.g. AWS ElastiCache RBAC user groups where the `default` user is disabled):

{% code title="feature_store.yaml" %}
```yaml
project: my_feature_repo
registry: data/registry.db
provider: local
online_store:
type: redis
connection_string: "redis1:6379,username=feast,password=my_password,ssl=true"
```
{% endcode %}

{% hint style="info" %}
The Go feature server's Redis online store supports `redis` and `redis_cluster` and accepts only the `password`, `username`, `ssl`, and `db` options in `connection_string` (`db` is ignored for clusters). Any other option causes an error.
{% endhint %}

## TTL configuration

The Redis online store supports two complementary TTL mechanisms:
Expand Down Expand Up @@ -195,7 +212,7 @@ The Redis online store implements `online_write_batch_async()` using the async R
| --- | --- | --- |
| `type` | `redis` | Online store type selector |
| `redis_type` | `redis` | Connection type: `redis`, `redis_cluster`, or `redis_sentinel` |
| `connection_string` | `localhost:6379` | Host:port and optional parameters. For cluster: `redis1:6379,redis2:6379,ssl=true,password=...` |
| `connection_string` | `localhost:6379` | Host:port and optional parameters (e.g. `password`, `username`, `ssl`, `db`). For cluster: `redis1:6379,redis2:6379,ssl=true,username=...,password=...` |
| `sentinel_master` | `mymaster` | Sentinel master name (only used when `redis_type: redis_sentinel`) |
| `key_ttl_seconds` | `null` | Redis `EXPIRE` TTL in seconds applied to the entity hash key after each write. Expires all feature views for that entity together. |
| `full_scan_for_deletion` | `true` | When `true`, deleting or renaming a feature view scans Redis to remove its hash fields. Set `false` to skip deletion scans (faster `feast apply`, but leaves orphaned data). |
Expand Down
17 changes: 12 additions & 5 deletions go/internal/feast/onlinestore/redisonlinestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func NewRedisOnlineStore(project string, config *registry.RepoConfig, onlineStor

var address []string
var password string
var username string
var tlsConfig *tls.Config
var db int // Default to 0

Expand All @@ -69,7 +70,7 @@ func NewRedisOnlineStore(project string, config *registry.RepoConfig, onlineStor
}
store.t = redisStoreType

// Parse connection_string and write it into conf.address, conf.password, and conf.ssl
// Parse connection_string and write it into conf.address, conf.username, conf.password, and conf.ssl
redisConnJson, ok := onlineStoreConfig["connection_string"]
if !ok {
// Default to "localhost:6379"
Expand All @@ -80,12 +81,14 @@ func NewRedisOnlineStore(project string, config *registry.RepoConfig, onlineStor
} else {
parts := strings.Split(redisConnStr, ",")
for _, part := range parts {
if strings.Contains(part, ":") {
address = append(address, part)
} else if strings.Contains(part, "=") {
// Check for options before addresses so that option values containing ':'
// (e.g. username=team:feast) are not mistaken for host:port addresses.
if strings.Contains(part, "=") {
kv := strings.SplitN(part, "=", 2)
if kv[0] == "password" {
password = kv[1]
} else if kv[0] == "username" {
username = kv[1]
Comment on lines +90 to +91

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. The : address check ran before the = option check, so username=team:feast (or a password containing :) was treated as an address. Fixed in 225b00a by checking for = first, the same order the Python SDK parser uses. Added TestNewRedisOnlineStoreWithColonInOptionValues and TestNewRedisOnlineStoreClusterWithColonInUsername; both fail without the fix and pass with it.

} else if kv[0] == "ssl" {
result, err := strconv.ParseBool(kv[1])
if err != nil {
Expand All @@ -99,8 +102,10 @@ func NewRedisOnlineStore(project string, config *registry.RepoConfig, onlineStor
return nil, err
}
} else {
return nil, fmt.Errorf("unrecognized option in connection_string: %s. Must be one of 'password', 'ssl'", kv[0])
return nil, fmt.Errorf("unrecognized option in connection_string: %s. Must be one of 'password', 'username', 'ssl', 'db'", kv[0])
}
} else if strings.Contains(part, ":") {
address = append(address, part)
} else {
return nil, fmt.Errorf("unable to parse a part of connection_string: %s. Must contain either ':' (addresses) or '=' (options", part)
}
Expand All @@ -117,6 +122,7 @@ func NewRedisOnlineStore(project string, config *registry.RepoConfig, onlineStor
log.Info().Msgf("Using Redis: %s", address[0])
store.client = redis.NewClient(&redis.Options{
Addr: address[0],
Username: username,
Password: password,
DB: db,
TLSConfig: tlsConfig,
Expand All @@ -128,6 +134,7 @@ func NewRedisOnlineStore(project string, config *registry.RepoConfig, onlineStor
log.Info().Msgf("Using Redis Cluster: %s", address)
store.clusterClient = redis.NewClusterClient(&redis.ClusterOptions{
Addrs: address,
Username: username,
Password: password,
TLSConfig: tlsConfig,
ReadOnly: true,
Expand Down
115 changes: 115 additions & 0 deletions go/internal/feast/onlinestore/redisonlinestore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/feast-dev/feast/go/protos/feast/types"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestNewRedisOnlineStore(t *testing.T) {
Expand All @@ -21,6 +22,7 @@ func TestNewRedisOnlineStore(t *testing.T) {
assert.Nil(t, err)
var opts = store.client.Options()
assert.Equal(t, opts.Addr, "redis://localhost:6379")
assert.Equal(t, opts.Username, "")
assert.Equal(t, opts.Password, "")
assert.Equal(t, opts.DB, 0)
assert.Nil(t, opts.TLSConfig)
Expand All @@ -38,6 +40,7 @@ func TestNewRedisOnlineStoreWithPassword(t *testing.T) {
assert.Nil(t, err)
var opts = store.client.Options()
assert.Equal(t, opts.Addr, "redis://localhost:6379")
assert.Equal(t, opts.Username, "")
assert.Equal(t, opts.Password, "secret")
}

Expand Down Expand Up @@ -71,6 +74,118 @@ func TestNewRedisOnlineStoreWithSsl(t *testing.T) {
assert.NotNil(t, opts.TLSConfig)
}

func TestNewRedisOnlineStoreWithUsername(t *testing.T) {
var config = map[string]interface{}{
"connection_string": "redis://localhost:6379,username=feast,password=secret",
}
rc := &registry.RepoConfig{
OnlineStore: config,
EntityKeySerializationVersion: 3,
}
store, err := NewRedisOnlineStore("test", rc, config)
require.NoError(t, err)
var opts = store.client.Options()
assert.Equal(t, "redis://localhost:6379", opts.Addr)
assert.Equal(t, "feast", opts.Username)
assert.Equal(t, "secret", opts.Password)
}

func TestNewRedisOnlineStoreWithUsernameAfterPassword(t *testing.T) {
var config = map[string]interface{}{
"connection_string": "redis://localhost:6379,password=secret,username=feast", // pragma: allowlist secret
}
rc := &registry.RepoConfig{
OnlineStore: config,
EntityKeySerializationVersion: 3,
}
store, err := NewRedisOnlineStore("test", rc, config)
require.NoError(t, err)
var opts = store.client.Options()
assert.Equal(t, "feast", opts.Username)
assert.Equal(t, "secret", opts.Password)
}

func TestNewRedisOnlineStoreClusterWithUsername(t *testing.T) {
var config = map[string]interface{}{
"redis_type": "redis_cluster",
"connection_string": "node1:6379,node2:6379,username=feast,password=secret,ssl=true", // pragma: allowlist secret
}
rc := &registry.RepoConfig{
OnlineStore: config,
EntityKeySerializationVersion: 3,
}
store, err := NewRedisOnlineStore("test", rc, config)
require.NoError(t, err)
var opts = store.clusterClient.Options()
assert.Equal(t, []string{"node1:6379", "node2:6379"}, opts.Addrs)
assert.Equal(t, "feast", opts.Username)
assert.Equal(t, "secret", opts.Password)
assert.NotNil(t, opts.TLSConfig)
}

func TestNewRedisOnlineStoreWithEqualsInValue(t *testing.T) {
var config = map[string]interface{}{
"connection_string": "redis://localhost:6379,username=feast,password=a=b", // pragma: allowlist secret
}
rc := &registry.RepoConfig{
OnlineStore: config,
EntityKeySerializationVersion: 3,
}
store, err := NewRedisOnlineStore("test", rc, config)
require.NoError(t, err)
var opts = store.client.Options()
assert.Equal(t, "feast", opts.Username)
assert.Equal(t, "a=b", opts.Password)
}

func TestNewRedisOnlineStoreWithColonInOptionValues(t *testing.T) {
var config = map[string]interface{}{
"connection_string": "localhost:6379,username=team:feast,password=p:w", // pragma: allowlist secret
}
rc := &registry.RepoConfig{
OnlineStore: config,
EntityKeySerializationVersion: 3,
}
store, err := NewRedisOnlineStore("test", rc, config)
require.NoError(t, err)
var opts = store.client.Options()
assert.Equal(t, "localhost:6379", opts.Addr)
assert.Equal(t, "team:feast", opts.Username)
assert.Equal(t, "p:w", opts.Password)
}

func TestNewRedisOnlineStoreClusterWithColonInUsername(t *testing.T) {
var config = map[string]interface{}{
"redis_type": "redis_cluster",
"connection_string": "node1:6379,node2:6379,username=team:feast,password=secret", // pragma: allowlist secret
}
rc := &registry.RepoConfig{
OnlineStore: config,
EntityKeySerializationVersion: 3,
}
store, err := NewRedisOnlineStore("test", rc, config)
require.NoError(t, err)
var opts = store.clusterClient.Options()
assert.Equal(t, []string{"node1:6379", "node2:6379"}, opts.Addrs)
assert.Equal(t, "team:feast", opts.Username)
}

func TestNewRedisOnlineStoreUnrecognizedOption(t *testing.T) {
var config = map[string]interface{}{
"connection_string": "redis://localhost:6379,foo=bar",
}
rc := &registry.RepoConfig{
OnlineStore: config,
EntityKeySerializationVersion: 3,
}
_, err := NewRedisOnlineStore("test", rc, config)
require.Error(t, err)
assert.Contains(t, err.Error(), "foo")
for _, opt := range []string{"'password'", "'username'", "'ssl'", "'db'"} {
assert.Contains(t, err.Error(), opt)
}
}

func TestBuildFeatureViewIndices(t *testing.T) {
r := &RedisOnlineStore{}

Expand Down