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
6c191d56
Commit
6c191d56
authored
Mar 27, 2014
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Booksleeve suite: Constraints; fix critical RedisValue == bug (comparing string to long)
parent
2c76086f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
44 deletions
+79
-44
Constraints.cs
MigratedBookSleeveTestSuite/Constraints.cs
+48
-42
RedisValue.cs
StackExchange.Redis/StackExchange/Redis/RedisValue.cs
+31
-2
No files found.
MigratedBookSleeveTestSuite/Constraints.cs
View file @
6c191d56
//using BookSleeve;
using
System.Threading.Tasks
;
//using NUnit.Framework;
using
NUnit.Framework
;
//using System;
using
StackExchange.Redis
;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;
//namespace Tests
namespace
Tests
//{
{
// [TestFixture]
[
TestFixture
]
// public class Constraints
public
class
Constraints
// {
{
// [Test]
[
Test
]
// public void TestManualIncr()
public
void
ValueEquals
()
// {
{
// using (var conn = Config.GetUnsecuredConnection(syncTimeout: 120000)) // big timeout while debugging
RedisValue
x
=
1
,
y
=
"1"
;
// {
Assert
.
IsTrue
(
x
.
Equals
(
y
),
"equals"
);
// for (int i = 0; i < 200; i++)
Assert
.
IsTrue
(
x
==
y
,
"operator"
);
// {
// conn.Keys.Remove(0, "foo");
// Assert.AreEqual(1, conn.Wait(ManualIncr(conn, 0, "foo")));
// Assert.AreEqual(2, conn.Wait(ManualIncr(conn, 0, "foo")));
// Assert.AreEqual(2, conn.Wait(conn.Strings.GetInt64(0, "foo")));
// }
// }
//
}
}
// public async Task<long?> ManualIncr(RedisConnection connection, int db, string key)
[
Test
]
// {
public
void
TestManualIncr
()
// var oldVal = await connection.Strings.GetInt64(db, key).SafeAwaitable();
{
// var newVal = (oldVal ?? 0) + 1;
using
(
var
muxer
=
Config
.
GetUnsecuredConnection
(
syncTimeout
:
120000
))
// big timeout while debugging
// using (var tran = connection.CreateTransaction())
{
// { // check hasn't changed
var
conn
=
muxer
.
GetDatabase
(
0
);
for
(
int
i
=
0
;
i
<
200
;
i
++)
{
conn
.
KeyDelete
(
"foo"
);
Assert
.
AreEqual
(
1
,
conn
.
Wait
(
ManualIncr
(
conn
,
"foo"
)));
Assert
.
AreEqual
(
2
,
conn
.
Wait
(
ManualIncr
(
conn
,
"foo"
)));
Assert
.
AreEqual
(
2
,
(
long
)
conn
.
StringGet
(
"foo"
));
}
}
//#pragma warning disable 4014
}
// tran.AddCondition(Condition.KeyEquals(db, key, oldVal));
// tran.Strings.Set(db, key, newVal);
public
async
Task
<
long
?>
ManualIncr
(
IDatabase
connection
,
string
key
)
//#pragma warning restore 4014
{
// if (!await tran.Execute().SafeAwaitable()) return null; // aborted
var
oldVal
=
(
long
?)
await
connection
.
StringGetAsync
(
key
);
// return newVal;
var
newVal
=
(
oldVal
??
0
)
+
1
;
// }
var
tran
=
connection
.
CreateTransaction
();
// }
{
// check hasn't changed
// }
//}
#pragma warning disable 4014
tran
.
AddCondition
(
Condition
.
StringEqual
(
key
,
oldVal
));
tran
.
StringSetAsync
(
key
,
newVal
);
#pragma warning restore 4014
if
(!
await
tran
.
ExecuteAsync
())
return
null
;
// aborted
return
newVal
;
}
}
}
}
StackExchange.Redis/StackExchange/Redis/RedisValue.cs
View file @
6c191d56
...
@@ -83,12 +83,12 @@ public bool IsNullOrEmpty
...
@@ -83,12 +83,12 @@ public bool IsNullOrEmpty
}
}
else
else
{
{
Equals
((
byte
[])
x
,
(
byte
[])
y
);
return
Equals
((
byte
[])
x
,
(
byte
[])
y
);
}
}
}
}
else
if
(
y
.
valueBlob
==
IntegerSentinel
)
else
if
(
y
.
valueBlob
==
IntegerSentinel
)
{
{
Equals
((
byte
[])
x
,
(
byte
[])
y
);
return
Equals
((
byte
[])
x
,
(
byte
[])
y
);
}
}
return
Equals
(
x
.
valueBlob
,
y
.
valueBlob
);
return
Equals
(
x
.
valueBlob
,
y
.
valueBlob
);
...
@@ -233,6 +233,13 @@ internal void AssertNotNull()
...
@@ -233,6 +233,13 @@ internal void AssertNotNull()
return
new
RedisValue
(
value
,
IntegerSentinel
);
return
new
RedisValue
(
value
,
IntegerSentinel
);
}
}
/// <summary>
/// <summary>
/// Creates a new RedisValue from a nullable Int32
/// </summary>
public
static
implicit
operator
RedisValue
(
int
?
value
)
{
return
value
==
null
?
@null
:
(
RedisValue
)
value
.
GetValueOrDefault
();
}
/// <summary>
/// Creates a new RedisValue from an Int64
/// Creates a new RedisValue from an Int64
/// </summary>
/// </summary>
public
static
implicit
operator
RedisValue
(
long
value
)
public
static
implicit
operator
RedisValue
(
long
value
)
...
@@ -240,12 +247,27 @@ internal void AssertNotNull()
...
@@ -240,12 +247,27 @@ internal void AssertNotNull()
return
new
RedisValue
(
value
,
IntegerSentinel
);
return
new
RedisValue
(
value
,
IntegerSentinel
);
}
}
/// <summary>
/// <summary>
/// Creates a new RedisValue from a nullable Int64
/// </summary>
public
static
implicit
operator
RedisValue
(
long
?
value
)
{
return
value
==
null
?
@null
:
(
RedisValue
)
value
.
GetValueOrDefault
();
}
/// <summary>
/// Creates a new RedisValue from a Double
/// Creates a new RedisValue from a Double
/// </summary>
/// </summary>
public
static
implicit
operator
RedisValue
(
double
value
)
public
static
implicit
operator
RedisValue
(
double
value
)
{
{
return
Format
.
ToString
(
value
);
return
Format
.
ToString
(
value
);
}
}
/// <summary>
/// Creates a new RedisValue from a nullable Double
/// </summary>
public
static
implicit
operator
RedisValue
(
double
?
value
)
{
return
value
==
null
?
@null
:
(
RedisValue
)
value
.
GetValueOrDefault
();
}
/// <summary>
/// <summary>
/// Creates a new RedisValue from a String
/// Creates a new RedisValue from a String
/// </summary>
/// </summary>
...
@@ -276,6 +298,13 @@ internal void AssertNotNull()
...
@@ -276,6 +298,13 @@ internal void AssertNotNull()
return
new
RedisValue
(
value
?
1
:
0
,
IntegerSentinel
);
return
new
RedisValue
(
value
?
1
:
0
,
IntegerSentinel
);
}
}
/// <summary>
/// <summary>
/// Creates a new RedisValue from a nullable Boolean
/// </summary>
public
static
implicit
operator
RedisValue
(
bool
?
value
)
{
return
value
==
null
?
@null
:
(
RedisValue
)
value
.
GetValueOrDefault
();
}
/// <summary>
/// Creates a new RedisValue from a Boolean
/// Creates a new RedisValue from a Boolean
/// </summary>
/// </summary>
public
static
explicit
operator
bool
(
RedisValue
value
)
public
static
explicit
operator
bool
(
RedisValue
value
)
...
...
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