Method keys_match() returns different keys types for Redis and memory
See original GitHub issueMethod keys_match()
returns keys in bytes
type for Redis cache and in str
type for memory cache. Is it a bug or feature?
Code example:
# setup two caches - for redis & memory
cache.setup(f'redis://{host}:{port}', password=pwd, prefix='test_redis')
cache.setup('mem://', prefix='test_mem')
# set values for memory and redis
await cache.set('test_redis:abc', 123)
await cache.set('test_mem:abc', 321)
# keys_match result
async def foo(mask):
async for key in cache.keys_match(mask):
print(key, type(key))
await foo('test_redis:*')
# b'test_redis:abc' <class 'bytes'>
await foo('test_mem:*')
# test_mem:abc <class 'str'>
Issue Analytics
- State:
- Created a year ago
- Comments:16 (6 by maintainers)
Top Results From Across the Web
Redis data types tutorial
Learning the basic Redis data types and how to use them. ... The ability to set or retrieve the value of multiple keys...
Read more >Find and Delete multiple keys matching by a pattern in Redis
Use scanstream to find and pipeline to delete keys matching pattern.Find and Delete multiple keys matching by a pattern in Redis in a...
Read more >Redis — An Introduction - Runtime Revolution
Redis is an in-memory key-value data store that you can integrate with your application to store volatile data. It's volatile because once ...
Read more >Redis Clustering Best Practices with Multiple Keys
Redis quickly stretched this concept with data types, where a single key could refer to multiple (even millions of) pieces of data.
Read more >How to obtain size in bytes for set of keys in Redis?
Is there a functionality similar to like sizeof(keysmatch:*)? NO. AFAIK, you have to use MEMORY USAGE . Is there a functionality that ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
That is why everybody must pin their requirements. And have a full tests coverage, of course. We can add a
DeprecationWarning
for the method, and update it on the next major release. Win-win, all will be happy. As a temporary workaround, another method may be added.@Krukov Do you mean creating a method with a new name? Will this method do the same as
keys_match
for the “Memory” and “Disk” backends, but return strings for the “Redis” backend? Simplified pseudo-code:The “Memory” cache is a dictionary with strings as keys. The input key is a string, and it is stored as a string and returned as a string. It is never converted or stored as bytes. What you are describing is expected behavior.
Maybe adding type hinting for the whole package code will simplify the package usage. It may be more clear right away what type to expect before running the code.
Any better ideas or proposals are welcome.