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
d6681264
Commit
d6681264
authored
Mar 11, 2018
by
Nick Craver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup: RedisServer
parent
a6ef7169
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
24 deletions
+23
-24
RedisServer.cs
StackExchange.Redis/StackExchange/Redis/RedisServer.cs
+23
-24
No files found.
StackExchange.Redis/StackExchange/Redis/RedisServer.cs
View file @
d6681264
...
...
@@ -9,15 +9,13 @@
namespace
StackExchange.Redis
{
internal
sealed
partial
class
RedisServer
:
RedisBase
,
IServer
{
private
readonly
ServerEndPoint
server
;
internal
RedisServer
(
ConnectionMultiplexer
multiplexer
,
ServerEndPoint
server
,
object
asyncState
)
:
base
(
multiplexer
,
asyncState
)
{
if
(
server
==
null
)
throw
new
ArgumentNullException
(
nameof
(
server
));
this
.
server
=
server
;
this
.
server
=
server
??
throw
new
ArgumentNullException
(
nameof
(
server
));
}
public
ClusterConfiguration
ClusterConfiguration
=>
server
.
ClusterConfiguration
;
...
...
@@ -32,8 +30,8 @@ internal RedisServer(ConnectionMultiplexer multiplexer, ServerEndPoint server, o
public
bool
AllowSlaveWrites
{
get
{
return
server
.
AllowSlaveWrites
;
}
set
{
server
.
AllowSlaveWrites
=
value
;
}
get
=>
server
.
AllowSlaveWrites
;
set
=>
server
.
AllowSlaveWrites
=
value
;
}
public
ServerType
ServerType
=>
server
.
ServerType
;
...
...
@@ -63,9 +61,10 @@ public Task<long> ClientKillAsync(long? id = null, ClientType? clientType = null
var
msg
=
GetClientKillMessage
(
endpoint
,
id
,
clientType
,
skipMe
,
flags
);
return
ExecuteAsync
(
msg
,
ResultProcessor
.
Int64
);
}
Message
GetClientKillMessage
(
EndPoint
endpoint
,
long
?
id
,
ClientType
?
clientType
,
bool
skipMe
,
CommandFlags
flags
)
private
Message
GetClientKillMessage
(
EndPoint
endpoint
,
long
?
id
,
ClientType
?
clientType
,
bool
skipMe
,
CommandFlags
flags
)
{
List
<
RedisValue
>
parts
=
new
List
<
RedisValue
>(
9
)
var
parts
=
new
List
<
RedisValue
>(
9
)
{
RedisLiterals
.
KILL
};
...
...
@@ -194,6 +193,7 @@ public Task ConfigSetAsync(RedisValue setting, RedisValue value, CommandFlags fl
ExecuteSync
(
Message
.
Create
(-
1
,
flags
|
CommandFlags
.
FireAndForget
,
RedisCommand
.
CONFIG
,
RedisLiterals
.
GET
,
setting
),
ResultProcessor
.
AutoConfigure
);
return
task
;
}
public
long
DatabaseSize
(
int
database
=
0
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
msg
=
Message
.
Create
(
database
,
flags
,
RedisCommand
.
DBSIZE
);
...
...
@@ -211,6 +211,7 @@ public RedisValue Echo(RedisValue message, CommandFlags flags)
var
msg
=
Message
.
Create
(-
1
,
flags
,
RedisCommand
.
ECHO
,
message
);
return
ExecuteSync
(
msg
,
ResultProcessor
.
RedisValue
);
}
public
Task
<
RedisValue
>
EchoAsync
(
RedisValue
message
,
CommandFlags
flags
)
{
var
msg
=
Message
.
Create
(-
1
,
flags
,
RedisCommand
.
ECHO
,
message
);
...
...
@@ -222,6 +223,7 @@ public void FlushAllDatabases(CommandFlags flags = CommandFlags.None)
var
msg
=
Message
.
Create
(-
1
,
flags
,
RedisCommand
.
FLUSHALL
);
ExecuteSync
(
msg
,
ResultProcessor
.
DemandOK
);
}
public
Task
FlushAllDatabasesAsync
(
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
msg
=
Message
.
Create
(-
1
,
flags
,
RedisCommand
.
FLUSHALL
);
...
...
@@ -240,10 +242,7 @@ public Task FlushDatabaseAsync(int database = 0, CommandFlags flags = CommandFla
return
ExecuteAsync
(
msg
,
ResultProcessor
.
DemandOK
);
}
public
ServerCounters
GetCounters
()
{
return
server
.
GetCounters
();
}
public
ServerCounters
GetCounters
()
=>
server
.
GetCounters
();
public
IGrouping
<
string
,
KeyValuePair
<
string
,
string
>>[]
Info
(
RedisValue
section
=
default
(
RedisValue
),
CommandFlags
flags
=
CommandFlags
.
None
)
{
...
...
@@ -319,6 +318,7 @@ public void MakeMaster(ReplicationChangeOptions options, TextWriter log = null)
{
multiplexer
.
MakeMaster
(
server
,
options
,
log
);
}
public
void
Save
(
SaveType
type
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
var
msg
=
GetSaveMessage
(
type
,
flags
);
...
...
@@ -527,9 +527,7 @@ internal static Message CreateSlaveOfMessage(EndPoint endpoint, CommandFlags fla
}
else
{
string
hostRaw
;
int
portRaw
;
if
(
Format
.
TryGetHostPort
(
endpoint
,
out
hostRaw
,
out
portRaw
))
if
(
Format
.
TryGetHostPort
(
endpoint
,
out
string
hostRaw
,
out
int
portRaw
))
{
host
=
hostRaw
;
port
=
portRaw
;
...
...
@@ -588,11 +586,10 @@ public void SlaveOf(EndPoint master, CommandFlags flags = CommandFlags.None)
var
configuration
=
this
.
multiplexer
.
RawConfig
;
// attempt to cease having an opinion on the master; will resume that when replication completes
// (note that this may fail; we aren't depending on it)
if
(!
string
.
IsNullOrWhiteSpace
(
configuration
.
TieBreaker
)
&&
this
.
multiplexer
.
CommandMap
.
IsAvailable
(
RedisCommand
.
DEL
))
&&
multiplexer
.
CommandMap
.
IsAvailable
(
RedisCommand
.
DEL
))
{
var
del
=
Message
.
Create
(
0
,
CommandFlags
.
FireAndForget
|
CommandFlags
.
NoRedirect
,
RedisCommand
.
DEL
,
(
RedisKey
)
configuration
.
TieBreaker
);
del
.
SetInternalCall
();
...
...
@@ -601,8 +598,8 @@ public void SlaveOf(EndPoint master, CommandFlags flags = CommandFlags.None)
ExecuteSync
(
slaveofMsg
,
ResultProcessor
.
DemandOK
);
// attempt to broadcast a reconfigure message to anybody listening to this server
var
channel
=
this
.
multiplexer
.
ConfigurationChangedChannel
;
if
(
channel
!=
null
&&
this
.
multiplexer
.
CommandMap
.
IsAvailable
(
RedisCommand
.
PUBLISH
))
var
channel
=
multiplexer
.
ConfigurationChangedChannel
;
if
(
channel
!=
null
&&
multiplexer
.
CommandMap
.
IsAvailable
(
RedisCommand
.
PUBLISH
))
{
var
pub
=
Message
.
Create
(-
1
,
CommandFlags
.
FireAndForget
|
CommandFlags
.
NoRedirect
,
RedisCommand
.
PUBLISH
,
(
RedisValue
)
channel
,
RedisLiterals
.
Wildcard
);
pub
.
SetInternalCall
();
...
...
@@ -636,7 +633,7 @@ private void FixFlags(Message message, ServerEndPoint server)
}
}
Message
GetSaveMessage
(
SaveType
type
,
CommandFlags
flags
=
CommandFlags
.
None
)
private
Message
GetSaveMessage
(
SaveType
type
,
CommandFlags
flags
=
CommandFlags
.
None
)
{
switch
(
type
)
{
...
...
@@ -649,7 +646,7 @@ Message GetSaveMessage(SaveType type, CommandFlags flags = CommandFlags.None)
}
}
ResultProcessor
<
bool
>
GetSaveResultProcessor
(
SaveType
type
)
private
ResultProcessor
<
bool
>
GetSaveResultProcessor
(
SaveType
type
)
{
switch
(
type
)
{
...
...
@@ -662,15 +659,15 @@ ResultProcessor<bool> GetSaveResultProcessor(SaveType type)
}
}
static
class
ScriptHash
private
static
class
ScriptHash
{
static
readonly
byte
[]
hex
=
{
private
static
readonly
byte
[]
hex
=
{
(
byte
)
'0'
,
(
byte
)
'1'
,
(
byte
)
'2'
,
(
byte
)
'3'
,
(
byte
)
'4'
,
(
byte
)
'5'
,
(
byte
)
'6'
,
(
byte
)
'7'
,
(
byte
)
'8'
,
(
byte
)
'9'
,
(
byte
)
'a'
,
(
byte
)
'b'
,
(
byte
)
'c'
,
(
byte
)
'd'
,
(
byte
)
'e'
,
(
byte
)
'f'
};
public
static
RedisValue
Encode
(
byte
[]
value
)
{
if
(
value
==
null
)
return
default
(
RedisValue
);
byte
[]
result
=
new
byte
[
value
.
Length
*
2
];
var
result
=
new
byte
[
value
.
Length
*
2
];
int
offset
=
0
;
for
(
int
i
=
0
;
i
<
value
.
Length
;
i
++)
{
...
...
@@ -680,6 +677,7 @@ public static RedisValue Encode(byte[] value)
}
return
result
;
}
public
static
RedisValue
Hash
(
string
value
)
{
if
(
value
==
null
)
return
default
(
RedisValue
);
...
...
@@ -691,7 +689,7 @@ public static RedisValue Hash(string value)
}
}
sealed
class
KeysScanEnumerable
:
CursorEnumerable
<
RedisKey
>
private
sealed
class
KeysScanEnumerable
:
CursorEnumerable
<
RedisKey
>
{
private
readonly
RedisValue
pattern
;
...
...
@@ -726,6 +724,7 @@ protected override Message CreateMessage(long cursor)
}
}
}
protected
override
ResultProcessor
<
ScanResult
>
Processor
=>
processor
;
public
static
readonly
ResultProcessor
<
ScanResult
>
processor
=
new
KeysResultProcessor
();
...
...
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