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

redisConnection must be exported variable #95

Closed
wants to merge 1 commit into from
Closed

redisConnection must be exported variable #95

wants to merge 1 commit into from

Conversation

dragtor
Copy link

@dragtor dragtor commented Oct 2, 2020

rmq.OpenConnection method returns *redisConnection . Thus, If we want to persist variable in any other struct it is not allowing.
Consider following example :

type RedisQueueDB struct {
	Tag      string
	Network  string
	Address  string
	Queue    string
	DB       int
	DataChan chan Action
	RedisConn *rmq.redisConnection
}

So I want to initialize redisConnection only once and want to reuse same connection through my RedisQueueDB.RedisConn object.

but , it is giving error as below :
redisConnection not exported by package rmq

Made change in repo accordingly . please review

@wellle
Copy link
Member

wellle commented Oct 5, 2020

Have you tried just using rmq.Connection? So in your example it would be:

type RedisQueueDB struct {
	Tag      string
	Network  string
	Address  string
	Queue    string
	DB       int
	DataChan chan Action
	RedisConn rmq.Connection
}

@dragtor
Copy link
Author

dragtor commented Oct 5, 2020

@wellle I am using below method and storing output to have single connection

connection := rmq.OpenConnection("my service", "tcp", "localhost:6379", 1)

but it's return type is *rmq.redisConnection , which is unexported.

@wellle
Copy link
Member

wellle commented Oct 5, 2020

Yes, but rmq.redisConnection can be assigned to a variable of type rmq.Connection, as the *rmq.redisConnection type implements the rmq.Connection interface. And the interface should be enough for your needs.

@dragtor
Copy link
Author

dragtor commented Oct 5, 2020

Yeh.. I missed that one. Thanks

@dragtor dragtor closed this Oct 5, 2020
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.

None yet

3 participants