• gm_redis - Redis Server Interface!
    17 replies, posted
[b]gm_redis - Redis Server Interface[/b] We commisioned it, and [url=https://github.com/danielga]MetaMan[/url] saved the day! This module provides full interactivity to your Redis server, it's pretty cut-and-dry. Ridiculously fast in-memory data store or key-value database (with some config), great for hugely fast cross-server interoperability vs SQL for things that don't require a schema, and doubles as a message broker so you can broadcast messages in a timely fashion to any number of connected servers. [b]Let's get some documentation:[/b] [lua] -- Current version redis.Version -- Current version number redis.VersionNum [/lua] [b]Client object, used for commands:[/b] [lua] -- Creates a redis_client object redis.CreateClient() -- returns object redis_client, string error -- Connects to the database redis_client:Connect(string ip, number port) -- returns bool success, string error -- Disconnects the database redis_client:Disconnect(string ip, number port) -- Sends a command & arguments and calls the callback on completion redis_client:Send(table command_args, function callback) -- returns bool success -- Commits your commands to the server (you must call this) redis_client:Commit() -- returns bool success, string error -- Polls the database (the module doesn't call this for you like mysql modules) redis_client:Poll() -- returns bool success -- Is the database connected? redis_client:IsConnected() -- returns bool connected -- Called when the databse is disconnected (handle reconnections here) redis_client:OnDisconnected() -- Example: local client = redis.CreateClient() client:Connect('localhost', 6379) client:Send({'SET', 'MyKey', 'MyValue'}) client:Send({'GET', 'MyKey'}, function(self, value) print(self, value) end) client:Commit() -- commit both commands, you can easily do thousands at a time if you wanted with little to no performance impact hook.Add('Think', client, function() redis_client:Poll() end) [/lua] [b]Subscriber object, used to listen for channel broadcasts:[/b] [lua] -- Creates a redis_subscriber object redis.CreateSubscriber() -- returns object redis_subscriber, string error -- Connects to the database redis_subscriber:Connect(string ip, number port) -- returns bool success, string error -- Disconnects the database redis_subscriber:Disconnect(string ip, number port) -- Subscribe to a channel redis_subscriber:Subscribe(string channel, function callback) -- returns bool success, string error -- Unsubscribe from a channel redis_subscriber:Unsubscribe(string channel, function callback) -- returns bool success, string error -- Subscribe to a channel redis_subscriber:PSubscribe(string channel, function callback) -- returns bool success, string error -- Unsubscribe from a channel redis_subscriber:PUnsubscribe(string channel, function callback) -- returns bool success, string error -- Commits your commands to the server (you must call this) redis_subscriber:Commit() -- bool success, string error -- Polls the database (the module doesn't call this for you like mysql modules) redis_subscriber:Poll() -- returns bool success -- Is the database connected? redis_subscriber:IsConnected() -- returns bool connected -- Called when the database is disconnected (handle reconnections here) redis_subscriber:OnDisconnected() -- Called when a message is received redis_subscriber:OnMessage(string channel, string message) -- Example: local subscriber = redis.CreateSubscriber() subscriber.OnMessage = function(self, channel, message) print(self, channel, message) end subscriber:Connect('localhost', 6379) subscriber:Subscribe('MyChannel') subscriber:Commit() hook.Add('Think', subscriber, function() redis_subscriber:Poll() end) client:Send({'PUBLISH', 'MyChannel', 'Hello world!'}) -- You use redis_client from above to publish to channels. redis_subscriber is just for listening client:Commit() [/lua] You should probably have some [url=https://redis.io/commands]basic understanding of Redis[/url] before trying to use the module. [b]Downloads:[/b] [b]Git:[/b] [url]https://github.com/SuperiorServers/gm_redis[/url] [b]Binaries:[/b] [url]https://github.com/SuperiorServers/gm_redis/releases[/url] [b]Example extension/wrapper #1:[/b] [url]https://github.com/SuperiorServers/gm_redis/blob/master/includes/modules/redis.lua[/url] [b]Example extension/wrapper #2:[/b] [url]https://github.com/SuperiorServers/dash/tree/master/lua/dash/libraries/server/redis[/url]
nice, thank you
First I've ever heard of redis but cool nonetheless.
Just out of curiosity, what uses do you have for Redis that MySQL or a regular relational DB cannot serve?
[QUOTE=Revenge282;51718021]Just out of curiosity, what uses do you have for Redis that MySQL or a regular relational DB cannot serve?[/QUOTE] I believe it's all about speed in this case
[QUOTE=Revenge282;51718021]Just out of curiosity, what uses do you have for Redis that MySQL or a regular relational DB cannot serve?[/QUOTE] It's extremely fast, simple to use, great for caching, has [URL="https://redis.io/clients"]libraries[/URL] for pretty much everything, and can replace some of the more common uses for sockets with its message system.
[QUOTE=code_gs;51718116]I believe it's all about speed in this case[/QUOTE] [QUOTE=StonedPenguin;51718203]It's extremely fast, simple to use, great for caching, has [URL="https://redis.io/clients"]libraries[/URL] for pretty much everything, and can replace some of the more common uses for sockets with its message system.[/QUOTE] So aside from messaging cases, why not use MySQL? It caches to memory, so the speeds vs Redis can't be all that different, plus it is reliable with it's data. Forgive me, I am not really familiar on NoSQL options.
In webdev Redis (and others like memcached) is used for things like caching dynamic data and sessions, along with queueing for offloading expensive tasks (another process would be listening for events to run them asynchronously) and messaging. For garrysmod, it's uses could be things like cross-server chat/sync, temporary storage of data, etc.
Nice, will be using this.
[QUOTE=Revenge282;51718218]So aside from messaging cases, why not use MySQL? It caches to memory, so the speeds vs Redis can't be all that different, plus it is reliable with it's data. Forgive me, I am not really familiar on NoSQL options.[/QUOTE] In addition to _Undefined's response, it's just a cleaner setup versus MySQL for data that's meant to be temporary. SQL solutions may [i]work[/i] but even as efficient or fast as MySQL gets, you'll still be interpreting queries and using a data structure that's meant for organized data. Redis is much more lightweight for that sort of use, strictly key-value, auto expiring keys. It's just a cheaper platform to centralize the less critical data that you'd like multiple servers to access.
Nice work, thanks. I've been looking for a longer version of a Redis module for GMod and now there is finally one.
What could cause this? [t]https://i.imgur.com/V7XPxaA.png[/t] I've put the module on two servers. Loads fine on the first, fails to load on the second. Even including it directly like on the image results in that output^. The servers use the same scripts more or less.
[QUOTE=ms333;52494155]more or less.[/QUOTE] What happens if the scripts in-use are identical? Also, are OS versions different, or do you just have two different srcds directories on the same machine?
[QUOTE=KingofBeast;52505298]What happens if the scripts in-use are identical? Also, are OS versions different, or do you just have two different srcds directories on the same machine?[/QUOTE] Same machine, different directories. I'll try to make the scripts on the two instances identical when possible, though there shouldn't be anything that could affect this. Other modules are loading fine.
:snip:
:snip:
Does it handle complex values like tables for example? Or should I serialize my data before sending to redis?
[QUOTE=pennerlord;52703719]Does it handle complex values like tables for example?[/QUOTE] No
Sorry, you need to Log In to post a reply to this thread.