本文整理汇总了C#中RedisClient.Select方法的典型用法代码示例。如果您正苦于以下问题:C# RedisClient.Select方法的具体用法?C# RedisClient.Select怎么用?C# RedisClient.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedisClient
的用法示例。
在下文中一共展示了RedisClient.Select方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ValidateTransfer
public string ValidateTransfer(string sourceAppId, string userId, string transferId, string transferToken)
{
var red = new RedisClient<string>();
var result = red.Get("transfertoken:" + transferId);
if (!string.IsNullOrEmpty(result))
{
var redResult = red.Del("transfertoken:" + transferId);
var redapp = new RedisClient<AppRegistry>();
redapp.Select(1);
var app = redapp.Get(HttpContext.Current.Items["AppId"] as string);
var str = "UserId=" + userId + "&TransferId=" + transferId + "&Salt=" + app.AppSecret ;
str = Hash.GetHash(str, Hash.HashType.SHA256);
if (transferToken != str)
{
throw new FaultException<UnauthorizedAccessException>(new UnauthorizedAccessException("token yanlış"));
}
string sessionguid = Guid.NewGuid().ToString();
var redis = new RedisClient<Common.SessionRegistry>();
var appId = HttpContext.Current.Items["AppId"] as string;
redis.Set(sessionguid, new SessionRegistry() { SessionCookie = sessionguid, AppId = appId, UserId = userId });
return sessionguid;
}
return null;
}
示例2: Initialize
private void Initialize()
{
try
{
// create the connection
Client = new RedisClient(_config.Host, _config.Port)
{
ReconnectAttempts = 3,
ReconnectTimeout = 200
};
// select the database
Client.Select(_config.DatabaseId);
// authenticate if needed.
if (!string.IsNullOrEmpty(_config.Password))
Client.Auth(_config.Password);
// check the version
var version = GetVersion();
if (version < _requiredMinimumVersion)
throw new Exception(string.Format("You are using redis version {0}, minimum required version is 2.6", version));
_logger.Information("Redis storage initialized: {0:l}:{1}, v{2:l}.", _config.Host, _config.Port, version);
}
catch (Exception e)
{
_logger.Error("Redis storage initialization failed: {0:l}:{1} - {2:l}", _config.Host, _config.Port, e.Message);
}
}
示例3: SelectTest
public void SelectTest()
{
using(var mock = new MockConnector("localhost", 9999, "+OK\r\n"))
using(var redis = new RedisClient(mock))
{
Assert.True( redis.Select(2));
Assert.Equal("*2\r\n$6\r\nSELECT\r\n$1\r\n2\r\n", mock.GetMessage());
}
}
示例4: Transfer
public string Transfer(string targetAppId, string transferToken)
{
NameValueCollection nv = new NameValueCollection();
nv["AppId"] = targetAppId;
nv["Secret"] = Guid.NewGuid().ToString();
nv["ExpireAt"] = DateTime.Now.AddMinutes(3).ToLongTimeString();
var redis = new RedisClient<AppRegistry>();
redis.Select(1);
var app = redis.Get(targetAppId);
string token = "AppId=" + targetAppId + "&UserId=" + HttpContext.Current.Items["UserId"] + "&Secret=" + Guid.NewGuid().ToString() + "&ExpireAt=" + DateTime.Now.AddMinutes(3).ToLongTimeString();
string transferId = Guid.NewGuid().ToString();
string token2 = "UserId=" + HttpContext.Current.Items["UserId"] + "&TransferId=" + transferId + "&Salt=" + app.AppSecret;
token2 = Common.Hash.GetHash(token2, Hash.HashType.SHA256);
token = Common.Crypto.EncryptStringAES(token, app.AppSecret);
var red = new RedisClient<string>();
red.Set("transfertoken:" + transferId, token2);
//red.ExpireAt("transfertoken:" + token, DateTime.Now.AddMinutes(1));
return "tid=" + transferId + "&tkn=" + token2;
}
示例5: SelectTest
public void SelectTest()
{
using (IRedisClient client = new RedisClient("localhost", ReidsDefaultTcpPort, 12))
{
Assert.IsTrue(client.Set("TestName3", "TestValue3"));
Assert.IsTrue(client.Select(13));
Assert.AreNotEqual(client.Get("TestName3"), "TestValue3");
Assert.IsTrue(client.Connected);
}
}