Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

YunzhiYike
Copy link
Contributor

@YunzhiYike YunzhiYike commented Jun 11, 2025

Fixes #4298
Fixes #2196
Fixes #2135

import goredis "github.com/redis/go-redis/v9"

func ExampleUsage(ctx context.Context, redis *Redis) error {
	client := redis.Client()
	universalClient, ok := client.(goredis.UniversalClient)
	if !ok {
		return errors.New("failed to assert to UniversalClient")
	}

	// Use universalClient for advanced operations like Pipeline
	pipe := universalClient.Pipeline()
	pipe.Set(ctx, "key1", "value1", 0)
	pipe.Set(ctx, "key2", "value2", 0)
	results, err := pipe.Exec(ctx)
	if err != nil {
		return err
	}
	// ... handle results
	return nil
}

@cyjaysong
Copy link
Contributor

可是咱们讨论了移除gredis😂

@YunzhiYike
Copy link
Contributor Author

可是咱们讨论了移除gredis😂

那是不是这个PR不会合并了?或者有没有其它方法使用暴露的pipeline方法

@cyjaysong
Copy link
Contributor

cyjaysong commented Jun 12, 2025

gredis 是基于go-redis封装的,你可以直接使用go-redis,你fork一下,然后创建一个自定义分支,加个获取redis配置的函数, 自己创建go-redis 实例来使用就行

//  database/gredis/gredis_redis.go

// GetConfig returns the deeply copied Config in the current client.
func (r *Redis) GetConfig() *Config {
	return r.config
}

@LanceAdd
Copy link
Contributor

LanceAdd commented Jun 16, 2025

我之前也准备提交这个,但是群里说gredis作为抽象层不应该暴露go-redis驱动的相关引用就放弃了,我现在是自定义了一个gredis,只保留了gins里对redis配置文件参数的解析和客户端的初始化还有多配置redis客户端获取,这样就能直接用go-redis驱动的方法,我看V3的计划表里也有删除gredis的意向,等等,我最近好像在某个isssues里也回复过老哥??

@houseme houseme requested review from Copilot and hailaz September 1, 2025 06:42
Copilot

This comment was marked as outdated.

@hailaz
Copy link
Contributor

hailaz commented Sep 3, 2025

@hailaz
Copy link
Contributor

hailaz commented Sep 3, 2025

@YunzhiYike
Copy link
Contributor Author

@LanceAdd @cyjaysong 看看这样折中解决行不行。https://github.com/gogf/gf/pull/4306/files#diff-27ba9cb3e60614ccdd6a2e5cdc82825ee6b1db0b8957c37fdbfa179cfd4ccd61R66

我觉得可以,还是需要提供Client暴露出来的

@hailaz hailaz requested a review from Copilot September 3, 2025 07:26
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for Redis pipeline operations by exposing the underlying Redis client through a new Client() method. This allows developers to access advanced Redis features like pipelining that aren't directly available through the standard Redis adapter interface.

  • Added Client() method to the AdapterOperation interface
  • Implemented Client() method in the Redis adapter to return the underlying client
  • Added comprehensive test coverage for the new functionality including pipeline operations

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
database/gredis/gredis_adapter.go Added Client() method to AdapterOperation interface with documentation
contrib/nosql/redis/redis_operation.go Implemented Client() method to expose underlying redis client
contrib/nosql/redis/redis_z_unit_test.go Added comprehensive tests for Client() method and pipeline functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@LanceAdd
Copy link
Contributor

LanceAdd commented Sep 3, 2025

@LanceAdd @cyjaysong 看看这样折中解决行不行。https://github.com/gogf/gf/pull/4306/files#diff-27ba9cb3e60614ccdd6a2e5cdc82825ee6b1db0b8957c37fdbfa179cfd4ccd61R66

我觉得可以,我自己是单独实现了一个获取底层client的package raw-gredis

@YunzhiYike
Copy link
Contributor Author

我之前也准备提交这个,但是群里说gredis作为抽象层不应该暴露go-redis驱动的相关引用就放弃了,我现在是自定义了一个gredis,只保留了gins里对redis配置文件参数的解析和客户端的初始化还有多配置redis客户端获取,这样就能直接用go-redis驱动的方法,我看V3的计划表里也有删除gredis的意向,等等,我最近好像在某个isssues里也回复过老哥??

没错你应该回复的就是我

@hailaz hailaz changed the title feat(redis):feat support redis pipeline fix: gredis support get raw client Sep 3, 2025
@hailaz hailaz changed the title fix: gredis support get raw client fix(database/gredis): gredis support get raw client Sep 3, 2025
@YunzhiYike
Copy link
Contributor Author

Quote reply

之前也是准备直接暴露Client但是也是社区说不要暴露底层所以就改成定义一个pipline方法

@hailaz hailaz merged commit 41a5484 into gogf:master Sep 3, 2025
13 checks passed
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 this pull request may close these issues.

g.Redis怎么使用pipeline How to use redis Pipeline? Whether gredis supports multi/exec or pipeline

5 participants