redis-extensions-base


Nameredis-extensions-base JSON
Version 4.1.6 PyPI version JSON
download
home_pagehttps://github.com/RedisClub/redis-extensions-py/tree/base+redis4.x
SummaryRedis-extensions-base is a base collection of custom extensions for Redis-py.
upload_time2023-01-29 15:59:48
maintainer
docs_urlNone
authorHackathon
requires_python
license
keywords redis extensions base
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # redis-extensions-base
Redis-extensions-base is a base collection of custom extensions for Redis-py.

## Installation
```
pip install redis-extensions-base
```

## Usage
```python
In [1]: import redis_extensions as redis

In [2]: r = redis.RedisExtensions(host='localhost', port=6379, db=0)

In [3]: r.zaddwithstamps('sorted_set', 1, 'a', 2, 'b')
Out[3]: 1

In [4]: r.zrange('sorted_set', 0, 100, withscores=True)
Out[4]: [('a', 11472205032192.0), ('b', 21472205032192.0)]

In [5]: r.zrange('sorted_set', 0, 100, withscores=True, score_cast_func=r.rawscore)
Out[5]: [('a', 1.0), ('b', 2.0)]

In [6]: r.zincrbywithstamps('sorted_set', 'a')
Out[6]: 0

In [7]: r.zrange('sorted_set', 0, 100, withscores=True)
Out[7]: [('b', 21472205032192.0), ('a', 21472205071514.0)]

In [8]: r.zrange('sorted_set', 0, 100, withscores=True, score_cast_func=r.rawscore)
Out[8]: [('b', 2.0), ('a', 2.0)]
```

## Expired
```python
In [1]: from redis_extensions import RedisExpires as exp

In [2]: exp.REDIS_EXPIRED
exp.REDIS_EXPIRED_HALF_HOUR  exp.REDIS_EXPIRED_ONE_HOUR   exp.REDIS_EXPIRED_ONE_WEEK
exp.REDIS_EXPIRED_ONE_DAY    exp.REDIS_EXPIRED_ONE_MONTH  exp.REDIS_EXPIRED_ONE_YEAR

In [2]: exp.REDIS_EXPIRED_ONE_HOUR
Out[2]: 3600

In [3]:

In [3]: import redis_extensions as redis

In [4]: r = redis.RedisExtensions(host='localhost', port=6379, db=0)

In [5]: r.REDIS_EXPIRED
r.REDIS_EXPIRED_HALF_HOUR  r.REDIS_EXPIRED_ONE_HOUR   r.REDIS_EXPIRED_ONE_WEEK
r.REDIS_EXPIRED_ONE_DAY    r.REDIS_EXPIRED_ONE_MONTH  r.REDIS_EXPIRED_ONE_YEAR

In [5]: r.REDIS_EXPIRED_ONE_HOUR
Out[5]: 3600
```

## Warnings
```python
In [1]: import redis_extensions as redis

In [2]: r = redis.RedisExtensions(host='localhost', port=6379, db=0)

In [3]: r.delete_keys('redis_extensions')
``r.keys()`` used, may be very very very slow when keys' amount very large
Out[3]: 0

In [4]: r.lock_exists('redis_extensions', regex=True)
``r.keys()`` used, may be very very very slow when keys' amount very large
Out[4]: []
```

## Solutions
* Lock
  ```python
  In [1]: import redis_extensions as redis

  In [2]: r = redis.RedisExtensions(host='localhost', port=6379, db=0)

  In [3]: r.acquire_lock('redis_extensions')
  Out[3]: '026ad2a7-2b58-435f-8ba2-467458a687f1'

  In [4]: r.acquire_lock('redis_extensions')
  Out[4]: False

  In [5]: r.release_lock('redis_extensions', '026ad2a7-2b58-435f-8ba2-467458a687f1')
  Out[5]: True

  In [6]: r.acquire_lock('redis_extensions', ex=10)
  Out[6]: '84f6b991-7c30-4210-947a-deb56bbc769a'

  In [7]: r.exists('redis:extensions:lock:redis_extensions')
  Out[7]: True

  In [8]: # 10 Seconds Later

  In [9]: r.exists('redis:extensions:lock:redis_extensions')
  Out[9]: False
  ```

* Quota
  ```python
  In [1]: import redis_extensions as redis

  In [2]: r = redis.RedisExtensions(host='localhost', port=6379, db=0)

  In [3]: r.quota('redis_extensions', amount=1, time=10)
  Out[3]: False

  In [4]: r.quota('redis_extensions', amount=1, time=10)
  Out[4]: True
  ```

* Quote/UnQuote
  ```python
  In [1]: import redis_extensions as redis

  In [2]: r = redis.RedisExtensions(host='localhost', port=6379, db=0)

  In [3]: r.quote('http://a.com')
  Out[3]: '6eb19fa3-9e26-457b-bb88-83ea5927ac29'

  In [4]: r.unquote('6eb19fa3-9e26-457b-bb88-83ea5927ac29')
  Out[4]: 'http://a.com'
  ```

* Token
  ```python
  In [1]: import redis_extensions as redis

  In [2]: r = redis.RedisExtensions(host='localhost', port=6379, db=0)

  In [3]: phone = '18888888888'

  In [4]: r.token(phone)
  Out[4]: '8bde88aa-71e9-4dea-846c-b1684a02b0f5'

  In [5]: r.token_exists(phone, '8bde88aa-71e9-4dea-846c-b1684a02b0f5')
  Out[5]: True

  In [6]: r.token_delete(phone)
  Out[6]: 1
  ```

* Signin
  ```python
  In [1]: import redis_extensions as redis

  In [2]: r = redis.RedisExtensions(host='localhost', port=6379, db=0)

  In [3]: r.signin_status('redis_extensions')
  Out[3]:
  {'delta_days': 10394,  # Signin Interval, Check Duplicate Signin
   'signed_today': False,  # Signed Today Or Not
   'signin_date': '1988-06-15',  # Last Signin Date
   'signin_days': 0,  # Continuous Signin Days
   'signin_longest_days': 0,  # Longest Continuous Signin Days In History
   'signin_total_days': 0}  # Total Signin Days

  In [4]: r.signin('redis_extensions')
  Out[4]:
  {'delta_days': 10394,
   'signed_today': True,
   'signin_date': '2016-11-29',
   'signin_days': 1,
   'signin_longest_days': 1,
   'signin_total_days': 1}

  In [5]: r.signin_status('redis_extensions')
  Out[5]:
  {'delta_days': 0,
   'signed_today': True,
   u'signin_date': u'2016-11-29',
   u'signin_days': 1,
   u'signin_longest_days': 1,
   u'signin_total_days': 1}

  In [6]: r.signin('redis_extensions')
  Out[6]:
  {'delta_days': 0,  # Duplicate Signin
   'signed_today': True,
   u'signin_date': u'2016-11-29',
   u'signin_days': 1,
   u'signin_longest_days': 1,
   u'signin_total_days': 1}
  ```

* Counter
  ```python
  In [1]: import redis_extensions as redis

  In [2]: r = redis.RedisExtensions(host='localhost', port=6379, db=0)

  In [3]: r.counter('a')
  Out[3]: (1, 0, 1)  # cur, pre, incr

  In [4]: r._counter_key('a')
  Out[4]: 'redis:extensions:counter:a:20170215'

  In [5]: r.ttl(_4)
  Out[5]: 86390L
  ```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/RedisClub/redis-extensions-py/tree/base+redis4.x",
    "name": "redis-extensions-base",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "Redis Extensions Base",
    "author": "Hackathon",
    "author_email": "kimi.huang@brightcells.com",
    "download_url": "https://files.pythonhosted.org/packages/57/30/054ed4545e874a31026ef6f4c71e92dab7f012c26c799c6f7e6c3ccf6740/redis-extensions-base-4.1.6.tar.gz",
    "platform": null,
    "description": "# redis-extensions-base\nRedis-extensions-base is a base collection of custom extensions for Redis-py.\n\n## Installation\n```\npip install redis-extensions-base\n```\n\n## Usage\n```python\nIn [1]: import redis_extensions as redis\n\nIn [2]: r = redis.RedisExtensions(host='localhost', port=6379, db=0)\n\nIn [3]: r.zaddwithstamps('sorted_set', 1, 'a', 2, 'b')\nOut[3]: 1\n\nIn [4]: r.zrange('sorted_set', 0, 100, withscores=True)\nOut[4]: [('a', 11472205032192.0), ('b', 21472205032192.0)]\n\nIn [5]: r.zrange('sorted_set', 0, 100, withscores=True, score_cast_func=r.rawscore)\nOut[5]: [('a', 1.0), ('b', 2.0)]\n\nIn [6]: r.zincrbywithstamps('sorted_set', 'a')\nOut[6]: 0\n\nIn [7]: r.zrange('sorted_set', 0, 100, withscores=True)\nOut[7]: [('b', 21472205032192.0), ('a', 21472205071514.0)]\n\nIn [8]: r.zrange('sorted_set', 0, 100, withscores=True, score_cast_func=r.rawscore)\nOut[8]: [('b', 2.0), ('a', 2.0)]\n```\n\n## Expired\n```python\nIn [1]: from redis_extensions import RedisExpires as exp\n\nIn [2]: exp.REDIS_EXPIRED\nexp.REDIS_EXPIRED_HALF_HOUR  exp.REDIS_EXPIRED_ONE_HOUR   exp.REDIS_EXPIRED_ONE_WEEK\nexp.REDIS_EXPIRED_ONE_DAY    exp.REDIS_EXPIRED_ONE_MONTH  exp.REDIS_EXPIRED_ONE_YEAR\n\nIn [2]: exp.REDIS_EXPIRED_ONE_HOUR\nOut[2]: 3600\n\nIn [3]:\n\nIn [3]: import redis_extensions as redis\n\nIn [4]: r = redis.RedisExtensions(host='localhost', port=6379, db=0)\n\nIn [5]: r.REDIS_EXPIRED\nr.REDIS_EXPIRED_HALF_HOUR  r.REDIS_EXPIRED_ONE_HOUR   r.REDIS_EXPIRED_ONE_WEEK\nr.REDIS_EXPIRED_ONE_DAY    r.REDIS_EXPIRED_ONE_MONTH  r.REDIS_EXPIRED_ONE_YEAR\n\nIn [5]: r.REDIS_EXPIRED_ONE_HOUR\nOut[5]: 3600\n```\n\n## Warnings\n```python\nIn [1]: import redis_extensions as redis\n\nIn [2]: r = redis.RedisExtensions(host='localhost', port=6379, db=0)\n\nIn [3]: r.delete_keys('redis_extensions')\n``r.keys()`` used, may be very very very slow when keys' amount very large\nOut[3]: 0\n\nIn [4]: r.lock_exists('redis_extensions', regex=True)\n``r.keys()`` used, may be very very very slow when keys' amount very large\nOut[4]: []\n```\n\n## Solutions\n* Lock\n  ```python\n  In [1]: import redis_extensions as redis\n\n  In [2]: r = redis.RedisExtensions(host='localhost', port=6379, db=0)\n\n  In [3]: r.acquire_lock('redis_extensions')\n  Out[3]: '026ad2a7-2b58-435f-8ba2-467458a687f1'\n\n  In [4]: r.acquire_lock('redis_extensions')\n  Out[4]: False\n\n  In [5]: r.release_lock('redis_extensions', '026ad2a7-2b58-435f-8ba2-467458a687f1')\n  Out[5]: True\n\n  In [6]: r.acquire_lock('redis_extensions', ex=10)\n  Out[6]: '84f6b991-7c30-4210-947a-deb56bbc769a'\n\n  In [7]: r.exists('redis:extensions:lock:redis_extensions')\n  Out[7]: True\n\n  In [8]: # 10 Seconds Later\n\n  In [9]: r.exists('redis:extensions:lock:redis_extensions')\n  Out[9]: False\n  ```\n\n* Quota\n  ```python\n  In [1]: import redis_extensions as redis\n\n  In [2]: r = redis.RedisExtensions(host='localhost', port=6379, db=0)\n\n  In [3]: r.quota('redis_extensions', amount=1, time=10)\n  Out[3]: False\n\n  In [4]: r.quota('redis_extensions', amount=1, time=10)\n  Out[4]: True\n  ```\n\n* Quote/UnQuote\n  ```python\n  In [1]: import redis_extensions as redis\n\n  In [2]: r = redis.RedisExtensions(host='localhost', port=6379, db=0)\n\n  In [3]: r.quote('http://a.com')\n  Out[3]: '6eb19fa3-9e26-457b-bb88-83ea5927ac29'\n\n  In [4]: r.unquote('6eb19fa3-9e26-457b-bb88-83ea5927ac29')\n  Out[4]: 'http://a.com'\n  ```\n\n* Token\n  ```python\n  In [1]: import redis_extensions as redis\n\n  In [2]: r = redis.RedisExtensions(host='localhost', port=6379, db=0)\n\n  In [3]: phone = '18888888888'\n\n  In [4]: r.token(phone)\n  Out[4]: '8bde88aa-71e9-4dea-846c-b1684a02b0f5'\n\n  In [5]: r.token_exists(phone, '8bde88aa-71e9-4dea-846c-b1684a02b0f5')\n  Out[5]: True\n\n  In [6]: r.token_delete(phone)\n  Out[6]: 1\n  ```\n\n* Signin\n  ```python\n  In [1]: import redis_extensions as redis\n\n  In [2]: r = redis.RedisExtensions(host='localhost', port=6379, db=0)\n\n  In [3]: r.signin_status('redis_extensions')\n  Out[3]:\n  {'delta_days': 10394,  # Signin Interval, Check Duplicate Signin\n   'signed_today': False,  # Signed Today Or Not\n   'signin_date': '1988-06-15',  # Last Signin Date\n   'signin_days': 0,  # Continuous Signin Days\n   'signin_longest_days': 0,  # Longest Continuous Signin Days In History\n   'signin_total_days': 0}  # Total Signin Days\n\n  In [4]: r.signin('redis_extensions')\n  Out[4]:\n  {'delta_days': 10394,\n   'signed_today': True,\n   'signin_date': '2016-11-29',\n   'signin_days': 1,\n   'signin_longest_days': 1,\n   'signin_total_days': 1}\n\n  In [5]: r.signin_status('redis_extensions')\n  Out[5]:\n  {'delta_days': 0,\n   'signed_today': True,\n   u'signin_date': u'2016-11-29',\n   u'signin_days': 1,\n   u'signin_longest_days': 1,\n   u'signin_total_days': 1}\n\n  In [6]: r.signin('redis_extensions')\n  Out[6]:\n  {'delta_days': 0,  # Duplicate Signin\n   'signed_today': True,\n   u'signin_date': u'2016-11-29',\n   u'signin_days': 1,\n   u'signin_longest_days': 1,\n   u'signin_total_days': 1}\n  ```\n\n* Counter\n  ```python\n  In [1]: import redis_extensions as redis\n\n  In [2]: r = redis.RedisExtensions(host='localhost', port=6379, db=0)\n\n  In [3]: r.counter('a')\n  Out[3]: (1, 0, 1)  # cur, pre, incr\n\n  In [4]: r._counter_key('a')\n  Out[4]: 'redis:extensions:counter:a:20170215'\n\n  In [5]: r.ttl(_4)\n  Out[5]: 86390L\n  ```\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Redis-extensions-base is a base collection of custom extensions for Redis-py.",
    "version": "4.1.6",
    "split_keywords": [
        "redis",
        "extensions",
        "base"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "aa94b082e034f67db34153f3228a4fdb113a49df8c3684660f4715faa59e3326",
                "md5": "bd8cfad58fb40dc8591215fd1466dadf",
                "sha256": "28f9824e37bb007ff7b4e4d56f5312fe8f54cf55f083d4a43994fa79c8126c41"
            },
            "downloads": -1,
            "filename": "redis_extensions_base-4.1.6-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bd8cfad58fb40dc8591215fd1466dadf",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 14210,
            "upload_time": "2023-01-29T15:59:46",
            "upload_time_iso_8601": "2023-01-29T15:59:46.623291Z",
            "url": "https://files.pythonhosted.org/packages/aa/94/b082e034f67db34153f3228a4fdb113a49df8c3684660f4715faa59e3326/redis_extensions_base-4.1.6-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5730054ed4545e874a31026ef6f4c71e92dab7f012c26c799c6f7e6c3ccf6740",
                "md5": "d44444c67913b0e75ae831c03f0fb440",
                "sha256": "0ba86ef181a5ace8e73f6cc6c01a3d4f3e13ac12a36d820f944c74d2f48d9acf"
            },
            "downloads": -1,
            "filename": "redis-extensions-base-4.1.6.tar.gz",
            "has_sig": false,
            "md5_digest": "d44444c67913b0e75ae831c03f0fb440",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 15584,
            "upload_time": "2023-01-29T15:59:48",
            "upload_time_iso_8601": "2023-01-29T15:59:48.654711Z",
            "url": "https://files.pythonhosted.org/packages/57/30/054ed4545e874a31026ef6f4c71e92dab7f012c26c799c6f7e6c3ccf6740/redis-extensions-base-4.1.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-29 15:59:48",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "redis-extensions-base"
}
        
Elapsed time: 0.10186s