This section provides an overview of what Redis is, and why a developer might want to use it.
It should also mention any large subjects within Redis, and link out to the related topics. Since the documentation for Redis is new, you may need to create initial versions of those related topics.
For valid characters in Redis keys, the manual explains this completely:
Redis keys are binary safe, this means that you can use any binary sequence as a key, from a string like "foo" to the content of a JPEG file. The empty string is also a valid key.
A few other rules about keys:
Very long keys are not a good idea, for instance a key of 1024 bytes is a bad idea not only memory-wise, but also because the lookup of the key in the dataset may require several costly key-comparisons. Even when the task at hand is to match the existence of a large value, to resort to hashing it (for example with SHA1) is a better idea, especially from the point of view of memory and bandwidth.
Very short keys are often not a good idea. There is little point in writing "u1000flw" as a key if you can instead write "user:1000:followers". The latter is more readable and the added space is minor compared to the space used by the key object itself and the value object. While short keys will obviously consume a bit less memory, your job is to find the right balance.
Try to stick with a schema. For instance "object-type:id" is a good idea, as in "user:1000". Dots or dashes are often used for multi-word fields, as in "comment:1234:reply.to" or "comment:1234:reply-to".
The maximum allowed key size is 512 MB.
Be careful with using the KEYS command against a production system, it can cause serious performance problems. If you need to do a search against the keyspace the SCAN commands are a better alternative.
To handle the pub/sub in redis, need to have one client for subscribe & different client for publish. Both can't be handled by same client. Though all other commands can be still handled with same client.
To connect on redis with python you need to install a client. You can install with pip using:
pip install redis
this will install redis-py
Optionally, you may want to install hiredis-py which delegates parsing of protocol messages to the C hiredis client. This can provide significant performance improvement in many situations. You can install hiredis with pip by executing:
pip install hiredis
More detail on the List datatype and all the commands that can be used in conjunction with them can be found in the official Redis documentation at Redis.io.
The full documentation on the Redis set datatype can be found at Redis.io.
The official documentation for Sorted Sets can be found at the Redis.io site.
Sorted sets are sometimes referred to as zsets. If you use the TYPE command on a sorted set key, the value zset will be returned.
Further information: