Coder Social home page Coder Social logo

southclaws / pawn-redis Goto Github PK

View Code? Open in Web Editor NEW
39.0 7.0 9.0 470 KB

Redis client for the Pawn language

License: MIT License

C++ 75.78% C 14.27% Makefile 0.44% SourcePawn 1.75% Pawn 3.44% CMake 4.27% Dockerfile 0.05%
redis sa-mp sa-mp-development pawn-package

pawn-redis's Introduction

Redis for SA:MP

A powerful Redis plugin granting access to a fast in-memory database and asynchronous message channels between other programs.

It's open source and available here

What Redis Is

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries.

(from the Redis official site)

In SA:MP terms: Redis is can be the GVar plugin on steroids. It can be a place to store large amounts of information and free up heap space (and cut compile times!)

You can also use Redis to delegate slower tasks to other programs through the power of pubsub message queues!

What Redis Is Not

Redis is not a permanent database. It exists entirely in memory which makes it very fast to read from and write to but it is not a replacement for something like MySQL to store data for a very long period of time.

Installation

Simply install to your project:

sampctl package install Southclaws/pawn-redis

Include in your code and begin using the library:

#include <redis>

pawn-redis's People

Contributors

adrfranklin avatar agraber avatar gurkansahinn avatar southclaws avatar ymde avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pawn-redis's Issues

PubSub

Hello.

Does pub/sub works properly in this plugin? I've tried to use it and got no events. Push works perfectly, but subscribing doesn't.

Implement bind reconnect

If a message bind loses connection, it should reconnect. Currently there's no such thing as disconnecting a bind so they should stay connected indefinitely. Possibly with exponential-backoff just in case the redis server falls over.

Redis Command

Hi, I use Redis_Command also I call the LPUSH command. The problem is that each space on a result serves as new record whether there are correction options?
My code:

new Redis:client;

new Redis:client_exists;

Redis_Connect("localhost", 6379, "", Redis:client);

new message_test[35];

format(message_test, 35, "LPUSH logs-1 'Hello World!'");

Redis_Command(Redis:client_exists, message_test);

Result:
image

Write proper unit tests

I'll write actual unit tests for the desired API with y_testing.
Also I'll add pawnc compilation to makefile and do the compilation on linux.

Implement BLPOP/LPUSH system for queues

I've decided to abandon SUBSCRIBE since it didn't work and I can't be bothered to figure out why.

This is partly based on a post by David Marquis about a self-implemented message queue protocol using pop/push instructions: http://blog.radiant3.ca/2013/01/03/reliable-delivery-message-queues-with-redis/

This solution will be simpler than that and require a little bit more code than the original SUBSCRIBE method but at least it works.

  • Publishing/Sending
    Publishing will be done via LPUSH and the reply object will be pushed to OnRedisEvent.
  • Subscribing/Waiting
    Instead of SUBSCRIBE, a thread will BLPOP infinitely in order to await messages.

At least for v0.1.0 this will be fine. I might fully implement David's minimal queue system in C, Python and Golang just because the abstraction will simplify things greatly!

Mistake

native Redis_GetHInt(Redis::client, const key[], const field[]);

Here should be only one : (Redis:client). Please fix my mistake.

Implement get/set for the core 4 types

Get/Set for ints, floats and strings

  • Redis_SetString

  • Redis_GetString

  • Redis_SetInt

  • Redis_GetInt

  • Redis_SetFloat

  • Redis_GetFloat

  • arrays will probably come later, maybe as arrays of ints, arrays of floats and multidimensional arrays

Pawn runtime error handling

The following code works fine when the Redis server is up and running but crashes the SA:MP server when Redis is shut down. As I've seen, there is currently no api of handling runtime errors in pawn so instances like this can happen and cause random server crashes if something happens to Redis.

new got[128];
new ret = Redis_GetString(_CACHE_RedisHandler, "key", got, 128);
printf("Redis ret: %d", ret);
printf("Redis got: %s", got);

Stacktrace:

[debug] Server crashed while executing core.amx
[debug] AMX backtrace:
[debug] #0 native Redis_GetString () in redis.DLL
[debug] #1 00084ba0 in main (0, 145088512) in core.amx
[debug] Native backtrace:
[debug] #0 77d73602 in ?? () in C:\WINDOWS\SYSTEM32\ntdll.dll
[debug] #1 77d42946 in ?? () in C:\WINDOWS\SYSTEM32\ntdll.dll
[debug] #2 73717ad6 in ?? () in C:\WINDOWS\SYSTEM32\VCRUNTIME140.dll
[debug] #3 6976223a in ?? () in plugins\redis.DLL
[debug] #4 6975f00d in ?? () in plugins\redis.DLL
[debug] #5 6975ef37 in ?? () in plugins\redis.DLL
[debug] #6 6975432d in ?? () in plugins\redis.DLL
[debug] #7 69757849 in ?? () in plugins\redis.DLL
[debug] #8 004010b6 in ?? () in samp-server.exe
[debug] #9 6022dc92 in ?? () in plugins\crashdetect.DLL
[debug] #10 60235318 in ?? () in plugins\crashdetect.DLL
[debug] #11 602297cc in ?? () in plugins\crashdetect.DLL
[debug] #12 6022dcf4 in ?? () in plugins\crashdetect.DLL
[debug] #13 5ee23484 in ?? () in plugins\streamer.DLL
[debug] #14 6f044369 in ?? () in plugins\pawncmd.DLL
[debug] #15 6f043efe in ?? () in plugins\pawncmd.DLL
[debug] #16 00492a21 in ?? () in samp-server.exe
[debug] #17 00452120 in ?? () in samp-server.exe
[debug] #18 5ee291e1 in ?? () in plugins\streamer.DLL
[debug] Registers:
[debug] EAX: 0019e430 EBX: 00000000 ECX: 00000000 EDX: 00000000
[debug] ESI: 0019e4a0 EDI: 0019ff60 EBP: 0040174f ESP: 0019fc20
[debug] EIP: 5ee291e1 EFLAGS: 00000202
[debug] Stack:
[debug] ESP+00000000: 00000000 5ee73610 0019fc38 0019fc54
[debug] ESP+00000020: 0019022e 00000000 0019fda4 004aa57b
[debug] ESP+00000040: 00000032 0100007f 004cf8a7 022ea090
[debug] ESP+00000060: 022ea090 00000000 00000000 0019fcd4
[debug] ESP+00000080: 00000000 00000008 022e0ae8 00000008
[debug] ESP+000000a0: 0019fcf0 022e0ad8 75903b40 022ea090
[debug] ESP+000000c0: 60235700 02993300 00000000 0000000f
[debug] ESP+000000e0: 00000000 00000000 00000000 00000000
[debug] ESP+00000100: 60147960 0019fd58 60147969 69779930
[debug] ESP+00000120: 0019fd68 77d0fbe0 00000000 00000000
[debug] ESP+00000140: 601479e0 0019fd7c 601479e9 69779930
[debug] ESP+00000160: 0088e760 6975607d 77d404cc 77b37d59
[debug] ESP+00000180: 77d2b8d0 0019fddc 004aa81b ffffffff
[debug] ESP+000001a0: 022ea090 00000a35 00000001 546c6148
[debug] ESP+000001c0: 5eda811c ffffffff 0019fdfc 5eda343f
[debug] ESP+000001e0: 0049104c 75903b40 022ea090 0049125c
[debug] ESP+00000200: 00000000 000023f0 0019ff70 002c4000
[debug] ESP+00000220: 00000244 00004e88 022ea090 656d6167
[debug] ESP+00000240: 002c4000 004ab530 0019fe58 0019ff60
[debug] ESP+00000260: 0049b531 0049b541 004ab530 0019ff60
[debug] ESP+00000280: 022e1868 022e1888 00000094 00000006
[debug] ESP+000002a0: 00000000 00000000 00000000 00000000
[debug] ESP+000002c0: 00000000 00000000 00000000 00000000
[debug] ESP+000002e0: 00000000 00000000 00000000 00000000
[debug] ESP+00000300: 00000000 00000000 00000000 00000000
[debug] ESP+00000320: 0049cbca 002c4000 00000000 00000000
[debug] ESP+00000340: 0019ffcc 0049d298 004ba530 00000000
[debug] ESP+00000360: 0019ffdc 77d3662d 002c4000 e7f10c37
[debug] ESP+00000380: 00000000 00000000 00000000 00000000
[debug] ESP+000003a0: 00000000 0019ff8c 00000000 0019ffe4
[debug] ESP+000003c0: 77d365fd ffffffff 77d551e6 00000000
[debug] ESP+000003e0: 78746341 00000020 00000001 00003334
[debug] Loaded modules:
[debug] 00400000 - 00519000 samp-server.exe
[debug] 77cd0000 - 77e6c000 ntdll.dll
[debug] 758e0000 - 759c0000 KERNEL32.DLL
[debug] 77a20000 - 77c1a000 KERNELBASE.dll
[debug] 75ab0000 - 76003000 SHELL32.dll
[debug] 753f0000 - 754b0000 msvcrt.dll
[debug] 77790000 - 777cb000 cfgmgr32.dll
[debug] 76180000 - 762a2000 ucrtbase.dll
[debug] 76680000 - 76709000 shcore.dll
[debug] 759c0000 - 75a7f000 RPCRT4.dll
[debug] 75330000 - 75350000 SspiCli.dll
[debug] 75320000 - 7532a000 CRYPTBASE.dll
[debug] 763a0000 - 76402000 bcryptPrimitives.dll
[debug] 77800000 - 77879000 sechost.dll
[debug] 76d10000 - 76f87000 combase.dll
[debug] 76710000 - 76d0e000 windows.storage.dll
[debug] 75770000 - 757f0000 msvcp_win.dll
[debug] 773f0000 - 7746e000 advapi32.dll
[debug] 77470000 - 7748c000 profapi.dll
[debug] 77570000 - 775c4000 powrprof.dll
[debug] 77490000 - 774d4000 shlwapi.dll
[debug] 777d0000 - 777f3000 GDI32.dll
[debug] 76410000 - 76576000 gdi32full.dll
[debug] 775f0000 - 77789000 USER32.dll
[debug] 758a0000 - 758b7000 win32u.dll
[debug] 754b0000 - 754bf000 kernel.appcore.dll
[debug] 758c0000 - 758d2000 cryptsp.dll
[debug] 74b50000 - 74b74000 WINMM.dll
[debug] 736d0000 - 736d8000 WSOCK32.dll
[debug] 76110000 - 7616f000 WS2_32.dll
[debug] 74b20000 - 74b43000 WINMMBASE.dll
[debug] 774e0000 - 77505000 IMM32.DLL
[debug] 60210000 - 60261000 crashdetect.DLL
[debug] 601a0000 - 60209000 MSVCP100.dll
[debug] 5fc40000 - 5fcff000 MSVCR100.dll
[debug] 610b0000 - 610fe000 mysql.DLL
[debug] 60130000 - 6019f000 MSVCP140.dll
[debug] 73710000 - 73724000 VCRUNTIME140.dll
[debug] 732a0000 - 732ba000 log-core.dll
[debug] 5fb70000 - 5fc3d000 libmariadb.dll
[debug] 77880000 - 77a18000 CRYPT32.dll
[debug] 753e0000 - 753ee000 MSASN1.dll
[debug] 6f9d0000 - 6f9da000 Secur32.dll
[debug] 73620000 - 73631000 napinsp.dll
[debug] 73600000 - 73616000 pnrpnsp.dll
[debug] 74880000 - 748d2000 mswsock.dll
[debug] 748e0000 - 74970000 DNSAPI.dll
[debug] 76170000 - 76177000 NSI.dll
[debug] 75260000 - 75293000 IPHLPAPI.DLL
[debug] 735f0000 - 735fb000 winrnr.dll
[debug] 6f9e0000 - 6f9f6000 NLAapi.dll
[debug] 734f0000 - 73500000 wshbth.dll
[debug] 735e0000 - 735e8000 rasadhlp.dll
[debug] 5ee20000 - 5ee87000 streamer.DLL
[debug] 10000000 - 1000e000 sscanf.DLL
[debug] 5eda0000 - 5ee1d000 SKY.DLL
[debug] 02260000 - 0226d000 timer.DLL
[debug] 5ecb0000 - 5ed9e000 MSVCR120.dll
[debug] 5ec30000 - 5eca1000 MSVCP120.dll
[debug] 6f040000 - 6f079000 pawncmd.DLL
[debug] 5de30000 - 5dfd9000 json.DLL
[debug] 746b0000 - 746d4000 USERENV.dll
[debug] 69750000 - 6977d000 redis.DLL
[debug] 73580000 - 735d1000 fwpuclnt.dll
[debug] 75a90000 - 75aa9000 bcrypt.dll

Correct README file

Your here link is broken ๐Ÿ˜ƒ it's directing to ../Southclaws/samp-redis instead of ../Southclaws/pawn-redis.
Nothing important, but has to be corrected.
image

undefined symbol "Redis_BindMessage"

I've downloaded the last version of redis.inc and when trying to compile the script, it returns the error:
error 017: undefined symbol "Redis_BindMessage"

I've found a version of redis.inc that contains the following:

native Redis_BindMessage(Redis:context, channel[], callback[]);
native Redis_SendMessage(Redis:context, channel[], data[]);

But, when I try to compile, the compiler returns:
error 017: undefined symbol "gRedis"
Error line:
Redis_BindMessage(gRedis, "localhost.rediscord.incoming", "OnDiscordChat");

Redis + Requests

Hi, we use pawn-requests (v 0.6.2) and pawn-redis (v 1.0.4), but finally we face a problem which consists that we receive not that result which we expect.

Code (double '):

    new message_test[512];
    new stringfy[512];
	new Node:node = JsonObject(
	    "key", JsonString("value"),
	    "keynew", JsonString("My Value")
	);
	JsonStringify(node, stringfy);
    format(message_test, 512, "LPUSH logs-1 '%s'", stringfy);
    Redis_Command(Redis:client_exists, message_test);

Result:
image

Code (double "):

    new message_test[512];
    new stringfy[512];
	new Node:node = JsonObject(
	    "key", JsonString("value"),
	    "keynew", JsonString("My Value")
	);
	JsonStringify(node, stringfy);
    format(message_test, 512, "LPUSH logs-1 \"%s\"", stringfy);
    Redis_Command(Redis:client_exists, message_test);

Result:
image

Add support for AUTH

Possibly the cause for #11 as the un-authenticated client would not be able to perform an BLPOP and would result in an unexpected response. This case should be handled.

Redis_GetInt gets wrong value when a key/value has not been set or the key was deleted

	new valIntRedis;
	Redis_GetInt(servidor[redisControl], "test1", valIntRedis); // Redis_GetInt without set KEY VALUE
	printf("%d",valIntRedis); // prints wrong value (1703440), expected to print "zero"

	new valIntRedis2;
	Redis_SetInt(servidor[redisControl], "test1", 12345);
	Redis_GetInt(servidor[redisControl], "test1", valIntRedis2);
	printf("%d",valIntRedis2); // prints correct value (12345)

	Redis_Command(servidor[redisControl], "DEL test1"); // Delete key "test1"

	new valIntRedis3;
	Redis_GetInt(servidor[redisControl], "test1", valIntRedis3); // Redis_GetInt with deleted KEY
	printf("%d",valIntRedis3); // prints wrong value (49000184), expected to print "zero"

I have used version 1.1.2 of the plugin (latest version)

BindMessage returns `reply type was not array`

Redis await error on channel 'ss.account.response': reply type was not array

On:

Redis_BindMessage(gRedis, REDIS_DOMAIN_ROOT"."REDIS_DOMAIN_ACCOUNTS".response", "OnAccountResponse");

Not sure what this one is all about. But it needs a unit test case either way.

Channel name in the subscribe callback

On the pub/sub function for pawn-redis, the callback from subscribe only forwards 1 param to the callback function and that is the content of the message sent via publish. (here)
However, in the source: here it has the first param as the channel and the second as the message.

Is there any way of getting the channel that sent the broadcast inside the callback in pawn if its callback(msg) and not callback(channel, msg) ?

If not, would it make sense of implementing it because more channels could be returning to the same callback however all of the data would be handled the same because there currently is no way of knowing which channel triggered the callback?

Implement basic pub/sub with callbacks

Subscribe will bind to a Pawn callback. I'll probably copy code from Pawpy's thread system and fix it up a bit (it was deadlocking iirc).

Publish will just be a basic command call.

  • Redis_Subscribe(Redis:context, channel[], callback[]);
  • Redis_Publish(Redis:context, channel[], data[]);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.