{"id":16200241,"url":"https://github.com/mobarski/st_redis_connection","last_synced_at":"2026-05-09T02:33:33.372Z","repository":{"id":184548796,"uuid":"672086562","full_name":"mobarski/st_redis_connection","owner":"mobarski","description":"Connect to Redis and other compatible databases (KeyDB, DragonflyDB, LedisDB, SSDB, ARDB) from your Streamlit app.","archived":false,"fork":false,"pushed_at":"2023-08-01T22:57:44.000Z","size":846,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-07T17:50:05.331Z","etag":null,"topics":["ardb","dragonflydb","keydb","ledisdb","python","redis","ssdb","streamlit"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mobarski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-28T22:23:48.000Z","updated_at":"2024-11-23T19:07:38.000Z","dependencies_parsed_at":"2024-11-03T09:41:03.615Z","dependency_job_id":"f0b1209c-8d1c-4003-9dc4-9bf4a377053c","html_url":"https://github.com/mobarski/st_redis_connection","commit_stats":null,"previous_names":["mobarski/st_redis_connection"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mobarski/st_redis_connection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mobarski%2Fst_redis_connection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mobarski%2Fst_redis_connection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mobarski%2Fst_redis_connection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mobarski%2Fst_redis_connection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mobarski","download_url":"https://codeload.github.com/mobarski/st_redis_connection/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mobarski%2Fst_redis_connection/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274152760,"owners_count":25231293,"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","status":"online","status_checked_at":"2025-09-08T02:00:09.813Z","response_time":121,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["ardb","dragonflydb","keydb","ledisdb","python","redis","ssdb","streamlit"],"created_at":"2024-10-10T09:29:39.198Z","updated_at":"2026-05-09T02:33:28.338Z","avatar_url":"https://github.com/mobarski.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Streamlit RedisConnection\n\nConnect to [Redis](https://redis.io/) and other compatible databases ([KeyDB](https://docs.keydb.dev/), [DragonflyDB](https://www.dragonflydb.io/), [LedisDB](https://ledisdb.io/), [SSDB](https://github.com/ideawu/ssdb), [ARDB](https://github.com/yinqiwen/ardb)) from your [Streamlit](https://streamlit.io/) app.\n\n\n\n## Installation\n\n`pip install git+https://github.com/mobarski/st_redis_connection`\n\n\n\n## Quick demonstration\n\n```python\nimport streamlit as st\nfrom st_redis_connection import RedisConnection\n\nredis = st.experimental_connection(\"my_redis\", type=RedisConnection)\ndb = redis.client()\ncnt = db.incr('my-counter')\nst.metric('Views', cnt)\n```\n\n\n\n## Main methods\n\n\n\n#### client()\n\n`connection.client() -\u003e redis.Redis | redis.Sentinel | redis.RedisCluster`\n\nGet Redis client object that will be used to issue commands to the server.\n\nMore info about it's methods [here](https://redis.readthedocs.io/en/latest/commands.html).\n\n\n\n#### lock()\n\n`connection.lock(name, timeout=None, sleep=0.1, blocking=True, blocking_timeout=None, thread_local=True) -\u003e redis.lock.Lock`\n\nA shared, distributed Lock using Redis.\n\nMore info [here](https://redis.readthedocs.io/en/latest/lock.html).\n\n\n\n## Configuration\n\nThe connection configuration can be:\n\n- passed via connection kwargs\n- passed through environmental variables\n- stored in Streamlit's [secrets.toml](https://docs.streamlit.io/library/advanced-features/secrets-management) file (~/.streamlit/secrets.toml on Linux)\n\nYou can find more information about managing connections in [this section](https://docs.streamlit.io/library/advanced-features/connecting-to-data#global-secrets-managing-multiple-apps-and-multiple-data-stores) of Streamlit documentation **and some examples below**.\n\nMost important parameters:\n\n- `host` - server host (default: 'localhost')\n- `port` - server port (default: 6379)\n- `username` - user name (default: default)\n- `password` - user password\n- `db` - numeric id of the database (default: 0)\n- `from_url` - configuration passed via URL. More info [here](https://redis.readthedocs.io/en/latest/connections.html#redis.Redis.from_url)\n- `mode` - Redis client type used in the connection:\n  - `redis` (default) - redis.Redis\n  - `sentinel` - redis.Sentinel\n  - `cluster` - redis.RedisCluster\n\nYou can read more about connecting to Redis [here](https://redis.readthedocs.io/en/latest/connections.html).\n\n\n\n## Usage examples\n\n\n\n##### simple_app.py\n\n```python\nimport streamlit as st\nfrom st_redis_connection import RedisConnection\n\nredis = st.experimental_connection(\"my_redis\", type=RedisConnection)\ndb = redis.client()\n\ncnt = db.incr('my-counter')\nst.metric('Views', cnt)\n```\n\n\n\n##### lua_scripting_app.py\n\n```python\nimport streamlit as st\nfrom st_redis_connection import RedisConnection\nfrom random import randint\n\nredis = st.experimental_connection(\"redis_dev\", type=RedisConnection)\ndb = redis.client()\n\n# Lua Scripting example - atomic CTR calculation\n# REF: https://redis.readthedocs.io/en/latest/lua_scripting.html\nrecalc_ctr = db.register_script(\"\"\"\nlocal clicks = redis.call('INCRBY', KEYS[1], ARGV[1])\nlocal views  = redis.call('INCRBY', KEYS[2], ARGV[2])\nlocal ctr = 1000 * clicks / views\nredis.call('SET', KEYS[3], ctr)\nreturn ctr\n\"\"\")\n\nnew_clicks = randint(0,5)\nnew_views  = 5\nctr = recalc_ctr(keys=['x:clicks','x:views','x:ctr'], args=[new_clicks, new_views])\n\nst.metric('CTR', ctr/1000)\n```\n\n\n\n##### pipeline_app.py\n\n```python\nimport streamlit as st\nfrom st_redis_connection import RedisConnection\nfrom random import randint\n\nredis = st.experimental_connection(\"redis_dev\", type=RedisConnection)\ndb = redis.client()\n\nnew_clicks = randint(0,5)\nnew_views  = 5\n\npipe = db.pipeline()\npipe.incrby('x:clicks', new_clicks)\npipe.incrby('x:views',  new_views)\nclicks,views = pipe.execute()\n\nctr = clicks / views\nst.metric('CTR', ctr)\n```\n\n\n\n##### demo_app.py\n\nYou can find live demo of this app [here](https://redis-connection-demo.streamlit.app/)\n\n```python\n# NOTE: for simplicity, this is far from being a good example of *how* to use Redis.\n\nimport streamlit as st\nfrom st_redis_connection import RedisConnection\n\nN_CLICKS = 100 # number of clicks to enable the reset button\n\nredis = st.experimental_connection(\"redis\", type=RedisConnection)\ndb = redis.client()\n\nclicks1 = int(db.get('clicks1') or 0)\nclicks2 = int(db.get('clicks2') or 0)\nviews   = int(db.get('views')   or 1)\n\nst.markdown('# Redis connection demo')\nc1,c2,c3 = st.columns(3)\n\nb1 = c1.button('Click me.')\nb2 = c2.button('No! Click me!')\nb3 = c3.button('Reset stats',\n               disabled = clicks1 + clicks2 \u003c N_CLICKS,\n               help = f'Reset all stats to zero. Enbled after {N_CLICKS} clicks.')\n\nif b1: db.incr('clicks1')\nif b2: db.incr('clicks2')\nif b3:\n    db.set('clicks1', 0)\n    db.set('clicks2', 0)\n    db.set('views',   1)\n\nif b1 or b2 or b3:\n    st.experimental_rerun()\nelse:\n    db.incr('views')\n\nc1.metric('button 1 clicks', clicks1)\nc2.metric('button 2 clicks', clicks2)\nc3.metric('total views', views)\n```\n\n\n\n## Configuration examples\n\n\n\n##### connection kwargs\n\n```python\nREDIS_URL = \"rediss://default:this-is-my-password@my-redis-host:25061\"\nredis = st.experimental_connection('', type=RedisConnection, from_url=REDIS_URL)\n```\n\n```python\nredis = st.experimental_connection('', type=RedisConnection, host='my-host', port=1234, password='my-password', db=2)\n```\n\n\n\n##### secrets.toml\n\n```toml\n[connections.my_redis]\nfrom_url = \"rediss://default:this-is-my-password@my-redis-host:25061/1\"\n\n[connections.redis2_db3]\nhost = \"my-redis-host2\"\nport = 6379\npassword = \"password-for-this-instance\"\ndb = 3\n\n[connections.redis3_sen]\nmode = \"sentinel\"\nsentinels = [[\"localhost\", 26379]]\npassword = \"another-password\"\n\n[connections.redis_cluster]\nmode = \"cluster\"\n```\n\n\n\n##### environmental variables\n\n```bash\nmy_redis_from_url = \"rediss://default:this-is-my-password@my-redis-host:25061/1\"\n\nredis2_db3_host = \"my-redis-host2\"\nredis2_db3_port = 25061\nredis2_db3_password = \"password-for-this-instance\"\nredis2_db3_db = 3\n\n# NOTE: currently Redis sentinels cannot be configured via env. variables\n# NOTE: currently Redis clusters  cannot be configured via env. variables\n```\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmobarski%2Fst_redis_connection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmobarski%2Fst_redis_connection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmobarski%2Fst_redis_connection/lists"}