Mnemosine is a key/value store written in Ruby. It was created for the CodeBrawl competition located here: http://codebrawl.com/contests/key-value-stores
You can run the Mnemosine server by running "./mnemosine" from the root directory. There is also a Ruby adapter you can use. The API covers a small amount of what Redis can do, plus a tiny bit it can't.
Mnemosine's API is fairly similar to the Redis API, with a few differences. Like Redis, Mnemosine gives you several data types. You can use different functions depending on the data type.
Key functions can be used on any value.
Deletes every key and value pair in the entire database.
Deletes the key and its associated value.
Lists all keys in the database.
Returns true if the key exists, false otherwise.
Returns a random key from the database.
Moves the value from one key to another, overwriting any data that be have been on the new key.
Like rename, but returns an error if the new key already exists.
Takes a block that is run on each key/value pair. Hopefully this can be expanded into a full map/reduce system at some point.
Takes a regular expression and returns any keys that match it.
These operations only work on strings or integers.
Sets the key to the given value.
Returns the value associated with the key.
Only works with strings. Appends v to the end of the value associated with k.
Only works with integers. Adds one to the integer value associated with k.
Only works with integers. Subtracts one from the integer value associated with k.
Only works with integers. Adds v to the integer value associated with k.
Only works with integers. Subtracts v from the integer value associated with k.
These functions only work with hashes.
Assigns v to the sub-key sk.
Like hset, but it will not overwrite an existing key.
Returns the value associated with the given key and sub-key.
Lists all keys in the hash.
Deletes the given sub-key from the hash, returning its value.
Checks to see if the given sub-key exists in the hash.
Returns the number of keys in the hash.
Returns the entire hash.
Increments the integer stored in sk.
Decrements the integer stored in sk.
Adds v to the integer stored in sk.
Subtracts v from the integer stored in sk.
Assigns v to the hash. Note that this overwrites everything. It would probably be preferable to merge it.
Seems to be exactly the same as hgetall. I think I intended for this to take an array of sub-keys and just return those.
This isn't very fleshed out yet. I intended to accomplish more with it, but my cat got very sick and the entire week has been spent dragging the poor guy to the emergency vet or various specialists. As such, there's not much here yet. I'd like to add some more functions, as well as length limited lists, which could be really cool for caching.
Sets a value at the index specified by sk.
Returns the value associated with sk.
Returns the values associated with the indexes between (and including) start and stop.
Inserts a value at replace, pushing any later keys further back. Redis is a little weird on this one, and I've emulated some of that weirdness. Redis wants you to specify whether you want to insert the value before or after the given key, which seems pointless. You're programmers, and you know how to add or subtract 1 from the index. However, Redis doesn't treat replace as an index, but as a value! That seems strange to me, and I'm not sure I like it. Still, that's how Redis does it, so I've made this function behave mostly the same.
Obviously Ruby is probably not a great choice for creating a database, as one typically wants very high performance. Instead, consider this to be a fun toy. It uses EventMachine on the server and passes JSON via persistent raw TCP connections. It also was also developed TDD style, so it could be good to look at if you're new to testing or Test::Unit.
I'll probably hack more features onto this as time permits. I'd like to get replication and sharding working, possibly a map/reduce system, and if I'm feeling really ambitious, perhaps some kind of indexed search.
There's currently no security on the database, and it only runs on localhost. As I said, this is just a fun little project, not a serious DB engine.
I'm putting this under the MIT license, so feel free to do whatever you want with it. My only request is that you don't use this as the basis for an entry into the upcoming CodeBrawl competition. While that would be hilarious, it would make me a sad panda.
Mnemosine offers a search system based on code execution. It's kind of like map reduce, but simpler and worse.
Mnemosine is only compatible with Ruby 1.9. You'll need to install the following gems to use Mnemosine:
- eventmachine
- json
- slop
- sourcify
Run the following command to install sourcify:
gem install ruby_parser file-tail sourcify