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
Show 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");
const
string
key
=
"hash-scan"
;
conn
.
KeyDeleteAsync
(
key
);
// var t1 = conn.Hashes.Scan(db, key);
conn
.
HashSetAsync
(
key
,
"abc"
,
"def"
);
// var t2 = conn.Hashes.Scan(db, key, "*h*");
conn
.
HashSetAsync
(
key
,
"ghi"
,
"jkl"
);
// var t3 = conn.Hashes.ScanString(db, key);
conn
.
HashSetAsync
(
key
,
"mno"
,
"pqr"
);
// var t4 = conn.Hashes.ScanString(db, key, "*h*");
var
t1
=
conn
.
HashScan
(
key
);
// var v1 = t1.ToArray();
var
t2
=
conn
.
HashScan
(
key
,
"*h*"
);
// var v2 = t2.ToArray();
var
t3
=
conn
.
HashScan
(
key
);
// var v3 = t3.ToArray();
var
t4
=
conn
.
HashScan
(
key
,
"*h*"
);
// var v4 = t4.ToArray();
var
v1
=
t1
.
ToArray
();
// Assert.AreEqual(3, v1.Length);
var
v2
=
t2
.
ToArray
();
// Assert.AreEqual(1, v2.Length);
var
v3
=
t3
.
ToArray
();
// Assert.AreEqual(3, v3.Length);
var
v4
=
t4
.
ToArray
();
// Assert.AreEqual(1, v4.Length);
// Array.Sort(v1, (x, y) => string.Compare(x.Key, y.Key));
Assert
.
AreEqual
(
3
,
v1
.
Length
);
// Array.Sort(v2, (x, y) => string.Compare(x.Key, y.Key));
Assert
.
AreEqual
(
1
,
v2
.
Length
);
// Array.Sort(v3, (x, y) => string.Compare(x.Key, y.Key));
Assert
.
AreEqual
(
3
,
v3
.
Length
);
// Array.Sort(v4, (x, y) => string.Compare(x.Key, y.Key));
Assert
.
AreEqual
(
1
,
v4
.
Length
);
Array
.
Sort
(
v1
,
(
x
,
y
)
=>
string
.
Compare
(
x
.
Name
,
y
.
Name
));
// Assert.AreEqual("abc=def,ghi=jkl,mno=pqr", string.Join(",", v1.Select(pair => pair.Key + "=" + Encoding.UTF8.GetString(pair.Value))));
Array
.
Sort
(
v2
,
(
x
,
y
)
=>
string
.
Compare
(
x
.
Name
,
y
.
Name
));
// Assert.AreEqual("ghi=jkl", string.Join(",", v2.Select(pair => pair.Key + "=" + Encoding.UTF8.GetString(pair.Value))));
Array
.
Sort
(
v3
,
(
x
,
y
)
=>
string
.
Compare
(
x
.
Name
,
y
.
Name
));
// Assert.AreEqual("abc=def,ghi=jkl,mno=pqr", string.Join(",", v3.Select(pair => pair.Key + "=" + pair.Value)));
Array
.
Sort
(
v4
,
(
x
,
y
)
=>
string
.
Compare
(
x
.
Name
,
y
.
Name
));
// Assert.AreEqual("ghi=jkl", string.Join(",", v4.Select(pair => pair.Key + "=" + pair.Value)));
// }
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
)));
// [Test]
Assert
.
AreEqual
(
"abc=def,ghi=jkl,mno=pqr"
,
string
.
Join
(
","
,
v3
.
Select
(
pair
=>
pair
.
Name
+
"="
+
pair
.
Value
)));
// public void TestIncrementOnHashThatDoesntExist()
Assert
.
AreEqual
(
"ghi=jkl"
,
string
.
Join
(
","
,
v4
.
Select
(
pair
=>
pair
.
Name
+
"="
+
pair
.
Value
)));
// {
}
// using (var conn = Config.GetUnsecuredConnection())
}
// {
[
Test
]
// conn.Keys.Remove(0, "keynotexist");
public
void
TestIncrementOnHashThatDoesntExist
()
// var result1 = conn.Wait(conn.Hashes.Increment(0, "keynotexist", "fieldnotexist", 1));
{
// var result2 = conn.Wait(conn.Hashes.Increment(0, "keynotexist", "anotherfieldnotexist", 1));
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
// Assert.AreEqual(1, result1);
{
// Assert.AreEqual(1, result2);
var
conn
=
muxer
.
GetDatabase
(
0
);
// }
conn
.
KeyDeleteAsync
(
"keynotexist"
);
// }
var
result1
=
conn
.
Wait
(
conn
.
HashIncrementAsync
(
"keynotexist"
,
"fieldnotexist"
,
1
));
// [Test]
var
result2
=
conn
.
Wait
(
conn
.
HashIncrementAsync
(
"keynotexist"
,
"anotherfieldnotexist"
,
1
));
// public void TestIncrByFloat()
Assert
.
AreEqual
(
1
,
result1
);
// {
Assert
.
AreEqual
(
1
,
result2
);
// using (var conn = Config.GetUnsecuredConnection(waitForOpen:true))
}
// {
}
// if (conn.Features.IncrementFloat)
[
Test
]
// {
public
void
TestIncrByFloat
()
// conn.Keys.Remove(5, "hash-test");
{
// for (int i = 1; i < 1000; i++)
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
(
waitForOpen
:
true
))
// {
{
// Assert.AreEqual((double)i, conn.Hashes.Increment(5, "hash-test", "a", 1.0).Result);
var
conn
=
muxer
.
GetDatabase
(
5
);
// Assert.AreEqual((double)(-i), conn.Hashes.Increment(5, "hash-test", "b", -1.0).Result);
if
(!
Config
.
GetFeatures
(
muxer
).
IncrementFloat
)
Assert
.
Inconclusive
();
// }
{
// }
conn
.
KeyDeleteAsync
(
"hash-test"
);
// }
for
(
int
i
=
1
;
i
<
1000
;
i
++)
// }
{
Assert
.
AreEqual
((
double
)
i
,
conn
.
HashIncrementAsync
(
"hash-test"
,
"a"
,
1.0
).
Result
);
Assert
.
AreEqual
((
double
)(-
i
),
conn
.
HashIncrementAsync
(
"hash-test"
,
"b"
,
-
1.0
).
Result
);
// [Test]
}
// public void TestGetAll()
}
// {
}
// using (var conn = Config.GetUnsecuredConnection())
}
// {
// const string key = "hash test";
[
Test
]
// conn.Keys.Remove(6, key);
public
void
TestGetAll
()
// var shouldMatch = new Dictionary<Guid, int>();
{
// var random = new Random();
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
{
// for (int i = 1; i < 1000; i++)
var
conn
=
muxer
.
GetDatabase
(
6
);
// {
const
string
key
=
"hash test"
;
// var guid = Guid.NewGuid();
conn
.
KeyDeleteAsync
(
key
);
// var value = random.Next(Int32.MaxValue);
var
shouldMatch
=
new
Dictionary
<
Guid
,
int
>();
var
random
=
new
Random
();
// shouldMatch[guid] = value;
for
(
int
i
=
1
;
i
<
1000
;
i
++)
// var x = conn.Hashes.Increment(6, key, guid.ToString(), value).Result; // Kill Async
{
// }
var
guid
=
Guid
.
NewGuid
();
//#pragma warning disable 618
var
value
=
random
.
Next
(
Int32
.
MaxValue
);
// var inRedisRaw = conn.GetHash(6, key).Result;
//#pragma warning restore 618
shouldMatch
[
guid
]
=
value
;
// var inRedis = new Dictionary<Guid, int>();
var
x
=
conn
.
HashIncrementAsync
(
key
,
guid
.
ToString
(),
value
).
Result
;
// Kill Async
// for (var i = 0; i < inRedisRaw.Length; i += 2)
}
// {
#pragma warning disable 618
// var guid = inRedisRaw[i];
var
inRedis
=
conn
.
HashGetAllAsync
(
key
).
Result
.
ToDictionary
(
// var num = inRedisRaw[i + 1];
x
=>
Guid
.
Parse
(
x
.
Name
),
x
=>
int
.
Parse
(
x
.
Value
));
#pragma warning restore 618
// inRedis[Guid.Parse(Encoding.ASCII.GetString(guid))] = int.Parse(Encoding.ASCII.GetString(num));
// }
Assert
.
AreEqual
(
shouldMatch
.
Count
,
inRedis
.
Count
);
// Assert.AreEqual(shouldMatch.Count, inRedis.Count);
foreach
(
var
k
in
shouldMatch
.
Keys
)
{
// foreach (var k in shouldMatch.Keys)
Assert
.
AreEqual
(
shouldMatch
[
k
],
inRedis
[
k
]);
// {
}
// Assert.AreEqual(shouldMatch[k], inRedis[k]);
}
// }
}
// }
// }
[
Test
]
public
void
TestGet
()
// [Test]
{
// public void TestGet()
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
// {
{
// using (var conn = Config.GetUnsecuredConnection())
var
key
=
"hash test"
;
// {
var
conn
=
muxer
.
GetDatabase
(
6
);
// var key = "hash test";
var
shouldMatch
=
new
Dictionary
<
Guid
,
int
>();
var
random
=
new
Random
();
// var shouldMatch = new Dictionary<Guid, int>();
// var random = new Random();
for
(
int
i
=
1
;
i
<
1000
;
i
++)
{
// for (int i = 1; i < 1000; i++)
var
guid
=
Guid
.
NewGuid
();
// {
var
value
=
random
.
Next
(
Int32
.
MaxValue
);
// var guid = Guid.NewGuid();
// var value = random.Next(Int32.MaxValue);
shouldMatch
[
guid
]
=
value
;
// shouldMatch[guid] = value;
var
x
=
conn
.
HashIncrementAsync
(
key
,
guid
.
ToString
(),
value
).
Result
;
// Kill Async
}
// var x = conn.Hashes.Increment(6, key, guid.ToString(), value).Result; // Kill Async
// }
foreach
(
var
k
in
shouldMatch
.
Keys
)
{
// foreach (var k in shouldMatch.Keys)
var
inRedis
=
conn
.
HashGetAsync
(
key
,
k
.
ToString
()).
Result
;
// {
var
num
=
int
.
Parse
((
string
)
inRedis
);
// var inRedis = conn.Hashes.Get(6, key, k.ToString()).Result;
// var num = int.Parse(Encoding.ASCII.GetString(inRedis));
Assert
.
AreEqual
(
shouldMatch
[
k
],
num
);
}
// Assert.AreEqual(shouldMatch[k], num);
}
// }
}
// }
// }
[
Test
]
public
void
TestSet
()
// http://redis.io/commands/hset
// [Test]
{
// public void TestSet() // http://redis.io/commands/hset
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
// {
{
// using (var conn = Config.GetUnsecuredConnection())
var
conn
=
muxer
.
GetDatabase
(
9
);
// {
conn
.
KeyDeleteAsync
(
"hashkey"
);
// conn.Keys.Remove(9, "hashkey");
var
val0
=
conn
.
HashGetAsync
(
"hashkey"
,
"field"
);
// var val0 = conn.Hashes.GetString(9, "hashkey", "field");
var
set0
=
conn
.
HashSetAsync
(
"hashkey"
,
"field"
,
"value1"
);
// var set0 = conn.Hashes.Set(9, "hashkey", "field", "value1");
var
val1
=
conn
.
HashGetAsync
(
"hashkey"
,
"field"
);
// var val1 = conn.Hashes.GetString(9, "hashkey", "field");
var
set1
=
conn
.
HashSetAsync
(
"hashkey"
,
"field"
,
"value2"
);
// var set1 = conn.Hashes.Set(9, "hashkey", "field", "value2");
var
val2
=
conn
.
HashGetAsync
(
"hashkey"
,
"field"
);
// var val2 = conn.Hashes.GetString(9, "hashkey", "field");
var
set2
=
conn
.
HashSetAsync
(
"hashkey"
,
"field-blob"
,
Encoding
.
UTF8
.
GetBytes
(
"value3"
));
// var set2 = conn.Hashes.Set(9, "hashkey", "field-blob", Encoding.UTF8.GetBytes("value3"));
var
val3
=
conn
.
HashGetAsync
(
"hashkey"
,
"field-blob"
);
// var val3 = conn.Hashes.Get(9, "hashkey", "field-blob");
Assert
.
AreEqual
(
null
,
(
string
)
val0
.
Result
);
// Assert.AreEqual(null, val0.Result);
Assert
.
AreEqual
(
true
,
set0
.
Result
);
// Assert.AreEqual(true, set0.Result);
Assert
.
AreEqual
(
"value1"
,
(
string
)
val1
.
Result
);
// Assert.AreEqual("value1", val1.Result);
Assert
.
AreEqual
(
false
,
set1
.
Result
);
// Assert.AreEqual(false, set1.Result);
Assert
.
AreEqual
(
"value2"
,
(
string
)
val2
.
Result
);
// Assert.AreEqual("value2", val2.Result);
Assert
.
AreEqual
(
true
,
set2
.
Result
);
// Assert.AreEqual(true, set2.Result);
Assert
.
AreEqual
(
"value3"
,
(
string
)
val3
.
Result
);
// Assert.AreEqual("value3", Encoding.UTF8.GetString(val3.Result));
}
// }
}
// }
[
Test
]
// [Test]
public
void
TestSetNotExists
()
// http://redis.io/commands/hsetnx
// public void TestSetNotExists() // http://redis.io/commands/hsetnx
{
// {
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
// using (var conn = Config.GetUnsecuredConnection())
{
// {
var
conn
=
muxer
.
GetDatabase
(
9
);
// conn.Keys.Remove(9, "hashkey");
conn
.
KeyDeleteAsync
(
"hashkey"
);
// var val0 = conn.Hashes.GetString(9, "hashkey", "field");
var
val0
=
conn
.
HashGetAsync
(
"hashkey"
,
"field"
);
// var set0 = conn.Hashes.SetIfNotExists(9, "hashkey", "field", "value1");
var
set0
=
conn
.
HashSetAsync
(
"hashkey"
,
"field"
,
"value1"
,
When
.
NotExists
);
// var val1 = conn.Hashes.GetString(9, "hashkey", "field");
var
val1
=
conn
.
HashGetAsync
(
"hashkey"
,
"field"
);
// var set1 = conn.Hashes.SetIfNotExists(9, "hashkey", "field", "value2");
var
set1
=
conn
.
HashSetAsync
(
"hashkey"
,
"field"
,
"value2"
,
When
.
NotExists
);
// var val2 = conn.Hashes.GetString(9, "hashkey", "field");
var
val2
=
conn
.
HashGetAsync
(
"hashkey"
,
"field"
);
// var set2 = conn.Hashes.SetIfNotExists(9, "hashkey", "field-blob", Encoding.UTF8.GetBytes("value3"));
var
set2
=
conn
.
HashSetAsync
(
"hashkey"
,
"field-blob"
,
Encoding
.
UTF8
.
GetBytes
(
"value3"
),
When
.
NotExists
);
// var val3 = conn.Hashes.Get(9, "hashkey", "field-blob");
var
val3
=
conn
.
HashGetAsync
(
"hashkey"
,
"field-blob"
);
// var set3 = conn.Hashes.SetIfNotExists(9, "hashkey", "field-blob", Encoding.UTF8.GetBytes("value3"));
var
set3
=
conn
.
HashSetAsync
(
"hashkey"
,
"field-blob"
,
Encoding
.
UTF8
.
GetBytes
(
"value3"
),
When
.
NotExists
);
// Assert.AreEqual(null, val0.Result);
Assert
.
AreEqual
(
null
,
(
string
)
val0
.
Result
);
// Assert.AreEqual(true, set0.Result);
Assert
.
AreEqual
(
true
,
set0
.
Result
);
// Assert.AreEqual("value1", val1.Result);
Assert
.
AreEqual
(
"value1"
,
(
string
)
val1
.
Result
);
// Assert.AreEqual(false, set1.Result);
Assert
.
AreEqual
(
false
,
set1
.
Result
);
// Assert.AreEqual("value1", val2.Result);
Assert
.
AreEqual
(
"value1"
,
(
string
)
val2
.
Result
);
// Assert.AreEqual(true, set2.Result);
Assert
.
AreEqual
(
true
,
set2
.
Result
);
// Assert.AreEqual("value3", Encoding.UTF8.GetString(val3.Result));
Assert
.
AreEqual
(
"value3"
,
(
string
)
val3
.
Result
);
// Assert.AreEqual(false, set3.Result);
Assert
.
AreEqual
(
false
,
set3
.
Result
);
// }
}
// }
}
// [Test]
[
Test
]
// public void TestDelSingle() // http://redis.io/commands/hdel
public
void
TestDelSingle
()
// http://redis.io/commands/hdel
// {
{
// using (var conn = Config.GetUnsecuredConnection())
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
// {
{
var
conn
=
muxer
.
GetDatabase
(
9
);
// conn.Keys.Remove(9, "hashkey");
conn
.
KeyDeleteAsync
(
"hashkey"
);
// var del0 = conn.Hashes.Remove(9, "hashkey", "field");
var
del0
=
conn
.
HashDeleteAsync
(
"hashkey"
,
"field"
);
// conn.Hashes.Set(9, "hashkey", "field", "value");
conn
.
HashSetAsync
(
"hashkey"
,
"field"
,
"value"
);
// var del1 = conn.Hashes.Remove(9, "hashkey", "field");
var
del1
=
conn
.
HashDeleteAsync
(
"hashkey"
,
"field"
);
// var del2 = conn.Hashes.Remove(9, "hashkey", "field");
var
del2
=
conn
.
HashDeleteAsync
(
"hashkey"
,
"field"
);
// Assert.AreEqual(false, del0.Result);
Assert
.
AreEqual
(
false
,
del0
.
Result
);
// Assert.AreEqual(true, del1.Result);
Assert
.
AreEqual
(
true
,
del1
.
Result
);
// Assert.AreEqual(false, del2.Result);
Assert
.
AreEqual
(
false
,
del2
.
Result
);
// }
}
// }
}
// [Test]
[
Test
]
// public void TestDelMulti() // http://redis.io/commands/hdel
public
void
TestDelMulti
()
// http://redis.io/commands/hdel
// {
{
// using (var conn = Config.GetUnsecuredConnection())
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
// {
{
// conn.Hashes.Set(3, "TestDelMulti", "key1", "val1");
var
conn
=
muxer
.
GetDatabase
(
3
);
// conn.Hashes.Set(3, "TestDelMulti", "key2", "val2");
conn
.
HashSetAsync
(
"TestDelMulti"
,
"key1"
,
"val1"
);
// conn.Hashes.Set(3, "TestDelMulti", "key3", "val3");
conn
.
HashSetAsync
(
"TestDelMulti"
,
"key2"
,
"val2"
);
conn
.
HashSetAsync
(
"TestDelMulti"
,
"key3"
,
"val3"
);
// var s1 = conn.Hashes.Exists(3, "TestDelMulti", "key1");
// var s2 = conn.Hashes.Exists(3, "TestDelMulti", "key2");
var
s1
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key1"
);
// var s3 = conn.Hashes.Exists(3, "TestDelMulti", "key3");
var
s2
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key2"
);
var
s3
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key3"
);
// var removed = conn.Hashes.Remove(3, "TestDelMulti", new[] { "key1", "key3" });
var
removed
=
conn
.
HashDeleteAsync
(
"TestDelMulti"
,
new
RedisValue
[]
{
"key1"
,
"key3"
});
// var d1 = conn.Hashes.Exists(3, "TestDelMulti", "key1");
// var d2 = conn.Hashes.Exists(3, "TestDelMulti", "key2");
var
d1
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key1"
);
// var d3 = conn.Hashes.Exists(3, "TestDelMulti", "key3");
var
d2
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key2"
);
var
d3
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key3"
);
// Assert.IsTrue(conn.Wait(s1));
// Assert.IsTrue(conn.Wait(s2));
Assert
.
IsTrue
(
conn
.
Wait
(
s1
));
// Assert.IsTrue(conn.Wait(s3));
Assert
.
IsTrue
(
conn
.
Wait
(
s2
));
Assert
.
IsTrue
(
conn
.
Wait
(
s3
));
// Assert.AreEqual(2, conn.Wait(removed));
Assert
.
AreEqual
(
2
,
conn
.
Wait
(
removed
));
// Assert.IsFalse(conn.Wait(d1));
// Assert.IsTrue(conn.Wait(d2));
Assert
.
IsFalse
(
conn
.
Wait
(
d1
));
// Assert.IsFalse(conn.Wait(d3));
Assert
.
IsTrue
(
conn
.
Wait
(
d2
));
Assert
.
IsFalse
(
conn
.
Wait
(
d3
));
// var removeFinal = conn.Hashes.Remove(3, "TestDelMulti", new[] {"key2"});
var
removeFinal
=
conn
.
HashDeleteAsync
(
"TestDelMulti"
,
new
RedisValue
[]
{
"key2"
});
// Assert.AreEqual(0, conn.Wait(conn.Hashes.GetLength(3, "TestDelMulti")));
// Assert.AreEqual(1, conn.Wait(removeFinal));
Assert
.
AreEqual
(
0
,
conn
.
Wait
(
conn
.
HashLengthAsync
(
"TestDelMulti"
)));
// }
Assert
.
AreEqual
(
1
,
conn
.
Wait
(
removeFinal
));
// }
}
// [Test]
}
// public void TestDelMultiInsideTransaction() // http://redis.io/commands/hdel
// {
[
Test
]
// using (var outer = Config.GetUnsecuredConnection())
public
void
TestDelMultiInsideTransaction
()
// http://redis.io/commands/hdel
// {
{
// using (var conn = outer.CreateTransaction())
using
(
var
outer
=
Config
.
GetUnsecuredConnection
())
// {
{
// conn.Hashes.Set(3, "TestDelMulti", "key1", "val1");
// conn.Hashes.Set(3, "TestDelMulti", "key2", "val2");
var
conn
=
outer
.
GetDatabase
(
3
).
CreateTransaction
();
// conn.Hashes.Set(3, "TestDelMulti", "key3", "val3");
{
conn
.
HashSetAsync
(
"TestDelMulti"
,
"key1"
,
"val1"
);
// var s1 = conn.Hashes.Exists(3, "TestDelMulti", "key1");
conn
.
HashSetAsync
(
"TestDelMulti"
,
"key2"
,
"val2"
);
// var s2 = conn.Hashes.Exists(3, "TestDelMulti", "key2");
conn
.
HashSetAsync
(
"TestDelMulti"
,
"key3"
,
"val3"
);
// var s3 = conn.Hashes.Exists(3, "TestDelMulti", "key3");
var
s1
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key1"
);
// var removed = conn.Hashes.Remove(3, "TestDelMulti", new[] { "key1", "key3" });
var
s2
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key2"
);
var
s3
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key3"
);
// var d1 = conn.Hashes.Exists(3, "TestDelMulti", "key1");
// var d2 = conn.Hashes.Exists(3, "TestDelMulti", "key2");
var
removed
=
conn
.
HashDeleteAsync
(
"TestDelMulti"
,
new
RedisValue
[]
{
"key1"
,
"key3"
});
// var d3 = conn.Hashes.Exists(3, "TestDelMulti", "key3");
var
d1
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key1"
);
// conn.Execute();
var
d2
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key2"
);
var
d3
=
conn
.
HashExistsAsync
(
"TestDelMulti"
,
"key3"
);
// Assert.IsTrue(conn.Wait(s1));
// Assert.IsTrue(conn.Wait(s2));
conn
.
Execute
();
// Assert.IsTrue(conn.Wait(s3));
Assert
.
IsTrue
(
conn
.
Wait
(
s1
));
// Assert.AreEqual(2, conn.Wait(removed));
Assert
.
IsTrue
(
conn
.
Wait
(
s2
));
Assert
.
IsTrue
(
conn
.
Wait
(
s3
));
// Assert.IsFalse(conn.Wait(d1));
// Assert.IsTrue(conn.Wait(d2));
Assert
.
AreEqual
(
2
,
conn
.
Wait
(
removed
));
// Assert.IsFalse(conn.Wait(d3));
// }
Assert
.
IsFalse
(
conn
.
Wait
(
d1
));
Assert
.
IsTrue
(
conn
.
Wait
(
d2
));
// }
Assert
.
IsFalse
(
conn
.
Wait
(
d3
));
// }
}
// [Test]
// public void TestExists() // http://redis.io/commands/hexists
}
// {
}
// using (var conn = Config.GetUnsecuredConnection())
[
Test
]
// {
public
void
TestExists
()
// http://redis.io/commands/hexists
// conn.Keys.Remove(9, "hashkey");
{
// var ex0 = conn.Hashes.Exists(9, "hashkey", "field");
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
// conn.Hashes.Set(9, "hashkey", "field", "value");
{
// var ex1 = conn.Hashes.Exists(9, "hashkey", "field");
var
conn
=
muxer
.
GetDatabase
(
9
);
// conn.Hashes.Remove(9, "hashkey", "field");
conn
.
KeyDeleteAsync
(
"hashkey"
);
// var ex2 = conn.Hashes.Exists(9, "hashkey", "field");
var
ex0
=
conn
.
HashExistsAsync
(
"hashkey"
,
"field"
);
conn
.
HashSetAsync
(
"hashkey"
,
"field"
,
"value"
);
var
ex1
=
conn
.
HashExistsAsync
(
"hashkey"
,
"field"
);
conn
.
HashDeleteAsync
(
"hashkey"
,
"field"
);
var
ex2
=
conn
.
HashExistsAsync
(
"hashkey"
,
"field"
);
//
Assert.AreEqual(false, ex0.Result);
Assert
.
AreEqual
(
false
,
ex0
.
Result
);
//
Assert.AreEqual(true, ex1.Result);
Assert
.
AreEqual
(
true
,
ex1
.
Result
);
//
Assert.AreEqual(false, ex0.Result);
Assert
.
AreEqual
(
false
,
ex0
.
Result
);
//
}
}
//
}
}
// [Test]
[
Test
]
// public void TestHashKeys() // http://redis.io/commands/hkeys
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.Hashes.GetKeys(9, "hashkey");
var
keys0
=
conn
.
HashKeysAsync
(
"hashkey"
);
// conn.Hashes.Set(9, "hashkey", "foo", "abc");
// conn.Hashes.Set(9, "hashkey", "bar", "def");
// var keys1 = conn.Hashes.GetKeys(9, "hashkey");
// Assert.AreEqual(0, keys0.Result.Length);
// var arr = keys1.Result;
conn
.
HashSetAsync
(
"hashkey"
,
"foo"
,
"abc"
);
// Assert.AreEqual(2, arr.Length);
conn
.
HashSetAsync
(
"hashkey"
,
"bar"
,
"def"
);
// Assert.AreEqual("foo", arr[0]);
// Assert.AreEqual("bar", arr[1]);
// }
var
keys1
=
conn
.
HashKeysAsync
(
"hashkey"
);
// }
// [Test]
Assert
.
AreEqual
(
0
,
keys0
.
Result
.
Length
);
// public void TestHashValues() // http://redis.io/commands/hvals
// {
var
arr
=
keys1
.
Result
;
// using (var conn = Config.GetUnsecuredConnection())
Assert
.
AreEqual
(
2
,
arr
.
Length
);
// {
Assert
.
AreEqual
(
"foo"
,
(
string
)
arr
[
0
]);
// conn.Keys.Remove(9, "hashkey");
Assert
.
AreEqual
(
"bar"
,
(
string
)
arr
[
1
]);
// var keys0 = conn.Hashes.GetValues(9, "hashkey");
// conn.Hashes.Set(9, "hashkey", "foo", "abc");
// conn.Hashes.Set(9, "hashkey", "bar", "def");
// var keys1 = conn.Hashes.GetValues(9, "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 conn = Config.GetUnsecuredConnection())
// {
// conn.Keys.Remove(9, "hashkey");
// var len0 = conn.Hashes.GetLength(9, "hashkey");
}
}
// conn.Hashes.Set(9, "hashkey", "foo", "abc");
[
Test
]
// conn.Hashes.Set(9, "hashkey", "bar", "def");
public
void
TestHashValues
()
// http://redis.io/commands/hvals
{
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
{
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 len1 = conn.Hashes.GetLength(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
]);
// Assert.AreEqual(0, len0.Result);
Assert
.
AreEqual
(
3
,
arr2
.
Length
);
// Assert.AreEqual(2, len1.Result);
Assert
.
AreEqual
(
"abc"
,
(
string
)
arr2
[
0
]);
Assert
.
AreEqual
(
"def"
,
(
string
)
arr2
[
1
]);
Assert
.
IsNull
((
string
)
arr2
[
2
]);
}
}
// }
[
Test
]
// }
public
void
TestGetPairs
()
// http://redis.io/commands/hgetall
{
// [Test]
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
// public void TestGetMulti() // http://redis.io/commands/hmget
{
// {
var
conn
=
muxer
.
GetDatabase
(
9
);
// using (var conn = Config.GetUnsecuredConnection())
conn
.
KeyDeleteAsync
(
"hashkey"
);
// {
// conn.Keys.Remove(9, "hashkey");
var
result0
=
conn
.
HashGetAllAsync
(
"hashkey"
);
// string[] fields = { "foo", "bar", "blop" };
conn
.
HashSetAsync
(
"hashkey"
,
"foo"
,
"abc"
);
// var result0 = conn.Hashes.GetString(9, "hashkey", fields);
conn
.
HashSetAsync
(
"hashkey"
,
"bar"
,
"def"
);
// conn.Hashes.Set(9, "hashkey", "foo", "abc");
var
result1
=
conn
.
HashGetAllAsync
(
"hashkey"
);
// conn.Hashes.Set(9, "hashkey", "bar", "def");
Assert
.
AreEqual
(
0
,
result0
.
Result
.
Length
);
// var result1 = conn.Hashes.GetString(9, "hashkey", fields);
var
result
=
result1
.
Result
.
ToStringDictionary
();
Assert
.
AreEqual
(
2
,
result
.
Count
);
// var result2 = conn.Hashes.Get(9, "hashkey", fields);
Assert
.
AreEqual
(
"abc"
,
result
[
"foo"
]);
Assert
.
AreEqual
(
"def"
,
result
[
"bar"
]);
}
}
// var arr0 = result0.Result;
[
Test
]
// var arr1 = result1.Result;
public
void
TestSetPairs
()
// http://redis.io/commands/hmset
// var arr2 = result2.Result;
{
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
())
// Assert.AreEqual(3, arr0.Length);
{
// Assert.IsNull(arr0[0]);
var
conn
=
muxer
.
GetDatabase
(
9
);
// Assert.IsNull(arr0[1]);
conn
.
KeyDeleteAsync
(
"hashkey"
);
// Assert.IsNull(arr0[2]);
var
result0
=
conn
.
HashGetAllAsync
(
"hashkey"
);
// Assert.AreEqual(3, arr1.Length);
// Assert.AreEqual("abc", arr1[0]);
var
data
=
new
HashEntry
[]
{
// Assert.AreEqual("def", arr1[1]);
new
HashEntry
(
"foo"
,
Encoding
.
UTF8
.
GetBytes
(
"abc"
)),
// Assert.IsNull(arr1[2]);
new
HashEntry
(
"bar"
,
Encoding
.
UTF8
.
GetBytes
(
"def"
))
};
// Assert.AreEqual(3, arr2.Length);
conn
.
HashSetAsync
(
"hashkey"
,
data
);
// Assert.AreEqual("abc", Encoding.UTF8.GetString(arr2[0]));
// Assert.AreEqual("def", Encoding.UTF8.GetString(arr2[1]));
var
result1
=
conn
.
HashGetAllAsync
(
"hashkey"
);
// Assert.IsNull(arr2[2]);
// }
Assert
.
AreEqual
(
0
,
result0
.
Result
.
Length
);
// }
var
result
=
result1
.
Result
.
ToStringDictionary
();
Assert
.
AreEqual
(
2
,
result
.
Count
);
// [Test]
Assert
.
AreEqual
(
"abc"
,
result
[
"foo"
]);
// public void TestGetPairs() // http://redis.io/commands/hgetall
Assert
.
AreEqual
(
"def"
,
result
[
"bar"
]);
// {
}
// using (var conn = Config.GetUnsecuredConnection())
}
// {
// conn.Keys.Remove(9, "hashkey");
}
}
// var result0 = conn.Hashes.GetAll(9, "hashkey");
// conn.Hashes.Set(9, "hashkey", "foo", "abc");
// conn.Hashes.Set(9, "hashkey", "bar", "def");
// var result1 = conn.Hashes.GetAll(9, "hashkey");
// 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]
// public void TestSetPairs() // http://redis.io/commands/hmset
// {
// using (var conn = Config.GetUnsecuredConnection())
// {
// conn.Keys.Remove(9, "hashkey");
// var result0 = conn.Hashes.GetAll(9, "hashkey");
// var data = new Dictionary<string, byte[]> {
// {"foo", Encoding.UTF8.GetBytes("abc")},
// {"bar", Encoding.UTF8.GetBytes("def")}
// };
// conn.Hashes.Set(9, "hashkey", data);
// var result1 = conn.Hashes.GetAll(9, "hashkey");
// 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"]));
// }
// }
// }
//}
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