Comments (5)
Hi,
You're on the right track with your last example, you want to keep a static
instance of a client manager like BasicRedisClientManager or
PooledRedisClientManager.
In the constructor you want to specify the host/port address like:
redisManager = new BasicRedisClientManager("RedisHostnameOrIpAddress:6379");
and then in your client code just do as you were doing before, i.e.:
using (var redis = redisManager.GetClient())
{
//and away you go
}
So it basically works like most connection pools, where the connection pool
manager is thread safe but the single IRedisClient is not.
Let me know if that helps?
- Demis
Original comment by [email protected]
on 26 Jul 2010 at 12:26
from servicestack.
Now I've
public class RedisGetter
{
static readonly BasicRedisClientManager _BasicRedisClientManager;
static RedisGetter()
{
_BasicRedisClientManager = new BasicRedisClientManager("127.0.0.1:6379");
}
and then use using block mentioned above
redis server console shows that number of clients connected is not continuously
growing, but at the end i've recevied error: "Only one usage of each socket
address (protocol/network address/port) is normally permitted 127.0.0.1:6379"
Original comment by okhotny
on 26 Jul 2010 at 12:34
from servicestack.
So can you show me how you're using it? is it like:
using (var redis = _BasicRedisClientManager.GetClient()) //connection is
created here
{
//...
} //connection is terminated here
Cause each time the using statement ends, it should dispose of it. Also
'RedisGetter' should be either be a singleton or you should ensure you only
have one instance of it (a static class would work too).
We're using the BasicRedisClientManager for production as well for handling
most of mflow.com's traffic and we're not encountering this issue. Although
we're accessing the single instance of 'BasicRedisClientManager' through an IOC
- tho it doesn't really matter how you're accessing it as both approaches
should work.
The difference between the 'BasicRedisClientManager' and the
'PooledRedisClientManager' is that the former creates a new connection when you
call '_BasicRedisClientManager.GetClient()' which terminates the connection
when it reaches the end of the using scope while the latter just places the
connection back on the pool but you get to control how many open connections
you want based on the 'PooledRedisClientManager.MaxWritePoolSize'. Again it
really shouldn't matter which one you use, just that you're accessing the right
way (i.e. inside the using statement block).
If its possible do you think you can create a self-contained test-case that
exhibits this issue, that way I can see and diagnose the issue from here.
- Demis
Original comment by [email protected]
on 26 Jul 2010 at 12:57
from servicestack.
Here is error:
[SocketException (0x2740): Only one usage of each socket address
(protocol/network address/port) is normally permitted 127.0.0.1:6379]
System.Net.Sockets.Socket.Connect(IPAddress[] addresses, Int32 port) +1551089
System.Net.Sockets.Socket.Connect(String host, Int32 port) +128
ServiceStack.Redis.RedisNativeClient.Connect() +95
[InvalidOperationException: could not connect to redis Instance at
127.0.0.1:6379]
ServiceStack.Redis.RedisNativeClient.Connect() +616
ServiceStack.Redis.RedisNativeClient.AssertConnectedSocket() +138
ServiceStack.Redis.RedisNativeClient.SendCommand(Byte[][] cmdWithBinaryArgs) +41
ServiceStack.Redis.RedisNativeClient.SendExpectData(Byte[][] cmdWithBinaryArgs) +15
ServiceStack.Redis.RedisNativeClient.GetBytes(String key) +85
ServiceStack.Redis.RedisClient.GetValue(String key) +8
RedisBanner.RedisGetter.BannerCountClick(Banner val) in D:\Hunter\Мои документы\Visual Studio 2008\Projects\RedisBanner\RedisBanner\RedisGetter.cs:173
Here is code:
public static class RedisGetter
{
private static readonly BasicRedisClientManager _BasicRedisClientManager;
static RedisGetter()
{
_BasicRedisClientManager = new BasicRedisClientManager("127.0.0.1:6379");
}
private static int BannerCountClick(Banner val)
{
int t = 0;
using (var RedisClient = _BasicRedisClientManager.GetClient())
{
int.TryParse(RedisClient.GetValue(string.Format("stat:banners:{0}:ClickCount", val.Id)), out t);
}
return t;
}
}
Original comment by okhotny
on 26 Jul 2010 at 1:39
from servicestack.
at server console:
it reports that current 0 active clients,
and it accepts new connection with incremented port numbers.
it works for some time, and then fails for most requests, but some requests are
passing.
Original comment by okhotny
on 26 Jul 2010 at 1:54
from servicestack.
Related Issues (20)
- Serializing byte[] cannot be Deserialized.
- CreateTransaction failing HOT 1
- TypeInitializationException when a class have a property that return an XElement value
- TypeInitializationException when deserialiaze a string to a class that have a static property
- Priority of Web Sockets HOT 1
- How to Store values in session
- Implement Forms Authentication Using ServiceStack HOT 1
- OrmPostgreSQL HOT 1
- Supporting for redis ZCOUNT command
- WCF helper implementation
- Null reference exception on call to GetAll HOT 2
- Broken link on Project Home HOT 2
- DeSerialising dictionary with type Dictionary<Tuple<string,string>,double>>() does not work
- Wrong Encoding
- ServiceStack.Redis reading large files from Redis server
- ServiceStack.Redis.RedisResponseException
- Db number is fogotten when using pooled clients.
- SOAP request and response wrappers
- Tutorial references ServiceStackHttpHandlerFactory which isn't included in ServiceStack.dll
- Future roadmap suggestion
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from servicestack.