{"id":19041033,"url":"https://github.com/everythingme/kickass-redis","last_synced_at":"2025-07-11T05:34:10.411Z","repository":{"id":3631786,"uuid":"4698299","full_name":"EverythingMe/kickass-redis","owner":"EverythingMe","description":"Loose python framework for kickass redis patterns","archived":false,"fork":false,"pushed_at":"2017-04-18T04:50:14.000Z","size":347,"stargazers_count":154,"open_issues_count":3,"forks_count":23,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-04-15T19:46:19.500Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EverythingMe.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-06-18T07:32:04.000Z","updated_at":"2024-02-06T10:25:35.000Z","dependencies_parsed_at":"2022-08-19T04:20:56.537Z","dependency_job_id":null,"html_url":"https://github.com/EverythingMe/kickass-redis","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EverythingMe%2Fkickass-redis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EverythingMe%2Fkickass-redis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EverythingMe%2Fkickass-redis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EverythingMe%2Fkickass-redis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EverythingMe","download_url":"https://codeload.github.com/EverythingMe/kickass-redis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252839678,"owners_count":21812148,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T22:26:36.420Z","updated_at":"2025-05-07T08:21:14.676Z","avatar_url":"https://github.com/EverythingMe.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Kickass-Redis - a loose framework of Redis based data solutions\n==================================================\n\nThis project aims to create a repository of useful python libraries built on top of redis (and using each other),\nto automate data modeling with Redis.\n\n##For discussion, help and contributing code - join the google group at https://groups.google.com/forum/#!forum/kickass-redis\n\nRedis is relatively low level, and while it is simple to start using, getting a good knowledge of how to model problems\nwith it in an efficient way can be tricky. So I've created this project to wrap common use cases, into a loose framework\nof redis based solutions for real world problems.\n\nThe project has started out as a bunch of code examples for a presentation I recently gave on [IL Tech Talks](http://www.iltechtalks.org.il/),  that can be found here: http://www.slideshare.net/dvirsky/kicking-ass-with-redis\n\n#Installation\n\nOption 1:\n\n1. Clone this repo or download the sources\n\n2. `cd kickass-redis`\n\n3. `python setup.py build`\n\n4. `sudo python setup.py install`\n\nOption 2:\n\n`sudo pip install kickass_redis`\n\n\n#Components\n----------\n\nTo kick things off, the framework includes the following components:\n\n## object_store\n\na fast yet simple ORM (well, OM actually) that automates creation, indexing and searching for complex objects using redis.\n\nIndexes include: simple string index, numeric index that supports sorting and ranges, simplistic full text index, and a unique key.\n\n###Example:\n\n```python\nfrom kickass_redis.patterns.object_store.objects import IndexedObject, KeySpec\nfrom kickass_redis.patterns.object_store.indexing import UnorderedKey, OrderedNumericalKey\nfrom kickass_redis.patterns.object_store.condition import Condition\n\nclass User(IndexedObject):\n\n\n    #which fields should be saved to redis\n    _spec = ('id', 'name', 'email', 'pwhash', 'registrationDate', 'score')\n\n    #The keys for this object\n    _keySpec = KeySpec(\n        UnorderedKey(prefix='users',fields=('name',)),\n        OrderedNumericalKey(prefix='users', field='score')\n    )\n\n    def __init__(self, **kwargs):\n        IndexedObject.__init__(self, **kwargs)\n        self.registrationDate = int(kwargs.get('registrationDate', time.time()))\n\n#Creating a user\nuser = User(email = 'user@domain.com', name = 'John Doe', pwhash = 'eabc626ec26bc6ae6cb2', score = 100)\nuser.save()\n\n#loading by name key\nusers =  User.get(Condition({'name': 'John Doe'}))\n\n#loading by id:\nusers = User.loadObjects((1,))\n\n#See example/users_example for a more detailed exmample and some benchmarks\n```\n\n\n\n\n\n\n## bitmap_counter\n\nefficient unique value counter (to be used mostly as a unique users counter) with time slots, making use of redis bitmaps.\n\nIt makes use of new redis-2.6 commands BITCOUNT and BITOP, so it will not function on redis-2.4.\n\n###Example:\n\n```python\nfrom kickass_redis.patterns.bitmap_counter import BitmapCounter\n\n#Daily unique users counter\ncounter = BitmapCounter('unique_users', timeResolutions=(BitmapCounter.RES_DAY,))\n\n#sampling current user\ncounter.add(3)\n\n#Getting the unique user count for today\ncounter.getCount((time.time(),), counter.RES_DAY)\n\n#Getting cohort analysis on your users for the past week\nweek = tuple((int(time.time() - i*86400) for i in  xrange(7, 0, -1)))\nprint counter.cohortAnalysis(week, counter.RES_DAY)\n\n#Getting funnel analysis on your users for the past week\nprint counter.funnelAnalysis(week, counter.RES_DAY)\n```\n\n###New:\nIt now also supports mapping of non sequential or non numeric ids to incemental ids, that makes it memory optimized.\n\n\n## LuaCall\n\nA convenience wrapper that allows you to edit, precache and call Lua scripts available in redis-2.6, as if they were native python functions.\n\n### Example:\n\nlet mult.lua contain the code:\n\n```lua\n\nlocal val = ARGV[1]*ARGV[2]\nredis.call('set', KEYS[1], val)\nreturn redis.call('get', KEYS[1])\n\n```\n\nRunning it from python:\n```python\nimport redis\nfrom kickass_redis.patterns.lua import LuaCall, LuaScriptError\nconn = redis.Redis()\n\n#Define the call, and make it runn on our connection\nmult = LuaCall(open('mult.lua'), conn)\n\n#Call it once:\nprint \"Result: %s\" % mult(keys = ('foor',), args = (3,10))\n\n#call it again\nprint \"Result: %s\" % mult(keys = ('foor2',), args = (5,20))\n\n```\n\n\n## idgenerator\n\n\nUsed in the object store, this can also be used standalone, as a centralized unique, incremental id generator using redis.\nTo optimize performance, it reserves in local memory many ids when accessing redis, which can be tuned.\n\n\n## redis_unit\n\nA unit-test like set of assertions about redis data to be used to validate the data inside a redis database.\n\n## requirements\n\n* redis-2.6 server(BITCOUNT/BITOP)\n* redis-py\n* [pyhash package](https://code.google.com/p/pyfasthash/)\n\n###Example:\n\n```python\n\nfrom kickass_redis.patterns.redis_unit import RedisDataTest\n\nclass MyTest(RedisDataTest):\n\n    def testSomeStuff(self):\n\n\n        self.assertPrefixCount('users:*', minAmount=100000)\n        self.assertKeysExists('users:1')\n        self.assertKeysType(self.test.T_HASH, 'users:1')\n        self.assertHashValue('users:1', 'name', self.equals('John'))\n\n\ntest = MyTest('localhost', 6379)\ntest.run()\n\n\n```\n\n\n---------------------------\n\n### To follow soon:\n\n   * geo search\n\n\n   * full text search\n\n\n   * hierarchical counters\n\n\n   * MySQL data sync\n\n\n   * Generic expiring object cache.\n\n\n# Feel free to contribute more recipes...\n\n#Project TODO:\n\n1. Add unit tests for all objects\n\n2. Add geo-key\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feverythingme%2Fkickass-redis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feverythingme%2Fkickass-redis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feverythingme%2Fkickass-redis/lists"}