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
86b98349
Commit
86b98349
authored
May 08, 2017
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new "NoScriptCache" command-flag; fix #617
parent
aa198df8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
93 deletions
+22
-93
Program.cs
BasicTest/Program.cs
+12
-90
CommandFlags.cs
StackExchange.Redis/StackExchange/Redis/CommandFlags.cs
+6
-1
Message.cs
StackExchange.Redis/StackExchange/Redis/Message.cs
+1
-1
RedisDatabase.cs
StackExchange.Redis/StackExchange/Redis/RedisDatabase.cs
+3
-1
No files found.
BasicTest/Program.cs
View file @
86b98349
using
System
;
using
StackExchange.Redis
;
using
System.Diagnostics
;
using
System.Reflection
;
using
System.Reflection
;
using
System.Runtime.CompilerServices
;
using
System.Runtime.CompilerServices
;
using
System.Threading
;
using
System
;
using
System.Threading.Tasks
;
using
StackExchange.Redis
;
using
System.IO
;
[
assembly
:
AssemblyVersion
(
"1.0.0"
)]
[
assembly
:
AssemblyVersion
(
"1.0.0"
)]
namespace
BasicTest
namespace
BasicTest
{
{
static
class
YourPreferredSerializer
{
public
static
T
Deserialize
<
T
>(
Stream
s
)
{
return
default
(
T
);
}
}
static
class
Program
static
class
Program
{
{
public
static
RedisValue
JsonGet
(
this
IDatabase
db
,
RedisKey
key
,
static
void
Main
()
string
path
=
"."
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
return
(
RedisValue
)
db
.
Execute
(
"JSON.GET"
,
new
object
[]
{
key
,
path
},
flags
);
}
public
static
T
JsonGet
<
T
>(
this
IDatabase
db
,
RedisKey
key
,
string
path
=
"."
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
byte
[]
bytes
=
(
byte
[])
db
.
Execute
(
"JSON.GET"
,
new
object
[]
{
key
,
path
},
flags
);
using
(
var
ms
=
new
MemoryStream
(
bytes
))
{
return
YourPreferredSerializer
.
Deserialize
<
T
>(
ms
);
}
}
static
void
Main
(
string
[]
args
)
{
{
using
(
var
conn
=
ConnectionMultiplexer
.
Connect
(
"127.0.0.1:6379"
))
using
(
var
conn
=
ConnectionMultiplexer
.
Connect
(
"127.0.0.1:6379"
))
{
{
var
db
=
conn
.
GetDatabase
();
var
db
=
conn
.
GetDatabase
();
// needs explicit RedisKey type for key-based
RedisKey
key
=
Me
();
// sharding to work; will still work with strings,
db
.
KeyDelete
(
key
);
// but no key-based sharding support
db
.
StringSet
(
key
,
"abc"
);
RedisKey
key
=
"some_key"
;
// note: if command renames are configured in
string
s
=
(
string
)
db
.
ScriptEvaluate
(
@"
// the API, they will still work automatically
local val = redis.call('get', KEYS[1])
db
.
Execute
(
"del"
,
key
);
redis.call('del', KEYS[1])
db
.
Execute
(
"set"
,
key
,
"12"
);
return val"
,
new
RedisKey
[]
{
key
},
flags
:
CommandFlags
.
NoScriptCache
);
db
.
Execute
(
"incrby"
,
key
,
4
);
int
i
=
(
int
)
db
.
Execute
(
"get"
,
key
);
Console
.
WriteLine
(
i
);
// 16;
Console
.
WriteLine
(
s
);
Console
.
WriteLine
(
db
.
KeyExists
(
key
));
}
}
//int AsyncOpsQty = 500000;
//if(args.Length == 1)
//{
// int tmp;
// if(int.TryParse(args[0], out tmp))
// AsyncOpsQty = tmp;
//}
//MassiveBulkOpsAsync(AsyncOpsQty, true, true);
//MassiveBulkOpsAsync(AsyncOpsQty, true, false);
//MassiveBulkOpsAsync(AsyncOpsQty, false, true);
//MassiveBulkOpsAsync(AsyncOpsQty, false, false);
}
}
static
void
MassiveBulkOpsAsync
(
int
AsyncOpsQty
,
bool
preserveOrder
,
bool
withContinuation
)
{
using
(
var
muxer
=
ConnectionMultiplexer
.
Connect
(
"localhost,resolvedns=1"
))
{
muxer
.
PreserveAsyncOrder
=
preserveOrder
;
RedisKey
key
=
"MBOA"
;
var
conn
=
muxer
.
GetDatabase
();
muxer
.
Wait
(
conn
.
PingAsync
());
#if CORE_CLR
int
number
=
0
;
#endif
Action
<
Task
>
nonTrivial
=
delegate
{
#if !CORE_CLR
Thread
.
SpinWait
(
5
);
#else
for
(
int
i
=
0
;
i
<
50
;
i
++)
{
number
++;
}
#endif
};
var
watch
=
Stopwatch
.
StartNew
();
for
(
int
i
=
0
;
i
<=
AsyncOpsQty
;
i
++)
{
var
t
=
conn
.
StringSetAsync
(
key
,
i
);
if
(
withContinuation
)
t
.
ContinueWith
(
nonTrivial
);
}
int
val
=
(
int
)
muxer
.
Wait
(
conn
.
StringGetAsync
(
key
));
watch
.
Stop
();
Console
.
WriteLine
(
"After {0}: {1}"
,
AsyncOpsQty
,
val
);
Console
.
WriteLine
(
"({3}, {4})\r\n{2}: Time for {0} ops: {1}ms; ops/s: {5}"
,
AsyncOpsQty
,
watch
.
ElapsedMilliseconds
,
Me
(),
withContinuation
?
"with continuation"
:
"no continuation"
,
preserveOrder
?
"preserve order"
:
"any order"
,
AsyncOpsQty
/
watch
.
Elapsed
.
TotalSeconds
);
}
}
internal
static
string
Me
([
CallerMemberName
]
string
caller
=
null
)
internal
static
string
Me
([
CallerMemberName
]
string
caller
=
null
)
{
{
return
caller
;
return
caller
;
...
...
StackExchange.Redis/StackExchange/Redis/CommandFlags.cs
View file @
86b98349
...
@@ -56,6 +56,11 @@ public enum CommandFlags
...
@@ -56,6 +56,11 @@ public enum CommandFlags
// 128: used for "internal call"; never user-specified, so not visible on the public API
// 128: used for "internal call"; never user-specified, so not visible on the public API
// 256: used for "retry"; never user-specified, so not visible on the public API
// 256: used for "script unavailable"; never user-specified, so not visible on the public API
/// <summary>
/// Indicates that script-related operations should use EVAL, not SCRIPT LOAD + EVALSHA
/// </summary>
NoScriptCache
=
512
,
}
}
}
}
StackExchange.Redis/StackExchange/Redis/Message.cs
View file @
86b98349
...
@@ -200,7 +200,7 @@ abstract class Message : ICompletable
...
@@ -200,7 +200,7 @@ abstract class Message : ICompletable
private
const
CommandFlags
UserSelectableFlags
private
const
CommandFlags
UserSelectableFlags
=
CommandFlags
.
None
|
CommandFlags
.
DemandMaster
|
CommandFlags
.
DemandSlave
=
CommandFlags
.
None
|
CommandFlags
.
DemandMaster
|
CommandFlags
.
DemandSlave
|
CommandFlags
.
PreferMaster
|
CommandFlags
.
PreferSlave
|
CommandFlags
.
PreferMaster
|
CommandFlags
.
PreferSlave
|
CommandFlags
.
HighPriority
|
CommandFlags
.
FireAndForget
|
CommandFlags
.
NoRedirect
;
|
CommandFlags
.
HighPriority
|
CommandFlags
.
FireAndForget
|
CommandFlags
.
NoRedirect
|
CommandFlags
.
NoScriptCache
;
private
CommandFlags
flags
;
private
CommandFlags
flags
;
internal
CommandFlags
FlagsRaw
{
get
{
return
flags
;
}
set
{
flags
=
value
;
}
}
internal
CommandFlags
FlagsRaw
{
get
{
return
flags
;
}
set
{
flags
=
value
;
}
}
...
...
StackExchange.Redis/StackExchange/Redis/RedisDatabase.cs
View file @
86b98349
...
@@ -2530,8 +2530,10 @@ public override int GetHashSlot(ServerSelectionStrategy serverSelectionStrategy)
...
@@ -2530,8 +2530,10 @@ public override int GetHashSlot(ServerSelectionStrategy serverSelectionStrategy)
public
IEnumerable
<
Message
>
GetMessages
(
PhysicalConnection
connection
)
public
IEnumerable
<
Message
>
GetMessages
(
PhysicalConnection
connection
)
{
{
if
(
script
!=
null
&&
connection
.
Multiplexer
.
CommandMap
.
IsAvailable
(
RedisCommand
.
SCRIPT
))
// a script was provided (rather than a hash); check it is known and supported
if
(
script
!=
null
&&
connection
.
Multiplexer
.
CommandMap
.
IsAvailable
(
RedisCommand
.
SCRIPT
)
&&
(
Flags
&
CommandFlags
.
NoScriptCache
)
==
0
)
{
{
// a script was provided (rather than a hash); check it is known and supported
asciiHash
=
connection
.
Bridge
.
ServerEndPoint
.
GetScriptHash
(
script
,
command
);
asciiHash
=
connection
.
Bridge
.
ServerEndPoint
.
GetScriptHash
(
script
,
command
);
if
(
asciiHash
==
null
)
if
(
asciiHash
==
null
)
...
...
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