How often should I open/close my Booksleeve connection?

偶尔善良 提交于 2019-12-03 11:16:38
bzlm

According to the author of Booksleeve,

The connection is thread safe and intended to be massively shared; don't do a connection per operation.

Should I be keeping this connection open, or should I be open/closing it after each query/transaction (as I'm doing now)?

There is probably a little overhead if you will open a new connection each time you want to make a query/transaction and although redis is designed for high level of concurrently connected clients, there might be performance problems if their number is around tens of thousands. As far as I know connection pooling should be done by the client libraries (because redis itself doesn't have this functionality), so you should check if booksleeve supports this stuff. Otherwise you should open the connection when your application starts and keep it open for it's lifetime (in case you don't need parallel clients connected to redis for some reason).

Also, is there any sort of official documentation for this library?

The only documentation I was able to find regarding how to use it was tests folder in it's source codes.

Ofer Zelig

For reference (continuing @bzlm's answer), I created a Singleton that always provides the same Redis connection using BookSleeve (if it's closed, it's being created. Else, the existing connection is being served).

Look at this: https://stackoverflow.com/a/8777999/290343

You consume it like that:

RedisConnection connection = Redis.RedisConnectionGateway.Current.GetConnection();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!