question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Documentation on using Redis Brain

See original GitHub issue

Is there some more detailed documentation on using the Hubot redis brain effectively, or good practices for it?

For example, the scripting docs (https://github.com/github/hubot/blob/f672bc03cf4bf415ce45ed60c38334d988fae8f4/docs/scripting.md) simply talk about storing and retrieving key-value strings.

However, if you look at scripts like this:

https://github.com/hubot-scripts/hubot-team/blob/4a811e2f1881e85848c5801f5ff8b665f09390fa/src/models/team.coffee

They use more slightly more complex structures (arrays, dicts etc.) - I assume these just get stringified, then stored in redis:

    teams = []
    for key, teamData of @store()
      continue if key is @defaultName()
      teams.push new Team(teamData.name, teamData.members)
    teams

They also seem to namespace things as follows (which I’d hadn’t realised you could do until I saw this):

    @robot.brain.data.teams or= {}

It’d be nice if there were more examples of the redis-brain in action, or even just pointers to good example scripts where we can see good practices for these things?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5

github_iconTop GitHub Comments

9reactions
michaelanselcommented, Jun 2, 2015

Given the way that persistence works, you can actually just maintain a pointer to an object in the brain, manipulate it all you want, and it will be persisted every saveInterval. So, in code:

myList = []
robot.brain.set('my-list', myList)
myList.append(1)
# robot.brain.get('my-list') == [1]
0reactions
victorhooicommented, May 31, 2015

Hmm, but if you use get/set, how do you store more complex data structures?

For example, say you have an array:

{ 'tickets': [ { 'id': 'C-41', 'title': 'foo is broken', 'due_date': Date.now() }, { 'id': 'G-41', 'title': 'bar is working', 'due_date': Date.now() } ] }

Or something like this:

> v = { 'tickets': { 'C-41':  { 'title': 'foo is broken', 'due_date': Date.now()} , 'G-42': { 'title': 'bar is working', 'due_date': Date.now()}} }
{ tickets:
   { 'C-41': { title: 'foo is broken', due_date: 1433037416251 },
     'G-42': { title: 'bar is working', due_date: 1433037416251 } } }

(These are somewhat contrived examples, I know).

How should you push/pop individual items to this, assuming it’s been set in the redis brain?

Do you pull the whole thing out into a variable, edit it, then set the whole thing back? Or is there a better way, using get/set?

Read more comments on GitHub >

github_iconTop Results From Across the Web

hubot-redis-brain: Documentation | Openbase
hubot-redis-brain. A hubot script to persist hubot's brain using redis. See src/redis-brain.coffee for full documentation.
Read more >
Redis cluster specification
Welcome to the Redis Cluster Specification. Here you'll find information about the algorithms and design rationales of Redis Cluster. This document is a...
Read more >
hubot-redis-brain-docker - npm package | Snyk
A hubot script to persist hubot's brain using redis in docker For more information about how to use ... See src/redis-brain.coffee for full...
Read more >
jubot.brain documentation
Get data from system brain. Before using this function, jubot.system should be started. Params k - Data key. Return Stored data.
Read more >
hubot - Replacing local redis server with a ... - Stack Overflow
'use strict' // Description: // Persist hubot's brain to redis ... else { robot.logger.info('hubot-redis-brain: Using default redis on ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found