Take the 2-minute tour ×

Is it possible to get auto generated unique key using spymemcached API?

I would like to use something like this:

String key = memcachedClient.add("Some data");
//key - auto generated next unused key 

So, if it's impossible can I use some kind of sequences to get next unused key?

Regards, Evgeniy

share|improve this question

1 Answer 1

A unique key is given by an hash function (Wiki-hash function). An hash function for different inputs gives (very) different outputs. So if you want a method that gives you a unique key try to implements an hash function. try to look for MD5 SHA1... there are a lot of algorithm..

share|improve this answer
thanks for your answer, as I know, it is possible that hash from different text can be the same. It is the critical point in my application. I think, that this problem solution should be related to spymemcached. –  evgeniy44 Nov 7 '12 at 8:39
that depends on how much the algorithm used is immune to collisions. A collision, in few word, is the probability that an hash is repeated. for example MD5 is 128bit so 2^128 possible combination. But there are algorithm that use 256 bit or more... –  andrea.marangoni Nov 7 '12 at 9:42
It wouldn't be good solution for my application, anyway thanks... –  evgeniy44 Nov 7 '12 at 13:16

Your Answer


