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

Question on cache correctness. #3736

Open
peifengll opened this issue Nov 22, 2023 · 5 comments
Open

Question on cache correctness. #3736

peifengll opened this issue Nov 22, 2023 · 5 comments
Labels

Comments

@peifengll
Copy link

peifengll commented Nov 22, 2023

个人对go-zero的sqlc部分进行了实践,加入了两个redis,在两个redis之间都放了相同的数据,这个数据是通过sqlc的查询操作放入redis的,之后进行sqlc的删除操作,但只有一个redis的该数据被删除,另一个的还在(但访问的时候又不去访问那个redis的数据,把第一个redis的配置注释掉,只剩这个有数据的redis时才会去访问它),在调试的时候发现在删除缓存的部分是只删除一个节点的key

// DelCtx deletes cached values with keys.
func (cc cacheCluster) DelCtx(ctx context.Context, keys ...string) error {
	switch len(keys) {
	case 0:
		return nil
	case 1:
		key := keys[0]
		c, ok := cc.dispatcher.Get(key)
		if !ok {
			return cc.errNotFound
		}

		return c.(Cache).DelCtx(ctx, key)
	default:
		var be errorx.BatchError
		nodes := make(map[any][]string)
		for _, key := range keys {
			c, ok := cc.dispatcher.Get(key)
			if !ok {
				be.Add(fmt.Errorf("key %q not found", key))
				continue
			}

			nodes[c] = append(nodes[c], key)
		}
		for c, ks := range nodes {
			if err := c.(Cache).DelCtx(ctx, ks...); err != nil {
				be.Add(err)
			}
		}

		return be.Err()
	}
}

另 一个的redis的脏数据确实没有处理

@kevwan
Copy link
Contributor

kevwan commented Nov 22, 2023

You put data into two redis nodes manually?

@kevwan kevwan changed the title 缓存正确性问题 Question on cache correctness. Nov 22, 2023
@peifengll
Copy link
Author

我有两个redis写在了配置里边,在注释掉其中一个redis的配置的情况下去查询数据,之后再只注释掉另一个redis的配置,这样两个redis就持有了相同的数据。

应用场景是这样:假比我们有a、b、c、d等多个服务,这多个服务都是要访问data表的,data本来是存在数据库中,后决定放到redis中去,鉴于服务比较多,对redis的请求也比较多,所以将redis也设置为了多个,多个redis都要持有一张一样的data表, 但是如果有了更改,希望能保证数据的一致性,多个redis之间,redismysql之间。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


I have two redis written in the configuration. I comment out the configuration of one redis to query the data, and then only comment out the configuration of the other redis, so that the two redis hold the same data.

The application scenario is like this: Suppose we have multiple services such as a, b, c, d, etc., and these multiple services all need to access the data table. The data originally exists in the database, and then we decided to put it in redis. In view of There are many services and there are many requests for redis, so we set up multiple redis. Multiple redis must hold the same data table. However, if there are changes, we hope to ensure the consistency of the data. More between redis and redismysql.

@kevwan
Copy link
Contributor

kevwan commented Nov 23, 2023

I don't think we can handle this. If you want to switch redis cluster, just delete all caches.

Copy link

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants