Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
StackExchange.Redis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
StackExchange.Redis
Commits
8dff32b9
Commit
8dff32b9
authored
Mar 28, 2014
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrated booksleeve hash tests
parent
2ff22de9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
485 additions
and
475 deletions
+485
-475
Hashes.cs
MigratedBookSleeveTestSuite/Hashes.cs
+485
-475
No files found.
MigratedBookSleeveTestSuite/Hashes.cs
View file @
8dff32b9
//using System;
using
System
;
//using System.Collections.Generic;
using
System.Collections.Generic
;
//using System.Text;
using
System.Text
;
//using System.Linq;
using
System.Linq
;
//using NUnit.Framework;
using
NUnit.Framework
;
using
StackExchange.Redis
;
//namespace Tests
//{
namespace
Tests
// [TestFixture]
{
// public class Hashes // http://redis.io/commands#hash
[
TestFixture
]
// {
public
class
Hashes
// http://redis.io/commands#hash
// [Test]
{
// public void TestIncrBy()
[
Test
]
// {
public
void
TestIncrBy
()
// using (var conn = Config.GetUnsecuredConnection())
{
// {
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
// conn.Keys.Remove(5, "hash-test");
{
// for (int i = 1; i < 1000; i++)
var
conn
=
muxer
.
GetDatabase
(
5
);
// {
conn
.
KeyDeleteAsync
(
"hash-test"
);
// Assert.AreEqual(i, conn.Hashes.Increment(5, "hash-test", "a", 1).Result);
for
(
int
i
=
1
;
i
<
1000
;
i
++)
// Assert.AreEqual(-i, conn.Hashes.Increment(5, "hash-test", "b", -1).Result);
{
// //Assert.AreEqual(i, conn.Wait(conn.Hashes.Increment(5, "hash-test", "a", 1)));
Assert
.
AreEqual
(
i
,
conn
.
HashIncrementAsync
(
"hash-test"
,
"a"
,
1
).
Result
);
// //Assert.AreEqual(-i, conn.Wait(conn.Hashes.Increment(5, "hash-test", "b", -1)));
Assert
.
AreEqual
(-
i
,
conn
.
HashIncrementAsync
(
"hash-test"
,
"b"
,
-
1
).
Result
);
// }
//Assert.AreEqual(i, conn.Wait(conn.Hashes.Increment(5, "hash-test", "a", 1)));
// }
//Assert.AreEqual(-i, conn.Wait(conn.Hashes.Increment(5, "hash-test", "b", -1)));
// }
}
}
// [Test]
}
// public void Scan()
// {
[
Test
]
// using (var conn = Config.GetUnsecuredConnection(waitForOpen: true))
public
void
Scan
()
// {
{
// if (!conn.Features.Scan) Assert.Inconclusive();
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
(
waitForOpen
:
true
))
// const int db = 3;
{
// const string key = "hash-scan";
if
(!
Config
.
GetFeatures
(
muxer
).
Scan
)
Assert
.
Inconclusive
();
// conn.Keys.Remove(db, key);
const
int
db
=
3
;
// conn.Hashes.Set(db, key, "abc", "def");
var
conn
=
muxer
.
GetDatabase
(
db
);
// conn.Hashes.Set(db, key, "ghi", "jkl");
// conn.Hashes.Set(db, key, "mno", "pqr");
// var t1 = conn.Hashes.Scan(db, key);
// var t2 = conn.Hashes.Scan(db, key, "*h*");
// var t3 = conn.Hashes.ScanString(db, key);
// var t4 = conn.Hashes.ScanString(db, key, "*h*");
// var v1 = t1.ToArray();
// var v2 = t2.ToArray();
// var v3 = t3.ToArray();
// var v4 = t4.ToArray();
// Assert.AreEqual(3, v1.Length);
// Assert.AreEqual(1, v2.Length);
// Assert.AreEqual(3, v3.Length);
// Assert.AreEqual(1, v4.Length);
// Array.Sort(v1, (x, y) => string.Compare(x.Key, y.Key));
// Array.Sort(v2, (x, y) => string.Compare(x.Key, y.Key));
// Array.Sort(v3, (x, y) => string.Compare(x.Key, y.Key));
// Array.Sort(v4, (x, y) => string.Compare(x.Key, y.Key));
// Assert.AreEqual("abc=def,ghi=jkl,mno=pqr", string.Join(",", v1.Select(pair => pair.Key + "=" + Encoding.UTF8.GetString(pair.Value))));
// Assert.AreEqual("ghi=jkl", string.Join(",", v2.Select(pair => pair.Key + "=" + Encoding.UTF8.GetString(pair.Value))));
// Assert.AreEqual("abc=def,ghi=jkl,mno=pqr", string.Join(",", v3.Select(pair => pair.Key + "=" + pair.Value)));
// Assert.AreEqual("ghi=jkl", string.Join(",", v4.Select(pair => pair.Key + "=" + pair.Value)));
// }
// }
// [Test]
// public void TestIncrementOnHashThatDoesntExist()
// {
// using (var conn = Config.GetUnsecuredConnection())
// {
// conn.Keys.Remove(0, "keynotexist");
// var result1 = conn.Wait(conn.Hashes.Increment(0, "keynotexist", "fieldnotexist", 1));
// var result2 = conn.Wait(conn.Hashes.Increment(0, "keynotexist", "anotherfieldnotexist", 1));
// Assert.AreEqual(1, result1);
// Assert.AreEqual(1, result2);
// }
// }
// [Test]
// public void TestIncrByFloat()
// {
// using (var conn = Config.GetUnsecuredConnection(waitForOpen:true))
// {
// if (conn.Features.IncrementFloat)
// {
// conn.Keys.Remove(5, "hash-test");
// for (int i = 1; i < 1000; i++)
// {
// Assert.AreEqual((double)i, conn.Hashes.Increment(5, "hash-test", "a", 1.0).Result);
// Assert.AreEqual((double)(-i), conn.Hashes.Increment(5, "hash-test", "b", -1.0).Result);
// }
// }
// }
// }
// [Test]
// public void TestGetAll()
// {
// using (var conn = Config.GetUnsecuredConnection())
// {
// const string key = "hash test";
const
string
key
=
"hash-scan"
;
// conn.Keys.Remove(6, key);
conn
.
KeyDeleteAsync
(
key
);
// var shouldMatch = new Dictionary<Guid, int>();
conn
.
HashSetAsync
(
key
,
"abc"
,
"def"
);
// var random = new Random();
conn
.
HashSetAsync
(
key
,
"ghi"
,
"jkl"
);
conn
.
HashSetAsync
(
key
,
"mno"
,
"pqr"
);
// for (int i = 1; i < 1000; i++)
// {
var
t1
=
conn
.
HashScan
(
key
);
// var guid = Guid.NewGuid();
var
t2
=
conn
.
HashScan
(
key
,
"*h*"
);
// var value = random.Next(Int32.MaxValue);
var
t3
=
conn
.
HashScan
(
key
);
var
t4
=
conn
.
HashScan
(
key
,
"*h*"
);
// shouldMatch[guid] = value;
var
v1
=
t1
.
ToArray
();
// var x = conn.Hashes.Increment(6, key, guid.ToString(), value).Result; // Kill Async
var
v2
=
t2
.
ToArray
();
// }
var
v3
=
t3
.
ToArray
();
//#pragma warning disable 618
var
v4
=
t4
.
ToArray
();
// var inRedisRaw = conn.GetHash(6, key).Result;
//#pragma warning restore 618
Assert
.
AreEqual
(
3
,
v1
.
Length
);
// var inRedis = new Dictionary<Guid, int>();
Assert
.
AreEqual
(
1
,
v2
.
Length
);
Assert
.
AreEqual
(
3
,
v3
.
Length
);
// for (var i = 0; i < inRedisRaw.Length; i += 2)
Assert
.
AreEqual
(
1
,
v4
.
Length
);
// {
Array
.
Sort
(
v1
,
(
x
,
y
)
=>
string
.
Compare
(
x
.
Name
,
y
.
Name
));
// var guid = inRedisRaw[i];
Array
.
Sort
(
v2
,
(
x
,
y
)
=>
string
.
Compare
(
x
.
Name
,
y
.
Name
));
// var num = inRedisRaw[i + 1];
Array
.
Sort
(
v3
,
(
x
,
y
)
=>
string
.
Compare
(
x
.
Name
,
y
.
Name
));
Array
.
Sort
(
v4
,
(
x
,
y
)
=>
string
.
Compare
(
x
.
Name
,
y
.
Name
));
// inRedis[Guid.Parse(Encoding.ASCII.GetString(guid))] = int.Parse(Encoding.ASCII.GetString(num));
// }
Assert
.
AreEqual
(
"abc=def,ghi=jkl,mno=pqr"
,
string
.
Join
(
","
,
v1
.
Select
(
pair
=>
pair
.
Name
+
"="
+
(
string
)
pair
.
Value
)));
Assert
.
AreEqual
(
"ghi=jkl"
,
string
.
Join
(
","
,
v2
.
Select
(
pair
=>
pair
.
Name
+
"="
+
(
string
)
pair
.
Value
)));
// Assert.AreEqual(shouldMatch.Count, inRedis.Count);
Assert
.
AreEqual
(
"abc=def,ghi=jkl,mno=pqr"
,
string
.
Join
(
","
,
v3
.
Select
(
pair
=>
pair
.
Name
+
"="
+
pair
.
Value
)));
Assert
.
AreEqual
(
"ghi=jkl"
,
string
.
Join
(
","
,
v4
.
Select
(
pair
=>
pair
.
Name
+
"="
+
pair
.
Value
)));
// foreach (var k in shouldMatch.Keys)
}
// {
}
// Assert.AreEqual(shouldMatch[k], inRedis[k]);
[
Test
]
// }
public
void
TestIncrementOnHashThatDoesntExist
()
// }
{
// }
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
{
// [Test]
var
conn
=
muxer
.
GetDatabase
(
0
);
// public void TestGet()
conn
.
KeyDeleteAsync
(
"keynotexist"
);
// {
var
result1
=
conn
.
Wait
(
conn
.
HashIncrementAsync
(
"keynotexist"
,
"fieldnotexist"
,
1
));
// using (var conn = Config.GetUnsecuredConnection())
var
result2
=
conn
.
Wait
(
conn
.
HashIncrementAsync
(
"keynotexist"
,
"anotherfieldnotexist"
,
1
));
// {
Assert
.
AreEqual
(
1
,
result1
);
// var key = "hash test";
Assert
.
AreEqual
(
1
,
result2
);
}
// var shouldMatch = new Dictionary<Guid, int>();
}
// var random = new Random();
[
Test
]
public
void
TestIncrByFloat
()
// for (int i = 1; i < 1000; i++)
{
// {
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
(
waitForOpen
:
true
))
// var guid = Guid.NewGuid();
{
// var value = random.Next(Int32.MaxValue);
var
conn
=
muxer
.
GetDatabase
(
5
);
if
(!
Config
.
GetFeatures
(
muxer
).
IncrementFloat
)
Assert
.
Inconclusive
();
// shouldMatch[guid] = value;
{
conn
.
KeyDeleteAsync
(
"hash-test"
);
// var x = conn.Hashes.Increment(6, key, guid.ToString(), value).Result; // Kill Async
for
(
int
i
=
1
;
i
<
1000
;
i
++)
// }
{
Assert
.
AreEqual
((
double
)
i
,
conn
.
HashIncrementAsync
(
"hash-test"
,
"a"
,
1.0
).
Result
);
// foreach (var k in shouldMatch.Keys)
Assert
.
AreEqual
((
double
)(-
i
),
conn
.
HashIncrementAsync
(
"hash-test"
,
"b"
,
-
1.0
).
Result
);
// {
}
// var inRedis = conn.Hashes.Get(6, key, k.ToString()).Result;
}
// var num = int.Parse(Encoding.ASCII.GetString(inRedis));
}
}
// Assert.AreEqual(shouldMatch[k], num);
// }
// }
[
Test
]
// }
public
void
TestGetAll
()
{
// [Test]
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
// public void TestSet() // http://redis.io/commands/hset
{
// {
var
conn
=
muxer
.
GetDatabase
(
6
);
// using (var conn = Config.GetUnsecuredConnection())
const
string
key
=
"hash test"
;
// {
conn
.
KeyDeleteAsync
(
key
);
// conn.Keys.Remove(9, "hashkey");
var
shouldMatch
=
new
Dictionary
<
Guid
,
int
>();
var
random
=
new
Random
();
// var val0 = conn.Hashes.GetString(9, "hashkey", "field");
// var set0 = conn.Hashes.Set(9, "hashkey", "field", "value1");
for
(
int
i
=
1
;
i
<
1000
;
i
++)
// var val1 = conn.Hashes.GetString(9, "hashkey", "field");
{
// var set1 = conn.Hashes.Set(9, "hashkey", "field", "value2");
var
guid
=
Guid
.
NewGuid
();
// var val2 = conn.Hashes.GetString(9, "hashkey", "field");
var
value
=
random
.
Next
(
Int32
.
MaxValue
);
// var set2 = conn.Hashes.Set(9, "hashkey", "field-blob", Encoding.UTF8.GetBytes("value3"));
shouldMatch
[
guid
]
=
value
;
// var val3 = conn.Hashes.Get(9, "hashkey", "field-blob");
var
x
=
conn
.
HashIncrementAsync
(
key
,
guid
.
ToString
(),
value
).
Result
;
// Kill Async
// Assert.AreEqual(null, val0.Result);
}
// Assert.AreEqual(true, set0.Result);
#pragma warning disable 618
// Assert.AreEqual("value1", val1.Result);
var
inRedis
=
conn
.
HashGetAllAsync
(
key
).
Result
.
ToDictionary
(
// Assert.AreEqual(false, set1.Result);
x
=>
Guid
.
Parse
(
x
.
Name
),
x
=>
int
.
Parse
(
x
.
Value
));
// Assert.AreEqual("value2", val2.Result);
#pragma warning restore 618
// Assert.AreEqual(true, set2.Result);
Assert
.
AreEqual
(
shouldMatch
.
Count
,
inRedis
.
Count
);
// Assert.AreEqual("value3", Encoding.UTF8.GetString(val3.Result));
foreach
(
var
k
in
shouldMatch
.
Keys
)
// }
{
// }
Assert
.
AreEqual
(
shouldMatch
[
k
],
inRedis
[
k
]);
// [Test]
}
// public void TestSetNotExists() // http://redis.io/commands/hsetnx
}
// {
}
// using (var conn = Config.GetUnsecuredConnection())
// {
[
Test
]
// conn.Keys.Remove(9, "hashkey");
public
void
TestGet
()
{
// var val0 = conn.Hashes.GetString(9, "hashkey", "field");
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
// var set0 = conn.Hashes.SetIfNotExists(9, "hashkey", "field", "value1");
{
// var val1 = conn.Hashes.GetString(9, "hashkey", "field");
var
key
=
"hash test"
;
// var set1 = conn.Hashes.SetIfNotExists(9, "hashkey", "field", "value2");
var
conn
=
muxer
.
GetDatabase
(
6
);
// var val2 = conn.Hashes.GetString(9, "hashkey", "field");
var
shouldMatch
=
new
Dictionary
<
Guid
,
int
>();
var
random
=
new
Random
();
// var set2 = conn.Hashes.SetIfNotExists(9, "hashkey", "field-blob", Encoding.UTF8.GetBytes("value3"));
// var val3 = conn.Hashes.Get(9, "hashkey", "field-blob");
for
(
int
i
=
1
;
i
<
1000
;
i
++)
// var set3 = conn.Hashes.SetIfNotExists(9, "hashkey", "field-blob", Encoding.UTF8.GetBytes("value3"));
{
var
guid
=
Guid
.
NewGuid
();
// Assert.AreEqual(null, val0.Result);
var
value
=
random
.
Next
(
Int32
.
MaxValue
);
// Assert.AreEqual(true, set0.Result);
// Assert.AreEqual("value1", val1.Result);
shouldMatch
[
guid
]
=
value
;
// Assert.AreEqual(false, set1.Result);
// Assert.AreEqual("value1", val2.Result);
var
x
=
conn
.
HashIncrementAsync
(
key
,
guid
.
ToString
(),
value
).
Result
;
// Kill Async
}
// Assert.AreEqual(true, set2.Result);
// Assert.AreEqual("value3", Encoding.UTF8.GetString(val3.Result));
foreach
(
var
k
in
shouldMatch
.
Keys
)
// Assert.AreEqual(false, set3.Result);
{
var
inRedis
=
conn
.
HashGetAsync
(
key
,
k
.
ToString
()).
Result
;
// }
var
num
=
int
.
Parse
((
string
)
inRedis
);
// }
// [Test]
Assert
.
AreEqual
(
shouldMatch
[
k
],
num
);
// public void TestDelSingle() // http://redis.io/commands/hdel
}
// {
}
// using (var conn = Config.GetUnsecuredConnection())
}
// {
[
Test
]
// conn.Keys.Remove(9, "hashkey");
public
void
TestSet
()
// http://redis.io/commands/hset
// var del0 = conn.Hashes.Remove(9, "hashkey", "field");
{
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
// conn.Hashes.Set(9, "hashkey", "field", "value");
{
var
conn
=
muxer
.
GetDatabase
(
9
);
// var del1 = conn.Hashes.Remove(9, "hashkey", "field");
conn
.
KeyDeleteAsync
(
"hashkey"
);
// var del2 = conn.Hashes.Remove(9, "hashkey", "field");
var
val0
=
conn
.
HashGetAsync
(
"hashkey"
,
"field"
);
// Assert.AreEqual(false, del0.Result);
var
set0
=
conn
.
HashSetAsync
(
"hashkey"
,
"field"
,
"value1"
);
// Assert.AreEqual(true, del1.Result);
var
val1
=
conn
.
HashGetAsync
(
"hashkey"
,
"field"
);
// Assert.AreEqual(false, del2.Result);
var
set1
=
conn
.
HashSetAsync
(
"hashkey"
,
"field"
,
"value2"
);
var
val2
=
conn
.
HashGetAsync
(
"hashkey"
,
"field"
);
// }
// }
var
set2
=
conn
.
HashSetAsync
(
"hashkey"
,
"field-blob"
,
Encoding
.
UTF8
.
GetBytes
(
"value3"
));
// [Test]
var
val3
=
conn
.
HashGetAsync
(
"hashkey"
,
"field-blob"
);
// public void TestDelMulti() // http://redis.io/commands/hdel
// {
Assert
.
AreEqual
(
null
,
(
string
)
val0
.
Result
);
// using (var conn = Config.GetUnsecuredConnection())
Assert
.
AreEqual
(
true
,
set0
.
Result
);
// {
Assert
.
AreEqual
(
"value1"
,
(
string
)
val1
.
Result
);
// conn.Hashes.Set(3, "TestDelMulti", "key1", "val1");
Assert
.
AreEqual
(
false
,
set1
.
Result
);
// conn.Hashes.Set(3, "TestDelMulti", "key2", "val2");
Assert
.
AreEqual
(
"value2"
,
(
string
)
val2
.
Result
);
// conn.Hashes.Set(3, "TestDelMulti", "key3", "val3");
Assert
.
AreEqual
(
true
,
set2
.
Result
);
// var s1 = conn.Hashes.Exists(3, "TestDelMulti", "key1");
Assert
.
AreEqual
(
"value3"
,
(
string
)
val3
.
Result
);
// var s2 = conn.Hashes.Exists(3, "TestDelMulti", "key2");
// var s3 = conn.Hashes.Exists(3, "TestDelMulti", "key3");
}
}
// var removed = conn.Hashes.Remove(3, "TestDelMulti", new[] { "key1", "key3" });
[
Test
]
public
void
TestSetNotExists
()
// http://redis.io/commands/hsetnx
// var d1 = conn.Hashes.Exists(3, "TestDelMulti", "key1");
{
// var d2 = conn.Hashes.Exists(3, "TestDelMulti", "key2");
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
// var d3 = conn.Hashes.Exists(3, "TestDelMulti", "key3");
{
var
conn
=
muxer
.
GetDatabase
(
9
);
// Assert.IsTrue(conn.Wait(s1));
conn
.
KeyDeleteAsync
(
"hashkey"
);
// Assert.IsTrue(conn.Wait(s2));
// Assert.IsTrue(conn.Wait(s3));
var
val0
=
conn
.
HashGetAsync
(
"hashkey"
,
"field"
);
var
set0
=
conn
.
HashSetAsync
(
"hashkey"
,
"field"
,
"value1"
,
When
.
NotExists
);
// Assert.AreEqual(2, conn.Wait(removed));
var
val1
=
conn
.
HashGetAsync
(
"hashkey"
,
"field"
);
var
set1
=
conn
.
HashSetAsync
(
"hashkey"
,
"field"
,
"value2"
,
When
.
NotExists
);
// Assert.IsFalse(conn.Wait(d1));
var
val2
=
conn
.
HashGetAsync
(
"hashkey"
,
"field"
);
// Assert.IsTrue(conn.Wait(d2));
// Assert.IsFalse(conn.Wait(d3));
var
set2
=
conn
.
HashSetAsync
(
"hashkey"
,
"field-blob"
,
Encoding
.
UTF8
.
GetBytes
(
"value3"
),
When
.
NotExists
);
var
val3
=
conn
.
HashGetAsync
(
"hashkey"
,
"field-blob"
);
// var removeFinal = conn.Hashes.Remove(3, "TestDelMulti", new[] {"key2"});
var
set3
=
conn
.
HashSetAsync
(
"hashkey"
,
"field-blob"
,
Encoding
.
UTF8
.
GetBytes
(
"value3"
),
When
.
NotExists
);
// Assert.AreEqual(0, conn.Wait(conn.Hashes.GetLength(3, "TestDelMulti")));
Assert
.
AreEqual
(
null
,
(
string
)
val0
.
Result
);
// Assert.AreEqual(1, conn.Wait(removeFinal));
Assert
.
AreEqual
(
true
,
set0
.
Result
);
// }
Assert
.
AreEqual
(
"value1"
,
(
string
)
val1
.
Result
);
// }
Assert
.
AreEqual
(
false
,
set1
.
Result
);
// [Test]
Assert
.
AreEqual
(
"value1"
,
(
string
)
val2
.
Result
);
// public void TestDelMultiInsideTransaction() // http://redis.io/commands/hdel
// {
Assert
.
AreEqual
(
true
,
set2
.
Result
);
// using (var outer = Config.GetUnsecuredConnection())
Assert
.
AreEqual
(
"value3"
,
(
string
)
val3
.
Result
);
// {
Assert
.
AreEqual
(
false
,
set3
.
Result
);
// using (var conn = outer.CreateTransaction())
// {
}
// conn.Hashes.Set(3, "TestDelMulti", "key1", "val1");
}
// conn.Hashes.Set(3, "TestDelMulti", "key2", "val2");
[
Test
]
// conn.Hashes.Set(3, "TestDelMulti", "key3", "val3");
public
void
TestDelSingle
()
// http://redis.io/commands/hdel
{
// var s1 = conn.Hashes.Exists(3, "TestDelMulti", "key1");
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
// var s2 = conn.Hashes.Exists(3, "TestDelMulti", "key2");
{
// var s3 = conn.Hashes.Exists(3, "TestDelMulti", "key3");
var
conn
=
muxer
.
GetDatabase
(
9
);
conn
.
KeyDeleteAsync
(
"hashkey"
);
// var removed = conn.Hashes.Remove(3, "TestDelMulti", new[] { "key1", "key3" });
var
del0
=
conn
.
HashDeleteAsync
(
"hashkey"
,
"field"
);
// var d1 = conn.Hashes.Exists(3, "TestDelMulti", "key1");
conn
.
HashSetAsync
(
"hashkey"
,
"field"
,
"value"
);
// var d2 = conn.Hashes.Exists(3, "TestDelMulti", "key2");
// var d3 = conn.Hashes.Exists(3, "TestDelMulti", "key3");
var
del1
=
conn
.
HashDeleteAsync
(
"hashkey"
,
"field"
);
var
del2
=
conn
.
HashDeleteAsync
(
"hashkey"
,
"field"
);
// conn.Execute();
Assert
.
AreEqual
(
false
,
del0
.
Result
);
// Assert.IsTrue(conn.Wait(s1));
Assert
.
AreEqual
(
true
,
del1
.
Result
);
// Assert.IsTrue(conn.Wait(s2));
Assert
.
AreEqual
(
false
,
del2
.
Result
);
// Assert.IsTrue(conn.Wait(s3));
}
// Assert.AreEqual(2, conn.Wait(removed));
}
[
Test
]
// Assert.IsFalse(conn.Wait(d1));
public
void
TestDelMulti
()
// http://redis.io/commands/hdel
// Assert.IsTrue(conn.Wait(d2));
{
// Assert.IsFalse(conn.Wait(d3));
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
// }
{
var
conn
=
muxer
.
GetDatabase
(
3
);
// }
conn
.
HashSetAsync
(
"TestDelMulti"
,
"key1"
,
"val1"
);
// }
conn
.
HashSetAsync
(
"TestDelMulti"
,
"key2"
,
"val2"
);
// [Test]
conn
.
HashSetAsync
(
"TestDelMulti"
,
"key3"
,
"val3"
);
// public void TestExists() // http://redis.io/commands/hexists
// {
var
s1
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key1"
);
// using (var conn = Config.GetUnsecuredConnection())
var
s2
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key2"
);
// {
var
s3
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key3"
);
// conn.Keys.Remove(9, "hashkey");
// var ex0 = conn.Hashes.Exists(9, "hashkey", "field");
var
removed
=
conn
.
HashDeleteAsync
(
"TestDelMulti"
,
new
RedisValue
[]
{
"key1"
,
"key3"
});
// conn.Hashes.Set(9, "hashkey", "field", "value");
// var ex1 = conn.Hashes.Exists(9, "hashkey", "field");
var
d1
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key1"
);
// conn.Hashes.Remove(9, "hashkey", "field");
var
d2
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key2"
);
// var ex2 = conn.Hashes.Exists(9, "hashkey", "field");
var
d3
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key3"
);
// Assert.AreEqual(false, ex0.Result);
Assert
.
IsTrue
(
conn
.
Wait
(
s1
));
// Assert.AreEqual(true, ex1.Result);
Assert
.
IsTrue
(
conn
.
Wait
(
s2
));
// Assert.AreEqual(false, ex0.Result);
Assert
.
IsTrue
(
conn
.
Wait
(
s3
));
// }
Assert
.
AreEqual
(
2
,
conn
.
Wait
(
removed
));
// }
Assert
.
IsFalse
(
conn
.
Wait
(
d1
));
// [Test]
Assert
.
IsTrue
(
conn
.
Wait
(
d2
));
// public void TestHashKeys() // http://redis.io/commands/hkeys
Assert
.
IsFalse
(
conn
.
Wait
(
d3
));
// {
// using (var conn = Config.GetUnsecuredConnection())
var
removeFinal
=
conn
.
HashDeleteAsync
(
"TestDelMulti"
,
new
RedisValue
[]
{
"key2"
});
// {
// conn.Keys.Remove(9, "hashkey");
Assert
.
AreEqual
(
0
,
conn
.
Wait
(
conn
.
HashLengthAsync
(
"TestDelMulti"
)));
Assert
.
AreEqual
(
1
,
conn
.
Wait
(
removeFinal
));
// var keys0 = conn.Hashes.GetKeys(9, "hashkey");
}
}
// conn.Hashes.Set(9, "hashkey", "foo", "abc");
// conn.Hashes.Set(9, "hashkey", "bar", "def");
[
Test
]
public
void
TestDelMultiInsideTransaction
()
// http://redis.io/commands/hdel
// var keys1 = conn.Hashes.GetKeys(9, "hashkey");
{
using
(
var
outer
=
Config
.
GetUnsecuredConnection
())
// Assert.AreEqual(0, keys0.Result.Length);
{
// var arr = keys1.Result;
var
conn
=
outer
.
GetDatabase
(
3
).
CreateTransaction
();
// Assert.AreEqual(2, arr.Length);
{
// Assert.AreEqual("foo", arr[0]);
conn
.
HashSetAsync
(
"TestDelMulti"
,
"key1"
,
"val1"
);
// Assert.AreEqual("bar", arr[1]);
conn
.
HashSetAsync
(
"TestDelMulti"
,
"key2"
,
"val2"
);
conn
.
HashSetAsync
(
"TestDelMulti"
,
"key3"
,
"val3"
);
// }
// }
var
s1
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key1"
);
var
s2
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key2"
);
// [Test]
var
s3
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key3"
);
// public void TestHashValues() // http://redis.io/commands/hvals
// {
var
removed
=
conn
.
HashDeleteAsync
(
"TestDelMulti"
,
new
RedisValue
[]
{
"key1"
,
"key3"
});
// using (var conn = Config.GetUnsecuredConnection())
// {
var
d1
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key1"
);
// conn.Keys.Remove(9, "hashkey");
var
d2
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key2"
);
var
d3
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key3"
);
// var keys0 = conn.Hashes.GetValues(9, "hashkey");
conn
.
Execute
();
// conn.Hashes.Set(9, "hashkey", "foo", "abc");
// conn.Hashes.Set(9, "hashkey", "bar", "def");
Assert
.
IsTrue
(
conn
.
Wait
(
s1
));
Assert
.
IsTrue
(
conn
.
Wait
(
s2
));
// var keys1 = conn.Hashes.GetValues(9, "hashkey");
Assert
.
IsTrue
(
conn
.
Wait
(
s3
));
// Assert.AreEqual(0, keys0.Result.Length);
Assert
.
AreEqual
(
2
,
conn
.
Wait
(
removed
));
// var arr = keys1.Result;
Assert
.
IsFalse
(
conn
.
Wait
(
d1
));
// Assert.AreEqual(2, arr.Length);
Assert
.
IsTrue
(
conn
.
Wait
(
d2
));
// Assert.AreEqual("abc", Encoding.UTF8.GetString(arr[0]));
Assert
.
IsFalse
(
conn
.
Wait
(
d3
));
// Assert.AreEqual("def", Encoding.UTF8.GetString(arr[1]));
}
// }
}
// }
}
[
Test
]
// [Test]
public
void
TestExists
()
// http://redis.io/commands/hexists
// public void TestHashLength() // http://redis.io/commands/hlen
{
// {
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
// using (var conn = Config.GetUnsecuredConnection())
{
// {
var
conn
=
muxer
.
GetDatabase
(
9
);
// conn.Keys.Remove(9, "hashkey");
conn
.
KeyDeleteAsync
(
"hashkey"
);
var
ex0
=
conn
.
HashExistsAsync
(
"hashkey"
,
"field"
);
// var len0 = conn.Hashes.GetLength(9, "hashkey");
conn
.
HashSetAsync
(
"hashkey"
,
"field"
,
"value"
);
var
ex1
=
conn
.
HashExistsAsync
(
"hashkey"
,
"field"
);
// conn.Hashes.Set(9, "hashkey", "foo", "abc");
conn
.
HashDeleteAsync
(
"hashkey"
,
"field"
);
// conn.Hashes.Set(9, "hashkey", "bar", "def");
var
ex2
=
conn
.
HashExistsAsync
(
"hashkey"
,
"field"
);
// var len1 = conn.Hashes.GetLength(9, "hashkey");
// Assert.AreEqual(0, len0.Result);
// Assert.AreEqual(2, len1.Result);
// }
// }
// [Test]
// public void TestGetMulti() // http://redis.io/commands/hmget
// {
// using (var conn = Config.GetUnsecuredConnection())
// {
// conn.Keys.Remove(9, "hashkey");
// string[] fields = { "foo", "bar", "blop" };
// var result0 = conn.Hashes.GetString(9, "hashkey", fields);
// conn.Hashes.Set(9, "hashkey", "foo", "abc");
// conn.Hashes.Set(9, "hashkey", "bar", "def");
// var result1 = conn.Hashes.GetString(9, "hashkey", fields);
// var result2 = conn.Hashes.Get(9, "hashkey", fields);
// var arr0 = result0.Result;
// var arr1 = result1.Result;
// var arr2 = result2.Result;
// Assert.AreEqual(3, arr0.Length);
// Assert.IsNull(arr0[0]);
// Assert.IsNull(arr0[1]);
// Assert.IsNull(arr0[2]);
// Assert.AreEqual(3, arr1.Length);
Assert
.
AreEqual
(
false
,
ex0
.
Result
);
// Assert.AreEqual("abc", arr1[0]);
Assert
.
AreEqual
(
true
,
ex1
.
Result
);
// Assert.AreEqual("def", arr1[1]);
Assert
.
AreEqual
(
false
,
ex0
.
Result
);
// Assert.IsNull(arr1[2]);
// Assert.AreEqual(3, arr2.Length);
}
// Assert.AreEqual("abc", Encoding.UTF8.GetString(arr2[0]));
}
// Assert.AreEqual("def", Encoding.UTF8.GetString(arr2[1]));
// Assert.IsNull(arr2[2]);
// }
// }
// [Test]
[
Test
]
// public void TestGetPairs() // http://redis.io/commands/hgetall
public
void
TestHashKeys
()
// http://redis.io/commands/hkeys
// {
{
// using (var conn = Config.GetUnsecuredConnection())
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
// {
{
// conn.Keys.Remove(9, "hashkey");
var
conn
=
muxer
.
GetDatabase
(
9
);
conn
.
KeyDeleteAsync
(
"hashkey"
);
var
keys0
=
conn
.
HashKeysAsync
(
"hashkey"
);
// var result0 = conn.Hashes.GetAll(9, "hashkey");
conn
.
HashSetAsync
(
"hashkey"
,
"foo"
,
"abc"
);
conn
.
HashSetAsync
(
"hashkey"
,
"bar"
,
"def"
);
// conn.Hashes.Set(9, "hashkey", "foo", "abc");
var
keys1
=
conn
.
HashKeysAsync
(
"hashkey"
);
// conn.Hashes.Set(9, "hashkey", "bar", "def");
// var result1 = conn.Hashes.GetAll(9, "hashkey");
Assert
.
AreEqual
(
0
,
keys0
.
Result
.
Length
);
var
arr
=
keys1
.
Result
;
Assert
.
AreEqual
(
2
,
arr
.
Length
);
Assert
.
AreEqual
(
"foo"
,
(
string
)
arr
[
0
]);
Assert
.
AreEqual
(
"bar"
,
(
string
)
arr
[
1
]);
// Assert.AreEqual(0, result0.Result.Count);
}
// var result = result1.Result;
}
// Assert.AreEqual(2, result.Count);
// Assert.AreEqual("abc", Encoding.UTF8.GetString(result["foo"]));
// Assert.AreEqual("def", Encoding.UTF8.GetString(result["bar"]));
// }
// }
// [Test]
[
Test
]
// public void TestSetPairs() // http://redis.io/commands/hmset
public
void
TestHashValues
()
// http://redis.io/commands/hvals
// {
{
// using (var conn = Config.GetUnsecuredConnection())
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
// {
{
// conn.Keys.Remove(9, "hashkey");
var
conn
=
muxer
.
GetDatabase
(
9
);
conn
.
KeyDeleteAsync
(
"hashkey"
);
var
keys0
=
conn
.
HashValuesAsync
(
"hashkey"
);
conn
.
HashSetAsync
(
"hashkey"
,
"foo"
,
"abc"
);
conn
.
HashSetAsync
(
"hashkey"
,
"bar"
,
"def"
);
var
keys1
=
conn
.
HashValuesAsync
(
"hashkey"
);
Assert
.
AreEqual
(
0
,
keys0
.
Result
.
Length
);
var
arr
=
keys1
.
Result
;
Assert
.
AreEqual
(
2
,
arr
.
Length
);
Assert
.
AreEqual
(
"abc"
,
Encoding
.
UTF8
.
GetString
(
arr
[
0
]));
Assert
.
AreEqual
(
"def"
,
Encoding
.
UTF8
.
GetString
(
arr
[
1
]));
}
}
[
Test
]
public
void
TestHashLength
()
// http://redis.io/commands/hlen
{
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
{
var
conn
=
muxer
.
GetDatabase
(
9
);
conn
.
KeyDeleteAsync
(
"hashkey"
);
var
len0
=
conn
.
HashLengthAsync
(
"hashkey"
);
conn
.
HashSetAsync
(
"hashkey"
,
"foo"
,
"abc"
);
conn
.
HashSetAsync
(
"hashkey"
,
"bar"
,
"def"
);
var
len1
=
conn
.
HashLengthAsync
(
"hashkey"
);
Assert
.
AreEqual
(
0
,
len0
.
Result
);
Assert
.
AreEqual
(
2
,
len1
.
Result
);
}
}
[
Test
]
public
void
TestGetMulti
()
// http://redis.io/commands/hmget
{
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
{
var
conn
=
muxer
.
GetDatabase
(
9
);
conn
.
KeyDeleteAsync
(
"hashkey"
);
RedisValue
[]
fields
=
{
"foo"
,
"bar"
,
"blop"
};
var
result0
=
conn
.
HashGetAsync
(
"hashkey"
,
fields
);
conn
.
HashSetAsync
(
"hashkey"
,
"foo"
,
"abc"
);
conn
.
HashSetAsync
(
"hashkey"
,
"bar"
,
"def"
);
var
result1
=
conn
.
HashGetAsync
(
"hashkey"
,
fields
);
var
result2
=
conn
.
HashGetAsync
(
"hashkey"
,
fields
);
var
arr0
=
result0
.
Result
;
var
arr1
=
result1
.
Result
;
var
arr2
=
result2
.
Result
;
// var result0 = conn.Hashes.GetAll(9, "hashkey");
Assert
.
AreEqual
(
3
,
arr0
.
Length
);
Assert
.
IsNull
((
string
)
arr0
[
0
]);
Assert
.
IsNull
((
string
)
arr0
[
1
]);
Assert
.
IsNull
((
string
)
arr0
[
2
]);
Assert
.
AreEqual
(
3
,
arr1
.
Length
);
Assert
.
AreEqual
(
"abc"
,
(
string
)
arr1
[
0
]);
Assert
.
AreEqual
(
"def"
,
(
string
)
arr1
[
1
]);
Assert
.
IsNull
((
string
)
arr1
[
2
]);
// var data = new Dictionary<string, byte[]> {
Assert
.
AreEqual
(
3
,
arr2
.
Length
);
// {"foo", Encoding.UTF8.GetBytes("abc")},
Assert
.
AreEqual
(
"abc"
,
(
string
)
arr2
[
0
]);
// {"bar", Encoding.UTF8.GetBytes("def")}
Assert
.
AreEqual
(
"def"
,
(
string
)
arr2
[
1
]);
// };
Assert
.
IsNull
((
string
)
arr2
[
2
]);
// conn.Hashes.Set(9, "hashkey", data);
}
}
// var result1 = conn.Hashes.GetAll(9, "hashkey");
// Assert.AreEqual(0, result0.Result.Count);
[
Test
]
// var result = result1.Result;
public
void
TestGetPairs
()
// http://redis.io/commands/hgetall
// Assert.AreEqual(2, result.Count);
{
// Assert.AreEqual("abc", Encoding.UTF8.GetString(result["foo"]));
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
// Assert.AreEqual("def", Encoding.UTF8.GetString(result["bar"]));
{
// }
var
conn
=
muxer
.
GetDatabase
(
9
);
// }
conn
.
KeyDeleteAsync
(
"hashkey"
);
var
result0
=
conn
.
HashGetAllAsync
(
"hashkey"
);
conn
.
HashSetAsync
(
"hashkey"
,
"foo"
,
"abc"
);
conn
.
HashSetAsync
(
"hashkey"
,
"bar"
,
"def"
);
var
result1
=
conn
.
HashGetAllAsync
(
"hashkey"
);
Assert
.
AreEqual
(
0
,
result0
.
Result
.
Length
);
var
result
=
result1
.
Result
.
ToStringDictionary
();
Assert
.
AreEqual
(
2
,
result
.
Count
);
Assert
.
AreEqual
(
"abc"
,
result
[
"foo"
]);
Assert
.
AreEqual
(
"def"
,
result
[
"bar"
]);
}
}
// }
[
Test
]
//}
public
void
TestSetPairs
()
// http://redis.io/commands/hmset
{
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
{
var
conn
=
muxer
.
GetDatabase
(
9
);
conn
.
KeyDeleteAsync
(
"hashkey"
);
var
result0
=
conn
.
HashGetAllAsync
(
"hashkey"
);
var
data
=
new
HashEntry
[]
{
new
HashEntry
(
"foo"
,
Encoding
.
UTF8
.
GetBytes
(
"abc"
)),
new
HashEntry
(
"bar"
,
Encoding
.
UTF8
.
GetBytes
(
"def"
))
};
conn
.
HashSetAsync
(
"hashkey"
,
data
);
var
result1
=
conn
.
HashGetAllAsync
(
"hashkey"
);
Assert
.
AreEqual
(
0
,
result0
.
Result
.
Length
);
var
result
=
result1
.
Result
.
ToStringDictionary
();
Assert
.
AreEqual
(
2
,
result
.
Count
);
Assert
.
AreEqual
(
"abc"
,
result
[
"foo"
]);
Assert
.
AreEqual
(
"def"
,
result
[
"bar"
]);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment