delphiredisclient - Redis client for Delphi

Delphi Redis Client版本2(此分支)与Delphi 10.1 Berlin兼容,更好。警告!如果您使用较旧的Delphi版本,则必须使用适用于Delphi 10 Seattle,XE8,XE7,XE6和XE5的Delphi Redis Client版本1(也适用于旧版本)。

Delphi REDIS客户端从第一个版本(或左右)开始在移动设备上运行,自从Delphi 10.2东京它也在Linux上工作(测试Ubuntu 16.x LTS)。

Delphi Redis Client能够发送所有Redis命令并使用内部解析器读取响应。此外,许多流行的命令具有专门的专用方法,这简化了利用率。

这是用于连接,发送命令和管理Redis服务器的Redis客户端界面。许多方法都是1-1映射到具有相同名称的Redis命令(例如,SET是Redis SET命令的映射)。计划实现某种集成设计模式的高级方法(例如,推送JSONObject,弹出流等)。

https://github.com/danieleteti/delphiredisclient

IRedisClient = interface
['{566C20FF-7D9F-4DAC-9B0E-A8AA7D29B0B4}']
function &SET(const AKey, AValue: string): boolean; overload;
function &SET(const AKey, AValue: TBytes): boolean; overload;
function &SET(const AKey: string; AValue: TBytes): boolean; overload;
function &SET(const AKey: string; AValue: TBytes; ASecsExpire: UInt64): boolean; overload;
function &SET(const AKey: string; AValue: string; ASecsExpire: UInt64): boolean; overload;
function SETNX(const AKey, AValue: string): boolean; overload;
function SETNX(const AKey, AValue: TBytes): boolean; overload;
function GET(const AKey: string; out AValue: string): boolean; overload;
function GET(const AKey: TBytes; out AValue: TBytes): boolean; overload;
function GET(const AKey: string; out AValue: TBytes): boolean; overload;
function DEL(const AKeys: array of string): Integer;
function TTL(const AKey: string): Integer;
function EXISTS(const AKey: string): boolean;
function MSET(const AKeysValues: array of string): boolean;
function KEYS(const AKeyPattern: string): TArray<string>;
function INCR(const AKey: string): NativeInt;
function DECR(const AKey: string): NativeInt;
function EXPIRE(const AKey: string; AExpireInSecond: UInt32): boolean; // strings functions
function APPEND(const AKey, AValue: TBytes): UInt64; overload;
function APPEND(const AKey, AValue: string): UInt64; overload;
function STRLEN(const AKey: string): UInt64;
function GETRANGE(const AKey: string; const AStart, AEnd: NativeInt): string;
function SETRANGE(const AKey: string; const AOffset: NativeInt; const AValue: string)
: NativeInt; // hash
function HSET(const AKey, aField: string; AValue: string): Integer; overload;
procedure HMSET(const AKey: string; aFields: TArray<string>; AValues: TArray<string>);
function HMGET(const AKey: string; aFields: TArray<string>): TArray<string>;
function HSET(const AKey, aField: string; AValue: TBytes): Integer; overload;
function HGET(const AKey, aField: string; out AValue: TBytes): boolean; overload;
function HGET(const AKey, aField: string; out AValue: string): boolean; overload;
function HDEL(const AKey: string; aFields: TArray<string>): Integer; // lists
function RPUSH(const AListKey: string; AValues: array of string): Integer;
function RPUSHX(const AListKey: string; AValues: array of string): Integer;
function RPOP(const AListKey: string; var Value: string): boolean;
function LPUSH(const AListKey: string; AValues: array of string): Integer;
function LPUSHX(const AListKey: string; AValues: array of string): Integer;
function LPOP(const AListKey: string; out Value: string): boolean;
function LLEN(const AListKey: string): Integer;
procedure LTRIM(const AListKey: string; const AIndexStart, AIndexStop: Integer);
function LRANGE(const AListKey: string; IndexStart, IndexStop: Integer)
: TArray<string>;
function RPOPLPUSH(const ARightListKey, ALeftListKey: string;
var APoppedAndPushedElement: string): boolean; overload;
function BRPOPLPUSH(const ARightListKey, ALeftListKey: string;
var APoppedAndPushedElement: string; ATimeout: Int32): boolean; overload;
function BLPOP(const AKeys: array of string; const ATimeout: Int32;
out Value: TArray<string>): boolean;
function BRPOP(const AKeys: array of string; const ATimeout: Int32;
out Value: TArray<string>): boolean;
function LREM(const AListKey: string; const ACount: Integer;
const AValue: string): Integer; // sets
function SADD(const AKey, AValue: TBytes): Integer; overload;
function SADD(const AKey, AValue: string): Integer; overload;
function SREM(const AKey, AValue: TBytes): Integer; overload;
function SREM(const AKey, AValue: string): Integer; overload;
function SMEMBERS(const AKey: string): TArray<string>;
function SCARD(const AKey: string): Integer; // ordered sets
function ZADD(const AKey: string; const AScore: Int64; const AMember: string): Integer;
function ZREM(const AKey: string; const AMember: string): Integer;
function ZCARD(const AKey: string): Integer;
function ZCOUNT(const AKey: string; const AMin, AMax: Int64): Integer;
function ZRANK(const AKey: string; const AMember: string; out ARank: Int64): boolean;
function ZRANGE(const AKey: string; const AStart, AStop: Int64): TArray<string>;
function ZRANGEWithScore(const AKey: string; const AStart, AStop: Int64): TArray<string>;
function ZINCRBY(const AKey: string; const AIncrement: Int64; const AMember: string): string; // lua scripts
function EVAL(const AScript: string; AKeys: array of string; AValues: array of string): Integer; // system
procedure FLUSHDB;
procedure SELECT(const ADBIndex: Integer);
procedure AUTH(const aPassword: string); // raw execute
function ExecuteAndGetArray(const RedisCommand: IRedisCommand)
: TArray<string>;
function ExecuteWithIntegerResult(const RedisCommand: string)
: TArray<string>; overload;
function ExecuteWithIntegerResult(const RedisCommand: IRedisCommand)
: Int64; overload;
function ExecuteWithStringResult(const RedisCommand: IRedisCommand): string; // pubsub
procedure SUBSCRIBE(const AChannels: array of string;
ACallback: TProc<string, string>;
ATimeoutCallback: TRedisTimeoutCallback = nil);
function PUBLISH(const AChannel: string; AMessage: string): Integer; // transactions
function MULTI(ARedisTansactionProc: TRedisTransactionProc): TArray<string>; overload;
procedure MULTI; overload;
function EXEC: TArray<string>;
procedure WATCH(const AKeys: array of string); procedure DISCARD;
// non sys
function Tokenize(const ARedisCommand: string): TArray<string>;
procedure Disconnect;
function InTransaction: boolean;
// client
procedure ClientSetName(const ClientName: string);
procedure SetCommandTimeout(const Timeout: Int32);
function Clone: IRedisClient;
end;

Delphi Redis Client is not tied to a specific TCP/IP library. Currently it uses INDY but you can implement the IRedisNetLibAdapter and wrap whatever library you like.

  IRedisNetLibAdapter = interface
['{2DB21166-2E68-4DC4-9870-5DCCAAE877A3}']
procedure Connect(const HostName: string; const Port: Word);
procedure Send(const Value: string);
procedure Write(const Bytes: TBytes);
procedure WriteCrLf(const Bytes: TBytes);
procedure SendCmd(const Values: IRedisCommand);
function Receive(const Timeout: Int32): string;
function ReceiveBytes(const ACount: Int64; const Timeout: Int32): System.TArray<System.Byte>;
procedure Disconnect;
function LastReadWasTimedOut: boolean;
end;

This is a simple demo showing the utilization pattern (using the builtin INDY library support).

program CmdsSample1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
System.SysUtils,
Redis.Commons, // Interfaces and types
Redis.Client, // The client itself
Redis.NetLib.INDY, // The tcp library used
Redis.Values; // nullable types for redis commands var
lRedis: IRedisClient;
lValue: TRedisString; begin
try
lRedis := TRedisClient.Create;
lRedis.Connect;
lRedis.&SET('firstname', 'Daniele');
lValue := lRedis.GET('firstname');
if not lValue.IsNull then
WriteLn('KEY FOUND! key "firstname" => ', lValue.Value);
WriteLn('DEL firstname');
lRedis.DEL(['firstname']); // remove the key
lValue := lRedis.GET('firstname');
if lValue.IsNull then
WriteLn('Key "firstname" doesn''t exist (it''s correct!)')
else
WriteLn(lValue.Value); // never printed except
on E: Exception do
WriteLn(E.ClassName, ': ', E.Message);
end;
readln; //just to keep the command prompt open end.

delphiredisclient开源GIT的更多相关文章

  1. 个人开源Git地址

    开源Git地址 序号 Git地址 描述 1 https://github.com/winds-june 各种源码.直接调用的jar包          2    

  2. 开源Git代码托管平台

    开源Git代码托管平台主要参考有以下4个: 1.GitHub 很多开源项目都来自GitHub,但是GitHub只能新建公开的Git仓库,私有 仓库要收费.GitHub地址:https://github ...

  3. 开源GIT仓库-----gitlab

    简介:GitLab是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目.它拥有与Github类似的功能,能够浏览源代码 ...

  4. [js开源组件开发]js手机联动选择地区仿ios 开源git

    js手机联动选择地区 前言:由于网上找到了一个mobiscrool,比较全,但是不开源,只能试用15天,正式版竟然要三千块钱,穷人只能自己动手,写了个只针对弹窗地区选择的. 本站点所有的资源均在git ...

  5. 提交到开源git时出现:fatal: refusing to merge unrelated histories的解决办法

    解决办法   创建本地库和fetch远程分支这些前面的步骤这里略过.可以自行百度. 解决办法: 1.cmd进入项目的根目录. 2.执行下面的命令:git pull origin master --al ...

  6. android studio提交到开源git时出现:fatal: refusing to merge unrelated histories的解决办法

    创建本地库和fetch远程分支这些前面的步骤这里略过.可以自行百度. 解决办法: 1.cmd进入项目的根目录. 2.执行下面的命令:git pull origin master --allow-unr ...

  7. 开源GIT仓库-----gogs

    简介:Gogs 是一款极易搭建的自助 Git 服务,其目标是打造一个最简单.最快速和最轻松的方式搭建自助 Git 服务.使用 Go 语言开发使得 Gogs 能够通过独立的二进制分发,并且支持 Go 语 ...

  8. [js开源组件开发]js手机联动选择日期 开源git

    js手机联动选择日期 这里在前面的<js手机联动选择地区>的基础上,改造数据源之后形成的一个日期的选择器,当然你可以使用之前的PC上模式的<日期控件>,它同时也支持手机端,ht ...

  9. Git各大平台(win/Linux/Mac)图形化界面客户端大汇总

    摘要: 介绍各平台下的图形化界面git客户端(本人并没有全部使用过),欢迎大家补充新的软件或者使用感受~  一.TortoiseGit - The coolest Interface to Git V ...

随机推荐

  1. 006_mac osx 应用跨屏幕

    一般情况下 mac osx 中一个应用程序只能在一个屏幕上显示,作为从 windows 转过来的用户有点不太习惯,Goolge 后发现还是有解决方案的(虽然不是很好用). 打开 Mac 的系统偏好设置 ...

  2. ScheduledThreadExecutor定时任务线程池

    ScheduledThreadPoolExecutor 继承自ThreadPoolExecutor实现了ScheduledExecutorService接口.主要完成定时或者周期的执行线程任务. 代码 ...

  3. python抓取内涵段子文章

    # coding:utf-8 from urllib.request import urlretrieve import threading import requests from bs4 impo ...

  4. [原创]Python/Django使用富文本编辑器XHeditor上传本地图片

    前言 为了在Django框架下使用Xheditor上传图片,居然折腾了我一个晚上.期间也遇到种种问题,网上相关资料极少.现在把经验分享给大家. 正文 xheditor篇 1.下载http://xhed ...

  5. 几个比较实用的CSS

    1.filter:chroma(color:#FFFFFF);    让指定的背景色透明,例: <table cellspacing = "0" cellpadding = ...

  6. CMT跟踪算法学习笔记(一)

    关于这个算法,已经有网友写出笔记. 这位网友用画图的方式总结出了算法的各个流程,并总结了源码中的各个类:http://blog.csdn.net/roamer_nuptgczx/article/det ...

  7. #Plugin 中国省市选择插件

    中国省市选择插件  ChineseCities 1.原生JS,不依赖jquery,zepto 2.前端学习交流群:814798690 源码查看 点击下载 https://github.com/chao ...

  8. 【LOJ】#2183. 「SDOI2015」序列统计

    题解 这个乘积比较麻烦,转换成原根的指数乘法就相当于指数加和了,可以NTT优化 注意判掉0 代码 #include <bits/stdc++.h> #define fi first #de ...

  9. linux设置最大打开文件数

    一.查看当前用户对进程打开文件最大数的限制 $ ulimit -a | grep open 二.系统对进程打开文件最大数是如何限制的 先来看man的一段解析: /proc/sys/fs/file-ma ...

  10. Javassist学习总结

    今天在弄dubbo时出现了一个依赖缺少问题,就好奇研究一下,这个依赖是啥. javassist是一个字节码类库,可以用他来动态生成类,动态修改类等等 1.介绍Javassist 要想将编译时不存在的类 ...