Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Issues with store plugin redis #57

Closed
tchandelle opened this issue Mar 16, 2022 · 2 comments · Fixed by #110
Closed

[BUG] Issues with store plugin redis #57

tchandelle opened this issue Mar 16, 2022 · 2 comments · Fixed by #110

Comments

@tchandelle
Copy link
Contributor

Describe the bug

In github.com/asim/go-micro/plugins/store/redis/v4 package :

  • List doesn't filter by table (ListFrom) . Also doesn't remove the table prefix in the return.
  • Read with ReadPrefix option doesn't fill the keys

How to reproduce the bug:

package main

import (
	"reflect"
	"testing"

	redisStore "github.com/asim/go-micro/plugins/store/redis/v4"
	"go-micro.dev/v4/store"
)

func init() {
	store.DefaultStore = redisStore.NewStore(store.Nodes("redis://redis:6379"))
}

func Test_store(t *testing.T) {
	store.DefaultStore.Write(
		&store.Record{Key: "key1", Value: []byte("val1")},
		store.WriteTo("", "table-a"),
	)
	store.DefaultStore.Write(
		&store.Record{Key: "key2", Value: []byte("val2")},
		store.WriteTo("", "table-b"),
	)
	store.DefaultStore.Write(
		&store.Record{Key: "key3", Value: []byte("val3")},
		store.WriteTo("", "table-a"),
	)

	gotList, _ := store.DefaultStore.List(store.ListFrom("", "table-a"))
	wantList := []string{"key1"}
	if !reflect.DeepEqual(gotList, wantList) {
		t.Errorf("DefaultStore.List() = %#v; want %#v", gotList, wantList)
	}

	gotRead, _ := store.DefaultStore.Read("", store.ReadFrom("", "table-a"), store.ReadPrefix())
	wantRead := []*store.Record{
		{Key: "key3", Value: []byte("val3"), Expiry: -1},
		{Key: "key1", Value: []byte("val1"), Expiry: -1},
	}
	if !reflect.DeepEqual(gotRead, wantRead) {
		t.Errorf("DefaultStore.Read() = %#v; want %#v", gotRead, wantRead)
		t.Errorf("DefaultStore.Read()[0] = %#v; want %#v", gotRead[0], wantRead[0])
		t.Errorf("DefaultStore.Read()[1] = %#v; want %#v", gotRead[1], wantRead[1])
	}

	gotRead, _ = store.DefaultStore.Read("key1", store.ReadFrom("", "table-a"))
	wantRead = []*store.Record{
		{Key: "key1", Value: []byte("val1"), Expiry: -1},
	}
	if !reflect.DeepEqual(gotRead, wantRead) {
		t.Errorf("DefaultStore.Read() = %#v; want %#v", gotRead, wantRead)
		t.Errorf("DefaultStore.Read()[0] = %#v; want %#v", gotRead[0], wantRead[0])
	}
}

Returns:

=== RUN   Test_store
    store_test.go:32: DefaultStore.List() = []string{"table-akey3", "table-bkey2", "table-akey1"}; want []string{"key1"}
    store_test.go:41: DefaultStore.Read() = []*store.Record{(*store.Record)(0xc000150000), (*store.Record)(0xc00007a000)}; want []*store.Record{(*store.Record)(0xc00007a040), (*store.Record)(0xc00007a080)}
    store_test.go:42: DefaultStore.Read()[0] = &store.Record{Key:"", Value:[]uint8{0x76, 0x61, 0x6c, 0x33}, Metadata:map[string]interface {}(nil), Expiry:-1}; want &store.Record{Key:"key3", Value:[]uint8{0x76, 0x61, 0x6c, 0x33}, Metadata:map[string]interface {}(nil), Expiry:-1}
    store_test.go:43: DefaultStore.Read()[1] = &store.Record{Key:"", Value:[]uint8{0x76, 0x61, 0x6c, 0x31}, Metadata:map[string]interface {}(nil), Expiry:-1}; want &store.Record{Key:"key1", Value:[]uint8{0x76, 0x61, 0x6c, 0x31}, Metadata:map[string]interface {}(nil), Expiry:-1}
--- FAIL: Test_store (0.06s)

Environment:

go version go1.16.14 linux/amd64

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.14"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/workspace/data_management/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2927763455=/tmp/go-build -gno-record-gcc-switches"
@xpunch xpunch transferred this issue from micro/go-micro Sep 17, 2022
@butonic
Copy link
Contributor

butonic commented May 10, 2023

This might have changed with #97

rhafer added a commit to rhafer/go-micro-plugins that referenced this issue May 10, 2023
The plugin stores the keys prefixed with the "Table" name in Redis. We
should remove that prefix from the keys returned by "List()".

Partial-Fix: micro#57
@rhafer
Copy link
Contributor

rhafer commented May 10, 2023

  • List doesn't filter by table (ListFrom)

As @butonic mentioned, this should be fixed since #97

Also doesn't remove the table prefix in the return.

This is addressed in #110

@asim asim closed this as completed in #110 May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants