How can I use a GUID or UUID for an object ID using Service Stack's Redis client?

I'm still going through Pluralsight tutorials on Service Stack and Redis and I'm getting worried. One of the requirements from my client is that the key of every object is a UUID (basically a Guid using ToString("N")). I'm worried because the only GetBy method I can see on the RedisClient uses an int. Not only would an int allow too few objects, it would also not accomplish the task of using an UUID.

有帮助吗?

解决方案

More than likely, the objects in your example inherit from IHasId<string>. The interface defines that you do have an Id field and its data type. This is what allows ServiceStack to find your objects by Id. This also explains why you are seeing them stuff the field by using ToString("N") on the Guid.

As for Redis, think of it as any other dictionary using a key/value pair. While there are recommended conventions out there for it, Redis should not care what the actual key is. As long as your application supplies the correct key to Redis, even if that key is a Guid, you will receive the object requested. ServiceStack will take care of the rest.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top