Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 31dc386

Browse files
committed
C# 7-ify
1 parent 06d615e commit 31dc386

File tree

4 files changed

+60
-106
lines changed

4 files changed

+60
-106
lines changed

src/ServiceStack.Redis/RedisClient.cs

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,7 @@ public RedisText Custom(params object[] cmdWithArgs)
122122

123123
public void SetValue(string key, string value)
124124
{
125-
var bytesValue = value != null
126-
? value.ToUtf8Bytes()
127-
: null;
128-
125+
var bytesValue = value?.ToUtf8Bytes();
129126
base.Set(key, bytesValue);
130127
}
131128

@@ -145,9 +142,7 @@ public bool SetValue(byte[] key, byte[] value, TimeSpan expireIn)
145142

146143
public void SetValue(string key, string value, TimeSpan expireIn)
147144
{
148-
var bytesValue = value != null
149-
? value.ToUtf8Bytes()
150-
: null;
145+
var bytesValue = value?.ToUtf8Bytes();
151146

152147
if (AssertServerVersionNumber() >= 2610)
153148
{
@@ -164,21 +159,19 @@ public void SetValue(string key, string value, TimeSpan expireIn)
164159

165160
public bool SetValueIfExists(string key, string value)
166161
{
167-
var bytesValue = value != null ? value.ToUtf8Bytes() : null;
168-
162+
var bytesValue = value?.ToUtf8Bytes();
169163
return base.Set(key, bytesValue, exists: true);
170164
}
171165

172166
public bool SetValueIfNotExists(string key, string value)
173167
{
174-
var bytesValue = value != null ? value.ToUtf8Bytes() : null;
175-
168+
var bytesValue = value?.ToUtf8Bytes();
176169
return base.Set(key, bytesValue, exists: false);
177170
}
178171

179172
public bool SetValueIfExists(string key, string value, TimeSpan expireIn)
180173
{
181-
var bytesValue = value != null ? value.ToUtf8Bytes() : null;
174+
var bytesValue = value?.ToUtf8Bytes();
182175

183176
if (expireIn.Milliseconds > 0)
184177
return base.Set(key, bytesValue, exists: true, expiryMs: (long)expireIn.TotalMilliseconds);
@@ -188,7 +181,7 @@ public bool SetValueIfExists(string key, string value, TimeSpan expireIn)
188181

189182
public bool SetValueIfNotExists(string key, string value, TimeSpan expireIn)
190183
{
191-
var bytesValue = value != null ? value.ToUtf8Bytes() : null;
184+
var bytesValue = value?.ToUtf8Bytes();
192185

193186
if (expireIn.Milliseconds > 0)
194187
return base.Set(key, bytesValue, exists: false, expiryMs: (long)expireIn.TotalMilliseconds);
@@ -245,9 +238,7 @@ public void SetAll(Dictionary<string, string> map)
245238
public string GetValue(string key)
246239
{
247240
var bytes = Get(key);
248-
return bytes == null
249-
? null
250-
: bytes.FromUtf8Bytes();
241+
return bytes?.FromUtf8Bytes();
251242
}
252243

253244
public string GetAndSetValue(string key, string value)
@@ -426,7 +417,7 @@ public List<string> SearchKeys(string pattern)
426417

427418
public List<string> GetValues(List<string> keys)
428419
{
429-
if (keys == null) throw new ArgumentNullException("keys");
420+
if (keys == null) throw new ArgumentNullException(nameof(keys));
430421
if (keys.Count == 0) return new List<string>();
431422

432423
var resultBytesArray = MGet(keys.ToArray());
@@ -445,7 +436,7 @@ public List<string> GetValues(List<string> keys)
445436

446437
public List<T> GetValues<T>(List<string> keys)
447438
{
448-
if (keys == null) throw new ArgumentNullException("keys");
439+
if (keys == null) throw new ArgumentNullException(nameof(keys));
449440
if (keys.Count == 0) return new List<T>();
450441

451442
var resultBytesArray = MGet(keys.ToArray());
@@ -465,7 +456,7 @@ public List<T> GetValues<T>(List<string> keys)
465456

466457
public Dictionary<string, string> GetValuesMap(List<string> keys)
467458
{
468-
if (keys == null) throw new ArgumentNullException("keys");
459+
if (keys == null) throw new ArgumentNullException(nameof(keys));
469460
if (keys.Count == 0) return new Dictionary<string, string>();
470461

471462
var keysArray = keys.ToArray();
@@ -493,7 +484,7 @@ public Dictionary<string, string> GetValuesMap(List<string> keys)
493484

494485
public Dictionary<string, T> GetValuesMap<T>(List<string> keys)
495486
{
496-
if (keys == null) throw new ArgumentNullException("keys");
487+
if (keys == null) throw new ArgumentNullException(nameof(keys));
497488
if (keys.Count == 0) return new Dictionary<string, T>();
498489

499490
var keysArray = keys.ToArray();
@@ -532,13 +523,11 @@ public long PublishMessage(string toChannel, string message)
532523

533524
#region IBasicPersistenceProvider
534525

535-
536526
Dictionary<string, HashSet<string>> registeredTypeIdsWithinPipelineMap = new Dictionary<string, HashSet<string>>();
537527

538528
internal HashSet<string> GetRegisteredTypeIdsWithinPipeline(string typeIdsSet)
539529
{
540-
HashSet<string> registeredTypeIdsWithinPipeline;
541-
if (!registeredTypeIdsWithinPipelineMap.TryGetValue(typeIdsSet, out registeredTypeIdsWithinPipeline))
530+
if (!registeredTypeIdsWithinPipelineMap.TryGetValue(typeIdsSet, out var registeredTypeIdsWithinPipeline))
542531
{
543532
registeredTypeIdsWithinPipeline = new HashSet<string>();
544533
registeredTypeIdsWithinPipelineMap[typeIdsSet] = registeredTypeIdsWithinPipeline;
@@ -664,7 +653,7 @@ public T Store<T>(T entity)
664653

665654
public object StoreObject(object entity)
666655
{
667-
if (entity == null) throw new ArgumentNullException("entity");
656+
if (entity == null) throw new ArgumentNullException(nameof(entity));
668657

669658
var id = entity.GetObjectId();
670659
var entityType = entity.GetType();
@@ -799,7 +788,7 @@ public RedisClient CloneClient()
799788
/// <returns></returns>
800789
public string UrnKey<T>(T value)
801790
{
802-
return String.Concat(NamespacePrefix, value.CreateUrn());
791+
return string.Concat(NamespacePrefix, value.CreateUrn());
803792
}
804793

805794
/// <summary>
@@ -809,7 +798,7 @@ public string UrnKey<T>(T value)
809798
/// <returns></returns>
810799
public string UrnKey<T>(object id)
811800
{
812-
return String.Concat(NamespacePrefix, IdUtils.CreateUrn<T>(id));
801+
return string.Concat(NamespacePrefix, IdUtils.CreateUrn<T>(id));
813802
}
814803

815804
/// <summary>
@@ -820,7 +809,7 @@ public string UrnKey<T>(object id)
820809
/// <returns></returns>
821810
public string UrnKey(Type type, object id)
822811
{
823-
return String.Concat(NamespacePrefix, IdUtils.CreateUrn(type, id));
812+
return string.Concat(NamespacePrefix, IdUtils.CreateUrn(type, id));
824813
}
825814

826815

@@ -833,8 +822,7 @@ public string UrnKey(Type type, object id)
833822

834823
public T ExecCachedLua<T>(string scriptBody, Func<string, T> scriptSha1)
835824
{
836-
string sha1;
837-
if (!CachedLuaSha1Map.TryGetValue(scriptBody, out sha1))
825+
if (!CachedLuaSha1Map.TryGetValue(scriptBody, out var sha1))
838826
CachedLuaSha1Map[scriptBody] = sha1 = LoadLuaScript(scriptBody);
839827

840828
try
@@ -1078,8 +1066,7 @@ public RedisServerRole GetServerRole()
10781066
return ToServerRole(roleName);
10791067
}
10801068

1081-
string role;
1082-
this.Info.TryGetValue("role", out role);
1069+
this.Info.TryGetValue("role", out var role);
10831070
return ToServerRole(role);
10841071
}
10851072

0 commit comments

Comments
 (0)