Skip to content

Commit

Permalink
[redisClient] some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
exilon committed Jul 14, 2020
1 parent 33f5db7 commit c187255
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Quick.Data.Redis.pas
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
interface

uses
{$IFDEF DEBUG_REDIS}
Quick.Debug.Utils,
{$ENDIF}
System.SysUtils,
System.DateUtils,
IdTCPClient,
Expand Down Expand Up @@ -83,7 +86,6 @@ TRedisClient = class
function Command(const aCommand : string; const aArguments : string = '') : IRedisResponse; overload;
function Command(const aCommand, aArgumentsFormat : string; aValues : array of const) : IRedisResponse; overload;
function EscapeString(const json: string) : string;
function IsIntegerResult(const aValue : string) : Boolean;
public
constructor Create;
destructor Destroy; override;
Expand Down Expand Up @@ -228,11 +230,6 @@ procedure TRedisClient.Connect;
end;
end;

function TRedisClient.IsIntegerResult(const aValue: string): Boolean;
begin
Result := IsInteger(StringReplace(aValue,':','',[]));
end;

function TRedisClient.EscapeString(const json: string): string;
begin
Result := StringReplace(json,'\','\\',[rfReplaceAll]);
Expand Down Expand Up @@ -278,7 +275,9 @@ function TRedisclient.Command(const aCommand : string; const aArguments : string
if fTCPClient.IOHandler.CheckForDataOnSource(fReadTimeout) then
begin
res := fTCPClient.IOHandler.ReadLn;

{$IFDEF DEBUG_REDIS}
TDebugger.Trace(Self,Format('Command "%s"',[res]));
{$ENDIF}
if not res.IsEmpty then
case res[Low(res)] of
'+' :
Expand Down Expand Up @@ -349,20 +348,23 @@ function TRedisClient.RedisBRPOP(const aKey: string; out oValue: string; aWaitTi
response := Command('BRPOP','%s %d',[aKey,aWaitTimeoutSecs]);
if response.IsDone then
begin
//if response.Response = '-1' then Exit;
fTCPClient.IOHandler.ReadLn; //$int
fTCPClient.IOHandler.ReadLn; //key
fTCPClient.IOHandler.ReadLn; //$int
oValue := fTCPClient.IOHandler.ReadLn; //value
Result := True;
end
else raise ERedisCommandError.CreateFmt('BLPOP Error: %s',[response.Response]);
else
begin
if not response.Response.IsEmpty then ERedisCommandError.CreateFmt('BRPOP Error: %s',[response.Response]);
end;
end;

function TRedisClient.RedisBRPOPLPUSH(const aKey, aKeyToMove: string; out oValue: string; aWaitTimeoutSecs: Integer): Boolean;
var
response : IRedisResponse;
begin
Result := False;
response := Command('BRPOPLPUSH','%s %s %d',[aKey,aKeyToMove,aWaitTimeoutSecs]);
if response.IsDone then
begin
Expand Down Expand Up @@ -416,9 +418,7 @@ function TRedisClient.RedisZADD(const aKey, aValue: string; aScore: Int64): Bool
function TRedisClient.RedisZRANGE(const aKey: string; aStartPosition, aEndPosition: Int64): TArray<string>;
var
response : IRedisResponse;
item : TRedisSortedItem;
value : string;
score : string;
i : Integer;
begin
Result := [];
Expand Down Expand Up @@ -465,6 +465,7 @@ function TRedisClient.RedisZREM(const aKey, aValue: string): Boolean;
var
response : IRedisResponse;
begin
Result := False;
response := Command('ZREM','%s "%s"',[aKey,EscapeString(aValue)]);
if response.IsDone then
begin
Expand All @@ -486,7 +487,6 @@ function TRedisClient.RedisBLPOP(const aKey: string; out oValue: string; aWaitTi
var
response : IRedisResponse;
begin
Result := False;
response := Command('BLPOP','%s %d',[aKey,aWaitTimeoutSecs]);
if response.IsDone then
begin
Expand Down

0 comments on commit c187255

Please sign in to comment.